Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: lowercase app and versions
Browse files Browse the repository at this point in the history
Signed-off-by: realanna <anna.reale@dynatrace.com>
RealAnna committed Jul 27, 2023
1 parent 64fb02a commit dcde670
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
@@ -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 {
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
@@ -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",

0 comments on commit dcde670

Please sign in to comment.