From ebbeebc23831f4fa3100f9097f0012884a9baec4 Mon Sep 17 00:00:00 2001 From: odubajDT Date: Thu, 15 Feb 2024 09:38:24 +0100 Subject: [PATCH] feat(lifecycle-operator): introduce promotionTask parameters in KeptnAppContext Signed-off-by: odubajDT --- .../scripts/.helm-tests/default/result.yaml | 53 ++++++++++++++++ .../.helm-tests/lifecycle-only/result.yaml | 53 ++++++++++++++++ .../lifecycle-with-certs/result.yaml | 53 ++++++++++++++++ .../api-reference/lifecycle/v1beta1/index.md | 5 ++ .../apis/lifecycle/v1beta1/common/phases.go | 6 ++ .../lifecycle/v1beta1/common/phases_test.go | 61 +++++++++++++++++++ .../v1beta1/keptnappcontext_types.go | 4 ++ .../v1beta1/keptnappversion_types.go | 41 ++++++++++++- .../v1beta1/keptnappversion_types_test.go | 47 +++++++++++++- .../v1beta1/zz_generated.deepcopy.go | 12 ++++ .../chart/templates/keptnappcontext-crd.yaml | 8 +++ .../chart/templates/keptnappversion-crd.yaml | 45 ++++++++++++++ .../lifecycle.keptn.sh_keptnappcontexts.yaml | 8 +++ .../lifecycle.keptn.sh_keptnappversions.yaml | 45 ++++++++++++++ .../lifecycle_v1beta1_keptnappcontext.yaml | 3 + .../lifecycle_v1beta1_keptnappversion.yaml | 2 + 16 files changed, 443 insertions(+), 3 deletions(-) diff --git a/.github/scripts/.helm-tests/default/result.yaml b/.github/scripts/.helm-tests/default/result.yaml index 190396ab9a..b6db62156d 100644 --- a/.github/scripts/.helm-tests/default/result.yaml +++ b/.github/scripts/.helm-tests/default/result.yaml @@ -575,6 +575,14 @@ spec: items: type: string type: array + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array spanLinks: description: |- SpanLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. @@ -1614,6 +1622,10 @@ spec: name: PostDeploymentEvaluationStatus priority: 1 type: string + - jsonPath: .status.promotionStatus + name: PromotionStatus + priority: 1 + type: string name: v1beta1 schema: openAPIV3Schema: @@ -1686,6 +1698,14 @@ spec: description: PreviousVersion is the version of the KeptnApp that has been deployed prior to this version. type: string + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array revision: default: 1 description: |- @@ -1886,6 +1906,39 @@ spec: type: string type: object type: array + promotionStatus: + default: Pending + description: PromotionStatus indicates the current status of the KeptnAppVersion's + Promotion phase. + type: string + promotionTaskStatus: + description: PromotionTaskStatus indicates the current state of each + promotionTask of the KeptnAppVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + description: KeptnState is a string containing current Phase + state (Progressing/Succeeded/Failed/Unknown/Pending/Cancelled) + type: string + type: object + type: array startTime: description: StartTime represents the time at which the deployment of the KeptnAppVersion started. diff --git a/.github/scripts/.helm-tests/lifecycle-only/result.yaml b/.github/scripts/.helm-tests/lifecycle-only/result.yaml index 6b7e87aa7b..0658703748 100644 --- a/.github/scripts/.helm-tests/lifecycle-only/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-only/result.yaml @@ -521,6 +521,14 @@ spec: items: type: string type: array + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array spanLinks: description: |- SpanLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. @@ -1560,6 +1568,10 @@ spec: name: PostDeploymentEvaluationStatus priority: 1 type: string + - jsonPath: .status.promotionStatus + name: PromotionStatus + priority: 1 + type: string name: v1beta1 schema: openAPIV3Schema: @@ -1632,6 +1644,14 @@ spec: description: PreviousVersion is the version of the KeptnApp that has been deployed prior to this version. type: string + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array revision: default: 1 description: |- @@ -1832,6 +1852,39 @@ spec: type: string type: object type: array + promotionStatus: + default: Pending + description: PromotionStatus indicates the current status of the KeptnAppVersion's + Promotion phase. + type: string + promotionTaskStatus: + description: PromotionTaskStatus indicates the current state of each + promotionTask of the KeptnAppVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + description: KeptnState is a string containing current Phase + state (Progressing/Succeeded/Failed/Unknown/Pending/Cancelled) + type: string + type: object + type: array startTime: description: StartTime represents the time at which the deployment of the KeptnAppVersion started. diff --git a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml index 9dd218c14c..8cf7adce8b 100644 --- a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml @@ -547,6 +547,14 @@ spec: items: type: string type: array + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array spanLinks: description: |- SpanLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. @@ -1588,6 +1596,10 @@ spec: name: PostDeploymentEvaluationStatus priority: 1 type: string + - jsonPath: .status.promotionStatus + name: PromotionStatus + priority: 1 + type: string name: v1beta1 schema: openAPIV3Schema: @@ -1660,6 +1672,14 @@ spec: description: PreviousVersion is the version of the KeptnApp that has been deployed prior to this version. type: string + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array revision: default: 1 description: |- @@ -1860,6 +1880,39 @@ spec: type: string type: object type: array + promotionStatus: + default: Pending + description: PromotionStatus indicates the current status of the KeptnAppVersion's + Promotion phase. + type: string + promotionTaskStatus: + description: PromotionTaskStatus indicates the current state of each + promotionTask of the KeptnAppVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + description: KeptnState is a string containing current Phase + state (Progressing/Succeeded/Failed/Unknown/Pending/Cancelled) + type: string + type: object + type: array startTime: description: StartTime represents the time at which the deployment of the KeptnAppVersion started. diff --git a/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md b/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md index ef4fe84310..ff9145ffaf 100644 --- a/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md +++ b/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md @@ -91,6 +91,7 @@ _Appears in:_ | `postDeploymentTasks` _string array_ | PostDeploymentTasks is a list of all tasks to be performed during the post-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnTaskDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | | `preDeploymentEvaluations` _string array_ | PreDeploymentEvaluations is a list of all evaluations to be performed during the pre-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnEvaluationDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | | `postDeploymentEvaluations` _string array_ | PostDeploymentEvaluations is a list of all evaluations to be performed during the post-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnEvaluationDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | +| `promotionTasks` _string array_ | PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. The items of this list refer to the names of KeptnTaskDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | #### EvaluationStatusItem @@ -252,6 +253,7 @@ _Appears in:_ | `postDeploymentTasks` _string array_ | PostDeploymentTasks is a list of all tasks to be performed during the post-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnTaskDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | | `preDeploymentEvaluations` _string array_ | PreDeploymentEvaluations is a list of all evaluations to be performed during the pre-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnEvaluationDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | | `postDeploymentEvaluations` _string array_ | PostDeploymentEvaluations is a list of all evaluations to be performed during the post-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnEvaluationDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | +| `promotionTasks` _string array_ | PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. The items of this list refer to the names of KeptnTaskDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | | `metadata` _object (keys:string, values:string)_ | Metadata contains additional key-value pairs for contextual information. || ✓ | | `spanLinks` _string array_ | SpanLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. For more information on OpenTelemetry span links, refer to the documentation: https://opentelemetry.io/docs/concepts/signals/traces/#span-links || ✓ | @@ -414,6 +416,7 @@ _Appears in:_ | `postDeploymentTasks` _string array_ | PostDeploymentTasks is a list of all tasks to be performed during the post-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnTaskDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | | `preDeploymentEvaluations` _string array_ | PreDeploymentEvaluations is a list of all evaluations to be performed during the pre-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnEvaluationDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | | `postDeploymentEvaluations` _string array_ | PostDeploymentEvaluations is a list of all evaluations to be performed during the post-deployment phase of the KeptnApp. The items of this list refer to the names of KeptnEvaluationDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | +| `promotionTasks` _string array_ | PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. The items of this list refer to the names of KeptnTaskDefinitions located in the same namespace as the KeptnApp, or in the Keptn namespace. || x | | `metadata` _object (keys:string, values:string)_ | Metadata contains additional key-value pairs for contextual information. || ✓ | | `spanLinks` _string array_ | SpanLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. For more information on OpenTelemetry span links, refer to the documentation: https://opentelemetry.io/docs/concepts/signals/traces/#span-links || ✓ | | `version` _string_ | Version defines the version of the application. For automatically created KeptnApps, the version is a function of all KeptnWorkloads that are part of the KeptnApp. || x | @@ -437,6 +440,7 @@ _Appears in:_ | --- | --- | --- | --- | | `preDeploymentStatus` _string_ | PreDeploymentStatus indicates the current status of the KeptnAppVersion's PreDeployment phase. |Pending| ✓ | | `postDeploymentStatus` _string_ | PostDeploymentStatus indicates the current status of the KeptnAppVersion's PostDeployment phase. |Pending| ✓ | +| `promotionStatus` _string_ | PromotionStatus indicates the current status of the KeptnAppVersion's Promotion phase. |Pending| ✓ | | `preDeploymentEvaluationStatus` _string_ | PreDeploymentEvaluationStatus indicates the current status of the KeptnAppVersion's PreDeploymentEvaluation phase. |Pending| ✓ | | `postDeploymentEvaluationStatus` _string_ | PostDeploymentEvaluationStatus indicates the current status of the KeptnAppVersion's PostDeploymentEvaluation phase. |Pending| ✓ | | `workloadOverallStatus` _string_ | WorkloadOverallStatus indicates the current status of the KeptnAppVersion's Workload deployment phase. |Pending| ✓ | @@ -444,6 +448,7 @@ _Appears in:_ | `currentPhase` _string_ | CurrentPhase indicates the current phase of the KeptnAppVersion. || ✓ | | `preDeploymentTaskStatus` _[ItemStatus](#itemstatus) array_ | PreDeploymentTaskStatus indicates the current state of each preDeploymentTask of the KeptnAppVersion. || ✓ | | `postDeploymentTaskStatus` _[ItemStatus](#itemstatus) array_ | PostDeploymentTaskStatus indicates the current state of each postDeploymentTask of the KeptnAppVersion. || ✓ | +| `promotionTaskStatus` _[ItemStatus](#itemstatus) array_ | PromotionTaskStatus indicates the current state of each promotionTask of the KeptnAppVersion. || ✓ | | `preDeploymentEvaluationTaskStatus` _[ItemStatus](#itemstatus) array_ | PreDeploymentEvaluationTaskStatus indicates the current state of each preDeploymentEvaluation of the KeptnAppVersion. || ✓ | | `postDeploymentEvaluationTaskStatus` _[ItemStatus](#itemstatus) array_ | PostDeploymentEvaluationTaskStatus indicates the current state of each postDeploymentEvaluation of the KeptnAppVersion. || ✓ | | `phaseTraceIDs` _[MapCarrier](https://pkg.go.dev/go.opentelemetry.io/otel/propagation#MapCarrier)_ | PhaseTraceIDs contains the trace IDs of the OpenTelemetry spans of each phase of the KeptnAppVersion. || ✓ | diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/common/phases.go b/lifecycle-operator/apis/lifecycle/v1beta1/common/phases.go index 32b8951959..875e193a8f 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/common/phases.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/common/phases.go @@ -23,6 +23,7 @@ var phases = []KeptnPhaseType{ PhaseAppPostDeployment, PhaseAppPreEvaluation, PhaseAppPostEvaluation, + PhasePromotion, PhaseAppDeployment, PhaseReconcileEvaluation, PhaseReconcileTask, @@ -65,6 +66,10 @@ func (p KeptnPhaseType) IsPostTask() bool { return strings.Contains(p.ShortName, "PostDeployTasks") } +func (p KeptnPhaseType) IsPromotionTask() bool { + return strings.Contains(p.ShortName, "PromotionTasks") +} + func GetShortPhaseName(phase string) string { for _, p := range phases { if phase == p.ShortName { @@ -91,6 +96,7 @@ var ( PhaseAppPostDeployment = KeptnPhaseType{LongName: "App Post-Deployment Tasks", ShortName: "AppPostDeployTasks"} PhaseAppPreEvaluation = KeptnPhaseType{LongName: "App Pre-Deployment Evaluations", ShortName: "AppPreDeployEvaluations"} PhaseAppPostEvaluation = KeptnPhaseType{LongName: "App Post-Deployment Evaluations", ShortName: "AppPostDeployEvaluations"} + PhasePromotion = KeptnPhaseType{LongName: "Promotion Tasks", ShortName: "PromotionTasks"} PhaseAppDeployment = KeptnPhaseType{LongName: "App Deployment", ShortName: "AppDeploy"} PhaseReconcileEvaluation = KeptnPhaseType{LongName: "Reconcile Evaluation", ShortName: "ReconcileEvaluation"} PhaseReconcileTask = KeptnPhaseType{LongName: "Reconcile Task", ShortName: "ReconcileTask"} diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/common/phases_test.go b/lifecycle-operator/apis/lifecycle/v1beta1/common/phases_test.go index 271732c1f1..6cd689e04a 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/common/phases_test.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/common/phases_test.go @@ -36,6 +36,10 @@ func TestKeptnPhaseType_IsEvaluation(t *testing.T) { State: PhaseAppPreDeployment, Want: false, }, + { + State: PhasePromotion, + Want: false, + }, } for _, tt := range tests { t.Run("", func(t *testing.T) { @@ -110,6 +114,10 @@ func TestKeptnPhaseType_IsPostEvaluation(t *testing.T) { State: PhaseAppPreDeployment, Want: false, }, + { + State: PhasePromotion, + Want: false, + }, } for _, tt := range tests { t.Run("", func(t *testing.T) { @@ -147,6 +155,10 @@ func TestKeptnPhaseType_IsTask(t *testing.T) { State: PhaseAppPreEvaluation, Want: false, }, + { + State: PhasePromotion, + Want: false, + }, } for _, tt := range tests { t.Run("", func(t *testing.T) { @@ -184,6 +196,10 @@ func TestKeptnPhaseType_IsPreTask(t *testing.T) { State: PhaseAppPreEvaluation, Want: false, }, + { + State: PhasePromotion, + Want: false, + }, } for _, tt := range tests { t.Run("", func(t *testing.T) { @@ -221,6 +237,10 @@ func TestKeptnPhaseType_IsPostTask(t *testing.T) { State: PhaseAppPreEvaluation, Want: false, }, + { + State: PhasePromotion, + Want: false, + }, } for _, tt := range tests { t.Run("", func(t *testing.T) { @@ -229,6 +249,47 @@ func TestKeptnPhaseType_IsPostTask(t *testing.T) { } } +func TestKeptnPhaseType_IsPromotionTask(t *testing.T) { + tests := []struct { + State KeptnPhaseType + Want bool + }{ + { + State: PhaseWorkloadDeployment, + Want: false, + }, + { + State: PhaseWorkloadPostDeployment, + Want: false, + }, + { + State: PhaseWorkloadPreDeployment, + Want: false, + }, + { + State: PhaseAppPostDeployment, + Want: false, + }, + { + State: PhaseAppPreDeployment, + Want: false, + }, + { + State: PhaseAppPreEvaluation, + Want: false, + }, + { + State: PhasePromotion, + Want: true, + }, + } + for _, tt := range tests { + t.Run("", func(t *testing.T) { + require.Equal(t, tt.State.IsPromotionTask(), tt.Want) + }) + } +} + func TestPhaseTraceID(t *testing.T) { trace := PhaseTraceID{} diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappcontext_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappcontext_types.go index 2e701c0f22..199f84698c 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappcontext_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappcontext_types.go @@ -39,6 +39,10 @@ type DeploymentTaskSpec struct { // The items of this list refer to the names of KeptnEvaluationDefinitions // located in the same namespace as the KeptnApp, or in the Keptn namespace. PostDeploymentEvaluations []string `json:"postDeploymentEvaluations,omitempty"` + // PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + // The items of this list refer to the names of KeptnTaskDefinitions + // located in the same namespace as the KeptnApp, or in the Keptn namespace. + PromotionTasks []string `json:"promotionTasks,omitempty"` } // KeptnAppContextSpec defines the desired state of KeptnAppContext diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go index 81cc373343..70e2632d8d 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go @@ -52,6 +52,10 @@ type KeptnAppVersionStatus struct { // +kubebuilder:default:=Pending // +optional PostDeploymentStatus common.KeptnState `json:"postDeploymentStatus,omitempty"` + // PromotionStatus indicates the current status of the KeptnAppVersion's Promotion phase. + // +kubebuilder:default:=Pending + // +optional + PromotionStatus common.KeptnState `json:"promotionStatus,omitempty"` // PreDeploymentEvaluationStatus indicates the current status of the KeptnAppVersion's PreDeploymentEvaluation phase. // +kubebuilder:default:=Pending // +optional @@ -76,6 +80,9 @@ type KeptnAppVersionStatus struct { // PostDeploymentTaskStatus indicates the current state of each postDeploymentTask of the KeptnAppVersion. // +optional PostDeploymentTaskStatus []ItemStatus `json:"postDeploymentTaskStatus,omitempty"` + // PromotionTaskStatus indicates the current state of each promotionTask of the KeptnAppVersion. + // +optional + PromotionTaskStatus []ItemStatus `json:"promotionTaskStatus,omitempty"` // PreDeploymentEvaluationTaskStatus indicates the current state of each preDeploymentEvaluation of the KeptnAppVersion. // +optional PreDeploymentEvaluationTaskStatus []ItemStatus `json:"preDeploymentEvaluationTaskStatus,omitempty"` @@ -120,6 +127,7 @@ type WorkloadStatus struct { // +kubebuilder:printcolumn:name="WorkloadOverallStatus",priority=1,type=string,JSONPath=`.status.workloadOverallStatus` // +kubebuilder:printcolumn:name="PostDeploymentStatus",priority=1,type=string,JSONPath=`.status.postDeploymentStatus` // +kubebuilder:printcolumn:name="PostDeploymentEvaluationStatus",priority=1,type=string,JSONPath=`.status.postDeploymentEvaluationStatus` +// +kubebuilder:printcolumn:name="PromotionStatus",priority=1,type=string,JSONPath=`.status.promotionStatus` // KeptnAppVersion is the Schema for the keptnappversions API type KeptnAppVersion struct { @@ -195,6 +203,10 @@ func (a KeptnAppVersion) IsPostDeploymentCompleted() bool { return a.Status.PostDeploymentStatus.IsCompleted() } +func (a KeptnAppVersion) IsPromotionCompleted() bool { + return a.Status.PromotionStatus.IsCompleted() +} + func (a KeptnAppVersion) IsPostDeploymentEvaluationCompleted() bool { return a.Status.PostDeploymentEvaluationStatus.IsCompleted() } @@ -203,6 +215,10 @@ func (a KeptnAppVersion) IsPostDeploymentFailed() bool { return a.Status.PostDeploymentStatus.IsFailed() } +func (a KeptnAppVersion) IsPromotionFailed() bool { + return a.Status.PromotionStatus.IsFailed() +} + func (a KeptnAppVersion) IsPostDeploymentEvaluationSucceeded() bool { return a.Status.PostDeploymentEvaluationStatus.IsSucceeded() } @@ -215,6 +231,10 @@ func (a KeptnAppVersion) IsPostDeploymentSucceeded() bool { return a.Status.PostDeploymentStatus.IsSucceeded() } +func (a KeptnAppVersion) IsPromotionSucceeded() bool { + return a.Status.PromotionStatus.IsSucceeded() +} + func (a KeptnAppVersion) AreWorkloadsCompleted() bool { return a.Status.WorkloadOverallStatus.IsCompleted() } @@ -296,6 +316,10 @@ func (a KeptnAppVersion) GetPostDeploymentTasks() []string { return a.Spec.PostDeploymentTasks } +func (a KeptnAppVersion) GetPromotionTasks() []string { + return a.Spec.PromotionTasks +} + func (a KeptnAppVersion) GetPreDeploymentTaskStatus() []ItemStatus { return a.Status.PreDeploymentTaskStatus } @@ -320,6 +344,10 @@ func (a KeptnAppVersion) GetPostDeploymentEvaluationTaskStatus() []ItemStatus { return a.Status.PostDeploymentEvaluationTaskStatus } +func (a KeptnAppVersion) GetPromotionTaskStatus() []ItemStatus { + return a.Status.PromotionTaskStatus +} + func (a KeptnAppVersion) GetAppName() string { return a.Spec.AppName } @@ -424,24 +452,31 @@ func (v KeptnAppVersion) GetWorkloadNameOfApp(workloadName string) string { //nolint:dupl func (a *KeptnAppVersion) DeprecateRemainingPhases(phase common.KeptnPhaseType) { - // no need to deprecate anything when post-eval tasks fail - if phase == common.PhaseAppPostEvaluation { + // no need to deprecate anything when promotion tasks fail + if phase == common.PhasePromotion { return } + // deprecate promotion tasks when post evaluation failed + if phase == common.PhaseAppPostEvaluation { + a.Status.PromotionStatus = common.StateDeprecated + } // deprecate post evaluation when post tasks failed if phase == common.PhaseAppPostDeployment { a.Status.PostDeploymentEvaluationStatus = common.StateDeprecated + a.Status.PromotionStatus = common.StateDeprecated } // deprecate post evaluation and tasks when app deployment failed if phase == common.PhaseAppDeployment { a.Status.PostDeploymentStatus = common.StateDeprecated a.Status.PostDeploymentEvaluationStatus = common.StateDeprecated + a.Status.PromotionStatus = common.StateDeprecated } // deprecate app deployment, post tasks and evaluations if app pre-eval failed if phase == common.PhaseAppPreEvaluation { a.Status.PostDeploymentStatus = common.StateDeprecated a.Status.PostDeploymentEvaluationStatus = common.StateDeprecated a.Status.WorkloadOverallStatus = common.StateDeprecated + a.Status.PromotionStatus = common.StateDeprecated } // deprecate pre evaluations, app deployment and post tasks and evaluations when pre-tasks failed if phase == common.PhaseAppPreDeployment { @@ -449,6 +484,7 @@ func (a *KeptnAppVersion) DeprecateRemainingPhases(phase common.KeptnPhaseType) a.Status.PostDeploymentEvaluationStatus = common.StateDeprecated a.Status.WorkloadOverallStatus = common.StateDeprecated a.Status.PreDeploymentEvaluationStatus = common.StateDeprecated + a.Status.PromotionStatus = common.StateDeprecated } // deprecate completely everything if phase == common.PhaseDeprecated { @@ -457,6 +493,7 @@ func (a *KeptnAppVersion) DeprecateRemainingPhases(phase common.KeptnPhaseType) a.Status.WorkloadOverallStatus = common.StateDeprecated a.Status.PreDeploymentEvaluationStatus = common.StateDeprecated a.Status.PreDeploymentStatus = common.StateDeprecated + a.Status.PromotionStatus = common.StateDeprecated a.Status.Status = common.StateDeprecated return } diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go index 8d555f98e8..cbb8795201 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go @@ -24,6 +24,7 @@ func TestKeptnAppVersion(t *testing.T) { PostDeploymentStatus: common.StateFailed, PostDeploymentEvaluationStatus: common.StateFailed, WorkloadOverallStatus: common.StateFailed, + PromotionStatus: common.StateFailed, Status: common.StateFailed, PreDeploymentTaskStatus: []ItemStatus{ { @@ -53,6 +54,13 @@ func TestKeptnAppVersion(t *testing.T) { Name: "taskname4", }, }, + PromotionTaskStatus: []ItemStatus{ + { + DefinitionName: "defname5", + Status: common.StateFailed, + Name: "taskname5", + }, + }, CurrentPhase: common.PhaseAppDeployment.ShortName, }, Spec: KeptnAppVersionSpec{ @@ -65,6 +73,7 @@ func TestKeptnAppVersion(t *testing.T) { PostDeploymentTasks: []string{"task3", "task4"}, PreDeploymentEvaluations: []string{"task5", "task6"}, PostDeploymentEvaluations: []string{"task7", "task8"}, + PromotionTasks: []string{"task9", "task10"}, }, }, PreviousVersion: "prev", @@ -89,6 +98,10 @@ func TestKeptnAppVersion(t *testing.T) { require.False(t, app.IsPostDeploymentEvaluationSucceeded()) require.True(t, app.IsPostDeploymentEvaluationFailed()) + require.True(t, app.IsPromotionCompleted()) + require.False(t, app.IsPromotionSucceeded()) + require.True(t, app.IsPromotionFailed()) + require.True(t, app.AreWorkloadsCompleted()) require.False(t, app.AreWorkloadsSucceeded()) require.True(t, app.AreWorkloadsFailed()) @@ -127,6 +140,7 @@ func TestKeptnAppVersion(t *testing.T) { require.Equal(t, []string{"task3", "task4"}, app.GetPostDeploymentTasks()) require.Equal(t, []string{"task5", "task6"}, app.GetPreDeploymentEvaluations()) require.Equal(t, []string{"task7", "task8"}, app.GetPostDeploymentEvaluations()) + require.Equal(t, []string{"task9", "task10"}, app.GetPromotionTasks()) require.Equal(t, []ItemStatus{ { @@ -160,6 +174,14 @@ func TestKeptnAppVersion(t *testing.T) { }, }, app.GetPostDeploymentEvaluationTaskStatus()) + require.Equal(t, []ItemStatus{ + { + DefinitionName: "defname5", + Status: common.StateFailed, + Name: "taskname5", + }, + }, app.GetPromotionTaskStatus()) + require.Equal(t, "appname", app.GetAppName()) require.Equal(t, "prev", app.GetPreviousVersion()) require.Equal(t, "appname", app.GetParentName()) @@ -299,6 +321,7 @@ func TestKeptnAppVersion_DeprecateRemainingPhases(t *testing.T) { PreDeploymentEvaluationStatus: common.StatePending, PostDeploymentStatus: common.StatePending, PostDeploymentEvaluationStatus: common.StatePending, + PromotionStatus: common.StatePending, WorkloadOverallStatus: common.StatePending, Status: common.StatePending, }, @@ -311,18 +334,34 @@ func TestKeptnAppVersion_DeprecateRemainingPhases(t *testing.T) { }{ { app: app, - phase: common.PhaseAppPostEvaluation, + phase: common.PhasePromotion, want: KeptnAppVersion{ Status: KeptnAppVersionStatus{ PreDeploymentStatus: common.StatePending, PreDeploymentEvaluationStatus: common.StatePending, PostDeploymentStatus: common.StatePending, PostDeploymentEvaluationStatus: common.StatePending, + PromotionStatus: common.StatePending, WorkloadOverallStatus: common.StatePending, Status: common.StatePending, }, }, }, + { + app: app, + phase: common.PhaseAppPostEvaluation, + want: KeptnAppVersion{ + Status: KeptnAppVersionStatus{ + PreDeploymentStatus: common.StatePending, + PreDeploymentEvaluationStatus: common.StatePending, + PostDeploymentStatus: common.StatePending, + PostDeploymentEvaluationStatus: common.StatePending, + PromotionStatus: common.StateDeprecated, + WorkloadOverallStatus: common.StatePending, + Status: common.StateFailed, + }, + }, + }, { app: app, phase: common.PhaseAppPostDeployment, @@ -332,6 +371,7 @@ func TestKeptnAppVersion_DeprecateRemainingPhases(t *testing.T) { PreDeploymentEvaluationStatus: common.StatePending, PostDeploymentStatus: common.StatePending, PostDeploymentEvaluationStatus: common.StateDeprecated, + PromotionStatus: common.StateDeprecated, WorkloadOverallStatus: common.StatePending, Status: common.StateFailed, }, @@ -346,6 +386,7 @@ func TestKeptnAppVersion_DeprecateRemainingPhases(t *testing.T) { PreDeploymentEvaluationStatus: common.StatePending, PostDeploymentStatus: common.StateDeprecated, PostDeploymentEvaluationStatus: common.StateDeprecated, + PromotionStatus: common.StateDeprecated, WorkloadOverallStatus: common.StatePending, Status: common.StateFailed, }, @@ -360,6 +401,7 @@ func TestKeptnAppVersion_DeprecateRemainingPhases(t *testing.T) { PreDeploymentEvaluationStatus: common.StatePending, PostDeploymentStatus: common.StateDeprecated, PostDeploymentEvaluationStatus: common.StateDeprecated, + PromotionStatus: common.StateDeprecated, WorkloadOverallStatus: common.StateDeprecated, Status: common.StateFailed, }, @@ -374,6 +416,7 @@ func TestKeptnAppVersion_DeprecateRemainingPhases(t *testing.T) { PreDeploymentEvaluationStatus: common.StateDeprecated, PostDeploymentStatus: common.StateDeprecated, PostDeploymentEvaluationStatus: common.StateDeprecated, + PromotionStatus: common.StateDeprecated, WorkloadOverallStatus: common.StateDeprecated, Status: common.StateFailed, }, @@ -388,6 +431,7 @@ func TestKeptnAppVersion_DeprecateRemainingPhases(t *testing.T) { PreDeploymentEvaluationStatus: common.StateDeprecated, PostDeploymentStatus: common.StateDeprecated, PostDeploymentEvaluationStatus: common.StateDeprecated, + PromotionStatus: common.StateDeprecated, WorkloadOverallStatus: common.StateDeprecated, Status: common.StateDeprecated, }, @@ -402,6 +446,7 @@ func TestKeptnAppVersion_DeprecateRemainingPhases(t *testing.T) { PreDeploymentEvaluationStatus: common.StatePending, PostDeploymentStatus: common.StatePending, PostDeploymentEvaluationStatus: common.StatePending, + PromotionStatus: common.StatePending, WorkloadOverallStatus: common.StatePending, Status: common.StateFailed, }, diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go b/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go index e2a5c7271c..d839ebc1c3 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go @@ -105,6 +105,11 @@ func (in *DeploymentTaskSpec) DeepCopyInto(out *DeploymentTaskSpec) { *out = make([]string, len(*in)) copy(*out, *in) } + if in.PromotionTasks != nil { + in, out := &in.PromotionTasks, &out.PromotionTasks + *out = make([]string, len(*in)) + copy(*out, *in) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new DeploymentTaskSpec. @@ -583,6 +588,13 @@ func (in *KeptnAppVersionStatus) DeepCopyInto(out *KeptnAppVersionStatus) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.PromotionTaskStatus != nil { + in, out := &in.PromotionTaskStatus, &out.PromotionTaskStatus + *out = make([]ItemStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } if in.PreDeploymentEvaluationTaskStatus != nil { in, out := &in.PreDeploymentEvaluationTaskStatus, &out.PreDeploymentEvaluationTaskStatus *out = make([]ItemStatus, len(*in)) diff --git a/lifecycle-operator/chart/templates/keptnappcontext-crd.yaml b/lifecycle-operator/chart/templates/keptnappcontext-crd.yaml index e38cc4cc15..be68c31288 100644 --- a/lifecycle-operator/chart/templates/keptnappcontext-crd.yaml +++ b/lifecycle-operator/chart/templates/keptnappcontext-crd.yaml @@ -85,6 +85,14 @@ spec: items: type: string type: array + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array spanLinks: description: |- SpanLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. diff --git a/lifecycle-operator/chart/templates/keptnappversion-crd.yaml b/lifecycle-operator/chart/templates/keptnappversion-crd.yaml index b2e8598e2b..5b6c3f3b13 100644 --- a/lifecycle-operator/chart/templates/keptnappversion-crd.yaml +++ b/lifecycle-operator/chart/templates/keptnappversion-crd.yaml @@ -905,6 +905,10 @@ spec: name: PostDeploymentEvaluationStatus priority: 1 type: string + - jsonPath: .status.promotionStatus + name: PromotionStatus + priority: 1 + type: string name: v1beta1 schema: openAPIV3Schema: @@ -977,6 +981,14 @@ spec: description: PreviousVersion is the version of the KeptnApp that has been deployed prior to this version. type: string + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array revision: default: 1 description: |- @@ -1177,6 +1189,39 @@ spec: type: string type: object type: array + promotionStatus: + default: Pending + description: PromotionStatus indicates the current status of the KeptnAppVersion's + Promotion phase. + type: string + promotionTaskStatus: + description: PromotionTaskStatus indicates the current state of each + promotionTask of the KeptnAppVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + description: KeptnState is a string containing current Phase + state (Progressing/Succeeded/Failed/Unknown/Pending/Cancelled) + type: string + type: object + type: array startTime: description: StartTime represents the time at which the deployment of the KeptnAppVersion started. diff --git a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappcontexts.yaml b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappcontexts.yaml index 9802f30931..c7846b8b75 100644 --- a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappcontexts.yaml +++ b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappcontexts.yaml @@ -79,6 +79,14 @@ spec: items: type: string type: array + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array spanLinks: description: |- SpanLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. diff --git a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappversions.yaml b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappversions.yaml index e098455297..39ad4b0203 100644 --- a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappversions.yaml +++ b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappversions.yaml @@ -887,6 +887,10 @@ spec: name: PostDeploymentEvaluationStatus priority: 1 type: string + - jsonPath: .status.promotionStatus + name: PromotionStatus + priority: 1 + type: string name: v1beta1 schema: openAPIV3Schema: @@ -959,6 +963,14 @@ spec: description: PreviousVersion is the version of the KeptnApp that has been deployed prior to this version. type: string + promotionTasks: + description: |- + PromotionTasks is a list of all tasks to be performed during the promotion phase of the KeptnApp. + The items of this list refer to the names of KeptnTaskDefinitions + located in the same namespace as the KeptnApp, or in the Keptn namespace. + items: + type: string + type: array revision: default: 1 description: |- @@ -1159,6 +1171,39 @@ spec: type: string type: object type: array + promotionStatus: + default: Pending + description: PromotionStatus indicates the current status of the KeptnAppVersion's + Promotion phase. + type: string + promotionTaskStatus: + description: PromotionTaskStatus indicates the current state of each + promotionTask of the KeptnAppVersion. + items: + properties: + definitionName: + description: DefinitionName is the name of the EvaluationDefinition/TaskDefinition + type: string + endTime: + description: EndTime represents the time at which the Item (Evaluation/Task) + started. + format: date-time + type: string + name: + description: Name is the name of the Evaluation/Task + type: string + startTime: + description: StartTime represents the time at which the Item + (Evaluation/Task) started. + format: date-time + type: string + status: + default: Pending + description: KeptnState is a string containing current Phase + state (Progressing/Succeeded/Failed/Unknown/Pending/Cancelled) + type: string + type: object + type: array startTime: description: StartTime represents the time at which the deployment of the KeptnAppVersion started. diff --git a/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnappcontext.yaml b/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnappcontext.yaml index 50964eb0ac..3af73c0c5a 100644 --- a/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnappcontext.yaml +++ b/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnappcontext.yaml @@ -21,6 +21,9 @@ spec: postDeploymentEvaluations: - eval1 - eval2 + promotionTasks: + - task1 + - task2 metadata: - key: abc123 spanLinks: diff --git a/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnappversion.yaml b/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnappversion.yaml index e93d4e3315..d052dc359c 100644 --- a/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnappversion.yaml +++ b/lifecycle-operator/config/samples/lifecycle_v1beta1_keptnappversion.yaml @@ -12,6 +12,8 @@ spec: - post-deployment-task postDeploymentEvaluations: - post-deployment-evaluation + promotionTasks: + - promotion-task metadata: - key: abc123 spanLinks: