address comments

This commit is contained in:
Jingfang Liu
2018-09-05 16:00:41 -07:00
parent 7b301446fa
commit 829cb2baa3
5 changed files with 10 additions and 13 deletions

View File

@@ -1,4 +1,4 @@
resources:
- serviceaccount.yaml
- rolebinding.yaml
namePrefix: base-
namePrefix: base-

View File

@@ -4,4 +4,4 @@ bases:
namePrefix: a-
resources:
- serviceaccount.yaml
- serviceaccount.yaml

View File

@@ -1,4 +1,4 @@
resources:
- serviceaccount.yaml
- rolebinding.yaml
namePrefix: base-
namePrefix: base-

View File

@@ -145,7 +145,7 @@ func (m ResMap) insert(newName string, obj *unstructured.Unstructured) error {
func (m ResMap) FilterBy(inputId resource.ResId) ResMap {
result := ResMap{}
for id, res := range m {
if id.Namespace() == inputId.Namespace() && id.HasSamePrefix(inputId) {
if id.Namespace() == inputId.Namespace() && id.HasSameLeftmostPrefix(inputId) {
result[id] = res
}
}

View File

@@ -97,7 +97,7 @@ func (n ResId) Namespace() string {
// CopyWithNewPrefix make a new copy from current ResId and append a new prefix
func (n ResId) CopyWithNewPrefix(p string) ResId {
return ResId{gvk: n.gvk, name: n.name, prefix: n.concatePrefix(p), namespace: n.namespace}
return ResId{gvk: n.gvk, name: n.name, prefix: n.concatPrefix(p), namespace: n.namespace}
}
// CopyWithNewNamespace make a new copy from current ResId and set a new namespace
@@ -105,14 +105,15 @@ func (n ResId) CopyWithNewNamespace(ns string) ResId {
return ResId{gvk: n.gvk, name: n.name, prefix: n.prefix, namespace: ns}
}
// HasSamePrefix check if two ResIds have the same leading prefix
func (n ResId) HasSamePrefix(id ResId) bool {
// HasSameLeftmostPrefix check if two ResIds have the same
// left most prefix.
func (n ResId) HasSameLeftmostPrefix(id ResId) bool {
prefixes1 := n.prefixList()
prefixes2 := id.prefixList()
return len(prefixes1) == 0 || len(prefixes2) == 0 || prefixes1[0] == prefixes2[0]
return prefixes1[0] == prefixes2[0]
}
func (n ResId) concatePrefix(p string) string {
func (n ResId) concatPrefix(p string) string {
if p == "" {
return n.prefix
}
@@ -123,9 +124,5 @@ func (n ResId) concatePrefix(p string) string {
}
func (n ResId) prefixList() []string {
var plist []string
if n.prefix == "" {
return plist
}
return strings.Split(n.prefix, ":")
}