mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-11 17:12:51 +00:00
Simplify code base.
- In ResMap, drop concept of internal Id to Resource map. The ResMap is now (just) a list, allowing only very particular edits. - Resources should now be maintained in the order loaded. A later PR can adjust tests to remove the internal legacy sorting, and confirm order-out is predictable from order-in. The PR would suppress the sort in tests, and reorder the output to make all tests pass again, and confirm that the new order matched depth-first input traversal. The FromMap fixture function was removed from all test inputs to establish a predictable input order. - Resources now have two 'Ids', OriginalId and CurrentId. The former is fixed as GVK-name-namespace at load time, the latter changes during transformations. The latter can be used to narrow name references when the former maps to multiple resources. We allow bases to be loaded more than once in a build (a diamond pattern), so the OriginalId is not unique across the resources set. The CurrentId is (and must be) unique, but is constantly mutating. Failing to make this distinction clear, and attempting to maintain a mapping from a single mutating Id to a resource was making the code too complex. - Drop prefix/suffix from ResId - the ResId is now immutable. A later PR can remove the distinction with ItemId. - This PR increases coverage of ResMap is since this is a large refactor. Higher level tests didn't need much change outside reordering of results at the resource level.
This commit is contained in:
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package resid
|
||||
|
||||
import (
|
||||
"strings"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
)
|
||||
|
||||
// ItemId contains the group, version, kind, namespace
|
||||
// and name of a resource
|
||||
type ItemId struct {
|
||||
// Gvk of the resource.
|
||||
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
|
||||
|
||||
// Name of the resource before transformation.
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
|
||||
// Namespace the resource belongs to.
|
||||
// An untransformed resource has no namespace.
|
||||
// A fully transformed resource has the namespace
|
||||
// from the top most overlay.
|
||||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||
}
|
||||
|
||||
// String of ItemId based on GVK, name and namespace
|
||||
func (i ItemId) String() string {
|
||||
ns := i.Namespace
|
||||
if ns == "" {
|
||||
ns = noNamespace
|
||||
}
|
||||
nm := i.Name
|
||||
if nm == "" {
|
||||
nm = noName
|
||||
}
|
||||
|
||||
return strings.Join(
|
||||
[]string{i.Gvk.String(), ns, nm}, separator)
|
||||
}
|
||||
|
||||
func (i ItemId) Equals(o ItemId) bool {
|
||||
return i.Name == o.Name &&
|
||||
i.Namespace == o.Namespace &&
|
||||
i.Gvk.Equals(o.Gvk)
|
||||
}
|
||||
|
||||
func NewItemId(g gvk.Gvk, ns, nm string) ItemId {
|
||||
return ItemId{
|
||||
Gvk: g,
|
||||
Namespace: ns,
|
||||
Name: nm,
|
||||
}
|
||||
}
|
||||
|
||||
func FromString(s string) ItemId {
|
||||
values := strings.Split(s, separator)
|
||||
g := gvk.FromString(values[0])
|
||||
|
||||
ns := values[1]
|
||||
if ns == noNamespace {
|
||||
ns = ""
|
||||
}
|
||||
nm := values[2]
|
||||
if nm == noName {
|
||||
nm = ""
|
||||
}
|
||||
return ItemId{
|
||||
Gvk: g,
|
||||
Namespace: ns,
|
||||
Name: nm,
|
||||
}
|
||||
}
|
||||
@@ -1,66 +0,0 @@
|
||||
/*
|
||||
Copyright 2019 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package resid
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
)
|
||||
|
||||
var itemIds = []ItemId{
|
||||
{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
}
|
||||
|
||||
func TestItemIds(t *testing.T) {
|
||||
for _, item := range itemIds {
|
||||
newItem := FromString(item.String())
|
||||
if newItem != item {
|
||||
t.Fatalf("Actual: %v, Expected: '%s'", newItem, item)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,18 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package resid
|
||||
|
||||
@@ -22,177 +9,89 @@ import (
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
)
|
||||
|
||||
// ResId is an immutable identifier of a k8s resource object.
|
||||
// ResId is an identifier of a k8s resource object.
|
||||
type ResId struct {
|
||||
ItemId
|
||||
// namePrefix of the resource.
|
||||
// An untransformed resource has no prefix.
|
||||
// A fully transformed resource has an arbitrary
|
||||
// number of prefixes concatenated together.
|
||||
Prefix string `json:"prefix,omitempty"`
|
||||
// Gvk of the resource.
|
||||
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
|
||||
|
||||
// nameSuffix of the resource.
|
||||
// An untransformed resource has no suffix.
|
||||
// A fully transformed resource has an arbitrary
|
||||
// number of suffixes concatenated together.
|
||||
Suffix string `json:"suffix,omitempty"`
|
||||
// Name of the resource before transformation.
|
||||
Name string `json:"name,omitempty" yaml:"name,omitempty"`
|
||||
|
||||
// Namespace the resource belongs to.
|
||||
// An untransformed resource has no namespace.
|
||||
// A fully transformed resource has the namespace
|
||||
// from the top most overlay.
|
||||
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
|
||||
}
|
||||
|
||||
// NewResIdWithNamespace creates new resource identifier
|
||||
// NewResIdWithNamespace creates new ResId
|
||||
// in a given namespace.
|
||||
func NewResIdWithNamespace(k gvk.Gvk, n, ns string) ResId {
|
||||
return ResId{ItemId: ItemId{Gvk: k, Name: n, Namespace: ns}}
|
||||
return ResId{Gvk: k, Name: n, Namespace: ns}
|
||||
}
|
||||
|
||||
// NewResIdWithPrefixSuffixNamespace creates new resource identifier with a prefix, suffix and a namespace
|
||||
func NewResIdWithPrefixSuffixNamespace(k gvk.Gvk, n, p, s, ns string) ResId {
|
||||
return ResId{ItemId: ItemId{Gvk: k, Name: n, Namespace: ns}, Prefix: p, Suffix: s}
|
||||
}
|
||||
|
||||
// NewResIdWithPrefixNamespace creates new resource identifier with a prefix and a namespace
|
||||
func NewResIdWithPrefixNamespace(k gvk.Gvk, n, p, ns string) ResId {
|
||||
return ResId{ItemId: ItemId{Gvk: k, Name: n, Namespace: ns}, Prefix: p}
|
||||
}
|
||||
|
||||
// NewResIdWithSuffixNamespace creates new resource identifier with a suffix and a namespace
|
||||
func NewResIdWithSuffixNamespace(k gvk.Gvk, n, s, ns string) ResId {
|
||||
return ResId{ItemId: ItemId{Gvk: k, Name: n, Namespace: ns}, Suffix: s}
|
||||
}
|
||||
|
||||
// NewResId creates new resource identifier
|
||||
// NewResId creates new ResId.
|
||||
func NewResId(k gvk.Gvk, n string) ResId {
|
||||
return ResId{ItemId: ItemId{Gvk: k, Name: n}}
|
||||
return ResId{Gvk: k, Name: n}
|
||||
}
|
||||
|
||||
// NewResIdKindOnly creates new resource identifier
|
||||
// NewResIdKindOnly creates a new ResId.
|
||||
func NewResIdKindOnly(k string, n string) ResId {
|
||||
return ResId{ItemId: ItemId{Gvk: gvk.FromKind(k), Name: n}}
|
||||
return ResId{Gvk: gvk.FromKind(k), Name: n}
|
||||
}
|
||||
|
||||
const (
|
||||
noNamespace = "~X"
|
||||
noPrefix = "~P"
|
||||
noName = "~N"
|
||||
noSuffix = "~S"
|
||||
separator = "|"
|
||||
)
|
||||
|
||||
// String of ResId based on GVK, name and prefix
|
||||
func (n ResId) String() string {
|
||||
ns := n.ItemId.Namespace
|
||||
func (id ResId) String() string {
|
||||
ns := id.Namespace
|
||||
if ns == "" {
|
||||
ns = noNamespace
|
||||
}
|
||||
p := n.Prefix
|
||||
if p == "" {
|
||||
p = noPrefix
|
||||
}
|
||||
nm := n.ItemId.Name
|
||||
nm := id.Name
|
||||
if nm == "" {
|
||||
nm = noName
|
||||
}
|
||||
s := n.Suffix
|
||||
if s == "" {
|
||||
s = noSuffix
|
||||
}
|
||||
|
||||
return strings.Join(
|
||||
[]string{n.ItemId.Gvk.String(), ns, p, nm, s}, separator)
|
||||
[]string{id.Gvk.String(), ns, nm}, separator)
|
||||
}
|
||||
|
||||
func FromString(s string) ResId {
|
||||
values := strings.Split(s, separator)
|
||||
g := gvk.FromString(values[0])
|
||||
|
||||
ns := values[1]
|
||||
if ns == noNamespace {
|
||||
ns = ""
|
||||
}
|
||||
nm := values[2]
|
||||
if nm == noName {
|
||||
nm = ""
|
||||
}
|
||||
return ResId{
|
||||
Gvk: g,
|
||||
Namespace: ns,
|
||||
Name: nm,
|
||||
}
|
||||
}
|
||||
|
||||
// GvknString of ResId based on GVK and name
|
||||
func (n ResId) GvknString() string {
|
||||
return n.ItemId.Gvk.String() + separator + n.ItemId.Name
|
||||
func (id ResId) GvknString() string {
|
||||
return id.Gvk.String() + separator + id.Name
|
||||
}
|
||||
|
||||
// GvknEquals returns true if the other id matches
|
||||
// Group/Version/Kind/name.
|
||||
func (n ResId) GvknEquals(id ResId) bool {
|
||||
return n.ItemId.Name == id.ItemId.Name && n.ItemId.Gvk.Equals(id.ItemId.Gvk)
|
||||
func (id ResId) GvknEquals(o ResId) bool {
|
||||
return id.Name == o.Name && id.Gvk.Equals(o.Gvk)
|
||||
}
|
||||
|
||||
// NsGvknEquals returns true if the other id matches
|
||||
// Equals returns true if the other id matches
|
||||
// namespace/Group/Version/Kind/name.
|
||||
func (n ResId) NsGvknEquals(id ResId) bool {
|
||||
// TODO: same a n.ItemId.Equals(id.ItemId)
|
||||
return n.ItemId.Namespace == id.ItemId.Namespace && n.GvknEquals(id)
|
||||
}
|
||||
|
||||
// Gvk returns Group/Version/Kind of the resource.
|
||||
func (n ResId) Gvk() gvk.Gvk {
|
||||
return n.ItemId.Gvk
|
||||
}
|
||||
|
||||
// Name returns resource name.
|
||||
func (n ResId) Name() string {
|
||||
return n.ItemId.Name
|
||||
}
|
||||
|
||||
// Namespace returns resource namespace.
|
||||
func (n ResId) Namespace() string {
|
||||
return n.ItemId.Namespace
|
||||
}
|
||||
|
||||
// CopyWithNewPrefixSuffix make a new copy from current ResId
|
||||
// and append a new prefix and suffix
|
||||
func (n ResId) CopyWithNewPrefixSuffix(p, s string) ResId {
|
||||
result := n
|
||||
if p != "" {
|
||||
result.Prefix = n.concatPrefix(p)
|
||||
}
|
||||
if s != "" {
|
||||
result.Suffix = n.concatSuffix(s)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// CopyWithNewNamespace make a new copy from current ResId and set a new namespace
|
||||
func (n ResId) CopyWithNewNamespace(ns string) ResId {
|
||||
result := n
|
||||
result.ItemId.Namespace = ns
|
||||
return result
|
||||
}
|
||||
|
||||
// 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 prefixes1[0] == prefixes2[0]
|
||||
}
|
||||
|
||||
// HasSameRightmostSuffix check if two ResIds have the same
|
||||
// right most suffix.
|
||||
func (n ResId) HasSameRightmostSuffix(id ResId) bool {
|
||||
suffixes1 := n.suffixList()
|
||||
suffixes2 := id.suffixList()
|
||||
return suffixes1[len(suffixes1)-1] == suffixes2[len(suffixes2)-1]
|
||||
}
|
||||
|
||||
func (n ResId) concatPrefix(p string) string {
|
||||
if p == "" {
|
||||
return n.Prefix
|
||||
}
|
||||
if n.Prefix == "" {
|
||||
return p
|
||||
}
|
||||
return p + ":" + n.Prefix
|
||||
}
|
||||
|
||||
func (n ResId) concatSuffix(s string) string {
|
||||
if s == "" {
|
||||
return n.Suffix
|
||||
}
|
||||
if n.Suffix == "" {
|
||||
return s
|
||||
}
|
||||
return n.Suffix + ":" + s
|
||||
}
|
||||
|
||||
func (n ResId) prefixList() []string {
|
||||
return strings.Split(n.Prefix, ":")
|
||||
}
|
||||
|
||||
func (n ResId) suffixList() []string {
|
||||
return strings.Split(n.Suffix, ":")
|
||||
func (id ResId) Equals(o ResId) bool {
|
||||
return id.Namespace == o.Namespace && id.GvknEquals(o)
|
||||
}
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
/*
|
||||
Copyright 2018 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
// Copyright 2019 The Kubernetes Authors.
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
package resid
|
||||
|
||||
@@ -28,93 +15,65 @@ var stringTests = []struct {
|
||||
}{
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
"g_v_k|ns|p|nm|s",
|
||||
"g_v_k|ns|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_v_k|ns|p|nm|s",
|
||||
"~G_v_k|ns|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_~V_k|ns|p|nm|s",
|
||||
"~G_~V_k|ns|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_~V_~K|ns|p|nm|s",
|
||||
"~G_~V_~K|ns|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_~V_~K|~X|p|nm|s",
|
||||
"~G_~V_~K|~X|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
Suffix: "s",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_~V_~K|~X|~P|nm|s",
|
||||
"~G_~V_~K|~X|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
Suffix: "s",
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
"~G_~V_~K|~X|~P|~N|s",
|
||||
"~G_~V_~K|~X|~N",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
"~G_~V_~K|~X|~P|~N|~S",
|
||||
"~G_~V_~K|~X|~N",
|
||||
},
|
||||
{
|
||||
ResId{},
|
||||
"~G_~V_~K|~X|~P|~N|~S",
|
||||
"~G_~V_~K|~X|~N",
|
||||
},
|
||||
}
|
||||
|
||||
@@ -132,87 +91,59 @@ var gvknStringTests = []struct {
|
||||
}{
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
"g_v_k|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_v_k|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_~V_k|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_~V_~K|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p",
|
||||
Suffix: "s",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_~V_~K|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
Suffix: "s",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
"~G_~V_~K|nm",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
Suffix: "s",
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
"~G_~V_~K|",
|
||||
},
|
||||
{
|
||||
ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
"~G_~V_~K|",
|
||||
},
|
||||
@@ -238,129 +169,81 @@ var GvknEqualsTest = []struct {
|
||||
}{
|
||||
{
|
||||
id1: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "AA",
|
||||
Suffix: "aa",
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
id2: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "BB",
|
||||
Suffix: "bb",
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
gVknResult: true,
|
||||
nSgVknResult: true,
|
||||
},
|
||||
{
|
||||
id1: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "AA",
|
||||
Suffix: "aa",
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
id2: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "Z",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "BB",
|
||||
Suffix: "bb",
|
||||
Namespace: "Z",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
gVknResult: true,
|
||||
nSgVknResult: false,
|
||||
},
|
||||
{
|
||||
id1: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "AA",
|
||||
Suffix: "aa",
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
id2: ResId{
|
||||
ItemId: ItemId{
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "BB",
|
||||
Suffix: "bb",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
gVknResult: true,
|
||||
nSgVknResult: false,
|
||||
},
|
||||
{
|
||||
id1: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "AA",
|
||||
Suffix: "aa",
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
id2: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "Z",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "BB",
|
||||
Suffix: "bb",
|
||||
Namespace: "Z",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
gVknResult: true,
|
||||
nSgVknResult: false,
|
||||
},
|
||||
{
|
||||
id1: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "AA",
|
||||
Suffix: "aa",
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
id2: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "Z",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "BB",
|
||||
Suffix: "bb",
|
||||
Namespace: "Z",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
gVknResult: true,
|
||||
nSgVknResult: false,
|
||||
},
|
||||
{
|
||||
id1: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "AA",
|
||||
Suffix: "aa",
|
||||
Namespace: "X",
|
||||
Name: "nm",
|
||||
},
|
||||
id2: ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "Z",
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "BB",
|
||||
Suffix: "bb",
|
||||
Namespace: "Z",
|
||||
Name: "nm",
|
||||
},
|
||||
gVknResult: true,
|
||||
nSgVknResult: false,
|
||||
@@ -373,59 +256,52 @@ func TestEquals(t *testing.T) {
|
||||
t.Fatalf("GvknEquals(\n%v,\n%v\n) should be %v",
|
||||
tst.id1, tst.id2, tst.gVknResult)
|
||||
}
|
||||
if tst.id1.NsGvknEquals(tst.id2) != tst.nSgVknResult {
|
||||
if tst.id1.Equals(tst.id2) != tst.nSgVknResult {
|
||||
t.Fatalf("NsGvknEquals(\n%v,\n%v\n) should be %v",
|
||||
tst.id1, tst.id2, tst.nSgVknResult)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestCopyWithNewPrefixSuffix(t *testing.T) {
|
||||
r1 := ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "a",
|
||||
Suffix: "b",
|
||||
}
|
||||
r2 := r1.CopyWithNewPrefixSuffix("p-", "-s")
|
||||
expected := ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "p-a",
|
||||
Suffix: "b-s",
|
||||
}
|
||||
if !r2.GvknEquals(expected) {
|
||||
t.Fatalf("%v should equal %v", r2, expected)
|
||||
}
|
||||
var ids = []ResId{
|
||||
{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Namespace: "ns",
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Gvk: gvk.Gvk{},
|
||||
Name: "nm",
|
||||
},
|
||||
{
|
||||
Gvk: gvk.Gvk{},
|
||||
},
|
||||
}
|
||||
|
||||
func TestCopyWithNewNamespace(t *testing.T) {
|
||||
r1 := ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "X",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "a",
|
||||
Suffix: "b",
|
||||
}
|
||||
r2 := r1.CopyWithNewNamespace("zzz")
|
||||
expected := ResId{
|
||||
ItemId: ItemId{
|
||||
Namespace: "zzz",
|
||||
Gvk: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
|
||||
Name: "nm",
|
||||
},
|
||||
Prefix: "a",
|
||||
Suffix: "b",
|
||||
}
|
||||
if !r2.GvknEquals(expected) {
|
||||
t.Fatalf("%v should equal %v", r2, expected)
|
||||
func TestFromString(t *testing.T) {
|
||||
for _, id := range ids {
|
||||
newId := FromString(id.String())
|
||||
if newId != id {
|
||||
t.Fatalf("Actual: %v, Expected: '%s'", newId, id)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user