Skip to content

Commit

Permalink
Consider currentId when replacing/merging resources
Browse files Browse the repository at this point in the history
When merging resources such as the output of a `configMapGenerator`,
we need to consider the `CurrentId`, otherwise, we cannot extend
a common base definition twice by adding different prefixes, and
then further kustomize them.

See #1442.
  • Loading branch information
jcpetruzza committed Sep 10, 2019
1 parent cd0187e commit 1237ae4
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
4 changes: 3 additions & 1 deletion pkg/resmap/resmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -603,8 +603,10 @@ func (m *resWrangler) AbsorbAll(other ResMap) error {
func (m *resWrangler) appendReplaceOrMerge(
res *resource.Resource) error {
id := res.CurId()
// Maybe also try by current id if nothing matches?
matches := m.GetMatchingResourcesByOriginalId(id.Equals)
if len(matches) == 0 {
matches = m.GetMatchingResourcesByCurrentId(id.Equals)
}
switch len(matches) {
case 0:
switch res.Behavior() {
Expand Down
60 changes: 60 additions & 0 deletions pkg/target/configmaps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,3 +251,63 @@ metadata:
name: p2-com2-c4b8md75k9
`)
}

func TestConfigMapGeneratorMergeNamePrefix(t *testing.T) {
th := kusttest_test.NewKustTestHarness(t, "/app")
th.WriteK("/app/base", `
configMapGenerator:
- name: cm
behavior: create
literals:
- foo=bar
`)
th.WriteK("/app/o1", `
resources:
- ../base
namePrefix: o1-
`)
th.WriteK("/app/o2", `
resources:
- ../base
nameSuffix: -o2
`)
th.WriteK("/app", `
resources:
- o1
- o2
configMapGenerator:
- name: o1-cm
behavior: merge
literals:
- big=bang
- name: cm-o2
behavior: merge
literals:
- big=crunch
`)
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, `
apiVersion: v1
data:
big: bang
foo: bar
kind: ConfigMap
metadata:
annotations: {}
labels: {}
name: o1-cm-28g596k77k
---
apiVersion: v1
data:
big: crunch
foo: bar
kind: ConfigMap
metadata:
annotations: {}
labels: {}
name: cm-o2-gfcc59fg5m
`)
}

0 comments on commit 1237ae4

Please sign in to comment.