diff --git a/.github/actions/spelling/expect.txt b/.github/actions/spelling/expect.txt index fb6daf6add..599cbc576c 100644 --- a/.github/actions/spelling/expect.txt +++ b/.github/actions/spelling/expect.txt @@ -657,3 +657,4 @@ yannh yml YOURNAME yourregistry +opentracing diff --git a/.github/scripts/.helm-tests/default/result.yaml b/.github/scripts/.helm-tests/default/result.yaml index 8a18ab1b4c..ea831ca91f 100644 --- a/.github/scripts/.helm-tests/default/result.yaml +++ b/.github/scripts/.helm-tests/default/result.yaml @@ -575,9 +575,9 @@ spec: items: type: string type: array - traceLinks: + spanLinks: description: |- - TraceLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. + 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 items: type: string @@ -1642,6 +1642,12 @@ spec: appName: description: AppName is the name of the KeptnApp. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for contextual + information. + type: object postDeploymentEvaluations: description: |- PostDeploymentEvaluations is a list of all evaluations to be performed @@ -1687,6 +1693,13 @@ spec: This can be used for restarting a KeptnApp which failed to deploy, e.g. due to a failed preDeploymentEvaluation/preDeploymentTask. type: integer + spanLinks: + description: |- + 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 + items: + type: string + type: array traceId: additionalProperties: type: string diff --git a/.github/scripts/.helm-tests/lifecycle-only/result.yaml b/.github/scripts/.helm-tests/lifecycle-only/result.yaml index 63be58164c..7dc4389af9 100644 --- a/.github/scripts/.helm-tests/lifecycle-only/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-only/result.yaml @@ -521,9 +521,9 @@ spec: items: type: string type: array - traceLinks: + spanLinks: description: |- - TraceLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. + 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 items: type: string @@ -1588,6 +1588,12 @@ spec: appName: description: AppName is the name of the KeptnApp. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for contextual + information. + type: object postDeploymentEvaluations: description: |- PostDeploymentEvaluations is a list of all evaluations to be performed @@ -1633,6 +1639,13 @@ spec: This can be used for restarting a KeptnApp which failed to deploy, e.g. due to a failed preDeploymentEvaluation/preDeploymentTask. type: integer + spanLinks: + description: |- + 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 + items: + type: string + type: array traceId: additionalProperties: type: string diff --git a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml index 75b43a0a7a..4ad828406b 100644 --- a/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml +++ b/.github/scripts/.helm-tests/lifecycle-with-certs/result.yaml @@ -547,9 +547,9 @@ spec: items: type: string type: array - traceLinks: + spanLinks: description: |- - TraceLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. + 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 items: type: string @@ -1616,6 +1616,12 @@ spec: appName: description: AppName is the name of the KeptnApp. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for contextual + information. + type: object postDeploymentEvaluations: description: |- PostDeploymentEvaluations is a list of all evaluations to be performed @@ -1661,6 +1667,13 @@ spec: This can be used for restarting a KeptnApp which failed to deploy, e.g. due to a failed preDeploymentEvaluation/preDeploymentTask. type: integer + spanLinks: + description: |- + 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 + items: + type: string + type: array traceId: additionalProperties: type: string diff --git a/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md b/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md index bf4d164f1c..384eaf437d 100644 --- a/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md +++ b/docs/docs/reference/api-reference/lifecycle/v1beta1/index.md @@ -244,6 +244,7 @@ KeptnAppContextSpec defines the desired state of KeptnAppContext _Appears in:_ - [KeptnAppContext](#keptnappcontext) +- [KeptnAppVersionSpec](#keptnappversionspec) | Field | Description | Default | Optional | | --- | --- | --- | --- | @@ -252,7 +253,7 @@ _Appears in:_ | `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 | | `metadata` _object (keys:string, values:string)_ | Refer to Kubernetes API documentation for fields of `metadata`. || ✓ | -| `traceLinks` _string array_ | TraceLinks 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 || ✓ | +| `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 || ✓ | #### KeptnAppContextStatus @@ -413,6 +414,8 @@ _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 | +| `metadata` _object (keys:string, values:string)_ | Refer to Kubernetes API documentation for fields of `metadata`. || ✓ | +| `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 | | `revision` _integer_ | Revision can be modified to trigger another deployment of a KeptnApp of the same version. This can be used for restarting a KeptnApp which failed to deploy, e.g. due to a failed preDeploymentEvaluation/preDeploymentTask. |1| ✓ | | `workloads` _[KeptnWorkloadRef](#keptnworkloadref) array_ | Workloads is a list of all KeptnWorkloads that are part of the KeptnApp. || ✓ | diff --git a/lifecycle-operator/apis/lifecycle/v1alpha1/keptnappversion_conversion_test.go b/lifecycle-operator/apis/lifecycle/v1alpha1/keptnappversion_conversion_test.go index 2134aef355..bcdff0b162 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha1/keptnappversion_conversion_test.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha1/keptnappversion_conversion_test.go @@ -52,18 +52,20 @@ func TestKeptnAppVersion_ConvertFrom(t *testing.T) { }, }, }, - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{ - "some-pre-deployment-task1", - }, - PostDeploymentTasks: []string{ - "some-post-deployment-task2", - }, - PreDeploymentEvaluations: []string{ - "some-pre-evaluation-task1", - }, - PostDeploymentEvaluations: []string{ - "some-pre-evaluation-task2", + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{ + "some-pre-deployment-task1", + }, + PostDeploymentTasks: []string{ + "some-post-deployment-task2", + }, + PreDeploymentEvaluations: []string{ + "some-pre-evaluation-task1", + }, + PostDeploymentEvaluations: []string{ + "some-pre-evaluation-task2", + }, }, }, AppName: "app", @@ -474,18 +476,20 @@ func TestKeptnAppVersion_ConvertTo(t *testing.T) { }, }, }, - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{ - "some-pre-deployment-task1", - }, - PostDeploymentTasks: []string{ - "some-post-deployment-task2", - }, - PreDeploymentEvaluations: []string{ - "some-pre-evaluation-task1", - }, - PostDeploymentEvaluations: []string{ - "some-pre-evaluation-task2", + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{ + "some-pre-deployment-task1", + }, + PostDeploymentTasks: []string{ + "some-post-deployment-task2", + }, + PreDeploymentEvaluations: []string{ + "some-pre-evaluation-task1", + }, + PostDeploymentEvaluations: []string{ + "some-pre-evaluation-task2", + }, }, }, AppName: "app", diff --git a/lifecycle-operator/apis/lifecycle/v1alpha2/keptnappversion_conversion_test.go b/lifecycle-operator/apis/lifecycle/v1alpha2/keptnappversion_conversion_test.go index 54eaf92329..93a4ea6282 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha2/keptnappversion_conversion_test.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha2/keptnappversion_conversion_test.go @@ -52,18 +52,20 @@ func TestKeptnAppVersion_ConvertFrom(t *testing.T) { }, }, }, - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{ - "some-pre-deployment-task1", - }, - PostDeploymentTasks: []string{ - "some-post-deployment-task2", - }, - PreDeploymentEvaluations: []string{ - "some-pre-evaluation-task1", - }, - PostDeploymentEvaluations: []string{ - "some-pre-evaluation-task2", + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{ + "some-pre-deployment-task1", + }, + PostDeploymentTasks: []string{ + "some-post-deployment-task2", + }, + PreDeploymentEvaluations: []string{ + "some-pre-evaluation-task1", + }, + PostDeploymentEvaluations: []string{ + "some-pre-evaluation-task2", + }, }, }, AppName: "app", @@ -474,18 +476,20 @@ func TestKeptnAppVersion_ConvertTo(t *testing.T) { }, }, }, - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{ - "some-pre-deployment-task1", - }, - PostDeploymentTasks: []string{ - "some-post-deployment-task2", - }, - PreDeploymentEvaluations: []string{ - "some-pre-evaluation-task1", - }, - PostDeploymentEvaluations: []string{ - "some-pre-evaluation-task2", + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{ + "some-pre-deployment-task1", + }, + PostDeploymentTasks: []string{ + "some-post-deployment-task2", + }, + PreDeploymentEvaluations: []string{ + "some-pre-evaluation-task1", + }, + PostDeploymentEvaluations: []string{ + "some-pre-evaluation-task2", + }, }, }, AppName: "app", diff --git a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_conversion_test.go b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_conversion_test.go index 71eac0a232..cb897f329b 100644 --- a/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_conversion_test.go +++ b/lifecycle-operator/apis/lifecycle/v1alpha3/keptnappversion_conversion_test.go @@ -52,18 +52,20 @@ func TestKeptnAppVersion_ConvertFrom(t *testing.T) { }, }, }, - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{ - "some-pre-deployment-task1", - }, - PostDeploymentTasks: []string{ - "some-post-deployment-task2", - }, - PreDeploymentEvaluations: []string{ - "some-pre-evaluation-task1", - }, - PostDeploymentEvaluations: []string{ - "some-pre-evaluation-task2", + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{ + "some-pre-deployment-task1", + }, + PostDeploymentTasks: []string{ + "some-post-deployment-task2", + }, + PreDeploymentEvaluations: []string{ + "some-pre-evaluation-task1", + }, + PostDeploymentEvaluations: []string{ + "some-pre-evaluation-task2", + }, }, }, AppName: "app", @@ -476,18 +478,20 @@ func TestKeptnAppVersion_ConvertTo(t *testing.T) { }, }, }, - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{ - "some-pre-deployment-task1", - }, - PostDeploymentTasks: []string{ - "some-post-deployment-task2", - }, - PreDeploymentEvaluations: []string{ - "some-pre-evaluation-task1", - }, - PostDeploymentEvaluations: []string{ - "some-pre-evaluation-task2", + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{ + "some-pre-deployment-task1", + }, + PostDeploymentTasks: []string{ + "some-post-deployment-task2", + }, + PreDeploymentEvaluations: []string{ + "some-pre-evaluation-task1", + }, + PostDeploymentEvaluations: []string{ + "some-pre-evaluation-task2", + }, }, }, AppName: "app", diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappcontext_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappcontext_types.go index 09ca90c133..2e701c0f22 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappcontext_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappcontext_types.go @@ -50,9 +50,9 @@ type KeptnAppContextSpec struct { Metadata map[string]string `json:"metadata,omitempty"` // +optional - // TraceLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. + // 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 - TraceLinks []string `json:"traceLinks,omitempty"` + SpanLinks []string `json:"spanLinks,omitempty"` } // KeptnAppContextStatus defines the observed state of KeptnAppContext diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go index 8b84c5ec79..4896902cff 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types.go @@ -30,8 +30,8 @@ import ( // KeptnAppVersionSpec defines the desired state of KeptnAppVersion type KeptnAppVersionSpec struct { - DeploymentTaskSpec `json:",inline"` - KeptnAppSpec `json:",inline"` + KeptnAppContextSpec `json:",inline"` + KeptnAppSpec `json:",inline"` // AppName is the name of the KeptnApp. AppName string `json:"appName"` // PreviousVersion is the version of the KeptnApp that has been deployed prior to this version. diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go index a94d8a2f79..f098ff481b 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/keptnappversion_types_test.go @@ -59,11 +59,13 @@ func TestKeptnAppVersion(t *testing.T) { KeptnAppSpec: KeptnAppSpec{ Version: "version", }, - DeploymentTaskSpec: DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task1", "task2"}, - PostDeploymentTasks: []string{"task3", "task4"}, - PreDeploymentEvaluations: []string{"task5", "task6"}, - PostDeploymentEvaluations: []string{"task7", "task8"}, + KeptnAppContextSpec: KeptnAppContextSpec{ + DeploymentTaskSpec: DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task1", "task2"}, + PostDeploymentTasks: []string{"task3", "task4"}, + PreDeploymentEvaluations: []string{"task5", "task6"}, + PostDeploymentEvaluations: []string{"task7", "task8"}, + }, }, PreviousVersion: "prev", AppName: "appname", diff --git a/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go b/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go index a69c4081ba..8e73cc4c32 100644 --- a/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go +++ b/lifecycle-operator/apis/lifecycle/v1beta1/zz_generated.deepcopy.go @@ -306,8 +306,8 @@ func (in *KeptnAppContextSpec) DeepCopyInto(out *KeptnAppContextSpec) { (*out)[key] = val } } - if in.TraceLinks != nil { - in, out := &in.TraceLinks, &out.TraceLinks + if in.SpanLinks != nil { + in, out := &in.SpanLinks, &out.SpanLinks *out = make([]string, len(*in)) copy(*out, *in) } @@ -540,7 +540,7 @@ func (in *KeptnAppVersionList) DeepCopyObject() runtime.Object { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *KeptnAppVersionSpec) DeepCopyInto(out *KeptnAppVersionSpec) { *out = *in - in.DeploymentTaskSpec.DeepCopyInto(&out.DeploymentTaskSpec) + in.KeptnAppContextSpec.DeepCopyInto(&out.KeptnAppContextSpec) in.KeptnAppSpec.DeepCopyInto(&out.KeptnAppSpec) if in.TraceId != nil { in, out := &in.TraceId, &out.TraceId diff --git a/lifecycle-operator/chart/templates/keptnappcontext-crd.yaml b/lifecycle-operator/chart/templates/keptnappcontext-crd.yaml index a47fc5a777..e38cc4cc15 100644 --- a/lifecycle-operator/chart/templates/keptnappcontext-crd.yaml +++ b/lifecycle-operator/chart/templates/keptnappcontext-crd.yaml @@ -85,9 +85,9 @@ spec: items: type: string type: array - traceLinks: + spanLinks: description: |- - TraceLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. + 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 items: type: string diff --git a/lifecycle-operator/chart/templates/keptnappversion-crd.yaml b/lifecycle-operator/chart/templates/keptnappversion-crd.yaml index bdf771b1a9..b2e8598e2b 100644 --- a/lifecycle-operator/chart/templates/keptnappversion-crd.yaml +++ b/lifecycle-operator/chart/templates/keptnappversion-crd.yaml @@ -933,6 +933,12 @@ spec: appName: description: AppName is the name of the KeptnApp. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for contextual + information. + type: object postDeploymentEvaluations: description: |- PostDeploymentEvaluations is a list of all evaluations to be performed @@ -978,6 +984,13 @@ spec: This can be used for restarting a KeptnApp which failed to deploy, e.g. due to a failed preDeploymentEvaluation/preDeploymentTask. type: integer + spanLinks: + description: |- + 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 + items: + type: string + type: array traceId: additionalProperties: type: string 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 42a2244bad..9802f30931 100644 --- a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappcontexts.yaml +++ b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappcontexts.yaml @@ -79,9 +79,9 @@ spec: items: type: string type: array - traceLinks: + spanLinks: description: |- - TraceLinks are links to OpenTelemetry span IDs for tracking. These links establish relationships between spans across different services, enabling distributed tracing. + 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 items: type: string 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 ce77ab5ac1..e098455297 100644 --- a/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappversions.yaml +++ b/lifecycle-operator/config/crd/bases/lifecycle.keptn.sh_keptnappversions.yaml @@ -915,6 +915,12 @@ spec: appName: description: AppName is the name of the KeptnApp. type: string + metadata: + additionalProperties: + type: string + description: Metadata contains additional key-value pairs for contextual + information. + type: object postDeploymentEvaluations: description: |- PostDeploymentEvaluations is a list of all evaluations to be performed @@ -960,6 +966,13 @@ spec: This can be used for restarting a KeptnApp which failed to deploy, e.g. due to a failed preDeploymentEvaluation/preDeploymentTask. type: integer + spanLinks: + description: |- + 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 + items: + type: string + type: array traceId: additionalProperties: type: string diff --git a/lifecycle-operator/controllers/common/evaluation/handler_test.go b/lifecycle-operator/controllers/common/evaluation/handler_test.go index 7f626b11ab..d8cb0fe2ce 100644 --- a/lifecycle-operator/controllers/common/evaluation/handler_test.go +++ b/lifecycle-operator/controllers/common/evaluation/handler_test.go @@ -71,8 +71,10 @@ func TestEvaluationHandler(t *testing.T) { name: "evaluation not started", object: &v1beta1.KeptnAppVersion{ Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentEvaluations: []string{"eval-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentEvaluations: []string{"eval-def"}, + }, }, }, }, @@ -102,8 +104,10 @@ func TestEvaluationHandler(t *testing.T) { name: "already done evaluation", object: &v1beta1.KeptnAppVersion{ Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentEvaluations: []string{"eval-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentEvaluations: []string{"eval-def"}, + }, }, }, Status: v1beta1.KeptnAppVersionStatus{ @@ -146,8 +150,10 @@ func TestEvaluationHandler(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentEvaluations: []string{"eval-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentEvaluations: []string{"eval-def"}, + }, }, }, Status: v1beta1.KeptnAppVersionStatus{ @@ -208,8 +214,10 @@ func TestEvaluationHandler(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentEvaluations: []string{"eval-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentEvaluations: []string{"eval-def"}, + }, }, }, Status: v1beta1.KeptnAppVersionStatus{ @@ -260,7 +268,7 @@ func TestEvaluationHandler(t *testing.T) { err := v1beta1.AddToScheme(scheme.Scheme) require.Nil(t, err) spanHandlerMock := telemetryfake.ISpanHandlerMock{ - GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) { + GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) { return context.TODO(), trace.SpanFromContext(context.TODO()), nil }, UnbindSpanFunc: func(reconcileObject client.Object, phase string) error { @@ -325,8 +333,10 @@ func TestEvaluationHandler_createEvaluation(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentEvaluations: []string{"eval-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentEvaluations: []string{"eval-def"}, + }, }, }, }, diff --git a/lifecycle-operator/controllers/common/task/handler_test.go b/lifecycle-operator/controllers/common/task/handler_test.go index 38a03f1bef..c8144b5694 100644 --- a/lifecycle-operator/controllers/common/task/handler_test.go +++ b/lifecycle-operator/controllers/common/task/handler_test.go @@ -71,8 +71,10 @@ func TestTaskHandler(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task-def"}, + }, }, }, }, @@ -99,8 +101,10 @@ func TestTaskHandler(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task-def", "other-task-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task-def", "other-task-def"}, + }, }, }, }, @@ -139,8 +143,10 @@ func TestTaskHandler(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task-def"}, + }, }, }, }, @@ -179,8 +185,10 @@ func TestTaskHandler(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task-def"}, + }, }, }, }, @@ -216,8 +224,10 @@ func TestTaskHandler(t *testing.T) { name: "already done task", object: &v1beta1.KeptnAppVersion{ Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task-def"}, + }, }, }, Status: v1beta1.KeptnAppVersionStatus{ @@ -260,8 +270,10 @@ func TestTaskHandler(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task-def"}, + }, }, }, Status: v1beta1.KeptnAppVersionStatus{ @@ -312,8 +324,10 @@ func TestTaskHandler(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task-def"}, + }, }, }, Status: v1beta1.KeptnAppVersionStatus{ @@ -365,7 +379,7 @@ func TestTaskHandler(t *testing.T) { err := v1beta1.AddToScheme(scheme.Scheme) require.Nil(t, err) spanHandlerMock := telemetryfake.ISpanHandlerMock{ - GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) { + GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) { return context.TODO(), trace.SpanFromContext(context.TODO()), nil }, UnbindSpanFunc: func(reconcileObject client.Object, phase string) error { @@ -424,8 +438,10 @@ func TestTaskHandler_createTask(t *testing.T) { Namespace: "namespace", }, Spec: v1beta1.KeptnAppVersionSpec{ - DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{"task-def"}, + KeptnAppContextSpec: v1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: v1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{"task-def"}, + }, }, }, }, diff --git a/lifecycle-operator/controllers/common/telemetry/fake/spanhandler_mock.go b/lifecycle-operator/controllers/common/telemetry/fake/spanhandler_mock.go index 5f9773de26..8b6ad0bc41 100644 --- a/lifecycle-operator/controllers/common/telemetry/fake/spanhandler_mock.go +++ b/lifecycle-operator/controllers/common/telemetry/fake/spanhandler_mock.go @@ -17,7 +17,7 @@ import ( // // // make and configure a mocked telemetry.ISpanHandler // mockedISpanHandler := &ISpanHandlerMock{ -// GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) { +// GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) { // panic("mock out the GetSpan method") // }, // UnbindSpanFunc: func(reconcileObject client.Object, phase string) error { @@ -31,7 +31,7 @@ import ( // } type ISpanHandlerMock struct { // GetSpanFunc mocks the GetSpan method. - GetSpanFunc func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) + GetSpanFunc func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) // UnbindSpanFunc mocks the UnbindSpan method. UnbindSpanFunc func(reconcileObject client.Object, phase string) error @@ -48,6 +48,8 @@ type ISpanHandlerMock struct { ReconcileObject client.Object // Phase is the phase argument value. Phase string + // Links is the links argument value. + Links []trace.Link } // UnbindSpan holds details about calls to the UnbindSpan method. UnbindSpan []struct { @@ -62,7 +64,7 @@ type ISpanHandlerMock struct { } // GetSpan calls GetSpanFunc. -func (mock *ISpanHandlerMock) GetSpan(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) { +func (mock *ISpanHandlerMock) GetSpan(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) { if mock.GetSpanFunc == nil { panic("ISpanHandlerMock.GetSpanFunc: method is nil but ISpanHandler.GetSpan was just called") } @@ -71,16 +73,18 @@ func (mock *ISpanHandlerMock) GetSpan(ctx context.Context, tracer telemetry.ITra Tracer telemetry.ITracer ReconcileObject client.Object Phase string + Links []trace.Link }{ Ctx: ctx, Tracer: tracer, ReconcileObject: reconcileObject, Phase: phase, + Links: links, } mock.lockGetSpan.Lock() mock.calls.GetSpan = append(mock.calls.GetSpan, callInfo) mock.lockGetSpan.Unlock() - return mock.GetSpanFunc(ctx, tracer, reconcileObject, phase) + return mock.GetSpanFunc(ctx, tracer, reconcileObject, phase, links...) } // GetSpanCalls gets all the calls that were made to GetSpan. @@ -92,12 +96,14 @@ func (mock *ISpanHandlerMock) GetSpanCalls() []struct { Tracer telemetry.ITracer ReconcileObject client.Object Phase string + Links []trace.Link } { var calls []struct { Ctx context.Context Tracer telemetry.ITracer ReconcileObject client.Object Phase string + Links []trace.Link } mock.lockGetSpan.RLock() calls = mock.calls.GetSpan diff --git a/lifecycle-operator/controllers/common/telemetry/spanhandler.go b/lifecycle-operator/controllers/common/telemetry/spanhandler.go index 9be63c4fd8..6972c96f79 100644 --- a/lifecycle-operator/controllers/common/telemetry/spanhandler.go +++ b/lifecycle-operator/controllers/common/telemetry/spanhandler.go @@ -15,7 +15,7 @@ import ( //go:generate moq -pkg fake -skip-ensure -out ./fake/spanhandler_mock.go . ISpanHandler type ISpanHandler interface { - GetSpan(ctx context.Context, tracer ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) + GetSpan(ctx context.Context, tracer ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) UnbindSpan(reconcileObject client.Object, phase string) error } @@ -29,7 +29,7 @@ type Handler struct { mtx sync.Mutex } -func (r *Handler) GetSpan(ctx context.Context, tracer ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) { +func (r *Handler) GetSpan(ctx context.Context, tracer ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) { piWrapper, err := interfaces.NewSpanItemWrapperFromClientObject(reconcileObject) if err != nil { return nil, nil, err @@ -44,7 +44,12 @@ func (r *Handler) GetSpan(ctx context.Context, tracer ITracer, reconcileObject c return span.Ctx, span.Span, nil } spanName := piWrapper.GetSpanName(phase) - childCtx, span := tracer.Start(ctx, spanName, trace.WithSpanKind(trace.SpanKindConsumer)) + childCtx, span := tracer.Start( + ctx, + spanName, + trace.WithSpanKind(trace.SpanKindConsumer), + trace.WithLinks(links...), + ) piWrapper.SetSpanAttributes(span) // also get attributes from context diff --git a/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go b/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go index f937d4b25c..cdb49d18e3 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnapp/controller.go @@ -143,7 +143,7 @@ func (r *KeptnAppReconciler) createAppVersion(ctx context.Context, app *klcv1bet appVersion := app.GenerateAppVersion(previousVersion) - appVersion.Spec.DeploymentTaskSpec = appContext.Spec.DeploymentTaskSpec + appVersion.Spec.KeptnAppContextSpec = appContext.Spec err := controllerutil.SetControllerReference(app, &appVersion, r.Scheme) if err != nil { diff --git a/lifecycle-operator/controllers/lifecycle/keptnapp/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnapp/controller_test.go index d82792dd45..ac639ddfe3 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnapp/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnapp/controller_test.go @@ -6,6 +6,7 @@ import ( "reflect" "testing" + "github.com/keptn/lifecycle-toolkit/lifecycle-operator/apis/lifecycle/v1beta1" lfcv1beta1 "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/eventsender" @@ -58,6 +59,12 @@ func TestKeptnAppReconciler_createAppVersionSuccess(t *testing.T) { "some-pre-evaluation-task2", }, }, + Metadata: map[string]string{ + "test1": "test2", + }, + SpanLinks: []string{ + "spanlink1", + }, }, Status: lfcv1beta1.KeptnAppContextStatus{}, } @@ -68,8 +75,14 @@ func TestKeptnAppReconciler_createAppVersionSuccess(t *testing.T) { t.Errorf("Error Creating appVersion: %s", err.Error()) } t.Log("Verifying created app") - assert.Equal(t, appVersion.Namespace, app.Namespace) - assert.Equal(t, appVersion.Name, fmt.Sprintf("%s-%s-%s", app.Name, app.Spec.Version, apicommon.Hash(app.Generation))) + require.Equal(t, appVersion.Namespace, app.Namespace) + require.Equal(t, appVersion.Name, fmt.Sprintf("%s-%s-%s", app.Name, app.Spec.Version, apicommon.Hash(app.Generation))) + require.Equal(t, v1beta1.KeptnAppVersionSpec{ + KeptnAppContextSpec: appContext.Spec, + KeptnAppSpec: app.Spec, + AppName: app.Name, + PreviousVersion: "", + }, appVersion.Spec) } func TestKeptnAppReconciler_createAppVersionWithLongName(t *testing.T) { diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go index a4a85ea668..2e4801bb20 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller.go @@ -31,6 +31,7 @@ import ( "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/telemetry" controllererrors "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/errors" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/codes" "go.opentelemetry.io/otel/metric" "go.opentelemetry.io/otel/propagation" @@ -94,7 +95,13 @@ func (r *KeptnAppVersionReconciler) Reconcile(ctx context.Context, req ctrl.Requ currentPhase := apicommon.PhaseAppPreDeployment - ctxAppTrace, spanAppTrace, err := r.SpanHandler.GetSpan(ctxAppTrace, r.getTracer(), appVersion, "") + ctxAppTrace, spanAppTrace, err := r.SpanHandler.GetSpan( + ctxAppTrace, + r.getTracer(), + appVersion, + "", + r.getLinkedSpans(appVersion)..., + ) if err != nil { r.Log.Error(err, "could not get span") } @@ -220,3 +227,26 @@ func (r *KeptnAppVersionReconciler) SetupWithManager(mgr ctrl.Manager) error { func (r *KeptnAppVersionReconciler) getTracer() telemetry.ITracer { return r.TracerFactory.GetTracer(traceComponentName) } + +func (r *KeptnAppVersionReconciler) getLinkedSpans(appVersion *klcv1beta1.KeptnAppVersion) []trace.Link { + result := make([]trace.Link, len(appVersion.Spec.SpanLinks)) + + for i, linkedSpan := range appVersion.Spec.SpanLinks { + r.Log.Info("Adding Link to span", "linkedSpan", linkedSpan) + + traceContextCarrier := propagation.MapCarrier(map[string]string{ + "traceparent": linkedSpan, + }) + + linkedCtx := context.Background() + linkedCtx = otel.GetTextMapPropagator().Extract(linkedCtx, traceContextCarrier) + + link := trace.LinkFromContext(linkedCtx, attribute.KeyValue{ + Key: "opentracing.ref_type", + Value: attribute.StringValue("follows-from"), + }) + result[i] = link + + } + return result +} diff --git a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go index 26063ad4fe..7e08a31649 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnappversion/controller_test.go @@ -7,6 +7,7 @@ import ( "strings" "testing" + "github.com/go-logr/logr" lfcv1beta1 "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/evaluation" @@ -19,6 +20,7 @@ import ( "github.com/keptn/lifecycle-toolkit/lifecycle-operator/controllers/common/testcommon" "github.com/stretchr/testify/require" "go.opentelemetry.io/otel" + "go.opentelemetry.io/otel/attribute" "go.opentelemetry.io/otel/propagation" "go.opentelemetry.io/otel/trace" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" @@ -141,9 +143,11 @@ func TestKeptnAppVersionReconciler_ReconcileFailed(t *testing.T) { KeptnAppSpec: lfcv1beta1.KeptnAppSpec{ Version: "1.0.0", }, - DeploymentTaskSpec: lfcv1beta1.DeploymentTaskSpec{ - PreDeploymentTasks: []string{ - "task", + KeptnAppContextSpec: lfcv1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: lfcv1beta1.DeploymentTaskSpec{ + PreDeploymentTasks: []string{ + "task", + }, }, }, AppName: "myapp", @@ -265,7 +269,7 @@ func setupReconciler(objs ...client.Object) (*KeptnAppVersionReconciler, chan st // fake span handler spanRecorder := &telemetryfake.ISpanHandlerMock{ - GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) { + GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) { return ctx, trace.SpanFromContext(ctx), nil }, UnbindSpanFunc: func(reconcileObject client.Object, phase string) error { return nil }, @@ -331,3 +335,60 @@ func TestKeptnApVersionReconciler_setupSpansContexts(t *testing.T) { }) } } + +func TestKeptnAppVersionReconciler_getLinkedSpans(t *testing.T) { + otel.SetTextMapPropagator(propagation.NewCompositeTextMapPropagator(propagation.TraceContext{}, propagation.Baggage{})) + type fields struct { + Log logr.Logger + } + type args struct { + version *lfcv1beta1.KeptnAppVersion + } + tests := []struct { + name string + fields fields + args args + want []trace.Link + }{ + { + name: "get linked trace", + fields: fields{ + Log: ctrl.Log.WithName("test-appVersionController"), + }, + args: args{ + version: &lfcv1beta1.KeptnAppVersion{ + Spec: lfcv1beta1.KeptnAppVersionSpec{ + KeptnAppContextSpec: lfcv1beta1.KeptnAppContextSpec{ + SpanLinks: []string{"00-c088f5c586bab8649159ccc39a9862f7-f862289833f1fba3-01"}, + }, + }, + }, + }, + want: []trace.Link{ + { + SpanContext: trace.NewSpanContext(trace.SpanContextConfig{ + SpanID: trace.SpanID([8]byte{0xf8, 0x62, 0x28, 0x98, 0x33, 0xf1, 0xfb, 0xa3}), + TraceID: trace.TraceID([16]byte{0xc0, 0x88, 0xf5, 0xc5, 0x86, 0xba, 0xb8, 0x64, 0x91, 0x59, 0xcc, 0xc3, 0x9a, 0x98, 0x62, 0xf7}), + TraceFlags: trace.TraceFlags(1), + Remote: true, + }), + Attributes: []attribute.KeyValue{ + { + Key: "opentracing.ref_type", + Value: attribute.StringValue("follows-from"), + }, + }, + }, + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + r := &KeptnAppVersionReconciler{ + Log: tt.fields.Log, + } + got := r.getLinkedSpans(tt.args.version) + require.Equal(t, tt.want, got) + }) + } +} diff --git a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go index 2afb861374..a15a578759 100644 --- a/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go +++ b/lifecycle-operator/controllers/lifecycle/keptnworkloadversion/controller_test.go @@ -1194,7 +1194,7 @@ func setupReconciler(objs ...client.Object) (*KeptnWorkloadVersionReconciler, ch recorder := record.NewFakeRecorder(100) spanHandlerMock := &telemetryfake.ISpanHandlerMock{ - GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string) (context.Context, trace.Span, error) { + GetSpanFunc: func(ctx context.Context, tracer telemetry.ITracer, reconcileObject client.Object, phase string, links ...trace.Link) (context.Context, trace.Span, error) { ctx, span := tracer.Start(ctx, phase, trace.WithSpanKind(trace.SpanKindConsumer)) return ctx, span, nil }, diff --git a/lifecycle-operator/test/component/appversion/appversion_test.go b/lifecycle-operator/test/component/appversion/appversion_test.go index c2f404e702..303d8e8dc8 100644 --- a/lifecycle-operator/test/component/appversion/appversion_test.go +++ b/lifecycle-operator/test/component/appversion/appversion_test.go @@ -94,8 +94,10 @@ var _ = Describe("Appversion", Ordered, func() { KeptnAppSpec: klcv1beta1.KeptnAppSpec{ Version: version, }, - DeploymentTaskSpec: klcv1beta1.DeploymentTaskSpec{ - PreDeploymentEvaluations: []string{"eval-def-appversion"}, + KeptnAppContextSpec: klcv1beta1.KeptnAppContextSpec{ + DeploymentTaskSpec: klcv1beta1.DeploymentTaskSpec{ + PreDeploymentEvaluations: []string{"eval-def-appversion"}, + }, }, }, }