From 49b32473caab937c0b228472359d6f3b5bb7982a Mon Sep 17 00:00:00 2001 From: jingfangliu Date: Tue, 9 Jul 2019 13:32:33 -0700 Subject: [PATCH] fix the regression on merging configmap with different namespace --- pkg/ifc/ifc.go | 1 + pkg/resource/resource.go | 1 + pkg/target/namespacedgenerators_test.go | 40 +++++++++++++++++++++++++ 3 files changed, 42 insertions(+) diff --git a/pkg/ifc/ifc.go b/pkg/ifc/ifc.go index 3c839d962..fff4bdb0d 100644 --- a/pkg/ifc/ifc.go +++ b/pkg/ifc/ifc.go @@ -57,6 +57,7 @@ type Kunstructured interface { GetKind() string GetName() string SetName(string) + SetNamespace(string) GetLabels() map[string]string SetLabels(map[string]string) GetAnnotations() map[string]string diff --git a/pkg/resource/resource.go b/pkg/resource/resource.go index fb3eeeac4..2d8c0a4d0 100644 --- a/pkg/resource/resource.go +++ b/pkg/resource/resource.go @@ -42,6 +42,7 @@ func (r *Resource) Replace(other *Resource) { r.SetAnnotations( mergeStringMaps(other.GetAnnotations(), r.GetAnnotations())) r.SetName(other.GetName()) + r.SetNamespace(other.GetNamespace()) r.copyOtherFields(other) } diff --git a/pkg/target/namespacedgenerators_test.go b/pkg/target/namespacedgenerators_test.go index 6d8e7a742..9d59d48ba 100644 --- a/pkg/target/namespacedgenerators_test.go +++ b/pkg/target/namespacedgenerators_test.go @@ -87,3 +87,43 @@ metadata: type: Opaque `) } + +func TestNamespacedGeneratorWithOverlays(t *testing.T) { + th := kusttest_test.NewKustTestHarness(t, "/app/overlay") + th.WriteK("/app/base", ` +namespace: base + +configMapGenerator: +- name: testCase + literals: + - base=true +`) + th.WriteK("/app/overlay", ` +resources: + - ../base + +namespace: overlay + +configMapGenerator: + - name: testCase + behavior: merge + literals: + - overlay=true +`) + m, err := th.MakeKustTarget().MakeCustomizedResMap() + if err != nil { + t.Fatalf("Err: %v", err) + } + th.AssertActualEqualsExpected(m, ` +apiVersion: v1 +data: + base: "true" + overlay: "true" +kind: ConfigMap +metadata: + annotations: {} + labels: {} + name: testCase-4g75kbk6gm + namespace: overlay +`) +}