From 0798406108b545e8f7debceae5dc1cb28f0a8d11 Mon Sep 17 00:00:00 2001 From: Florian Bacher Date: Fri, 26 Jan 2024 18:31:42 +0100 Subject: [PATCH] feat(lifecycle-operator): add context metadata and traceParent of current phase to tasks (#2858) Signed-off-by: Florian Bacher --- .../scripts/.helm-tests/default/result.yaml | 6 +++ .../.helm-tests/lifecycle-only/result.yaml | 6 +++ .../lifecycle-with-certs/result.yaml | 6 +++ .../api-reference/lifecycle/v1beta1/index.md | 1 + .../v1beta1/keptnappversion_types.go | 2 +- .../v1beta1/keptnappversion_types_test.go | 2 +- .../apis/lifecycle/v1beta1/keptntask_types.go | 3 ++ .../v1beta1/keptnworkloadversion_types.go | 2 +- .../keptnworkloadversion_types_test.go | 2 +- .../v1beta1/zz_generated.deepcopy.go | 9 +++- .../chart/templates/keptntask-crd.yaml | 6 +++ .../bases/lifecycle.keptn.sh_keptntasks.yaml | 6 +++ .../controllers/common/context/context.go | 4 +- .../common/helperfunctions_test.go | 12 +++++ .../controllers/common/task/handler.go | 21 ++++++++- .../controllers/common/task/handler_test.go | 42 ++++++++++++++++- .../lifecycle/keptnappversion/controller.go | 4 +- .../keptnworkloadversion/controller.go | 16 +++---- .../imagepullsecret/00-install.yaml | 1 + .../podtato-head-application/00-install.yaml | 8 ++++ .../00-assert.yaml | 8 ++++ .../00-install.yaml | 45 +++++++++++++++++++ .../00-teststep.yaml | 4 ++ .../01-assert.yaml | 41 +++++++++++++++++ .../00-install.yaml | 4 -- .../00-install.yaml | 4 -- .../00-install.yaml | 4 -- .../00-install.yaml | 1 + .../00-install.yaml | 10 +++-- .../01-assert.yaml | 4 ++ .../00-install.yaml | 4 -- .../simple-deployment/00-install.yaml | 4 -- .../00-install.yaml | 4 -- .../02-install.yaml | 4 -- test/integration/simple-task/00-assert.yaml | 5 ++- test/integration/simple-task/00-install.yaml | 3 ++ 36 files changed, 254 insertions(+), 54 deletions(-) create mode 100644 test/integration/simple-deployment-annotated-with-app-context/00-assert.yaml create mode 100644 test/integration/simple-deployment-annotated-with-app-context/00-install.yaml create mode 100644 test/integration/simple-deployment-annotated-with-app-context/00-teststep.yaml create mode 100644 test/integration/simple-deployment-annotated-with-app-context/01-assert.yaml diff --git a/.github/scripts/.helm-tests/default/result.yaml b/.github/scripts/.helm-tests/default/result.yaml index b90ae958cb..b632adddae 100644 --- a/.github/scripts/.helm-tests/default/result.yaml +++ b/.github/scripts/.helm-tests/default/result.yaml @@ -3335,6 +3335,12 @@ spec: description: AppVersion the version of the KeptnApp the KeptnTask is being executed for. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for + contextual information. + type: object objectType: description: ObjectType indicates whether the KeptnTask is being executed for a KeptnApp or KeptnWorkload. diff --git a/.github/scripts/.helm-tests/lifecycle-only/result.yaml b/.github/scripts/.helm-tests/lifecycle-only/result.yaml index 8d22526161..5dab11bf97 100644 --- a/.github/scripts/.helm-tests/lifecycle-only/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-only/result.yaml @@ -3281,6 +3281,12 @@ spec: description: AppVersion the version of the KeptnApp the KeptnTask is being executed for. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for + contextual information. + type: object objectType: description: ObjectType indicates whether the KeptnTask is being executed for a KeptnApp or KeptnWorkload. diff --git a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml index 4f2118be47..ec69e89e58 100644 --- a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml @@ -3313,6 +3313,12 @@ spec: description: AppVersion the version of the KeptnApp the KeptnTask is being executed for. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for + contextual information. + type: object objectType: description: ObjectType indicates whether the KeptnTask is being executed for a KeptnApp or KeptnWorkload. diff --git a/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md b/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md index 6f3d1f016a..142b5b39b2 100644 --- a/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md +++ b/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md @@ -1004,6 +1004,7 @@ _Appears in:_ | `workloadVersion` _string_ | WorkloadVersion the version of the KeptnWorkload the KeptnTask is being executed for. || ✓ | | `taskType` _string_ | TaskType indicates whether the KeptnTask is part of the pre- or postDeployment phase. || ✓ | | `objectType` _string_ | ObjectType indicates whether the KeptnTask is being executed for a KeptnApp or KeptnWorkload. || ✓ | +| `metadata` _object (keys:string, values:string)_ | Refer to Kubernetes API documentation for fields of `metadata`. || ✓ | #### TaskParameters diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go index 4896902cff..81cc373343 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go @@ -415,7 +415,7 @@ func (a KeptnAppVersion) SetSpanAttributes(span trace.Span) { } func (a KeptnAppVersion) GetSpanKey(phase string) string { - return fmt.Sprintf("%s.%s.%s.%s", a.Spec.TraceId["traceparent"], a.Spec.AppName, a.Spec.Version, phase) + return fmt.Sprintf("%s.%s.%s.%s.%s", a.Spec.TraceId["traceparent"], a.Spec.AppName, a.ObjectMeta.Namespace, a.Spec.Version, phase) } func (v KeptnAppVersion) GetWorkloadNameOfApp(workloadName string) string { diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go index f098ff481b..8d555f98e8 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go @@ -180,7 +180,7 @@ func TestKeptnAppVersion(t *testing.T) { require.Equal(t, "version", app.GetVersion()) - require.Equal(t, "trace1.appname.version.phase", app.GetSpanKey("phase")) + require.Equal(t, "trace1.appname.namespace.version.phase", app.GetSpanKey("phase")) retries := int32(5) task := app.GenerateTask(KeptnTaskDefinition{ diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptntask_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptntask_types.go index 5a34c1e82c..9a93bb10be 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptntask_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptntask_types.go @@ -82,6 +82,9 @@ type TaskContext struct { // ObjectType indicates whether the KeptnTask is being executed for a KeptnApp or KeptnWorkload. // +optional ObjectType string `json:"objectType"` + // +optional + // Metadata contains additional key-value pairs for contextual information. + Metadata map[string]string `json:"metadata,omitempty"` } type TaskParameters struct { diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types.go index cf58e38a14..ef554bf93c 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types.go @@ -424,7 +424,7 @@ func (w KeptnWorkloadVersion) GetSpanAttributes() []attribute.KeyValue { } func (w KeptnWorkloadVersion) GetSpanKey(phase string) string { - return fmt.Sprintf("%s.%s.%s.%s", w.Spec.TraceId["traceparent"], w.Spec.WorkloadName, w.Spec.Version, phase) + return fmt.Sprintf("%s.%s.%s.%s.%s", w.Spec.TraceId["traceparent"], w.Spec.WorkloadName, w.ObjectMeta.Namespace, w.Spec.Version, phase) } func (w KeptnWorkloadVersion) GetSpanName(phase string) string { diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types_test.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types_test.go index 4f72d801dd..8688babd1a 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types_test.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnworkloadversion_types_test.go @@ -180,7 +180,7 @@ func TestKeptnWorkloadVersion(t *testing.T) { require.Equal(t, "version", workload.GetVersion()) - require.Equal(t, "trace1.workloadname.version.phase", workload.GetSpanKey("phase")) + require.Equal(t, "trace1.workloadname.namespace.version.phase", workload.GetSpanKey("phase")) retries := int32(5) task := workload.GenerateTask(KeptnTaskDefinition{ diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go b/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go index 6ba6bfb062..e2a5c7271c 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go @@ -1019,7 +1019,7 @@ func (in *KeptnTaskList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KeptnTaskSpec) DeepCopyInto(out *KeptnTaskSpec) { *out = *in - out.Context = in.Context + in.Context.DeepCopyInto(&out.Context) in.Parameters.DeepCopyInto(&out.Parameters) out.SecureParameters = in.SecureParameters if in.Retries != nil { @@ -1426,6 +1426,13 @@ func (in *ServiceAccountSpec) DeepCopy() *ServiceAccountSpec { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *TaskContext) DeepCopyInto(out *TaskContext) { *out = *in + if in.Metadata != nil { + in, out := &in.Metadata, &out.Metadata + *out = make(map[string]string, len(*in)) + for key, val := range *in { + (*out)[key] = val + } + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TaskContext. diff --git a/lifecycle-operator/chart/templates/keptntask-crd.yaml b/lifecycle-operator/chart/templates/keptntask-crd.yaml index 4462c97a06..afc1bd857e 100644 --- a/lifecycle-operator/chart/templates/keptntask-crd.yaml +++ b/lifecycle-operator/chart/templates/keptntask-crd.yaml @@ -487,6 +487,12 @@ spec: description: AppVersion the version of the KeptnApp the KeptnTask is being executed for. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for + contextual information. + type: object objectType: description: ObjectType indicates whether the KeptnTask is being executed for a KeptnApp or KeptnWorkload. diff --git a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml index 71057181fd..397510753b 100644 --- a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml +++ b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptntasks.yaml @@ -478,6 +478,12 @@ spec: description: AppVersion the version of the KeptnApp the KeptnTask is being executed for. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for + contextual information. + type: object objectType: description: ObjectType indicates whether the KeptnTask is being executed for a KeptnApp or KeptnWorkload. diff --git a/lifecycle-operator/controllers/common/context/context.go b/lifecycle-operator/controllers/common/context/context.go index 986aa558a1..0a9c6a4dc7 100644 --- a/lifecycle-operator/controllers/common/context/context.go +++ b/lifecycle-operator/controllers/common/context/context.go @@ -1,6 +1,8 @@ package context -import "context" +import ( + "context" +) type keptnAppContextKeyType string diff --git a/lifecycle-operator/controllers/common/helperfunctions_test.go b/lifecycle-operator/controllers/common/helperfunctions_test.go index 0192dd167e..04a4244a8a 100644 --- a/lifecycle-operator/controllers/common/helperfunctions_test.go +++ b/lifecycle-operator/controllers/common/helperfunctions_test.go @@ -361,6 +361,18 @@ func Test_MergeMaps(t *testing.T) { "test3": "testy3", }, }, + { + name: "one map is nil", + map1: nil, + map2: map[string]string{ + "test1": "testy1", + "test3": "testy3", + }, + want: map[string]string{ + "test1": "testy1", + "test3": "testy3", + }, + }, } for _, tt := range tests { diff --git a/lifecycle-operator/controllers/common/task/handler.go b/lifecycle-operator/controllers/common/task/handler.go index ba565597a3..29e6ebabba 100644 --- a/lifecycle-operator/controllers/common/task/handler.go +++ b/lifecycle-operator/controllers/common/task/handler.go @@ -9,12 +9,16 @@ import ( klcv1beta1 "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1/common" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common" + keptncontext "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/context" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/eventsender" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/lifecycle/interfaces" + "go.opentelemetry.io/otel" "go.opentelemetry.io/otel/codes" + "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" + "golang.org/x/exp/maps" "k8s.io/apimachinery/pkg/api/errors" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/types" @@ -124,7 +128,7 @@ func (r Handler) ReconcileTasks(ctx context.Context, phaseCtx context.Context, r } //nolint:dupl -func (r Handler) CreateKeptnTask(ctx context.Context, namespace string, reconcileObject client.Object, taskCreateAttributes CreateTaskAttributes) (string, error) { +func (r Handler) CreateKeptnTask(ctx, phaseCtx context.Context, namespace string, reconcileObject client.Object, taskCreateAttributes CreateTaskAttributes) (string, error) { piWrapper, err := interfaces.NewPhaseItemWrapperFromClientObject(reconcileObject) if err != nil { return "", err @@ -133,6 +137,7 @@ func (r Handler) CreateKeptnTask(ctx context.Context, namespace string, reconcil phase := apicommon.PhaseCreateTask newTask := piWrapper.GenerateTask(taskCreateAttributes.Definition, taskCreateAttributes.CheckType) + injectKeptnContext(phaseCtx, &newTask) err = controllerutil.SetControllerReference(reconcileObject, &newTask, r.Scheme) if err != nil { r.Log.Error(err, "could not set controller reference:") @@ -147,6 +152,18 @@ func (r Handler) CreateKeptnTask(ctx context.Context, namespace string, reconcil return newTask.Name, nil } +func injectKeptnContext(phaseCtx context.Context, newTask *klcv1beta1.KeptnTask) { + if metadata, ok := keptncontext.GetAppMetadataFromContext(phaseCtx); ok { + traceContextCarrier := &propagation.MapCarrier{} + otel.GetTextMapPropagator().Inject(phaseCtx, traceContextCarrier) + newTask.Spec.Context.Metadata = map[string]string{} + maps.Copy(newTask.Spec.Context.Metadata, metadata) + for _, key := range traceContextCarrier.Keys() { + newTask.Spec.Context.Metadata[key] = traceContextCarrier.Get(key) + } + } +} + func (r Handler) setTaskFailureEvents(task *klcv1beta1.KeptnTask, spanTrace trace.Span) { spanTrace.AddEvent(fmt.Sprintf("task '%s' failed with reason: '%s'", task.Name, task.Status.Message), trace.WithTimestamp(time.Now().UTC())) } @@ -172,7 +189,7 @@ func (r Handler) handleTaskNotExists(ctx context.Context, phaseCtx context.Conte return controllererrors.ErrCannotGetKeptnTaskDefinition } taskCreateAttributes.Definition = *definition - taskName, err = r.CreateKeptnTask(ctx, piWrapper.GetNamespace(), reconcileObject, taskCreateAttributes) + taskName, err = r.CreateKeptnTask(ctx, phaseCtx, piWrapper.GetNamespace(), reconcileObject, taskCreateAttributes) if err != nil { return err } diff --git a/lifecycle-operator/controllers/common/task/handler_test.go b/lifecycle-operator/controllers/common/task/handler_test.go index c8144b5694..a361951c8c 100644 --- a/lifecycle-operator/controllers/common/task/handler_test.go +++ b/lifecycle-operator/controllers/common/task/handler_test.go @@ -2,18 +2,23 @@ package task import ( "context" + "fmt" "strings" "testing" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1" apicommon "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1/common" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/config" + keptncontext "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/context" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/eventsender" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" telemetryfake "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry/fake" "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/testcommon" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "github.com/stretchr/testify/require" + "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/propagation" + sdktrace "go.opentelemetry.io/otel/sdk/trace" "go.opentelemetry.io/otel/trace" "go.opentelemetry.io/otel/trace/noop" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -463,6 +468,7 @@ func TestTaskHandler_createTask(t *testing.T) { t.Run(tt.name, func(t *testing.T) { err := v1beta1.AddToScheme(scheme.Scheme) require.Nil(t, err) + handler := Handler{ SpanHandler: &telemetryfake.ISpanHandlerMock{}, Log: ctrl.Log.WithName("controller"), @@ -471,9 +477,43 @@ func TestTaskHandler_createTask(t *testing.T) { Tracer: noop.NewTracerProvider().Tracer("tracer"), Scheme: scheme.Scheme, } - name, err := handler.CreateKeptnTask(context.TODO(), "namespace", tt.object, tt.createAttr) + + // create a context with a traceParent and metadata attributes + + name, err := handler.CreateKeptnTask(context.TODO(), context.TODO(), "namespace", tt.object, tt.createAttr) + require.True(t, strings.Contains(name, tt.wantName)) require.Equal(t, tt.wantErr, err) }) } } + +func Test_injectKeptnContext(t *testing.T) { + otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) + + tp := sdktrace.NewTracerProvider() + + tracer := tp.Tracer("keptn") + + ctx := keptncontext.WithAppMetadata(context.TODO(), map[string]string{ + "foo": "bar", + }) + ctx, span := tracer.Start(ctx, "my-span") + defer span.End() + + task := &v1beta1.KeptnTask{} + injectKeptnContext(ctx, task) + + require.Equal( + t, map[string]string{ + "foo": "bar", + "traceparent": fmt.Sprintf( + "00-%s-%s-01", + span.SpanContext().TraceID().String(), + span.SpanContext().SpanID().String(), + ), + }, + task.Spec.Context.Metadata, + ) + +} diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go index 292d62684c..8cc3c102a1 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go @@ -206,9 +206,7 @@ func (r *KeptnAppVersionReconciler) setupSpansContexts(ctx context.Context, appV appTraceContextCarrier := propagation.MapCarrier(appVersion.Spec.TraceId) ctxAppTrace := otel.GetTextMapPropagator().Extract(context.TODO(), appTraceContextCarrier) - ctxAppTrace = appcontext.WithAppMetadata(ctxAppTrace, appVersion.Spec.Metadata, map[string]string{ - "traceParent": appVersion.Spec.TraceId["traceparent"], - }) + ctxAppTrace = appcontext.WithAppMetadata(ctxAppTrace, appVersion.Spec.Metadata) endFunc := func() { if appVersion.IsEndTimeSet() { r.Log.Info("Increasing app count") diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller.go index 00a278b537..687fb1b6b0 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller.go @@ -336,6 +336,14 @@ func (r *KeptnWorkloadVersionReconciler) checkPreEvaluationStatusOfApp(ctx conte return true, nil } + // set the App context metadata + if !reflect.DeepEqual(appVersion.Spec.Metadata, workloadVersion.Status.AppContextMetadata) { + workloadVersion.Status.AppContextMetadata = appVersion.Spec.Metadata + if err := r.Status().Update(ctx, workloadVersion); err != nil { + return true, err + } + } + // set the App trace id if not already set if len(workloadVersion.Spec.TraceId) < 1 { appDeploymentTraceID := appVersion.Status.PhaseTraceIDs[apicommon.PhaseAppDeployment.ShortName] @@ -348,14 +356,6 @@ func (r *KeptnWorkloadVersionReconciler) checkPreEvaluationStatusOfApp(ctx conte return true, err } } - - // set the App context metadata - if !reflect.DeepEqual(appVersion.Spec.Metadata, workloadVersion.Status.AppContextMetadata) { - workloadVersion.Status.AppContextMetadata = appVersion.Spec.Metadata - if err := r.Status().Update(ctx, workloadVersion); err != nil { - return true, err - } - } return false, nil } diff --git a/test/integration/imagepullsecret/00-install.yaml b/test/integration/imagepullsecret/00-install.yaml index d21b7677ef..97deb5e9f3 100644 --- a/test/integration/imagepullsecret/00-install.yaml +++ b/test/integration/imagepullsecret/00-install.yaml @@ -5,6 +5,7 @@ metadata: annotations: container: test spec: + ttlSecondsAfterFinished: 1000 container: name: testy-test image: busybox:1.36.1 diff --git a/test/integration/podtato-head-application/00-install.yaml b/test/integration/podtato-head-application/00-install.yaml index 1a3ae638af..338b637c3e 100644 --- a/test/integration/podtato-head-application/00-install.yaml +++ b/test/integration/podtato-head-application/00-install.yaml @@ -90,6 +90,7 @@ spec: keptn.sh/app: podtato-head keptn.sh/workload: podtato-head-hat keptn.sh/version: 0.1.0 + keptn.sh/metadata: "commit-id=1234,stage=dev" spec: terminationGracePeriodSeconds: 5 containers: @@ -137,6 +138,7 @@ spec: keptn.sh/workload: podtato-head-left-leg keptn.sh/version: 0.1.0 keptn.sh/pre-deployment-tasks: check-entry-service + keptn.sh/metadata: "commit-id=1234,stage=dev" spec: terminationGracePeriodSeconds: 5 containers: @@ -184,6 +186,7 @@ spec: keptn.sh/workload: podtato-head-left-arm keptn.sh/version: 0.1.0 keptn.sh/pre-deployment-tasks: check-entry-service + keptn.sh/metadata: "commit-id=1234,stage=dev" spec: terminationGracePeriodSeconds: 5 containers: @@ -231,6 +234,7 @@ spec: keptn.sh/workload: podtato-head-right-leg keptn.sh/version: 0.1.0 keptn.sh/pre-deployment-tasks: check-entry-service + keptn.sh/metadata: "commit-id=1234,stage=dev" spec: terminationGracePeriodSeconds: 5 containers: @@ -278,6 +282,7 @@ spec: keptn.sh/workload: podtato-head-right-arm keptn.sh/version: 0.1.0 keptn.sh/pre-deployment-tasks: check-entry-service + keptn.sh/metadata: "commit-id=1234,stage=dev" spec: terminationGracePeriodSeconds: 5 containers: @@ -311,6 +316,7 @@ kind: KeptnTaskDefinition metadata: name: post-deployment-hello spec: + ttlSecondsAfterFinished: 1000 function: inline: code: | @@ -321,6 +327,7 @@ kind: KeptnTaskDefinition metadata: name: pre-deployment-hello spec: + ttlSecondsAfterFinished: 1000 function: inline: code: | @@ -331,6 +338,7 @@ kind: KeptnTaskDefinition metadata: name: check-entry-service spec: + ttlSecondsAfterFinished: 1000 function: httpRef: url: https://raw.githubusercontent.com/keptn/lifecycle-toolkit/main/runtimes/deno-runtime/samples/ts/http.ts diff --git a/test/integration/simple-deployment-annotated-with-app-context/00-assert.yaml b/test/integration/simple-deployment-annotated-with-app-context/00-assert.yaml new file mode 100644 index 0000000000..fadaaa4a22 --- /dev/null +++ b/test/integration/simple-deployment-annotated-with-app-context/00-assert.yaml @@ -0,0 +1,8 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: test + name: test +status: + readyReplicas: 2 diff --git a/test/integration/simple-deployment-annotated-with-app-context/00-install.yaml b/test/integration/simple-deployment-annotated-with-app-context/00-install.yaml new file mode 100644 index 0000000000..cbfcc8a83f --- /dev/null +++ b/test/integration/simple-deployment-annotated-with-app-context/00-install.yaml @@ -0,0 +1,45 @@ +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnAppContext +metadata: + name: waiter +spec: + metadata: + test-metadata: test-metadata +--- +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnTaskDefinition +metadata: + name: pre-deployment-hello +spec: + ttlSecondsAfterFinished: 1000 + function: + inline: + code: | + console.log("Pre-Deployment Task has been executed"); +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app: test + name: test + annotations: + keptn.sh/workload: waiter + keptn.sh/version: "0.4" + keptn.sh/pre-deployment-tasks: pre-deployment-hello + keptn.sh/metadata: "commit-id=1234,stage=dev" +spec: + replicas: 2 + selector: + matchLabels: + app: test + strategy: {} + template: + metadata: + labels: + app: test + spec: + containers: + - image: busybox + name: busybox + command: ['sh', '-c', 'echo The app is running! && sleep infinity'] diff --git a/test/integration/simple-deployment-annotated-with-app-context/00-teststep.yaml b/test/integration/simple-deployment-annotated-with-app-context/00-teststep.yaml new file mode 100644 index 0000000000..ad4f1d95d5 --- /dev/null +++ b/test/integration/simple-deployment-annotated-with-app-context/00-teststep.yaml @@ -0,0 +1,4 @@ +apiVersion: kuttl.dev/v1 +kind: TestStep +commands: + - script: kubectl annotate ns $NAMESPACE keptn.sh/lifecycle-toolkit='enabled' diff --git a/test/integration/simple-deployment-annotated-with-app-context/01-assert.yaml b/test/integration/simple-deployment-annotated-with-app-context/01-assert.yaml new file mode 100644 index 0000000000..016fbb3c4f --- /dev/null +++ b/test/integration/simple-deployment-annotated-with-app-context/01-assert.yaml @@ -0,0 +1,41 @@ +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnWorkload +metadata: + name: waiter-waiter +spec: + metadata: + commit-id: "1234" + stage: dev +--- +apiVersion: lifecycle.keptn.sh/v1beta1 +kind: KeptnWorkloadVersion +metadata: + name: waiter-waiter-0.4 +spec: + metadata: + commit-id: "1234" + stage: dev +status: + currentPhase: Completed + deploymentStatus: Succeeded + postDeploymentEvaluationStatus: Succeeded + postDeploymentStatus: Succeeded + preDeploymentEvaluationStatus: Succeeded + preDeploymentStatus: Succeeded + preDeploymentTaskStatus: + - status: Succeeded + definitionName: pre-deployment-hello +--- +apiVersion: batch/v1 +kind: Job +spec: + template: + spec: + containers: + - env: + - name: KEPTN_CONTEXT + # yamllint disable-line rule:line-length + value: '{"workloadName":"waiter-waiter","appName":"waiter","appVersion":"","workloadVersion":"0.4","taskType":"pre","objectType":"Workload","metadata":{"commit-id":"1234","stage":"dev","test-metadata":"test-metadata"}}' + - name: CMD_ARGS + - name: SCRIPT + value: /var/data/function.ts diff --git a/test/integration/simple-deployment-annotated/00-install.yaml b/test/integration/simple-deployment-annotated/00-install.yaml index 796a1530f3..1af5317990 100644 --- a/test/integration/simple-deployment-annotated/00-install.yaml +++ b/test/integration/simple-deployment-annotated/00-install.yaml @@ -36,7 +36,3 @@ spec: - image: busybox name: busybox command: ['sh', '-c', 'echo The app is running! && sleep infinity'] - initContainers: - - name: init-myservice - image: busybox:1.36.1 - command: ['sh', '-c', 'sleep 30'] diff --git a/test/integration/simple-deployment-evaluation/00-install.yaml b/test/integration/simple-deployment-evaluation/00-install.yaml index 84a2070736..58b4bc6dbf 100644 --- a/test/integration/simple-deployment-evaluation/00-install.yaml +++ b/test/integration/simple-deployment-evaluation/00-install.yaml @@ -54,7 +54,3 @@ spec: - image: busybox name: busybox command: ['sh', '-c', 'echo The app is running! && sleep infinity'] - initContainers: - - name: init-myservice - image: busybox:1.36.1 - command: ['sh', '-c', 'sleep 10'] diff --git a/test/integration/simple-deployment-k8s-recommended-label/00-install.yaml b/test/integration/simple-deployment-k8s-recommended-label/00-install.yaml index d5ac7f6b42..0b9f5537a2 100644 --- a/test/integration/simple-deployment-k8s-recommended-label/00-install.yaml +++ b/test/integration/simple-deployment-k8s-recommended-label/00-install.yaml @@ -23,7 +23,3 @@ spec: - image: busybox name: busybox command: ['sh', '-c', 'echo The app is running! && sleep infinity'] - initContainers: - - name: init-myservice - image: busybox:1.36.1 - command: ['sh', '-c', 'sleep 30'] diff --git a/test/integration/simple-deployment-python-runtime/00-install.yaml b/test/integration/simple-deployment-python-runtime/00-install.yaml index 47e3eca9f0..026d1ff0c9 100644 --- a/test/integration/simple-deployment-python-runtime/00-install.yaml +++ b/test/integration/simple-deployment-python-runtime/00-install.yaml @@ -13,6 +13,7 @@ metadata: annotations: python: test spec: + ttlSecondsAfterFinished: 500 python: parameters: map: diff --git a/test/integration/simple-deployment-recursive-task/00-install.yaml b/test/integration/simple-deployment-recursive-task/00-install.yaml index e986138133..c23fed77d5 100644 --- a/test/integration/simple-deployment-recursive-task/00-install.yaml +++ b/test/integration/simple-deployment-recursive-task/00-install.yaml @@ -10,7 +10,10 @@ apiVersion: lifecycle.keptn.sh/v1beta1 kind: KeptnTaskDefinition metadata: name: pre-deployment-hello + labels: + task-definition: "child" spec: + ttlSecondsAfterFinished: 1000 function: functionRef: name: pre-deployment-parent @@ -25,7 +28,10 @@ apiVersion: lifecycle.keptn.sh/v1beta1 kind: KeptnTaskDefinition metadata: name: pre-deployment-parent + labels: + task-definition: "parent" spec: + ttlSecondsAfterFinished: 300 function: parameters: map: @@ -66,7 +72,3 @@ spec: - image: busybox name: busybox command: ['sh', '-c', 'echo The app is running! && sleep infinity'] - initContainers: - - name: init-myservice - image: busybox:1.36.1 - command: ['sh', '-c', 'sleep 30'] diff --git a/test/integration/simple-deployment-recursive-task/01-assert.yaml b/test/integration/simple-deployment-recursive-task/01-assert.yaml index 12c869f335..14e37ba348 100644 --- a/test/integration/simple-deployment-recursive-task/01-assert.yaml +++ b/test/integration/simple-deployment-recursive-task/01-assert.yaml @@ -6,6 +6,8 @@ metadata: keptn.sh/app: waiter keptn.sh/version: "0.4" keptn.sh/workload: waiter-waiter + labels: + task-definition: "parent" spec: template: spec: @@ -36,6 +38,8 @@ metadata: keptn.sh/app: waiter keptn.sh/version: "0.4" keptn.sh/workload: waiter-waiter + labels: + task-definition: "child" ownerReferences: - apiVersion: lifecycle.keptn.sh/v1beta1 blockOwnerDeletion: true diff --git a/test/integration/simple-deployment-sanitize-version-number/00-install.yaml b/test/integration/simple-deployment-sanitize-version-number/00-install.yaml index 316f7a6e4b..f239412cdf 100644 --- a/test/integration/simple-deployment-sanitize-version-number/00-install.yaml +++ b/test/integration/simple-deployment-sanitize-version-number/00-install.yaml @@ -34,7 +34,3 @@ spec: - image: busybox name: busybox command: ['sh', '-c', 'echo The app is running! && sleep infinity'] - initContainers: - - name: init-myservice - image: busybox:1.36.1 - command: ['sh', '-c', 'sleep 30'] diff --git a/test/integration/simple-deployment/00-install.yaml b/test/integration/simple-deployment/00-install.yaml index 980242fc82..bc9ac36778 100644 --- a/test/integration/simple-deployment/00-install.yaml +++ b/test/integration/simple-deployment/00-install.yaml @@ -34,7 +34,3 @@ spec: - image: busybox name: busybox command: ['sh', '-c', 'echo The app is running! && sleep infinity'] - initContainers: - - name: init-myservice - image: busybox:1.36.1 - command: ['sh', '-c', 'sleep 30'] diff --git a/test/integration/simple-statefulset-annotated/00-install.yaml b/test/integration/simple-statefulset-annotated/00-install.yaml index 578c048ef1..f759c56d23 100644 --- a/test/integration/simple-statefulset-annotated/00-install.yaml +++ b/test/integration/simple-statefulset-annotated/00-install.yaml @@ -39,7 +39,3 @@ spec: - image: busybox name: busybox command: ['sh', '-c', 'echo The app is running! && sleep infinity'] - initContainers: - - name: init-myservice - image: busybox:1.36.1 - command: ['sh', '-c', 'sleep 30'] diff --git a/test/integration/simple-statefulset-annotated/02-install.yaml b/test/integration/simple-statefulset-annotated/02-install.yaml index 566928e835..56ff99e782 100644 --- a/test/integration/simple-statefulset-annotated/02-install.yaml +++ b/test/integration/simple-statefulset-annotated/02-install.yaml @@ -25,7 +25,3 @@ spec: - image: busybox name: busybox command: ['sh', '-c', 'echo The app is running! && sleep infinity'] - initContainers: - - name: init-myservice - image: busybox:1.36.1 - command: ['sh', '-c', 'sleep 30'] diff --git a/test/integration/simple-task/00-assert.yaml b/test/integration/simple-task/00-assert.yaml index 9fc76e2d5e..29dbe33eda 100644 --- a/test/integration/simple-task/00-assert.yaml +++ b/test/integration/simple-task/00-assert.yaml @@ -9,10 +9,11 @@ spec: containers: - env: - name: KEPTN_CONTEXT - value: '{"workloadName":"workload","appName":"podtato-head","appVersion":"1.0.0","workloadVersion":"0.1.0","taskType":"","objectType":""}' + # yamllint disable-line rule:line-length + value: '{"workloadName":"workload","appName":"podtato-head","appVersion":"1.0.0","workloadVersion":"0.1.0","taskType":"","objectType":"","metadata":{"commit-id":"1234"}}' - name: CMD_ARGS - name: SCRIPT value: /var/data/function.ts imagePullPolicy: IfNotPresent name: keptn-function-runner - ttlSecondsAfterFinished: 300 + ttlSecondsAfterFinished: 1000 diff --git a/test/integration/simple-task/00-install.yaml b/test/integration/simple-task/00-install.yaml index 01ee26904c..421a45cd6b 100644 --- a/test/integration/simple-task/00-install.yaml +++ b/test/integration/simple-task/00-install.yaml @@ -3,6 +3,7 @@ kind: KeptnTaskDefinition metadata: name: pre-deployment-hello spec: + ttlSecondsAfterFinished: 1000 function: inline: code: | @@ -23,3 +24,5 @@ spec: taskType: "" workloadName: "workload" workloadVersion: "0.1.0" + metadata: + commit-id: "1234"