mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 00:52:55 +00:00
Fix some minor nits around namespace code.
This commit is contained in:
@@ -4,7 +4,6 @@
|
|||||||
package build
|
package build
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -18,6 +17,7 @@ import (
|
|||||||
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
"sigs.k8s.io/kustomize/v3/pkg/pgmconfig"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/plugins"
|
"sigs.k8s.io/kustomize/v3/pkg/plugins"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
"sigs.k8s.io/kustomize/v3/pkg/resmap"
|
||||||
|
"sigs.k8s.io/kustomize/v3/pkg/resource"
|
||||||
"sigs.k8s.io/kustomize/v3/pkg/target"
|
"sigs.k8s.io/kustomize/v3/pkg/target"
|
||||||
"sigs.k8s.io/kustomize/v3/plugin/builtin"
|
"sigs.k8s.io/kustomize/v3/plugin/builtin"
|
||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
@@ -202,43 +202,38 @@ func NewCmdBuildPrune(
|
|||||||
|
|
||||||
func writeIndividualFiles(
|
func writeIndividualFiles(
|
||||||
fSys fs.FileSystem, folderPath string, m resmap.ResMap) error {
|
fSys fs.FileSystem, folderPath string, m resmap.ResMap) error {
|
||||||
|
|
||||||
byNamespace := m.GroupedByNamespace()
|
byNamespace := m.GroupedByNamespace()
|
||||||
nsNeeded := len(byNamespace) > 1
|
for namespace, resList := range byNamespace {
|
||||||
for namespace, nresources := range byNamespace {
|
for _, res := range resList {
|
||||||
for _, res := range nresources {
|
fName := fileName(res)
|
||||||
basename := fmt.Sprintf(
|
if len(byNamespace) > 1 {
|
||||||
"%s_%s.yaml",
|
fName = strings.ToLower(namespace) + "_" + fName
|
||||||
strings.ToLower(res.GetGvk().String()),
|
|
||||||
strings.ToLower(res.GetName()),
|
|
||||||
)
|
|
||||||
|
|
||||||
// Preserve backward compatibility with kustomize 2.1.0.
|
|
||||||
// No need to cluter filename with namespace if all the objects
|
|
||||||
// are in the same namespace. The not namespaceable objects
|
|
||||||
// are grouped in the "%no_namespace%" bucket.
|
|
||||||
if (nsNeeded) && (namespace != "%no_namespace%") {
|
|
||||||
basename = fmt.Sprintf(
|
|
||||||
"%s_%s",
|
|
||||||
strings.ToLower(namespace),
|
|
||||||
strings.ToLower(basename),
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
err := writeFile(fSys, folderPath, fName, res)
|
||||||
filename := filepath.Join(
|
|
||||||
folderPath,
|
|
||||||
basename,
|
|
||||||
)
|
|
||||||
|
|
||||||
out, err := yaml.Marshal(res.Map())
|
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
err = fSys.WriteFile(filename, out)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
for _, res := range m.NonNamespaceable() {
|
||||||
|
err := writeFile(fSys, folderPath, fileName(res), res)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func fileName(res *resource.Resource) string {
|
||||||
|
return strings.ToLower(res.GetGvk().String()) +
|
||||||
|
"_" + strings.ToLower(res.GetName()) + ".yaml"
|
||||||
|
}
|
||||||
|
|
||||||
|
func writeFile(
|
||||||
|
fSys fs.FileSystem, path, fName string, res *resource.Resource) error {
|
||||||
|
out, err := yaml.Marshal(res.Map())
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return fSys.WriteFile(filepath.Join(path, fName), out)
|
||||||
|
}
|
||||||
|
|||||||
@@ -186,7 +186,7 @@ var notNamespaceableKinds = []string{
|
|||||||
"VolumeAttachment",
|
"VolumeAttachment",
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNamespaceableKind returns true if x is a namespeable Gvk
|
// IsNamespaceableKind returns true if x is a namespaceable Gvk
|
||||||
// Implements https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#not-all-objects-are-in-a-namespace
|
// Implements https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/#not-all-objects-are-in-a-namespace
|
||||||
func (x Gvk) IsNamespaceableKind() bool {
|
func (x Gvk) IsNamespaceableKind() bool {
|
||||||
for _, k := range notNamespaceableKinds {
|
for _, k := range notNamespaceableKinds {
|
||||||
|
|||||||
@@ -41,9 +41,11 @@ func NewResIdKindOnly(k string, n string) ResId {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const (
|
const (
|
||||||
noNamespace = "~X"
|
noNamespace = "~X"
|
||||||
noName = "~N"
|
noName = "~N"
|
||||||
separator = "|"
|
separator = "|"
|
||||||
|
TotallyNotANamespace = "_non_namespaceable_"
|
||||||
|
DefaultNamespace = "default"
|
||||||
)
|
)
|
||||||
|
|
||||||
// String of ResId based on GVK, name and prefix
|
// String of ResId based on GVK, name and prefix
|
||||||
@@ -96,22 +98,32 @@ func (id ResId) Equals(o ResId) bool {
|
|||||||
return id.IsNsEquals(o) && id.GvknEquals(o)
|
return id.IsNsEquals(o) && id.GvknEquals(o)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNsEquals returns true if the other id matches namespace
|
// IsNsEquals returns true if the id is in
|
||||||
// or both are in the default namespace
|
// the same effective namespace.
|
||||||
// or both are not namespaceable id.
|
|
||||||
func (id ResId) IsNsEquals(o ResId) bool {
|
func (id ResId) IsNsEquals(o ResId) bool {
|
||||||
return id.Namespace == o.Namespace ||
|
return id.EffectiveNamespace() == o.EffectiveNamespace()
|
||||||
(id.IsInDefaultNs() && o.IsInDefaultNs()) ||
|
|
||||||
(!id.IsNamespaceable() && !o.IsNamespaceable())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsInDefaultNs returns true if id is a namespable ResId and the Namespace
|
// IsInDefaultNs returns true if id is a namespaceable
|
||||||
// is either not set or set to "default"
|
// ResId and the Namespace is either not set or set
|
||||||
|
// to DefaultNamespace.
|
||||||
func (id ResId) IsInDefaultNs() bool {
|
func (id ResId) IsInDefaultNs() bool {
|
||||||
return id.IsNamespaceable() && (id.Namespace == "" || id.Namespace == "default")
|
return id.IsNamespaceableKind() && id.isPutativelyDefaultNs()
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsNamespaceable returns true if id is a namespable ResId
|
func (id ResId) isPutativelyDefaultNs() bool {
|
||||||
func (id ResId) IsNamespaceable() bool {
|
return id.Namespace == "" || id.Namespace == DefaultNamespace
|
||||||
return id.IsNamespaceableKind()
|
}
|
||||||
|
|
||||||
|
// EffectiveNamespace returns a non-ambiguous, non-empty
|
||||||
|
// namespace for use in reporting and equality tests.
|
||||||
|
func (id ResId) EffectiveNamespace() string {
|
||||||
|
// The order of these checks matters.
|
||||||
|
if !id.IsNamespaceableKind() {
|
||||||
|
return TotallyNotANamespace
|
||||||
|
}
|
||||||
|
if id.isPutativelyDefaultNs() {
|
||||||
|
return DefaultNamespace
|
||||||
|
}
|
||||||
|
return id.Namespace
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -161,104 +161,169 @@ func TestGvknString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var GvknEqualsTest = []struct {
|
|
||||||
id1 ResId
|
|
||||||
id2 ResId
|
|
||||||
gVknResult bool
|
|
||||||
nSgVknResult bool
|
|
||||||
}{
|
|
||||||
{
|
|
||||||
id1: ResId{
|
|
||||||
Namespace: "X",
|
|
||||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
id2: ResId{
|
|
||||||
Namespace: "X",
|
|
||||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
gVknResult: true,
|
|
||||||
nSgVknResult: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id1: ResId{
|
|
||||||
Namespace: "X",
|
|
||||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
id2: ResId{
|
|
||||||
Namespace: "Z",
|
|
||||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
gVknResult: true,
|
|
||||||
nSgVknResult: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id1: ResId{
|
|
||||||
Namespace: "X",
|
|
||||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
id2: ResId{
|
|
||||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
gVknResult: true,
|
|
||||||
nSgVknResult: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id1: ResId{
|
|
||||||
Namespace: "X",
|
|
||||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
id2: ResId{
|
|
||||||
Namespace: "Z",
|
|
||||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
gVknResult: true,
|
|
||||||
nSgVknResult: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id1: ResId{
|
|
||||||
Namespace: "X",
|
|
||||||
Gvk: gvk.Gvk{Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
id2: ResId{
|
|
||||||
Namespace: "Z",
|
|
||||||
Gvk: gvk.Gvk{Kind: "k"},
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
gVknResult: true,
|
|
||||||
nSgVknResult: false,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
id1: ResId{
|
|
||||||
Namespace: "X",
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
id2: ResId{
|
|
||||||
Namespace: "Z",
|
|
||||||
Name: "nm",
|
|
||||||
},
|
|
||||||
gVknResult: true,
|
|
||||||
nSgVknResult: false,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestEquals(t *testing.T) {
|
func TestEquals(t *testing.T) {
|
||||||
|
|
||||||
|
var GvknEqualsTest = []struct {
|
||||||
|
id1 ResId
|
||||||
|
id2 ResId
|
||||||
|
gVknResult bool
|
||||||
|
nsEquals bool
|
||||||
|
equals bool
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Namespace: "X",
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Namespace: "X",
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
gVknResult: true,
|
||||||
|
nsEquals: true,
|
||||||
|
equals: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Namespace: "X",
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Namespace: "Z",
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
gVknResult: true,
|
||||||
|
nsEquals: false,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Namespace: "X",
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
gVknResult: true,
|
||||||
|
nsEquals: false,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Namespace: "X",
|
||||||
|
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Namespace: "Z",
|
||||||
|
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
gVknResult: true,
|
||||||
|
nsEquals: false,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Namespace: "X",
|
||||||
|
Gvk: gvk.Gvk{Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Namespace: "Z",
|
||||||
|
Gvk: gvk.Gvk{Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
gVknResult: true,
|
||||||
|
nsEquals: false,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Gvk: gvk.Gvk{Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Gvk: gvk.Gvk{Kind: "k"},
|
||||||
|
Name: "nm2",
|
||||||
|
},
|
||||||
|
gVknResult: false,
|
||||||
|
nsEquals: true,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Gvk: gvk.Gvk{Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Gvk: gvk.Gvk{Kind: "Node"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
gVknResult: false,
|
||||||
|
nsEquals: false,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Gvk: gvk.Gvk{Kind: "Node"},
|
||||||
|
Name: "nm1",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Gvk: gvk.Gvk{Kind: "Node"},
|
||||||
|
Name: "nm2",
|
||||||
|
},
|
||||||
|
gVknResult: false,
|
||||||
|
nsEquals: true,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Namespace: "default",
|
||||||
|
Gvk: gvk.Gvk{Kind: "k"},
|
||||||
|
Name: "nm1",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Gvk: gvk.Gvk{Kind: "k"},
|
||||||
|
Name: "nm2",
|
||||||
|
},
|
||||||
|
gVknResult: false,
|
||||||
|
nsEquals: true,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id1: ResId{
|
||||||
|
Namespace: "X",
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
id2: ResId{
|
||||||
|
Namespace: "Z",
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
gVknResult: true,
|
||||||
|
nsEquals: false,
|
||||||
|
equals: false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
for _, tst := range GvknEqualsTest {
|
for _, tst := range GvknEqualsTest {
|
||||||
if tst.id1.GvknEquals(tst.id2) != tst.gVknResult {
|
if tst.id1.GvknEquals(tst.id2) != tst.gVknResult {
|
||||||
t.Fatalf("GvknEquals(\n%v,\n%v\n) should be %v",
|
t.Fatalf("GvknEquals(\n%v,\n%v\n) should be %v",
|
||||||
tst.id1, tst.id2, tst.gVknResult)
|
tst.id1, tst.id2, tst.gVknResult)
|
||||||
}
|
}
|
||||||
if tst.id1.Equals(tst.id2) != tst.nSgVknResult {
|
if tst.id1.IsNsEquals(tst.id2) != tst.nsEquals {
|
||||||
t.Fatalf("NsGvknEquals(\n%v,\n%v\n) should be %v",
|
t.Fatalf("IsNsEquals(\n%v,\n%v\n) should be %v",
|
||||||
tst.id1, tst.id2, tst.nSgVknResult)
|
tst.id1, tst.id2, tst.equals)
|
||||||
|
}
|
||||||
|
if tst.id1.Equals(tst.id2) != tst.equals {
|
||||||
|
t.Fatalf("Equals(\n%v,\n%v\n) should be %v",
|
||||||
|
tst.id1, tst.id2, tst.equals)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -305,3 +370,56 @@ func TestFromString(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestEffectiveNamespace(t *testing.T) {
|
||||||
|
var test = []struct {
|
||||||
|
id ResId
|
||||||
|
expected string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
id: ResId{
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "Node"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
expected: TotallyNotANamespace,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: ResId{
|
||||||
|
Namespace: "foo",
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "Node"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
expected: TotallyNotANamespace,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: ResId{
|
||||||
|
Namespace: "foo",
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
expected: "foo",
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: ResId{
|
||||||
|
Namespace: "",
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
expected: DefaultNamespace,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: ResId{
|
||||||
|
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||||
|
Name: "nm",
|
||||||
|
},
|
||||||
|
expected: DefaultNamespace,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tst := range test {
|
||||||
|
if actual := tst.id.EffectiveNamespace(); actual != tst.expected {
|
||||||
|
t.Fatalf("EffectiveNamespace was %s, expected %s",
|
||||||
|
actual, tst.expected)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -93,13 +93,19 @@ type ResMap interface {
|
|||||||
// Same as GetByOriginalId.
|
// Same as GetByOriginalId.
|
||||||
GetById(resid.ResId) (*resource.Resource, error)
|
GetById(resid.ResId) (*resource.Resource, error)
|
||||||
|
|
||||||
// GroupedByNamespace provides map of discardable slice
|
// GroupedByNamespace returns a map of namespace
|
||||||
// of resource pointer
|
// to a slice of *Resource in that namespace.
|
||||||
// The not namespaceable resources are added to the "cluster-wide" key.
|
// Resources for whom IsNamespaceableKind is false are
|
||||||
// The resources in the default namespace are added to the "default" key.
|
// are not included at all (see NonNamespaceable).
|
||||||
// The rest of the resources are grouped in their respectiv namespace.
|
// Resources with an empty namespace are placed
|
||||||
|
// in the resid.DefaultNamespace entry.
|
||||||
GroupedByNamespace() map[string][]*resource.Resource
|
GroupedByNamespace() map[string][]*resource.Resource
|
||||||
|
|
||||||
|
// NonNamespaceable returns a slice of resources that
|
||||||
|
// cannot be placed in a namespace, e.g.
|
||||||
|
// Node, ClusterRole, Namespace itself, etc.
|
||||||
|
NonNamespaceable() []*resource.Resource
|
||||||
|
|
||||||
// AllIds returns all CurrentIds.
|
// AllIds returns all CurrentIds.
|
||||||
AllIds() []resid.ResId
|
AllIds() []resid.ResId
|
||||||
|
|
||||||
@@ -352,25 +358,25 @@ func (m *resWrangler) GetById(id resid.ResId) (*resource.Resource, error) {
|
|||||||
|
|
||||||
// GroupedByNamespace implements ResMap.GroupByNamespace
|
// GroupedByNamespace implements ResMap.GroupByNamespace
|
||||||
func (m *resWrangler) GroupedByNamespace() map[string][]*resource.Resource {
|
func (m *resWrangler) GroupedByNamespace() map[string][]*resource.Resource {
|
||||||
|
items := m.groupedByNamespace()
|
||||||
|
delete(items, resid.TotallyNotANamespace)
|
||||||
|
return items
|
||||||
|
}
|
||||||
|
|
||||||
|
// NonNamespaceable implements ResMap.NonNamespaceable
|
||||||
|
func (m *resWrangler) NonNamespaceable() []*resource.Resource {
|
||||||
|
return m.groupedByNamespace()[resid.TotallyNotANamespace]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *resWrangler) groupedByNamespace() map[string][]*resource.Resource {
|
||||||
byNamespace := make(map[string][]*resource.Resource)
|
byNamespace := make(map[string][]*resource.Resource)
|
||||||
for _, res := range m.rList {
|
for _, res := range m.rList {
|
||||||
// Add to the notNamespaceable bucket by default.
|
namespace := res.CurId().EffectiveNamespace()
|
||||||
namespace := "%no_namespace%"
|
|
||||||
|
|
||||||
if res.OrgId().IsNamespaceable() {
|
|
||||||
namespace = res.OrgId().Namespace
|
|
||||||
if res.OrgId().IsInDefaultNs() {
|
|
||||||
namespace = "default"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if _, found := byNamespace[namespace]; !found {
|
if _, found := byNamespace[namespace]; !found {
|
||||||
byNamespace[namespace] = make([]*resource.Resource, 0)
|
byNamespace[namespace] = []*resource.Resource{}
|
||||||
}
|
}
|
||||||
|
|
||||||
byNamespace[namespace] = append(byNamespace[namespace], res)
|
byNamespace[namespace] = append(byNamespace[namespace], res)
|
||||||
}
|
}
|
||||||
|
|
||||||
return byNamespace
|
return byNamespace
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user