Skip to content

Commit

Permalink
feat(lifecycle-operator): introduce a possibility to configure number…
Browse files Browse the repository at this point in the history
… of retries and interval for KeptnEvaluationDefinition (#3141)

Signed-off-by: odubajDT <ondrej.dubaj@dynatrace.com>
  • Loading branch information
odubajDT committed Feb 29, 2024
1 parent 97b4aec commit 65f7327
Show file tree
Hide file tree
Showing 23 changed files with 336 additions and 30 deletions.
13 changes: 13 additions & 0 deletions .github/scripts/.helm-tests/default/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions .github/scripts/.helm-tests/lifecycle-only/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
13 changes: 13 additions & 0 deletions .github/scripts/.helm-tests/lifecycle-with-certs/result.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 20 additions & 1 deletion docs/docs/reference/api-reference/lifecycle/v1beta1/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions docs/docs/reference/crd-reference/evaluationdefinition.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ kind: KeptnEvaluationDefinition
metadata:
name: <evaluation-name>
spec:
retries: <number-of-retries>
retryInterval: <duration>
objectives:
- evaluationTarget: "<value>"
keptnMetricRef:
Expand Down Expand Up @@ -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.
Expand All @@ -78,6 +90,8 @@ metadata:
name: my-prometheus-evaluation
namespace: example
spec:
retries: 5
retryInterval: 10s
source: prometheus
objectives:
- keptnMetricRef:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
16 changes: 3 additions & 13 deletions lifecycle-operator/apis/lifecycle/v1beta1/keptnevaluation_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
},
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -251,15 +251,26 @@ 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(),
WorkloadVersion: workload.GetVersion(),
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)

Expand Down

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 @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
Expand Down

0 comments on commit 65f7327

Please sign in to comment.