Skip to content

Commit

Permalink
include nameprefix and namesuffix to find matched reference for clust…
Browse files Browse the repository at this point in the history
…er level kinds
  • Loading branch information
Liujingfang1 committed Jul 12, 2019
1 parent cd00ce7 commit eeed195
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
15 changes: 14 additions & 1 deletion pkg/resmap/resmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,20 @@ func (m *resWrangler) SubsetThatCouldBeReferencedByResource(
inputRes *resource.Resource) ResMap {
inputId := inputRes.OrgId()
if !inputId.IsNamespaceableKind() {
return m
if inputRes.GetOutermostNamePrefix() == "" {
return m
}
result := New()
for _, r := range m.Resources() {
if r.GetOutermostNamePrefix() == inputRes.GetOutermostNamePrefix() &&
r.GetOutermostNameSuffix() == inputRes.GetOutermostNameSuffix() {
err := result.Append(r)
if err != nil {
panic(err)
}
}
}
return result
}
result := New()
for _, r := range m.Resources() {
Expand Down
74 changes: 74 additions & 0 deletions pkg/target/resourceconflict_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func writeBase(th *kusttest_test.KustTestHarness) {
resources:
- serviceaccount.yaml
- rolebinding.yaml
- clusterrolebinding.yaml
namePrefix: pfx-
nameSuffix: -sfx
`)
Expand All @@ -34,6 +35,19 @@ roleRef:
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: serviceaccount
`)
th.WriteF("/app/base/clusterrolebinding.yaml", `
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: rolebinding
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: serviceaccount
`)
Expand Down Expand Up @@ -86,6 +100,18 @@ roleRef:
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: pfx-serviceaccount-sfx
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: pfx-rolebinding-sfx
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: pfx-serviceaccount-sfx
`)
Expand Down Expand Up @@ -114,6 +140,18 @@ roleRef:
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: a-pfx-serviceaccount-sfx-suffixA
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: a-pfx-rolebinding-sfx-suffixA
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: a-pfx-serviceaccount-sfx-suffixA
`)
Expand Down Expand Up @@ -142,6 +180,18 @@ roleRef:
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: b-pfx-serviceaccount-sfx-suffixB
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: b-pfx-rolebinding-sfx-suffixB
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: b-pfx-serviceaccount-sfx-suffixB
`)
Expand Down Expand Up @@ -174,6 +224,18 @@ subjects:
- kind: ServiceAccount
name: a-pfx-serviceaccount-sfx-suffixA
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: a-pfx-rolebinding-sfx-suffixA
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: a-pfx-serviceaccount-sfx-suffixA
---
apiVersion: v1
kind: ServiceAccount
metadata:
Expand All @@ -188,6 +250,18 @@ roleRef:
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: b-pfx-serviceaccount-sfx-suffixB
---
apiVersion: rbac.authorization.k8s.io/v1beta1
kind: ClusterRoleBinding
metadata:
name: b-pfx-rolebinding-sfx-suffixB
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: role
subjects:
- kind: ServiceAccount
name: b-pfx-serviceaccount-sfx-suffixB
`)
Expand Down

0 comments on commit eeed195

Please sign in to comment.