Merge pull request #3441 from natasha41575/namePrefixNamespaceBehavior

Update name references by checking both the original and current namespaces
This commit is contained in:
Jeff Regan
2021-01-13 16:21:05 -08:00
committed by GitHub
2 changed files with 63 additions and 1 deletions

View File

@@ -90,7 +90,10 @@ func (f Filter) setMapping(node *yaml.RNode) error {
namespace := namespaceNode.YNode().Value
bynamespace := f.ReferralCandidates.GroupedByOriginalNamespace()
if _, ok := bynamespace[namespace]; !ok {
return nil
bynamespace = f.ReferralCandidates.GroupedByCurrentNamespace()
if _, ok := bynamespace[namespace]; !ok {
return nil
}
}
subset = bynamespace[namespace]
}

View File

@@ -594,3 +594,62 @@ func TestVariablesDisambiguatedWithNamespace(t *testing.T) {
m := th.Run(".", th.MakeDefaultOptions())
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
`)
}