Skip to content

Commit

Permalink
Adjust Test 506 to new behavior
Browse files Browse the repository at this point in the history
- Variables not involving nameprefix are resolved properly.
- variables resolved properly for first pod.
- Still quite a lot of work to get the variable resolved properly
  for Pod2.
  • Loading branch information
jbrette committed Jun 26, 2019
1 parent 506d57c commit c846b09
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 11 deletions.
8 changes: 5 additions & 3 deletions pkg/resmap/resmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,9 +208,11 @@ func (m *resWrangler) Append(res *resource.Resource) error {
id := res.CurId()
if r := m.GetMatchingResourcesByCurrentId(id.Equals); len(r) > 0 {
// This allows diamond import of resources.
// Only errors if the resources are different because they have
// been loaded from a different source.
if !res.Equals(r[0]) {
// We can assert the same resource as been loaded because there is
// only one resource in the list with the same name and
// value of the resource we intend to append is identical to the one
// we already added to the list.
if len(r) > 1 || !res.Equals(r[0]) {
return fmt.Errorf(
"may not add resource with an already registered id: %s", id)
}
Expand Down
27 changes: 19 additions & 8 deletions pkg/target/variableref_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,13 @@ vars:
name: myServerPod
fieldref:
fieldpath: metadata.name
- name: IMAGE_NAME
objref:
apiVersion: v1
kind: Pod
name: myServerPod
fieldref:
fieldpath: spec.containers[0].image
`)
th.WriteF("/app/base/pod.yaml", `
apiVersion: v1
Expand All @@ -326,6 +333,8 @@ spec:
env:
- name: POD_NAME
value: $(POD_NAME)
- name: IMAGE_NAME
value: $(IMAGE_NAME)
`)
th.WriteK("/app/o1", `
nameprefix: p1-
Expand All @@ -343,7 +352,7 @@ resources:
- ../o2
`)

const presumablyDesired = `
const pod2StillBoggus = `
apiVersion: v1
kind: Pod
metadata:
Expand All @@ -353,6 +362,8 @@ spec:
- env:
- name: POD_NAME
value: p1-base-myServerPod
- name: IMAGE_NAME
value: whatever
image: whatever
name: myServer
---
Expand All @@ -364,17 +375,17 @@ spec:
containers:
- env:
- name: POD_NAME
value: p2-base-myServerPod
value: p1-base-myServerPod
- name: IMAGE_NAME
value: whatever
image: whatever
name: myServer
`
_, err := th.MakeKustTarget().MakeCustomizedResMap()
if err == nil {
t.Fatalf("should have an error")
}
if !strings.Contains(err.Error(), "var 'POD_NAME' already encountered") {
t.Fatalf("unexpected err: %v", err)
m, err := th.MakeKustTarget().MakeCustomizedResMap()
if err != nil {
t.Fatalf("Err: %v", err)
}
th.AssertActualEqualsExpected(m, pod2StillBoggus)
}

func TestVarRefBig(t *testing.T) {
Expand Down

0 comments on commit c846b09

Please sign in to comment.