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 0ba92d52c..d9ec28d71 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/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.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, 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) {