From 829cb2baa386e473b86a90f588e0e8007b8d06ae Mon Sep 17 00:00:00 2001 From: Jingfang Liu Date: Wed, 5 Sep 2018 16:00:41 -0700 Subject: [PATCH] address comments --- .../base/kustomization.yaml | 2 +- .../overlays/a/kustomization.yaml | 2 +- .../base/kustomization.yaml | 2 +- pkg/resmap/resmap.go | 2 +- pkg/resource/resid.go | 15 ++++++--------- 5 files changed, 10 insertions(+), 13 deletions(-) diff --git a/pkg/commands/testdata/testcase-multibases-conflict/base/kustomization.yaml b/pkg/commands/testdata/testcase-multibases-conflict/base/kustomization.yaml index 9084ca255..f913dbaf5 100644 --- a/pkg/commands/testdata/testcase-multibases-conflict/base/kustomization.yaml +++ b/pkg/commands/testdata/testcase-multibases-conflict/base/kustomization.yaml @@ -1,4 +1,4 @@ resources: - serviceaccount.yaml - rolebinding.yaml -namePrefix: base- \ No newline at end of file +namePrefix: base- diff --git a/pkg/commands/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml b/pkg/commands/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml index 0ff4668b5..166dba8ac 100644 --- a/pkg/commands/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml +++ b/pkg/commands/testdata/testcase-multibases-conflict/overlays/a/kustomization.yaml @@ -4,4 +4,4 @@ bases: namePrefix: a- resources: -- serviceaccount.yaml \ No newline at end of file +- serviceaccount.yaml diff --git a/pkg/commands/testdata/testcase-multibases-nonconflict/base/kustomization.yaml b/pkg/commands/testdata/testcase-multibases-nonconflict/base/kustomization.yaml index 9084ca255..f913dbaf5 100644 --- a/pkg/commands/testdata/testcase-multibases-nonconflict/base/kustomization.yaml +++ b/pkg/commands/testdata/testcase-multibases-nonconflict/base/kustomization.yaml @@ -1,4 +1,4 @@ resources: - serviceaccount.yaml - rolebinding.yaml -namePrefix: base- \ No newline at end of file +namePrefix: base- diff --git a/pkg/resmap/resmap.go b/pkg/resmap/resmap.go index 60ec6f131..5471541e8 100644 --- a/pkg/resmap/resmap.go +++ b/pkg/resmap/resmap.go @@ -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 } } diff --git a/pkg/resource/resid.go b/pkg/resource/resid.go index 563e8701e..c970eb9b1 100644 --- a/pkg/resource/resid.go +++ b/pkg/resource/resid.go @@ -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, ":") }