mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-12 01:14:22 +00:00
address comments
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
resources:
|
resources:
|
||||||
- serviceaccount.yaml
|
- serviceaccount.yaml
|
||||||
- rolebinding.yaml
|
- rolebinding.yaml
|
||||||
namePrefix: base-
|
namePrefix: base-
|
||||||
|
|||||||
@@ -4,4 +4,4 @@ bases:
|
|||||||
namePrefix: a-
|
namePrefix: a-
|
||||||
|
|
||||||
resources:
|
resources:
|
||||||
- serviceaccount.yaml
|
- serviceaccount.yaml
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
resources:
|
resources:
|
||||||
- serviceaccount.yaml
|
- serviceaccount.yaml
|
||||||
- rolebinding.yaml
|
- rolebinding.yaml
|
||||||
namePrefix: base-
|
namePrefix: base-
|
||||||
|
|||||||
@@ -145,7 +145,7 @@ func (m ResMap) insert(newName string, obj *unstructured.Unstructured) error {
|
|||||||
func (m ResMap) FilterBy(inputId resource.ResId) ResMap {
|
func (m ResMap) FilterBy(inputId resource.ResId) ResMap {
|
||||||
result := ResMap{}
|
result := ResMap{}
|
||||||
for id, res := range m {
|
for id, res := range m {
|
||||||
if id.Namespace() == inputId.Namespace() && id.HasSamePrefix(inputId) {
|
if id.Namespace() == inputId.Namespace() && id.HasSameLeftmostPrefix(inputId) {
|
||||||
result[id] = res
|
result[id] = res
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ func (n ResId) Namespace() string {
|
|||||||
|
|
||||||
// CopyWithNewPrefix make a new copy from current ResId and append a new prefix
|
// CopyWithNewPrefix make a new copy from current ResId and append a new prefix
|
||||||
func (n ResId) CopyWithNewPrefix(p string) ResId {
|
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
|
// 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}
|
return ResId{gvk: n.gvk, name: n.name, prefix: n.prefix, namespace: ns}
|
||||||
}
|
}
|
||||||
|
|
||||||
// HasSamePrefix check if two ResIds have the same leading prefix
|
// HasSameLeftmostPrefix check if two ResIds have the same
|
||||||
func (n ResId) HasSamePrefix(id ResId) bool {
|
// left most prefix.
|
||||||
|
func (n ResId) HasSameLeftmostPrefix(id ResId) bool {
|
||||||
prefixes1 := n.prefixList()
|
prefixes1 := n.prefixList()
|
||||||
prefixes2 := id.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 == "" {
|
if p == "" {
|
||||||
return n.prefix
|
return n.prefix
|
||||||
}
|
}
|
||||||
@@ -123,9 +124,5 @@ func (n ResId) concatePrefix(p string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (n ResId) prefixList() []string {
|
func (n ResId) prefixList() []string {
|
||||||
var plist []string
|
|
||||||
if n.prefix == "" {
|
|
||||||
return plist
|
|
||||||
}
|
|
||||||
return strings.Split(n.prefix, ":")
|
return strings.Split(n.prefix, ":")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user