From e5d7e44484dd9fe9754419d0d05ddc240f867c5a Mon Sep 17 00:00:00 2001 From: yeya24 Date: Thu, 17 Oct 2019 14:34:23 -0400 Subject: [PATCH 1/3] add labels to cronjob pod template Signed-off-by: yeya24 --- pkg/cronjob/es_index_cleaner.go | 17 +++++++++-------- pkg/cronjob/spark_dependencies.go | 17 +++++++++-------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/pkg/cronjob/es_index_cleaner.go b/pkg/cronjob/es_index_cleaner.go index 0ba92d52c..644ab2aea 100644 --- a/pkg/cronjob/es_index_cleaner.go +++ b/pkg/cronjob/es_index_cleaner.go @@ -45,6 +45,14 @@ func CreateEsIndexCleaner(jaeger *v1.Jaeger) *batchv1beta1.CronJob { "sidecar.istio.io/inject": "false", "linkerd.io/inject": "disabled", }, + Labels: map[string]string{ + "app": "jaeger", + "app.kubernetes.io/name": name, + "app.kubernetes.io/instance": jaeger.Name, + "app.kubernetes.io/component": "cronjob-es-index-cleaner", + "app.kubernetes.io/part-of": "jaeger", + "app.kubernetes.io/managed-by": "jaeger-operator", + }, } commonSpec := util.Merge([]v1.JaegerCommonSpec{jaeger.Spec.Storage.EsIndexCleaner.JaegerCommonSpec, jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) @@ -53,14 +61,7 @@ func CreateEsIndexCleaner(jaeger *v1.Jaeger) *batchv1beta1.CronJob { ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: jaeger.Namespace, - Labels: map[string]string{ - "app": "jaeger", - "app.kubernetes.io/name": name, - "app.kubernetes.io/instance": jaeger.Name, - "app.kubernetes.io/component": "cronjob-es-index-cleaner", - "app.kubernetes.io/part-of": "jaeger", - "app.kubernetes.io/managed-by": "jaeger-operator", - }, + Labels: commonSpec.Labels, OwnerReferences: []metav1.OwnerReference{ { APIVersion: jaeger.APIVersion, diff --git a/pkg/cronjob/spark_dependencies.go b/pkg/cronjob/spark_dependencies.go index 338101d4a..6957bd01a 100644 --- a/pkg/cronjob/spark_dependencies.go +++ b/pkg/cronjob/spark_dependencies.go @@ -53,6 +53,14 @@ func CreateSparkDependencies(jaeger *v1.Jaeger) *batchv1beta1.CronJob { "sidecar.istio.io/inject": "false", "linkerd.io/inject": "disabled", }, + Labels: map[string]string{ + "app": "jaeger", + "app.kubernetes.io/name": name, + "app.kubernetes.io/instance": jaeger.Name, + "app.kubernetes.io/component": "cronjob-es-index-cleaner", + "app.kubernetes.io/part-of": "jaeger", + "app.kubernetes.io/managed-by": "jaeger-operator", + }, } commonSpec := util.Merge([]v1.JaegerCommonSpec{jaeger.Spec.Storage.Dependencies.JaegerCommonSpec, jaeger.Spec.JaegerCommonSpec, baseCommonSpec}) @@ -61,14 +69,7 @@ func CreateSparkDependencies(jaeger *v1.Jaeger) *batchv1beta1.CronJob { ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: jaeger.Namespace, - Labels: map[string]string{ - "app": "jaeger", - "app.kubernetes.io/name": name, - "app.kubernetes.io/instance": jaeger.Name, - "app.kubernetes.io/component": "cronjob-spark-dependencies", - "app.kubernetes.io/part-of": "jaeger", - "app.kubernetes.io/managed-by": "jaeger-operator", - }, + Labels: commonSpec.Labels, OwnerReferences: []metav1.OwnerReference{ { APIVersion: jaeger.APIVersion, From e10264cc38b57c86dc01b5d9d10dca310c56a2dc Mon Sep 17 00:00:00 2001 From: yeya24 Date: Thu, 17 Oct 2019 14:44:12 -0400 Subject: [PATCH 2/3] make format Signed-off-by: yeya24 --- go.sum | 1 + pkg/cronjob/es_index_cleaner.go | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/go.sum b/go.sum index fab5e7f3e..87f01814a 100644 --- a/go.sum +++ b/go.sum @@ -808,6 +808,7 @@ sigs.k8s.io/controller-runtime v0.2.0 h1:5gL30PXOisGZl+Osi4CmLhvMUj77BO3wJeouKF2 sigs.k8s.io/controller-runtime v0.2.0/go.mod h1:ZHqrRDZi3f6BzONcvlUxkqCKgwasGk5FZrnSv9TVZF4= sigs.k8s.io/controller-tools v0.2.0 h1:AmQ/0JKBJAjyAiPAkrAf9QW06jkx2lc5hpxMjamsFpw= sigs.k8s.io/controller-tools v0.2.0/go.mod h1:8t/X+FVWvk6TaBcsa+UKUBbn7GMtvyBKX30SGl4em6Y= +sigs.k8s.io/controller-tools v0.2.1 h1:HoCik83vXOpPi7KSJWdPRmiGntyOzK0v0BTV4U+pl8o= sigs.k8s.io/kustomize v2.0.3+incompatible/go.mod h1:MkjgH3RdOWrievjo6c9T245dYlB5QeXV4WCbnt/PEpU= sigs.k8s.io/testing_frameworks v0.1.1 h1:cP2l8fkA3O9vekpy5Ks8mmA0NW/F7yBdXf8brkWhVrs= sigs.k8s.io/testing_frameworks v0.1.1/go.mod h1:VVBKrHmJ6Ekkfz284YKhQePcdycOzNH9qL6ht1zEr/U= diff --git a/pkg/cronjob/es_index_cleaner.go b/pkg/cronjob/es_index_cleaner.go index 644ab2aea..d9ec28d71 100644 --- a/pkg/cronjob/es_index_cleaner.go +++ b/pkg/cronjob/es_index_cleaner.go @@ -61,7 +61,7 @@ func CreateEsIndexCleaner(jaeger *v1.Jaeger) *batchv1beta1.CronJob { ObjectMeta: metav1.ObjectMeta{ Name: name, Namespace: jaeger.Namespace, - Labels: commonSpec.Labels, + Labels: commonSpec.Labels, OwnerReferences: []metav1.OwnerReference{ { APIVersion: jaeger.APIVersion, From 9e82f48c3a262800cb93febd1834a7cedebf2da4 Mon Sep 17 00:00:00 2001 From: yeya24 Date: Fri, 18 Oct 2019 16:10:20 -0400 Subject: [PATCH 3/3] add label test Signed-off-by: yeya24 --- pkg/cronjob/es_index_cleaner_test.go | 3 +++ pkg/cronjob/spark_dependencies_test.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/pkg/cronjob/es_index_cleaner_test.go b/pkg/cronjob/es_index_cleaner_test.go index 22a77ca06..a3cb43ac9 100644 --- a/pkg/cronjob/es_index_cleaner_test.go +++ b/pkg/cronjob/es_index_cleaner_test.go @@ -116,6 +116,9 @@ func TestEsIndexCleanerLabels(t *testing.T) { assert.Equal(t, "operator", cjob.Spec.JobTemplate.Spec.Template.Labels["name"]) assert.Equal(t, "world", cjob.Spec.JobTemplate.Spec.Template.Labels["hello"]) assert.Equal(t, "false", cjob.Spec.JobTemplate.Spec.Template.Labels["another"]) + + // Check if the labels of cronjob pod template equal to the labels of cronjob. + assert.Equal(t, cjob.ObjectMeta.Labels, cjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Labels) } func TestEsIndexCleanerResources(t *testing.T) { diff --git a/pkg/cronjob/spark_dependencies_test.go b/pkg/cronjob/spark_dependencies_test.go index 9422621df..57d45d5ee 100644 --- a/pkg/cronjob/spark_dependencies_test.go +++ b/pkg/cronjob/spark_dependencies_test.go @@ -137,6 +137,9 @@ func TestDependenciesLabels(t *testing.T) { assert.Equal(t, "operator", cjob.Spec.JobTemplate.Spec.Template.Labels["name"]) assert.Equal(t, "world", cjob.Spec.JobTemplate.Spec.Template.Labels["hello"]) assert.Equal(t, "false", cjob.Spec.JobTemplate.Spec.Template.Labels["another"]) + + // Check if the labels of cronjob pod template equal to the labels of cronjob. + assert.Equal(t, cjob.ObjectMeta.Labels, cjob.Spec.JobTemplate.Spec.Template.ObjectMeta.Labels) } func TestSparkDependenciesResources(t *testing.T) {