diff --git a/operator/api/v1alpha1/keptnappversion_types.go b/operator/api/v1alpha1/keptnappversion_types.go index 0695dbb9f0..b7257ce0a2 100644 --- a/operator/api/v1alpha1/keptnappversion_types.go +++ b/operator/api/v1alpha1/keptnappversion_types.go @@ -186,6 +186,14 @@ func (a *KeptnAppVersion) SetEndTime() { } } +func (a KeptnAppVersion) GetStartTime() time.Time { + return a.Status.StartTime.Time +} + +func (a KeptnAppVersion) GetEndTime() time.Time { + return a.Status.EndTime.Time +} + func (a *KeptnAppVersion) IsStartTimeSet() bool { return !a.Status.StartTime.IsZero() } @@ -194,6 +202,10 @@ func (a *KeptnAppVersion) IsEndTimeSet() bool { return !a.Status.EndTime.IsZero() } +func (a *KeptnAppVersion) Complete() { + a.SetEndTime() +} + func (a KeptnAppVersion) GetActiveMetricsAttributes() []attribute.KeyValue { return []attribute.KeyValue{ common.AppName.String(a.Spec.AppName), @@ -275,14 +287,6 @@ func (a *KeptnAppVersion) SetState(state common.KeptnState) { a.Status.Status = state } -func (a KeptnAppVersion) GetStartTime() time.Time { - return a.Status.StartTime.Time -} - -func (a KeptnAppVersion) GetEndTime() time.Time { - return a.Status.EndTime.Time -} - func (a KeptnAppVersion) GetCurrentPhase() string { return a.Status.CurrentPhase } @@ -291,18 +295,10 @@ func (a *KeptnAppVersion) SetCurrentPhase(phase string) { a.Status.CurrentPhase = phase } -func (a *KeptnAppVersion) Complete() { - a.SetEndTime() -} - func (a KeptnAppVersion) GetVersion() string { return a.Spec.Version } -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) -} - func (a KeptnAppVersion) GenerateTask(traceContextCarrier propagation.MapCarrier, taskDefinition string, checkType common.CheckType) KeptnTask { return KeptnTask{ ObjectMeta: metav1.ObjectMeta{ @@ -321,10 +317,6 @@ func (a KeptnAppVersion) GenerateTask(traceContextCarrier propagation.MapCarrier } } -func (a KeptnAppVersion) SetSpanAttributes(span trace.Span) { - span.SetAttributes(a.GetSpanAttributes()...) -} - func (a KeptnAppVersion) GenerateEvaluation(traceContextCarrier propagation.MapCarrier, evaluationDefinition string, checkType common.CheckType) KeptnEvaluation { return KeptnEvaluation{ ObjectMeta: metav1.ObjectMeta{ @@ -356,6 +348,14 @@ func (a KeptnAppVersion) GetSpanAttributes() []attribute.KeyValue { } } +func (a KeptnAppVersion) SetSpanAttributes(span trace.Span) { + span.SetAttributes(a.GetSpanAttributes()...) +} + +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) +} + func (v KeptnAppVersion) GetWorkloadNameOfApp(workloadName string) string { return fmt.Sprintf("%s-%s", v.Spec.AppName, workloadName) } diff --git a/operator/api/v1alpha1/keptnappversion_types_test.go b/operator/api/v1alpha1/keptnappversion_types_test.go deleted file mode 100644 index 68f4c47396..0000000000 --- a/operator/api/v1alpha1/keptnappversion_types_test.go +++ /dev/null @@ -1,41 +0,0 @@ -package v1alpha1 - -import ( - "testing" -) - -func TestKeptnAppVersion_GetWorkloadNameOfApp(t *testing.T) { - type fields struct { - Spec KeptnAppVersionSpec - } - type args struct { - workloadName string - } - tests := []struct { - name string - fields fields - args args - want string - }{ - { - name: "", - fields: fields{ - Spec: KeptnAppVersionSpec{AppName: "my-app"}, - }, - args: args{ - workloadName: "my-workload", - }, - want: "my-app-my-workload", - }, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - v := KeptnAppVersion{ - Spec: tt.fields.Spec, - } - if got := v.GetWorkloadNameOfApp(tt.args.workloadName); got != tt.want { - t.Errorf("GetWorkloadNameOfApp() = %v, want %v", got, tt.want) - } - }) - } -} diff --git a/operator/api/v1alpha1/keptnworkloadinstance_types.go b/operator/api/v1alpha1/keptnworkloadinstance_types.go index 660dcf1b52..2eaad509d7 100644 --- a/operator/api/v1alpha1/keptnworkloadinstance_types.go +++ b/operator/api/v1alpha1/keptnworkloadinstance_types.go @@ -203,6 +203,18 @@ func (w *KeptnWorkloadInstance) IsEndTimeSet() bool { return !w.Status.EndTime.IsZero() } +func (w KeptnWorkloadInstance) GetStartTime() time.Time { + return w.Status.StartTime.Time +} + +func (w KeptnWorkloadInstance) GetEndTime() time.Time { + return w.Status.EndTime.Time +} + +func (w *KeptnWorkloadInstance) Complete() { + w.SetEndTime() +} + func (t *TaskStatus) SetStartTime() { if t.StartTime.IsZero() { t.StartTime = metav1.NewTime(time.Now().UTC()) @@ -307,14 +319,6 @@ func (w KeptnWorkloadInstance) GetNamespace() string { return w.Namespace } -func (w KeptnWorkloadInstance) GetStartTime() time.Time { - return w.Status.StartTime.Time -} - -func (w KeptnWorkloadInstance) GetEndTime() time.Time { - return w.Status.EndTime.Time -} - func (w *KeptnWorkloadInstance) SetState(state common.KeptnState) { w.Status.Status = state } @@ -327,22 +331,10 @@ func (w *KeptnWorkloadInstance) SetCurrentPhase(phase string) { w.Status.CurrentPhase = phase } -func (w *KeptnWorkloadInstance) Complete() { - w.SetEndTime() -} - func (w KeptnWorkloadInstance) GetVersion() string { return w.Spec.Version } -func (w KeptnWorkloadInstance) GetSpanKey(phase string) string { - return fmt.Sprintf("%s.%s.%s.%s", w.Spec.TraceId["traceparent"], w.Spec.WorkloadName, w.Spec.Version, phase) -} - -func (w KeptnWorkloadInstance) GetSpanName(phase string) string { - return fmt.Sprintf("%s/%s", w.Spec.WorkloadName, phase) -} - func (w KeptnWorkloadInstance) GenerateTask(traceContextCarrier propagation.MapCarrier, taskDefinition string, checkType common.CheckType) KeptnTask { return KeptnTask{ ObjectMeta: metav1.ObjectMeta{ @@ -352,8 +344,8 @@ func (w KeptnWorkloadInstance) GenerateTask(traceContextCarrier propagation.MapC }, Spec: KeptnTaskSpec{ AppName: w.GetAppName(), - WorkloadVersion: w.GetParentName(), - Workload: w.GetVersion(), + WorkloadVersion: w.GetVersion(), + Workload: w.GetParentName(), TaskDefinition: taskDefinition, Parameters: TaskParameters{}, SecureParameters: SecureParameters{}, @@ -362,10 +354,6 @@ func (w KeptnWorkloadInstance) GenerateTask(traceContextCarrier propagation.MapC } } -func (w KeptnWorkloadInstance) SetSpanAttributes(span trace.Span) { - span.SetAttributes(w.GetSpanAttributes()...) -} - func (w KeptnWorkloadInstance) GenerateEvaluation(traceContextCarrier propagation.MapCarrier, evaluationDefinition string, checkType common.CheckType) KeptnEvaluation { return KeptnEvaluation{ ObjectMeta: metav1.ObjectMeta{ @@ -375,8 +363,8 @@ func (w KeptnWorkloadInstance) GenerateEvaluation(traceContextCarrier propagatio }, Spec: KeptnEvaluationSpec{ AppName: w.GetAppName(), - WorkloadVersion: w.GetParentName(), - Workload: w.GetVersion(), + WorkloadVersion: w.GetVersion(), + Workload: w.GetParentName(), EvaluationDefinition: evaluationDefinition, Type: checkType, RetryInterval: metav1.Duration{ @@ -394,3 +382,15 @@ func (w KeptnWorkloadInstance) GetSpanAttributes() []attribute.KeyValue { common.WorkloadNamespace.String(w.Namespace), } } + +func (w KeptnWorkloadInstance) GetSpanKey(phase string) string { + return fmt.Sprintf("%s.%s.%s.%s", w.Spec.TraceId["traceparent"], w.Spec.WorkloadName, w.Spec.Version, phase) +} + +func (w KeptnWorkloadInstance) GetSpanName(phase string) string { + return fmt.Sprintf("%s/%s", w.Spec.WorkloadName, phase) +} + +func (w KeptnWorkloadInstance) SetSpanAttributes(span trace.Span) { + span.SetAttributes(w.GetSpanAttributes()...) +} diff --git a/operator/api/v1alpha1/tests/keptnappversion_test.go b/operator/api/v1alpha1/tests/keptnappversion_test.go index 79b06ef98d..687341e7b2 100644 --- a/operator/api/v1alpha1/tests/keptnappversion_test.go +++ b/operator/api/v1alpha1/tests/keptnappversion_test.go @@ -207,3 +207,39 @@ func TestKeptnAppVersion(t *testing.T) { common.AppNamespace.String("namespace"), }, app.GetSpanAttributes()) } + +func TestKeptnAppVersion_GetWorkloadNameOfApp(t *testing.T) { + type fields struct { + Spec v1alpha1.KeptnAppVersionSpec + } + type args struct { + workloadName string + } + tests := []struct { + name string + fields fields + args args + want string + }{ + { + name: "", + fields: fields{ + Spec: v1alpha1.KeptnAppVersionSpec{AppName: "my-app"}, + }, + args: args{ + workloadName: "my-workload", + }, + want: "my-app-my-workload", + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + v := v1alpha1.KeptnAppVersion{ + Spec: tt.fields.Spec, + } + if got := v.GetWorkloadNameOfApp(tt.args.workloadName); got != tt.want { + t.Errorf("GetWorkloadNameOfApp() = %v, want %v", got, tt.want) + } + }) + } +} diff --git a/operator/api/v1alpha1/tests/keptnworkloadinstance_test.go b/operator/api/v1alpha1/tests/keptnworkloadinstance_test.go index f3df4ad938..5152e3b6dd 100644 --- a/operator/api/v1alpha1/tests/keptnworkloadinstance_test.go +++ b/operator/api/v1alpha1/tests/keptnworkloadinstance_test.go @@ -185,8 +185,8 @@ func TestKeptnWorkloadInstance(t *testing.T) { task := workload.GenerateTask(map[string]string{}, "taskdef", common.PostDeploymentCheckType) require.Equal(t, v1alpha1.KeptnTaskSpec{ AppName: workload.GetAppName(), - WorkloadVersion: workload.GetParentName(), - Workload: workload.GetVersion(), + WorkloadVersion: workload.GetVersion(), + Workload: workload.GetParentName(), TaskDefinition: "taskdef", Parameters: v1alpha1.TaskParameters{}, SecureParameters: v1alpha1.SecureParameters{}, @@ -196,8 +196,8 @@ func TestKeptnWorkloadInstance(t *testing.T) { evaluation := workload.GenerateEvaluation(map[string]string{}, "taskdef", common.PostDeploymentCheckType) require.Equal(t, v1alpha1.KeptnEvaluationSpec{ AppName: workload.GetAppName(), - WorkloadVersion: workload.GetParentName(), - Workload: workload.GetVersion(), + WorkloadVersion: workload.GetVersion(), + Workload: workload.GetParentName(), EvaluationDefinition: "taskdef", Type: common.PostDeploymentCheckType, RetryInterval: metav1.Duration{ diff --git a/operator/controllers/common/evaluationhandler.go b/operator/controllers/common/evaluationhandler.go index 4f9c7d6e38..0d060d1fc9 100644 --- a/operator/controllers/common/evaluationhandler.go +++ b/operator/controllers/common/evaluationhandler.go @@ -52,8 +52,8 @@ func (r EvaluationHandler) ReconcileEvaluations(ctx context.Context, reconcileOb evaluations = piWrapper.GetPreDeploymentEvaluations() statuses = piWrapper.GetPreDeploymentEvaluationTaskStatus() case apicommon.PostDeploymentEvaluationCheckType: - evaluations = piWrapper.GetPreDeploymentEvaluations() - statuses = piWrapper.GetPreDeploymentEvaluationTaskStatus() + evaluations = piWrapper.GetPostDeploymentEvaluations() + statuses = piWrapper.GetPostDeploymentEvaluationTaskStatus() } var summary apicommon.StatusSummary diff --git a/operator/controllers/common/interfaces.go b/operator/controllers/common/interfaces.go index 0b37bed6b8..6527b0eff1 100644 --- a/operator/controllers/common/interfaces.go +++ b/operator/controllers/common/interfaces.go @@ -18,17 +18,11 @@ type PhaseItem interface { SetState(apicommon.KeptnState) GetCurrentPhase() string SetCurrentPhase(string) - GetVersion() string - GetActiveMetricsAttributes() []attribute.KeyValue - GetDurationMetricsAttributes() []attribute.KeyValue - GetMetricsAttributes() []attribute.KeyValue - GetSpanAttributes() []attribute.KeyValue - GetSpanKey(phase string) string - GetSpanName(phase string) string Complete() IsEndTimeSet() bool GetEndTime() time.Time GetStartTime() time.Time + GetVersion() string GetPreviousVersion() string GetParentName() string GetNamespace() string @@ -43,6 +37,12 @@ type PhaseItem interface { GetPostDeploymentEvaluationTaskStatus() []klcv1alpha1.EvaluationStatus GenerateTask(traceContextCarrier propagation.MapCarrier, taskDefinition string, checkType common.CheckType) klcv1alpha1.KeptnTask GenerateEvaluation(traceContextCarrier propagation.MapCarrier, evaluationDefinition string, checkType common.CheckType) klcv1alpha1.KeptnEvaluation + GetActiveMetricsAttributes() []attribute.KeyValue + GetDurationMetricsAttributes() []attribute.KeyValue + GetMetricsAttributes() []attribute.KeyValue + GetSpanAttributes() []attribute.KeyValue + GetSpanKey(phase string) string + GetSpanName(phase string) string SetSpanAttributes(span trace.Span) } @@ -74,10 +74,6 @@ func (pw *PhaseItemWrapper) SetCurrentPhase(phase string) { pw.Obj.SetCurrentPhase(phase) } -func (pw PhaseItemWrapper) GetDurationMetricsAttributes() []attribute.KeyValue { - return pw.Obj.GetDurationMetricsAttributes() -} - func (pw PhaseItemWrapper) GetEndTime() time.Time { return pw.Obj.GetEndTime() } @@ -86,6 +82,10 @@ func (pw PhaseItemWrapper) GetStartTime() time.Time { return pw.Obj.GetStartTime() } +func (pw PhaseItemWrapper) IsEndTimeSet() bool { + return pw.Obj.IsEndTimeSet() +} + func (pw *PhaseItemWrapper) Complete() { pw.Obj.Complete() } @@ -94,18 +94,6 @@ func (pw PhaseItemWrapper) GetVersion() string { return pw.Obj.GetVersion() } -func (pw PhaseItemWrapper) GetSpanKey(phase string) string { - return pw.Obj.GetSpanKey(phase) -} - -func (pw PhaseItemWrapper) GetSpanName(phase string) string { - return pw.Obj.GetSpanName(phase) -} - -func (pw PhaseItemWrapper) IsEndTimeSet() bool { - return pw.Obj.IsEndTimeSet() -} - func (pw PhaseItemWrapper) GetPreviousVersion() string { return pw.Obj.GetPreviousVersion() } @@ -118,6 +106,10 @@ func (pw PhaseItemWrapper) GetNamespace() string { return pw.Obj.GetNamespace() } +func (pw PhaseItemWrapper) GetAppName() string { + return pw.Obj.GetAppName() +} + func (pw PhaseItemWrapper) GetPreDeploymentTasks() []string { return pw.Obj.GetPreDeploymentTasks() } @@ -150,14 +142,18 @@ func (pw PhaseItemWrapper) GetPostDeploymentEvaluationTaskStatus() []klcv1alpha1 return pw.Obj.GetPostDeploymentEvaluationTaskStatus() } -func (pw PhaseItemWrapper) GetAppName() string { - return pw.Obj.GetAppName() -} - func (pw PhaseItemWrapper) GetActiveMetricsAttributes() []attribute.KeyValue { return pw.Obj.GetActiveMetricsAttributes() } +func (pw PhaseItemWrapper) GetMetricsAttributes() []attribute.KeyValue { + return pw.Obj.GetMetricsAttributes() +} + +func (pw PhaseItemWrapper) GetDurationMetricsAttributes() []attribute.KeyValue { + return pw.Obj.GetDurationMetricsAttributes() +} + func (pw PhaseItemWrapper) GenerateTask(traceContextCarrier propagation.MapCarrier, taskDefinition string, checkType common.CheckType) klcv1alpha1.KeptnTask { return pw.Obj.GenerateTask(traceContextCarrier, taskDefinition, checkType) } @@ -174,8 +170,12 @@ func (pw PhaseItemWrapper) GetSpanAttributes() []attribute.KeyValue { return pw.Obj.GetSpanAttributes() } -func (pw PhaseItemWrapper) GetMetricsAttributes() []attribute.KeyValue { - return pw.Obj.GetMetricsAttributes() +func (pw PhaseItemWrapper) GetSpanKey(phase string) string { + return pw.Obj.GetSpanKey(phase) +} + +func (pw PhaseItemWrapper) GetSpanName(phase string) string { + return pw.Obj.GetSpanName(phase) } func NewListItemWrapperFromClientObjectList(object client.ObjectList) (*ListItemWrapper, error) { diff --git a/operator/controllers/common/taskhandler.go b/operator/controllers/common/taskhandler.go index 71081b1ab5..4e022f94dd 100644 --- a/operator/controllers/common/taskhandler.go +++ b/operator/controllers/common/taskhandler.go @@ -53,8 +53,8 @@ func (r TaskHandler) ReconcileTasks(ctx context.Context, reconcileObject client. tasks = piWrapper.GetPreDeploymentTasks() statuses = piWrapper.GetPreDeploymentTaskStatus() case apicommon.PostDeploymentCheckType: - tasks = piWrapper.GetPreDeploymentTasks() - statuses = piWrapper.GetPreDeploymentTaskStatus() + tasks = piWrapper.GetPostDeploymentTasks() + statuses = piWrapper.GetPostDeploymentTaskStatus() } var summary apicommon.StatusSummary