From 1db7bacf823c55571690a545124e6bd69e1797ee Mon Sep 17 00:00:00 2001 From: odubajDT <93584209+odubajDT@users.noreply.github.com> Date: Thu, 29 Feb 2024 15:02:37 +0100 Subject: [PATCH] feat(lifecycle-operator): introduce a possibility to configure number of retries and interval for KeptnEvaluationDefinition (#3141) Signed-off-by: odubajDT Signed-off-by: vickysomtee --- .../scripts/.helm-tests/default/result.yaml | 13 +++ .../.helm-tests/lifecycle-only/result.yaml | 13 +++ .../lifecycle-with-certs/result.yaml | 13 +++ .../api-reference/lifecycle/v1beta1/index.md | 21 ++++- .../crd-reference/evaluationdefinition.md | 14 ++++ .../v1beta1/keptnappversion_types.go | 5 +- .../v1beta1/keptnappversion_types_test.go | 15 +++- .../v1beta1/keptnevaluation_types.go | 16 +--- .../keptnevaluationdefinition_types.go | 20 +++++ .../apis/lifecycle/v1beta1/keptntask_types.go | 1 - .../v1beta1/keptnworkloadversion_types.go | 5 +- .../keptnworkloadversion_types_test.go | 15 +++- .../v1beta1/zz_generated.deepcopy.go | 19 ++++- .../keptnevaluationdefinition-crd.yaml | 13 +++ ...e.keptn.sh_keptnevaluationdefinitions.yaml | 13 +++ ...cle_v1beta1_keptnevaluationdefinition.yaml | 2 + .../keptnevaluation/controller_test.go | 21 ++++- .../component/appversion/appversion_test.go | 4 +- .../component/evaluation/evaluation_test.go | 4 +- .../workloadversion/workloadversion_test.go | 4 +- .../00-assert.yaml | 34 ++++++++ .../00-install.yaml | 84 +++++++++++++++++++ .../chainsaw-test.yaml | 17 ++++ 23 files changed, 336 insertions(+), 30 deletions(-) create mode 100644 test/chainsaw/integration/app-failing-pre-evaluation-retry/00-assert.yaml create mode 100644 test/chainsaw/integration/app-failing-pre-evaluation-retry/00-install.yaml create mode 100755 test/chainsaw/integration/app-failing-pre-evaluation-retry/chainsaw-test.yaml diff --git a/.github/scripts/.helm-tests/default/result.yaml b/.github/scripts/.helm-tests/default/result.yaml index 2cc542bdc3a..b487a5c6330 100644 --- a/.github/scripts/.helm-tests/default/result.yaml +++ b/.github/scripts/.helm-tests/default/result.yaml @@ -2890,6 +2890,19 @@ spec: - keptnMetricRef type: object type: array + retries: + default: 10 + description: |- + Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or + missed evaluation objective, before considering the KeptnEvaluation to be failed. + type: integer + retryInterval: + default: 5s + description: |- + RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error + or a missed objective. + pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ + type: string required: - objectives type: object diff --git a/.github/scripts/.helm-tests/lifecycle-only/result.yaml b/.github/scripts/.helm-tests/lifecycle-only/result.yaml index 832005719ed..8363f1f4a9b 100644 --- a/.github/scripts/.helm-tests/lifecycle-only/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-only/result.yaml @@ -2836,6 +2836,19 @@ spec: - keptnMetricRef type: object type: array + retries: + default: 10 + description: |- + Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or + missed evaluation objective, before considering the KeptnEvaluation to be failed. + type: integer + retryInterval: + default: 5s + description: |- + RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error + or a missed objective. + pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ + type: string required: - objectives type: object diff --git a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml index af8bad76953..4d9acc6f2f6 100644 --- a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml @@ -2867,6 +2867,19 @@ spec: - keptnMetricRef type: object type: array + retries: + default: 10 + description: |- + Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or + missed evaluation objective, before considering the KeptnEvaluation to be failed. + type: integer + retryInterval: + default: 5s + description: |- + RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error + or a missed objective. + pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ + type: string required: - objectives type: object diff --git a/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md b/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md index 61bb40eee75..bc0db5d8d88 100644 --- a/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md +++ b/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md @@ -110,6 +110,23 @@ _Appears in:_ | `message` _string_ | Message contains additional information about the evaluation of an objective. This can include explanations about why an evaluation has failed (e.g. due to a missed objective), or if there was any error during the evaluation of the objective. || ✓ | +#### FailureConditions + + + +FailureConditions represent the failure conditions (number of retries and retry interval) +for the evaluation to be considered as failed + +_Appears in:_ +- [KeptnEvaluationDefinitionSpec](#keptnevaluationdefinitionspec) +- [KeptnEvaluationSpec](#keptnevaluationspec) + +| Field | Description | Default | Optional | +| --- | --- | --- | --- | +| `retries` _integer_ | Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or missed evaluation objective, before considering the KeptnEvaluation to be failed. |10| ✓ | +| `retryInterval` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#duration-v1-meta)_ | RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error or a missed objective. |5s| ✓ | + + #### FunctionReference @@ -521,6 +538,8 @@ _Appears in:_ | Field | Description | Default | Optional | | --- | --- | --- | --- | | `objectives` _[Objective](#objective) array_ | Objectives is a list of objectives that have to be met for a KeptnEvaluation referencing this KeptnEvaluationDefinition to be successful. || x | +| `retries` _integer_ | Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or missed evaluation objective, before considering the KeptnEvaluation to be failed. |10| ✓ | +| `retryInterval` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#duration-v1-meta)_ | RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error or a missed objective. |5s| ✓ | #### KeptnEvaluationList @@ -555,9 +574,9 @@ _Appears in:_ | `appName` _string_ | AppName defines the KeptnApp for which the KeptnEvaluation is done. || ✓ | | `appVersion` _string_ | AppVersion defines the version of the KeptnApp for which the KeptnEvaluation is done. || ✓ | | `evaluationDefinition` _string_ | EvaluationDefinition refers to the name of the KeptnEvaluationDefinition which includes the objectives for the KeptnEvaluation. The KeptnEvaluationDefinition can be located in the same namespace as the KeptnEvaluation, or in the Keptn namespace. || x | +| `checkType` _string_ | Type indicates whether the KeptnEvaluation is part of the pre- or postDeployment phase. || ✓ | | `retries` _integer_ | Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or missed evaluation objective, before considering the KeptnEvaluation to be failed. |10| ✓ | | `retryInterval` _[Duration](https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.28/#duration-v1-meta)_ | RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error or a missed objective. |5s| ✓ | -| `checkType` _string_ | Type indicates whether the KeptnEvaluation is part of the pre- or postDeployment phase. || ✓ | #### KeptnEvaluationStatus diff --git a/docs/docs/reference/crd-reference/evaluationdefinition.md b/docs/docs/reference/crd-reference/evaluationdefinition.md index d4701622924..aeb3d08d592 100644 --- a/docs/docs/reference/crd-reference/evaluationdefinition.md +++ b/docs/docs/reference/crd-reference/evaluationdefinition.md @@ -18,6 +18,8 @@ kind: KeptnEvaluationDefinition metadata: name: spec: + retries: + retryInterval: objectives: - evaluationTarget: "" keptnMetricRef: @@ -56,6 +58,16 @@ spec: This is used to define success or failure criteria for the referenced `KeptnMetric` in order to pass or fail the pre- and post-evaluation stages + * **retries** -- specifies the number of times + an `Keptnevaluation` defined by the `KeptnEvaluationDefinition` + should be restarted if an attempt is unsuccessful. + The default value is `10`. + * **retryInterval** -- specifies the time + to wait between the retries. + The value supplied should specify the unit of measurement; + for example, `5s` indicates 5 seconds and `5m` indicates 5 minutes. + The default value is `5s`. + ## Usage A `KeptnEvaluationDefinition` references one or more [KeptnMetric](metric.md) resources. @@ -78,6 +90,8 @@ metadata: name: my-prometheus-evaluation namespace: example spec: + retries: 5 + retryInterval: 10s source: prometheus objectives: - keptnMetricRef: diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go index de533ff6ee1..f40964ef0d3 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go @@ -428,8 +428,9 @@ func (a KeptnAppVersion) GenerateEvaluation(evaluationDefinition KeptnEvaluation AppName: a.Spec.AppName, EvaluationDefinition: evaluationDefinition.Name, Type: checkType, - RetryInterval: metav1.Duration{ - Duration: 5 * time.Second, + FailureConditions: FailureConditions{ + RetryInterval: evaluationDefinition.Spec.FailureConditions.RetryInterval, + Retries: evaluationDefinition.Spec.FailureConditions.Retries, }, }, } diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go index 4c9e642c534..f862f340bdd 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go @@ -272,14 +272,25 @@ func TestKeptnAppVersion(t *testing.T) { ObjectMeta: v1.ObjectMeta{ Name: "eval-def", }, + Spec: KeptnEvaluationDefinitionSpec{ + FailureConditions: FailureConditions{ + RetryInterval: v1.Duration{ + Duration: 5 * time.Second, + }, + Retries: 5, + }, + }, }, common.PostDeploymentCheckType) require.Equal(t, KeptnEvaluationSpec{ AppVersion: app.GetVersion(), AppName: app.GetParentName(), EvaluationDefinition: "eval-def", Type: common.PostDeploymentCheckType, - RetryInterval: v1.Duration{ - Duration: 5 * time.Second, + FailureConditions: FailureConditions{ + RetryInterval: v1.Duration{ + Duration: 5 * time.Second, + }, + Retries: 5, }, }, evaluation.Spec) diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluation_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluation_types.go index cd318d35767..c239171697c 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluation_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluation_types.go @@ -45,22 +45,12 @@ type KeptnEvaluationSpec struct { // The KeptnEvaluationDefinition can be // located in the same namespace as the KeptnEvaluation, or in the Keptn namespace. EvaluationDefinition string `json:"evaluationDefinition"` - // Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or - // missed evaluation objective, before considering the KeptnEvaluation to be failed. - // +kubebuilder:default:=10 - // +optional - Retries int `json:"retries,omitempty"` - // RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error - // or a missed objective. - // +optional - // +kubebuilder:default:="5s" - // +kubebuilder:validation:Pattern="^0|([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$" - // +kubebuilder:validation:Type:=string - // +optional - RetryInterval metav1.Duration `json:"retryInterval,omitempty"` // Type indicates whether the KeptnEvaluation is part of the pre- or postDeployment phase. // +optional Type common.CheckType `json:"checkType,omitempty"` + // FailureConditions represent the failure conditions (number of retries and retry interval) + // for the evaluation to be considered as failed + FailureConditions `json:",inline"` } // KeptnEvaluationStatus defines the observed state of KeptnEvaluation diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluationdefinition_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluationdefinition_types.go index 9da5fd5c26d..29a2d46b14f 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluationdefinition_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluationdefinition_types.go @@ -25,6 +25,26 @@ type KeptnEvaluationDefinitionSpec struct { // Objectives is a list of objectives that have to be met for a KeptnEvaluation referencing this // KeptnEvaluationDefinition to be successful. Objectives []Objective `json:"objectives"` + // FailureConditions represent the failure conditions (number of retries and retry interval) + // for the evaluation to be considered as failed + FailureConditions `json:",inline"` +} + +// FailureConditions represent the failure conditions (number of retries and retry interval) +// for the evaluation to be considered as failed +type FailureConditions struct { + // Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or + // missed evaluation objective, before considering the KeptnEvaluation to be failed. + // +kubebuilder:default:=10 + // +optional + Retries int `json:"retries,omitempty"` + // RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error + // or a missed objective. + // +kubebuilder:default:="5s" + // +kubebuilder:validation:Pattern="^0|([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$" + // +kubebuilder:validation:Type:=string + // +optional + RetryInterval metav1.Duration `json:"retryInterval,omitempty"` } type Objective struct { diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptntask_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptntask_types.go index 9a93bb10be0..4b8c3c161c2 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptntask_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptntask_types.go @@ -55,7 +55,6 @@ type KeptnTaskSpec struct { // Timeout specifies the maximum time to wait for the task to be completed successfully. // If the task does not complete successfully within this time frame, it will be // considered to be failed. - // +optional // +kubebuilder:default:="5m" // +kubebuilder:validation:Pattern="^0|([0-9]+(\\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$" // +kubebuilder:validation:Type:=string diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types.go index 248966389c8..7517d86b735 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types.go @@ -429,8 +429,9 @@ func (w KeptnWorkloadVersion) GenerateEvaluation(evaluationDefinition KeptnEvalu Workload: w.GetParentName(), EvaluationDefinition: evaluationDefinition.Name, Type: checkType, - RetryInterval: metav1.Duration{ - Duration: 5 * time.Second, + FailureConditions: FailureConditions{ + RetryInterval: evaluationDefinition.Spec.RetryInterval, + Retries: evaluationDefinition.Spec.Retries, }, }, } diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types_test.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types_test.go index 223d92d13d2..f3f7f4d5a1c 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types_test.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types_test.go @@ -251,6 +251,14 @@ func TestKeptnWorkloadVersion(t *testing.T) { ObjectMeta: v1.ObjectMeta{ Name: "eval-def", }, + Spec: KeptnEvaluationDefinitionSpec{ + FailureConditions: FailureConditions{ + RetryInterval: v1.Duration{ + Duration: 5 * time.Second, + }, + Retries: 5, + }, + }, }, common.PostDeploymentCheckType) require.Equal(t, KeptnEvaluationSpec{ AppName: workload.GetAppName(), @@ -258,8 +266,11 @@ func TestKeptnWorkloadVersion(t *testing.T) { Workload: workload.GetParentName(), EvaluationDefinition: "eval-def", Type: common.PostDeploymentCheckType, - RetryInterval: v1.Duration{ - Duration: 5 * time.Second, + FailureConditions: FailureConditions{ + RetryInterval: v1.Duration{ + Duration: 5 * time.Second, + }, + Retries: 5, }, }, evaluation.Spec) diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go b/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go index d839ebc1c3e..78e5f1a3d2a 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go @@ -137,6 +137,22 @@ func (in *EvaluationStatusItem) DeepCopy() *EvaluationStatusItem { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *FailureConditions) DeepCopyInto(out *FailureConditions) { + *out = *in + out.RetryInterval = in.RetryInterval +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new FailureConditions. +func (in *FailureConditions) DeepCopy() *FailureConditions { + if in == nil { + return nil + } + out := new(FailureConditions) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FunctionReference) DeepCopyInto(out *FunctionReference) { *out = *in @@ -734,6 +750,7 @@ func (in *KeptnEvaluationDefinitionSpec) DeepCopyInto(out *KeptnEvaluationDefini *out = make([]Objective, len(*in)) copy(*out, *in) } + out.FailureConditions = in.FailureConditions } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnEvaluationDefinitionSpec. @@ -781,7 +798,7 @@ func (in *KeptnEvaluationList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KeptnEvaluationSpec) DeepCopyInto(out *KeptnEvaluationSpec) { *out = *in - out.RetryInterval = in.RetryInterval + out.FailureConditions = in.FailureConditions } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new KeptnEvaluationSpec. diff --git a/lifecycle-operator/chart/templates/keptnevaluationdefinition-crd.yaml b/lifecycle-operator/chart/templates/keptnevaluationdefinition-crd.yaml index 90669aeb121..b8f75102a62 100644 --- a/lifecycle-operator/chart/templates/keptnevaluationdefinition-crd.yaml +++ b/lifecycle-operator/chart/templates/keptnevaluationdefinition-crd.yaml @@ -259,6 +259,19 @@ spec: - keptnMetricRef type: object type: array + retries: + default: 10 + description: |- + Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or + missed evaluation objective, before considering the KeptnEvaluation to be failed. + type: integer + retryInterval: + default: 5s + description: |- + RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error + or a missed objective. + pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ + type: string required: - objectives type: object diff --git a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnevaluationdefinitions.yaml b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnevaluationdefinitions.yaml index 76999614fc8..36db7463a7f 100644 --- a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnevaluationdefinitions.yaml +++ b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnevaluationdefinitions.yaml @@ -251,6 +251,19 @@ spec: - keptnMetricRef type: object type: array + retries: + default: 10 + description: |- + Retries indicates how many times the KeptnEvaluation can be attempted in the case of an error or + missed evaluation objective, before considering the KeptnEvaluation to be failed. + type: integer + retryInterval: + default: 5s + description: |- + RetryInterval specifies the interval at which the KeptnEvaluation is retried in the case of an error + or a missed objective. + pattern: ^0|([0-9]+(\.[0-9]+)?(ns|us|µs|ms|s|m|h))+$ + type: string required: - objectives type: object diff --git a/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnevaluationdefinition.yaml b/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnevaluationdefinition.yaml index b47939c067b..becba399d56 100644 --- a/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnevaluationdefinition.yaml +++ b/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnevaluationdefinition.yaml @@ -4,6 +4,8 @@ metadata: name: keptnevaluationdefinition-sample spec: source: prometheus + retries: 5 + retryInterval: 10s objectives: - name: prometheus query: "sum(prometheus_engine_query_duration_seconds_count)" diff --git a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller_test.go index 08f72caa10c..2d58f06b8e4 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnevaluation/controller_test.go @@ -52,6 +52,9 @@ func TestKeptnEvaluationReconciler_Reconcile_FailEvaluation(t *testing.T) { EvaluationTarget: "<5", }, }, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 1, + }, }, } @@ -62,7 +65,9 @@ func TestKeptnEvaluationReconciler_Reconcile_FailEvaluation(t *testing.T) { }, Spec: klcv1beta1.KeptnEvaluationSpec{ EvaluationDefinition: evaluationDefinition.Name, - Retries: 1, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 1, + }, }, } @@ -121,6 +126,9 @@ func TestKeptnEvaluationReconciler_Reconcile_SucceedEvaluation(t *testing.T) { EvaluationTarget: "<11", }, }, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 1, + }, }, } @@ -131,7 +139,9 @@ func TestKeptnEvaluationReconciler_Reconcile_SucceedEvaluation(t *testing.T) { }, Spec: klcv1beta1.KeptnEvaluationSpec{ EvaluationDefinition: evaluationDefinition.Name, - Retries: 1, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 1, + }, }, } @@ -190,6 +200,9 @@ func TestKeptnEvaluationReconciler_Reconcile_SucceedEvaluation_withDefinitionInD EvaluationTarget: "<11", }, }, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 1, + }, }, } @@ -200,7 +213,9 @@ func TestKeptnEvaluationReconciler_Reconcile_SucceedEvaluation_withDefinitionInD }, Spec: klcv1beta1.KeptnEvaluationSpec{ EvaluationDefinition: evaluationDefinition.Name, - Retries: 1, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 1, + }, }, } diff --git a/lifecycle-operator/test/component/appversion/appversion_test.go b/lifecycle-operator/test/component/appversion/appversion_test.go index 303d8e8dc86..03040d21460 100644 --- a/lifecycle-operator/test/component/appversion/appversion_test.go +++ b/lifecycle-operator/test/component/appversion/appversion_test.go @@ -50,7 +50,9 @@ var _ = Describe("Appversion", Ordered, func() { AppName: appName, AppVersion: version, Type: apicommon.PreDeploymentEvaluationCheckType, - Retries: 10, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 10, + }, }, } diff --git a/lifecycle-operator/test/component/evaluation/evaluation_test.go b/lifecycle-operator/test/component/evaluation/evaluation_test.go index cf93b276453..aa645a5f932 100644 --- a/lifecycle-operator/test/component/evaluation/evaluation_test.go +++ b/lifecycle-operator/test/component/evaluation/evaluation_test.go @@ -273,6 +273,9 @@ func makeEvaluationDefinition(name string, namespaceName string, objectiveName s EvaluationTarget: "<10", }, }, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 3, + }, }, } @@ -314,7 +317,6 @@ func makeEvaluation(name string, namespaceName string, evaluationDefinition stri AppName: "app", EvaluationDefinition: evaluationDefinition, Type: apicommon.PreDeploymentEvaluationCheckType, - Retries: 3, }, } diff --git a/lifecycle-operator/test/component/workloadversion/workloadversion_test.go b/lifecycle-operator/test/component/workloadversion/workloadversion_test.go index c584229f1b6..3172bddd4af 100644 --- a/lifecycle-operator/test/component/workloadversion/workloadversion_test.go +++ b/lifecycle-operator/test/component/workloadversion/workloadversion_test.go @@ -257,7 +257,9 @@ var _ = Describe("WorkloadVersion", Ordered, func() { Workload: appName + "-wname", WorkloadVersion: "2.0", Type: apicommon.PreDeploymentEvaluationCheckType, - Retries: 10, + FailureConditions: klcv1beta1.FailureConditions{ + Retries: 10, + }, }, } diff --git a/test/chainsaw/integration/app-failing-pre-evaluation-retry/00-assert.yaml b/test/chainsaw/integration/app-failing-pre-evaluation-retry/00-assert.yaml new file mode 100644 index 00000000000..2669a9824f3 --- /dev/null +++ b/test/chainsaw/integration/app-failing-pre-evaluation-retry/00-assert.yaml @@ -0,0 +1,34 @@ +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnAppVersion +metadata: + name: podtato-head-0.1.0-6b86b273 +status: + currentPhase: AppPreDeployEvaluations + postDeploymentEvaluationStatus: Deprecated + postDeploymentStatus: Deprecated + preDeploymentEvaluationStatus: Failed + preDeploymentStatus: Succeeded + status: Failed + workloadOverallStatus: Deprecated +--- +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnEvaluation +spec: + checkType: pre-eval + evaluationDefinition: available-cpus + appName: podtato-head + appVersion: 0.1.0 + retries: 2 + retryInterval: 3s +--- +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnEvaluationDefinition +metadata: + name: available-cpus +spec: + objectives: + - evaluationTarget: ">1000" + keptnMetricRef: + name: available-cpus + retries: 2 + retryInterval: 3s diff --git a/test/chainsaw/integration/app-failing-pre-evaluation-retry/00-install.yaml b/test/chainsaw/integration/app-failing-pre-evaluation-retry/00-install.yaml new file mode 100644 index 00000000000..940dbbd340e --- /dev/null +++ b/test/chainsaw/integration/app-failing-pre-evaluation-retry/00-install.yaml @@ -0,0 +1,84 @@ +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnAppContext +metadata: + name: podtato-head +spec: + preDeploymentEvaluations: + - available-cpus +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: podtato-head-entry + labels: + app: podtato-head +spec: + selector: + matchLabels: + component: podtato-head-entry + template: + metadata: + labels: + component: podtato-head-entry + annotations: + keptn.sh/app: podtato-head + keptn.sh/workload: podtato-head-entry + keptn.sh/version: 0.1.0 + spec: + terminationGracePeriodSeconds: 5 + containers: + - name: server + image: ghcr.io/podtato-head/entry:latest + imagePullPolicy: Always + ports: + - containerPort: 9000 + env: + - name: PODTATO_PORT + value: "9000" +--- +apiVersion: v1 +kind: Service +metadata: + name: podtato-head-entry + labels: + app: podtato-head +spec: + selector: + component: podtato-head-entry + ports: + - name: http + port: 9000 + protocol: TCP + targetPort: 9000 + type: LoadBalancer +--- +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnEvaluationDefinition +metadata: + name: available-cpus +spec: + objectives: + - evaluationTarget: ">1000" + keptnMetricRef: + name: available-cpus + retries: 2 + retryInterval: 3s +--- +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetric +metadata: + name: available-cpus +spec: + fetchIntervalSeconds: 10 + provider: + name: prometheus + query: >- + sum(kube_node_status_capacity{resource='cpu'}) +--- +apiVersion: metrics.keptn.sh/v1beta1 +kind: KeptnMetricsProvider +metadata: + name: prometheus +spec: + type: prometheus + targetServer: "http://prometheus-k8s.monitoring.svc.cluster.local:9090" diff --git a/test/chainsaw/integration/app-failing-pre-evaluation-retry/chainsaw-test.yaml b/test/chainsaw/integration/app-failing-pre-evaluation-retry/chainsaw-test.yaml new file mode 100755 index 00000000000..5d32fa08410 --- /dev/null +++ b/test/chainsaw/integration/app-failing-pre-evaluation-retry/chainsaw-test.yaml @@ -0,0 +1,17 @@ +# yaml-language-server: $schema=https://raw.githubusercontent.com/kyverno/chainsaw/main/.schemas/json/test-chainsaw-v1alpha1.json +apiVersion: chainsaw.kyverno.io/v1alpha1 +kind: Test +metadata: + name: app-failing-pre-evaluation-retry +spec: + namespaceTemplate: + metadata: + annotations: + keptn.sh/lifecycle-toolkit: enabled + steps: + - name: step-00 + try: + - apply: + file: 00-install.yaml + - assert: + file: 00-assert.yaml