diff --git a/api/internal/target/kusttarget.go b/api/internal/target/kusttarget.go index 8b71403ac4..d5534cfa54 100644 --- a/api/internal/target/kusttarget.go +++ b/api/internal/target/kusttarget.go @@ -158,6 +158,11 @@ func (kt *KustTarget) makeCustomizedResMap() (resmap.ResMap, error) { return nil, err } + err = kt.IgnoreLocal(ra) + if err != nil { + return nil, err + } + return ra.ResMap(), nil } @@ -238,10 +243,6 @@ func (kt *KustTarget) accumulateTarget(ra *accumulator.ResAccumulator) ( return nil, errors.Wrapf( err, "merging vars %v", kt.kustomization.Vars) } - err = kt.IgnoreLocal(ra) - if err != nil { - return nil, err - } return ra, nil } diff --git a/api/krusty/namereference_test.go b/api/krusty/namereference_test.go index 2937465719..c39c51715f 100644 --- a/api/krusty/namereference_test.go +++ b/api/krusty/namereference_test.go @@ -671,3 +671,118 @@ metadata: name: newNs `) } + +func TestIssue4884_UseLocalConfigAsNameRefSource(t *testing.T) { + th := kusttest_test.MakeHarness(t) + th.WriteK(".", ` +resources: + - resources.yaml + +namePrefix: prefix- + +configurations: + - kustomize-nameref.yaml +`) + th.WriteF("kustomize-nameref.yaml", ` +nameReference: +- kind: IngressHost + fieldSpecs: + - path: spec/rules/host + kind: Ingress + - path: spec/tls/hosts + kind: Ingress + - path: spec/template/spec/containers/env/value + kind: Deployment +- kind: IngressSecret + fieldSpecs: + - path: spec/tls/secretName + kind: Ingress +namePrefix: +- path: metadata/name + kind: IngressHost +- path: metadata/name + kind: IngressSecret + +`) + th.WriteF("resources.yaml", ` +apiVersion: local/v1 +kind: IngressHost +metadata: + name: test.fakedomain.com + namespace: test + annotations: + config.kubernetes.io/local-config: "true" +--- +apiVersion: local/v1 +kind: IngressSecret +metadata: + name: test-secret + namespace: test + annotations: + config.kubernetes.io/local-config: "true" +--- +apiVersion: v1 +kind: Ingress +metadata: + name: test-ingress + namespace: test +spec: + rules: + - host: test.fakedomain.com + - host: do-not-touch.otherdomain.com + tls: + - hosts: + - test.fakedomain.com + secretName: test-secret + - hosts: + - do-not-touch.otherdomain.com + secretname: do-not-touch +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment + namespace: test +spec: + template: + spec: + containers: + - name: tester + env: + - name: domain-name + value: test.fakedomain.com +`) + m := th.Run(".", th.MakeDefaultOptions()) + th.AssertActualEqualsExpected(m, ` +apiVersion: v1 +kind: Ingress +metadata: + name: test-ingress + namespace: test +spec: + rules: + - host: prefix-test.fakedomain.com + - host: do-not-touch.otherdomain.com + tls: + - hosts: + - prefix-test.fakedomain.com + secretName: prefix-test-secret + - hosts: + - do-not-touch.otherdomain.com + secretname: do-not-touch +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: test-deployment + namespace: test +spec: + template: + spec: + containers: + - env: + - name: domain-name + value: prefix-test.fakedomain.com + name: tester +`) +}