From 64fb02a2276c18771ec77395893e00cf96c3e62d Mon Sep 17 00:00:00 2001 From: realanna Date: Thu, 27 Jul 2023 14:50:55 +0200 Subject: [PATCH 1/3] fix: lowercase app and versions Signed-off-by: realanna --- operator/webhooks/pod_mutator/pod_mutating_webhook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator/webhooks/pod_mutator/pod_mutating_webhook.go b/operator/webhooks/pod_mutator/pod_mutating_webhook.go index 04f2e34aec..9b7e3d5fe7 100644 --- a/operator/webhooks/pod_mutator/pod_mutating_webhook.go +++ b/operator/webhooks/pod_mutator/pod_mutating_webhook.go @@ -398,8 +398,8 @@ func (a *PodMutatingWebhook) generateWorkload(ctx context.Context, pod *corev1.P }, }, Spec: klcv1alpha3.KeptnWorkloadSpec{ - AppName: applicationName, - Version: version, + AppName: strings.ToLower(applicationName), + Version: strings.ToLower(version), ResourceReference: klcv1alpha3.ResourceReference{UID: ownerRef.UID, Kind: ownerRef.Kind, Name: ownerRef.Name}, PreDeploymentTasks: preDeploymentTasks, PostDeploymentTasks: postDeploymentTasks, From dcde6700523797dc3e01870e0ab340a77299c9bb Mon Sep 17 00:00:00 2001 From: realanna Date: Thu, 27 Jul 2023 15:04:19 +0200 Subject: [PATCH 2/3] fix: lowercase app and versions Signed-off-by: realanna --- operator/webhooks/pod_mutator/pod_mutating_webhook.go | 9 +++++++-- .../webhooks/pod_mutator/pod_mutating_webhook_test.go | 8 ++++---- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/operator/webhooks/pod_mutator/pod_mutating_webhook.go b/operator/webhooks/pod_mutator/pod_mutating_webhook.go index 9b7e3d5fe7..e436ec846b 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", From ac5c4d18bbf1825317f5877d04622d04a49948c3 Mon Sep 17 00:00:00 2001 From: realanna Date: Thu, 27 Jul 2023 15:54:46 +0200 Subject: [PATCH 3/3] fix: lowercase app and versions Signed-off-by: realanna --- operator/webhooks/pod_mutator/pod_mutating_webhook.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/operator/webhooks/pod_mutator/pod_mutating_webhook.go b/operator/webhooks/pod_mutator/pod_mutating_webhook.go index e436ec846b..d7183acf8c 100644 --- a/operator/webhooks/pod_mutator/pod_mutating_webhook.go +++ b/operator/webhooks/pod_mutator/pod_mutating_webhook.go @@ -398,8 +398,8 @@ func (a *PodMutatingWebhook) generateWorkload(ctx context.Context, pod *corev1.P }, }, Spec: klcv1alpha3.KeptnWorkloadSpec{ - AppName: strings.ToLower(applicationName), - Version: strings.ToLower(version), + AppName: applicationName, + Version: version, ResourceReference: klcv1alpha3.ResourceReference{UID: ownerRef.UID, Kind: ownerRef.Kind, Name: ownerRef.Name}, PreDeploymentTasks: preDeploymentTasks, PostDeploymentTasks: postDeploymentTasks,