diff --git a/operator/webhooks/pod_mutator/pod_mutating_webhook.go b/operator/webhooks/pod_mutator/pod_mutating_webhook.go index 04f2e34aec..d7183acf8c 100644 --- a/operator/webhooks/pod_mutator/pod_mutating_webhook.go +++ b/operator/webhooks/pod_mutator/pod_mutating_webhook.go @@ -357,8 +357,8 @@ func (a *PodMutatingWebhook) handleApp(ctx context.Context, logger logr.Logger, } func (a *PodMutatingWebhook) generateWorkload(ctx context.Context, pod *corev1.Pod, namespace string) *klcv1alpha3.KeptnWorkload { - version, _ := getLabelOrAnnotation(&pod.ObjectMeta, apicommon.VersionAnnotation, apicommon.K8sRecommendedVersionAnnotations) - applicationName, _ := getLabelOrAnnotation(&pod.ObjectMeta, apicommon.AppAnnotation, apicommon.K8sRecommendedAppAnnotations) + version := a.getVersion(pod) + applicationName := a.getAppName(pod) var preDeploymentTasks []string var postDeploymentTasks []string @@ -446,6 +446,11 @@ func (a *PodMutatingWebhook) getAppName(pod *corev1.Pod) string { return strings.ToLower(applicationName) } +func (a *PodMutatingWebhook) getVersion(pod *corev1.Pod) string { + version, _ := getLabelOrAnnotation(&pod.ObjectMeta, apicommon.VersionAnnotation, apicommon.K8sRecommendedVersionAnnotations) + return strings.ToLower(version) +} + func (a *PodMutatingWebhook) getOwnerReference(resource metav1.ObjectMeta) metav1.OwnerReference { reference := metav1.OwnerReference{} if len(resource.OwnerReferences) != 0 { diff --git a/operator/webhooks/pod_mutator/pod_mutating_webhook_test.go b/operator/webhooks/pod_mutator/pod_mutating_webhook_test.go index 764a79781c..67971737bf 100644 --- a/operator/webhooks/pod_mutator/pod_mutating_webhook_test.go +++ b/operator/webhooks/pod_mutator/pod_mutating_webhook_test.go @@ -1364,8 +1364,8 @@ func TestPodMutatingWebhook_Handle_MultiService(t *testing.T) { Namespace: "default", Annotations: map[string]string{ apicommon.WorkloadAnnotation: "my-workload", - apicommon.VersionAnnotation: "0.1", - apicommon.AppAnnotation: "my-app", + apicommon.VersionAnnotation: "V0.1", + apicommon.AppAnnotation: "my-App", }, OwnerReferences: []metav1.OwnerReference{ { @@ -1417,7 +1417,7 @@ func TestPodMutatingWebhook_Handle_MultiService(t *testing.T) { require.Nil(t, err) - require.Equal(t, "my-app", kacr.Spec.AppName) + require.Equal(t, "my-app", kacr.Spec.AppName) // this makes sure that everything is lowercase // here we do not want a single-service annotation require.Empty(t, kacr.Annotations[apicommon.AppTypeAnnotation]) @@ -1432,7 +1432,7 @@ func TestPodMutatingWebhook_Handle_MultiService(t *testing.T) { require.Equal(t, klcv1alpha3.KeptnWorkloadSpec{ AppName: kacr.Spec.AppName, - Version: "0.1", + Version: "v0.1", ResourceReference: klcv1alpha3.ResourceReference{ UID: "1234", Kind: "Deployment",