mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Merge pull request #3441 from natasha41575/namePrefixNamespaceBehavior
Update name references by checking both the original and current namespaces
This commit is contained in:
@@ -90,7 +90,10 @@ func (f Filter) setMapping(node *yaml.RNode) error {
|
|||||||
namespace := namespaceNode.YNode().Value
|
namespace := namespaceNode.YNode().Value
|
||||||
bynamespace := f.ReferralCandidates.GroupedByOriginalNamespace()
|
bynamespace := f.ReferralCandidates.GroupedByOriginalNamespace()
|
||||||
if _, ok := bynamespace[namespace]; !ok {
|
if _, ok := bynamespace[namespace]; !ok {
|
||||||
return nil
|
bynamespace = f.ReferralCandidates.GroupedByCurrentNamespace()
|
||||||
|
if _, ok := bynamespace[namespace]; !ok {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
}
|
}
|
||||||
subset = bynamespace[namespace]
|
subset = bynamespace[namespace]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -594,3 +594,62 @@ func TestVariablesDisambiguatedWithNamespace(t *testing.T) {
|
|||||||
m := th.Run(".", th.MakeDefaultOptions())
|
m := th.Run(".", th.MakeDefaultOptions())
|
||||||
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
|
th.AssertActualEqualsExpected(m, namespaceNeedInVarExpectedOutput)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TestAddNamePrefixWithNamespace tests that adding a name prefix works within
|
||||||
|
// namespaces other than the default namespace.
|
||||||
|
// Test for issue #3430
|
||||||
|
func TestAddNamePrefixWithNamespace(t *testing.T) {
|
||||||
|
th := kusttest_test.MakeHarness(t)
|
||||||
|
|
||||||
|
th.WriteF("/app/serviceaccount.yaml", `
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
`)
|
||||||
|
|
||||||
|
th.WriteF("/app/clusterrolebinding.yaml", `
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: prometheus
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: prometheus
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: prometheus
|
||||||
|
namespace: iter8-monitoring
|
||||||
|
`)
|
||||||
|
|
||||||
|
th.WriteK("/app", `
|
||||||
|
namePrefix: iter8-
|
||||||
|
namespace: iter8-monitoring
|
||||||
|
resources:
|
||||||
|
- clusterrolebinding.yaml
|
||||||
|
- serviceaccount.yaml
|
||||||
|
`)
|
||||||
|
|
||||||
|
m := th.Run("/app", th.MakeDefaultOptions())
|
||||||
|
th.AssertActualEqualsExpected(m, `
|
||||||
|
apiVersion: rbac.authorization.k8s.io/v1beta1
|
||||||
|
kind: ClusterRoleBinding
|
||||||
|
metadata:
|
||||||
|
name: iter8-prometheus
|
||||||
|
roleRef:
|
||||||
|
apiGroup: rbac.authorization.k8s.io
|
||||||
|
kind: ClusterRole
|
||||||
|
name: prometheus
|
||||||
|
subjects:
|
||||||
|
- kind: ServiceAccount
|
||||||
|
name: iter8-prometheus
|
||||||
|
namespace: iter8-monitoring
|
||||||
|
---
|
||||||
|
apiVersion: v1
|
||||||
|
kind: ServiceAccount
|
||||||
|
metadata:
|
||||||
|
name: iter8-prometheus
|
||||||
|
namespace: iter8-monitoring
|
||||||
|
`)
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user