-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(operator): implement KeptnAppCreationRequest controller (#1191)
Signed-off-by: Florian Bacher <[email protected]>
- Loading branch information
Showing
16 changed files
with
801 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
operator/apis/lifecycle/v1alpha3/keptnappcreationrequest_types_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package v1alpha3 | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/keptn/lifecycle-toolkit/operator/apis/lifecycle/v1alpha3/common" | ||
v1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func TestKeptnAppCreationRequest_IsSingleService(t *testing.T) { | ||
type fields struct { | ||
ObjectMeta v1.ObjectMeta | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
want bool | ||
}{ | ||
{ | ||
name: "single-service application", | ||
fields: fields{ObjectMeta: v1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
common.AppTypeAnnotation: string(common.AppTypeSingleService), | ||
}, | ||
}}, | ||
want: true, | ||
}, | ||
{ | ||
name: "multi-service application", | ||
fields: fields{ObjectMeta: v1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
common.AppTypeAnnotation: string(common.AppTypeMultiService), | ||
}, | ||
}}, | ||
want: false, | ||
}, | ||
{ | ||
name: "anything else", | ||
fields: fields{ObjectMeta: v1.ObjectMeta{ | ||
Annotations: map[string]string{ | ||
common.AppTypeAnnotation: "", | ||
}, | ||
}}, | ||
want: false, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
kacr := &KeptnAppCreationRequest{ | ||
ObjectMeta: tt.fields.ObjectMeta, | ||
} | ||
if got := kacr.IsSingleService(); got != tt.want { | ||
t.Errorf("IsSingleService() = %v, want %v", got, tt.want) | ||
} | ||
}) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package config | ||
|
||
import ( | ||
"sync" | ||
"time" | ||
) | ||
|
||
const defaultKeptnAppCreationRequestTimeout = 30 * time.Second | ||
|
||
//go:generate moq -pkg fake -skip-ensure -out ./fake/config_mock.go . IConfig:MockConfig | ||
type IConfig interface { | ||
SetCreationRequestTimeout(value time.Duration) | ||
GetCreationRequestTimeout() time.Duration | ||
} | ||
|
||
type ControllerConfig struct { | ||
keptnAppCreationRequestTimeout time.Duration | ||
} | ||
|
||
var instance *ControllerConfig | ||
var once = sync.Once{} | ||
|
||
func Instance() *ControllerConfig { | ||
once.Do(func() { | ||
instance = &ControllerConfig{keptnAppCreationRequestTimeout: defaultKeptnAppCreationRequestTimeout} | ||
}) | ||
return instance | ||
} | ||
|
||
func (o *ControllerConfig) SetCreationRequestTimeout(value time.Duration) { | ||
o.keptnAppCreationRequestTimeout = value | ||
} | ||
|
||
func (o *ControllerConfig) GetCreationRequestTimeout() time.Duration { | ||
return o.keptnAppCreationRequestTimeout | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package config | ||
|
||
import ( | ||
"testing" | ||
"time" | ||
|
||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
func TestConfig_GetDefaultCreationRequestTimeout(t *testing.T) { | ||
i := Instance() | ||
|
||
timeout := i.GetCreationRequestTimeout() | ||
|
||
require.Equal(t, defaultKeptnAppCreationRequestTimeout, timeout) | ||
} | ||
|
||
func TestConfig_SetDefaultCreationRequestTimeout(t *testing.T) { | ||
i := Instance() | ||
|
||
i.SetCreationRequestTimeout(5 * time.Second) | ||
|
||
timeout := i.GetCreationRequestTimeout() | ||
require.Equal(t, 5*time.Second, timeout) | ||
} | ||
|
||
func TestGetOptionsInstance(t *testing.T) { | ||
o := Instance() | ||
require.NotNil(t, o) | ||
|
||
o.SetCreationRequestTimeout(5 * time.Second) | ||
|
||
// verify that all sets/gets operator on the same instance | ||
o2 := Instance() | ||
|
||
timeout := o2.GetCreationRequestTimeout() | ||
require.Equal(t, 5*time.Second, timeout) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.