Skip to content

Commit

Permalink
fix(operator): sanitize app name annotation from uppercase to lowerca…
Browse files Browse the repository at this point in the history
…se (keptn#1793)

Signed-off-by: realanna <[email protected]>
  • Loading branch information
RealAnna committed Jul 28, 2023
1 parent 03ca7dd commit 0986360
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
9 changes: 7 additions & 2 deletions operator/webhooks/pod_mutator/pod_mutating_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions operator/webhooks/pod_mutator/pod_mutating_webhook_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down Expand Up @@ -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])

Expand All @@ -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",
Expand Down

0 comments on commit 0986360

Please sign in to comment.