diff --git a/api/internal/target/kusttarget_configplugin.go b/api/internal/target/kusttarget_configplugin.go index f05c6584dd..0991c5fac7 100644 --- a/api/internal/target/kusttarget_configplugin.go +++ b/api/internal/target/kusttarget_configplugin.go @@ -288,7 +288,7 @@ var transformerConfigurators = map[builtinhelpers.BuiltinPluginType]func( } else { // merge spec/template/metadata fieldSpec if includeTemplate flag is true if label.IncludeTemplates { - fss, err = fss.MergeOne(types.FieldSpec{Path: "spec/template/metadata/labels", CreateIfNotPresent: true}) + fss, err = fss.MergeOne(types.FieldSpec{Path: "spec/template/metadata/labels", CreateIfNotPresent: false}) if err != nil { return nil, errors.Wrap(err, "failed to merge template fieldSpec") } diff --git a/api/krusty/inlinelabels_test.go b/api/krusty/inlinelabels_test.go index 7e5e4e24f0..2979c27e4f 100644 --- a/api/krusty/inlinelabels_test.go +++ b/api/krusty/inlinelabels_test.go @@ -160,66 +160,3 @@ spec: foo: bar `) } - -func TestKustomizationLabelsInTemplateWhenLabelsIsNil(t *testing.T) { - th := kusttest_test.MakeHarness(t) - th.WriteF("app/deployment.yaml", ` -apiVersion: apps/v1 -kind: Deployment -metadata: - name: deployment -spec: - replicas: 1 - template: - spec: - containers: - - name: test-server - image: test-server -`) - th.WriteK("/app", ` -resources: -- deployment.yaml - -commonLabels: - app: test-server - -labels: -- pairs: - app.kubernetes.io/component: a - app.kubernetes.io/instance: b - app.kubernetes.io/name: c - app.kubernetes.io/part-of: d - includeSelectors: false - includeTemplates: true -`) - m := th.Run("/app", th.MakeDefaultOptions()) - th.AssertActualEqualsExpected(m, ` -apiVersion: apps/v1 -kind: Deployment -metadata: - labels: - app: test-server - app.kubernetes.io/component: a - app.kubernetes.io/instance: b - app.kubernetes.io/name: c - app.kubernetes.io/part-of: d - name: deployment -spec: - replicas: 1 - selector: - matchLabels: - app: test-server - template: - metadata: - labels: - app: test-server - app.kubernetes.io/component: a - app.kubernetes.io/instance: b - app.kubernetes.io/name: c - app.kubernetes.io/part-of: d - spec: - containers: - - image: test-server - name: test-server -`) -}