Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(lifecycle-operator): adapt KeptnConfig reconciler to set up observabilityTimeout parameter #3154

Merged
merged 2 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions lifecycle-operator/controllers/common/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package config
import (
"sync"
"time"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

const defaultKeptnAppCreationRequestTimeout = 30 * time.Second
Expand All @@ -17,13 +19,16 @@ type IConfig interface {
GetDefaultNamespace() string
SetBlockDeployment(value bool)
GetBlockDeployment() bool
SetObservabilityTimeout(timeout metav1.Duration)
GetObservabilityTimeout() metav1.Duration
}

type ControllerConfig struct {
keptnAppCreationRequestTimeout time.Duration
cloudEventsEndpoint string
defaultNamespace string
blockDeployment bool
observabilityTimeout metav1.Duration
}

var instance *ControllerConfig
Expand All @@ -34,6 +39,9 @@ func Instance() *ControllerConfig {
instance = &ControllerConfig{
keptnAppCreationRequestTimeout: defaultKeptnAppCreationRequestTimeout,
blockDeployment: true,
observabilityTimeout: metav1.Duration{
Duration: time.Duration(5 * time.Minute),
},
}
})
return instance
Expand Down Expand Up @@ -70,3 +78,11 @@ func (o *ControllerConfig) SetBlockDeployment(value bool) {
func (o *ControllerConfig) GetBlockDeployment() bool {
return o.blockDeployment
}

func (o *ControllerConfig) SetObservabilityTimeout(timeout metav1.Duration) {
o.observabilityTimeout = timeout
}

func (o *ControllerConfig) GetObservabilityTimeout() metav1.Duration {
return o.observabilityTimeout
}
17 changes: 17 additions & 0 deletions lifecycle-operator/controllers/common/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"time"

"github.com/stretchr/testify/require"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

func TestConfig_GetDefaultCreationRequestTimeout(t *testing.T) {
Expand Down Expand Up @@ -64,3 +65,19 @@ func TestConfig_SetAndGetBlockDeployment(t *testing.T) {
i.SetBlockDeployment(false)
require.False(t, i.GetBlockDeployment())
}

func TestConfig_SetAndGetObservabilityTimeout(t *testing.T) {
i := Instance()

require.Equal(t, metav1.Duration{
Duration: time.Duration(5 * time.Minute),
}, i.GetObservabilityTimeout())

i.SetObservabilityTimeout(metav1.Duration{
Duration: time.Duration(10 * time.Minute),
})

require.Equal(t, metav1.Duration{
Duration: time.Duration(10 * time.Minute),
}, i.GetObservabilityTimeout())
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ func (r *KeptnConfigReconciler) Reconcile(ctx context.Context, req ctrl.Request)
r.config.SetCreationRequestTimeout(time.Duration(cfg.Spec.KeptnAppCreationRequestTimeoutSeconds) * time.Second)
r.config.SetCloudEventsEndpoint(cfg.Spec.CloudEventsEndpoint)
r.config.SetBlockDeployment(cfg.Spec.BlockDeployment)
r.config.SetObservabilityTimeout(cfg.Spec.ObservabilityTimeout)
result, err := r.reconcileOtelCollectorUrl(cfg)
if err != nil {
return result, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
wantCloudEventsEndpointConfig string
wantBlockDeployment bool
blockDeploymentCalls int
wantObservabilityTimeout metav1.Duration
observabilityTimeoutCalls int
}{
{
name: "test 1",
Expand All @@ -61,13 +63,20 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
Spec: optionsv1alpha1.KeptnConfigSpec{
OTelCollectorUrl: "",
BlockDeployment: true,
ObservabilityTimeout: metav1.Duration{
Duration: time.Duration(5 * time.Minute),
},
},
},
lastAppliedConfig: &optionsv1alpha1.KeptnConfigSpec{},
want: ctrl.Result{},
wantErr: false,
wantBlockDeployment: true,
blockDeploymentCalls: 1,
lastAppliedConfig: &optionsv1alpha1.KeptnConfigSpec{},
want: ctrl.Result{},
wantErr: false,
wantBlockDeployment: true,
blockDeploymentCalls: 1,
observabilityTimeoutCalls: 1,
wantObservabilityTimeout: metav1.Duration{
Duration: time.Duration(5 * time.Minute),
},
},
{
name: "test 2",
Expand All @@ -88,12 +97,19 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
Spec: optionsv1alpha1.KeptnConfigSpec{
OTelCollectorUrl: "",
BlockDeployment: true,
ObservabilityTimeout: metav1.Duration{
Duration: time.Duration(5 * time.Minute),
},
},
},
want: ctrl.Result{},
wantErr: false,
wantBlockDeployment: true,
blockDeploymentCalls: 1,
want: ctrl.Result{},
wantErr: false,
wantBlockDeployment: true,
blockDeploymentCalls: 1,
observabilityTimeoutCalls: 1,
wantObservabilityTimeout: metav1.Duration{
Duration: time.Duration(5 * time.Minute),
},
},
{
name: "test 3",
Expand All @@ -112,9 +128,10 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
Namespace: "keptn-system",
},
},
want: ctrl.Result{},
wantErr: false,
blockDeploymentCalls: 0,
want: ctrl.Result{},
wantErr: false,
blockDeploymentCalls: 0,
observabilityTimeoutCalls: 0,
},
{
name: "test 4",
Expand All @@ -141,6 +158,9 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
KeptnAppCreationRequestTimeoutSeconds: 10,
CloudEventsEndpoint: "ce-endpoint",
BlockDeployment: false,
ObservabilityTimeout: metav1.Duration{
Duration: time.Duration(5 * time.Minute),
},
},
},
want: ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second},
Expand All @@ -149,6 +169,10 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
wantErr: true,
wantBlockDeployment: false,
blockDeploymentCalls: 1,
observabilityTimeoutCalls: 1,
wantObservabilityTimeout: metav1.Duration{
Duration: time.Duration(5 * time.Minute),
},
},
{
name: "test 5",
Expand All @@ -174,6 +198,9 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
KeptnAppCreationRequestTimeoutSeconds: 10,
CloudEventsEndpoint: "ce-endpoint",
BlockDeployment: false,
ObservabilityTimeout: metav1.Duration{
Duration: time.Duration(10 * time.Minute),
},
},
},
want: ctrl.Result{Requeue: true, RequeueAfter: 10 * time.Second},
Expand All @@ -182,6 +209,10 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
wantErr: true,
wantBlockDeployment: false,
blockDeploymentCalls: 1,
observabilityTimeoutCalls: 1,
wantObservabilityTimeout: metav1.Duration{
Duration: time.Duration(10 * time.Minute),
},
},
}
for _, tt := range tests {
Expand Down Expand Up @@ -211,6 +242,10 @@ func TestKeptnConfigReconciler_Reconcile(t *testing.T) {
if tt.blockDeploymentCalls > 0 {
require.Equal(t, tt.wantBlockDeployment, mockConfig.SetBlockDeploymentCalls()[0].Value)
}
require.Len(t, mockConfig.SetObservabilityTimeoutCalls(), tt.observabilityTimeoutCalls)
if tt.observabilityTimeoutCalls > 0 {
require.Equal(t, tt.wantObservabilityTimeout, mockConfig.SetObservabilityTimeoutCalls()[0].Timeout)
}
})
}
}
Expand Down Expand Up @@ -353,6 +388,7 @@ func setupReconciler(withConfig *optionsv1alpha1.KeptnConfig) *KeptnConfigReconc
SetCloudEventsEndpointFunc: func(endpoint string) {},
SetCreationRequestTimeoutFunc: func(value time.Duration) {},
SetBlockDeploymentFunc: func(value bool) {},
SetObservabilityTimeoutFunc: func(timeout metav1.Duration) {},
}
return r
}
Loading