Support for ConfigMap generator with identical names in different namespaces.

- Attempt to account, at build time, for subsequent kubectl apply behavior.
  (empty or no namespace means default).
- Account for the fact that not all objects have a namespace.
- Add new Equal method to ResId address merge name conflict
- Add GroupByName to resources by namespaces to resolve filenames conflict
- Added corresponding unit tests.
- Change the fail test for issue #1155
This commit is contained in:
Jerome Brette
2019-06-20 12:33:27 -05:00
parent 762d3143eb
commit 2bba0a6aa3
5 changed files with 216 additions and 20 deletions

View File

@@ -486,18 +486,108 @@ func TestGeneratingIntoNamespaces(t *testing.T) {
th.WriteK("/app", `
configMapGenerator:
- name: test
namespace: bob
namespace: default
literals:
- key=value
- name: test
namespace: kube-system
literals:
- key=value
secretGenerator:
- name: test
namespace: default
literals:
- username=admin
- password=somepw
- name: test
namespace: kube-system
literals:
- username=admin
- password=somepw
`)
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
key: value
kind: ConfigMap
metadata:
name: test-t5t4md8fdm
namespace: default
---
apiVersion: v1
data:
key: value
kind: ConfigMap
metadata:
name: test-t5t4md8fdm
namespace: kube-system
---
apiVersion: v1
data:
password: c29tZXB3
username: YWRtaW4=
kind: Secret
metadata:
name: test-h65t9hg6kc
namespace: default
type: Opaque
---
apiVersion: v1
data:
password: c29tZXB3
username: YWRtaW4=
kind: Secret
metadata:
name: test-h65t9hg6kc
namespace: kube-system
type: Opaque
`)
}
// Valid that conflict is detected is the name are identical
// and namespace left to default
func TestConfigMapGeneratingIntoSameNamespace(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app")
th.WriteK("/app", `
configMapGenerator:
- name: test
namespace: default
literals:
- key=value
- name: test
namespace: kube-system
literals:
- key=value
`)
_, err := th.MakeKustTarget().MakeCustomizedResMap()
// Document #1155
// This actually should be nil; it should work, and
// have some expected output.
if err == nil {
t.Fatalf("expected error")
}
if !strings.Contains(err.Error(), "must merge or replace") {
t.Fatalf("unexpected error %v", err)
}
}
// Valid that conflict is detected is the name are identical
// and namespace left to default
func TestSecretGeneratingIntoSameNamespace(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app")
th.WriteK("/app", `
secretGenerator:
- name: test
namespace: default
literals:
- username=admin
- password=somepw
- name: test
literals:
- username=admin
- password=somepw
`)
_, err := th.MakeKustTarget().MakeCustomizedResMap()
if err == nil {
t.Fatalf("expected error")
}