Skip to content

Commit

Permalink
Merge pull request #4895 from KnVerey/remove-local-last
Browse files Browse the repository at this point in the history
Remove local-only resources at the last minute
  • Loading branch information
k8s-ci-robot committed Dec 1, 2022
2 parents 663b777 + fb0f567 commit 0f4f978
Show file tree
Hide file tree
Showing 2 changed files with 120 additions and 4 deletions.
9 changes: 5 additions & 4 deletions api/internal/target/kusttarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
115 changes: 115 additions & 0 deletions api/krusty/namereference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
`)
}

0 comments on commit 0f4f978

Please sign in to comment.