diff --git a/pkg/transformers/labelsandannotations_test.go b/pkg/transformers/labelsandannotations_test.go index 02cad6861..f35467cbe 100644 --- a/pkg/transformers/labelsandannotations_test.go +++ b/pkg/transformers/labelsandannotations_test.go @@ -33,6 +33,7 @@ var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deploy var foo = schema.GroupVersionKind{Group: "example.com", Version: "v1", Kind: "Foo"} var crd = schema.GroupVersionKind{Group: "apiwctensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"} var job = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"} +var cronjob = schema.GroupVersionKind{Group: "batch", Version: "v1beta1", Kind: "CronJob"} func TestLabelsRun(t *testing.T) { m := resmap.ResMap{ @@ -131,6 +132,61 @@ func TestLabelsRun(t *testing.T) { }, }, }), + resource.NewResId(cronjob, "cronjob1"): resource.NewResourceFromMap( + map[string]interface{}{ + "apiVersion": "batch/v1beta1", + "kind": "CronJob", + "metadata": map[string]interface{}{ + "name": "cronjob1", + }, + "spec": map[string]interface{}{ + "schedule": "* 23 * * *", + "jobTemplate": map[string]interface{}{ + "spec": map[string]interface{}{ + "template": map[string]interface{}{ + "spec": map[string]interface{}{ + "containers": []interface{}{ + map[string]interface{}{ + "name": "nginx", + "image": "nginx:1.7.9", + }, + }, + }, + }, + }, + }, + }, + }), + resource.NewResId(cronjob, "cronjob2"): resource.NewResourceFromMap( + map[string]interface{}{ + "apiVersion": "batch/v1beta1", + "kind": "CronJob", + "metadata": map[string]interface{}{ + "name": "cronjob2", + }, + "spec": map[string]interface{}{ + "schedule": "* 23 * * *", + "jobTemplate": map[string]interface{}{ + "spec": map[string]interface{}{ + "selector": map[string]interface{}{ + "matchLabels": map[string]interface{}{ + "old-label": "old-value", + }, + }, + "template": map[string]interface{}{ + "spec": map[string]interface{}{ + "containers": []interface{}{ + map[string]interface{}{ + "name": "nginx", + "image": "nginx:1.7.9", + }, + }, + }, + }, + }, + }, + }, + }), } expected := resmap.ResMap{ resource.NewResId(cmap, "cm1"): resource.NewResourceFromMap( @@ -274,6 +330,83 @@ func TestLabelsRun(t *testing.T) { }, }, }), + resource.NewResId(cronjob, "cronjob1"): resource.NewResourceFromMap( + map[string]interface{}{ + "apiVersion": "batch/v1beta1", + "kind": "CronJob", + "metadata": map[string]interface{}{ + "name": "cronjob1", + "labels": map[string]interface{}{ + "label-key1": "label-value1", + "label-key2": "label-value2", + }, + }, + "spec": map[string]interface{}{ + "schedule": "* 23 * * *", + "jobTemplate": map[string]interface{}{ + "spec": map[string]interface{}{ + "template": map[string]interface{}{ + "metadata": map[string]interface{}{ + "labels": map[string]interface{}{ + "label-key1": "label-value1", + "label-key2": "label-value2", + }, + }, + "spec": map[string]interface{}{ + "containers": []interface{}{ + map[string]interface{}{ + "name": "nginx", + "image": "nginx:1.7.9", + }, + }, + }, + }, + }, + }, + }, + }), + resource.NewResId(cronjob, "cronjob2"): resource.NewResourceFromMap( + map[string]interface{}{ + "apiVersion": "batch/v1beta1", + "kind": "CronJob", + "metadata": map[string]interface{}{ + "name": "cronjob2", + "labels": map[string]interface{}{ + "label-key1": "label-value1", + "label-key2": "label-value2", + }, + }, + "spec": map[string]interface{}{ + "schedule": "* 23 * * *", + "jobTemplate": map[string]interface{}{ + "spec": map[string]interface{}{ + "selector": map[string]interface{}{ + "matchLabels": map[string]interface{}{ + "old-label": "old-value", + "label-key1": "label-value1", + "label-key2": "label-value2", + }, + }, + "template": map[string]interface{}{ + "metadata": map[string]interface{}{ + "labels": map[string]interface{}{ + "label-key1": "label-value1", + "label-key2": "label-value2", + }, + }, + "spec": map[string]interface{}{ + "containers": []interface{}{ + map[string]interface{}{ + "name": "nginx", + "image": "nginx:1.7.9", + }, + }, + }, + }, + }, + }, + }, + }), } lt, err := NewDefaultingLabelsMapTransformer(map[string]string{"label-key1": "label-value1", "label-key2": "label-value2"}) diff --git a/pkg/transformers/labelsandannotationsconfig.go b/pkg/transformers/labelsandannotationsconfig.go index 7295f8f74..dbb73e32d 100644 --- a/pkg/transformers/labelsandannotationsconfig.go +++ b/pkg/transformers/labelsandannotationsconfig.go @@ -95,12 +95,7 @@ var defaultLabelsPathConfigs = []PathConfig{ { GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "CronJob"}, Path: []string{"spec", "jobTemplate", "spec", "selector", "matchLabels"}, - CreateIfNotPresent: true, - }, - { - GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "CronJob"}, - Path: []string{"spec", "jobTemplate", "spec", "metadata", "labels"}, - CreateIfNotPresent: true, + CreateIfNotPresent: false, }, { GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "CronJob"},