mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-06-14 02:20:53 +00:00
Refactor crd package to depend on transformerconfig
This commit is contained in:
@@ -562,23 +562,3 @@ func TestAnnotationsRun(t *testing.T) {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddPathConfigs(t *testing.T) {
|
||||
aexpected := len(defaultAnnotationsPathConfigs) + 1
|
||||
lexpected := len(defaultLabelsPathConfigs) + 1
|
||||
pathConfigs := []PathConfig{
|
||||
{
|
||||
GroupVersionKind: &gvk.Gvk{Group: "GroupA", Kind: "KindB"},
|
||||
Path: []string{"path", "to", "a", "field"},
|
||||
CreateIfNotPresent: true,
|
||||
},
|
||||
}
|
||||
AddLabelsPathConfigs(pathConfigs...)
|
||||
AddAnnotationsPathConfigs(pathConfigs[0])
|
||||
if len(defaultAnnotationsPathConfigs) != aexpected {
|
||||
t.Fatalf("actual %v doesn't match expected: %v", len(defaultAnnotationsPathConfigs), aexpected)
|
||||
}
|
||||
if len(defaultLabelsPathConfigs) != lexpected {
|
||||
t.Fatalf("actual %v doesn't match expected: %v", len(defaultLabelsPathConfigs), lexpected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,13 +224,3 @@ var defaultAnnotationsPathConfigs = []PathConfig{
|
||||
CreateIfNotPresent: true,
|
||||
},
|
||||
}
|
||||
|
||||
// AddLabelsPathConfigs adds extra path configs to the default one
|
||||
func AddLabelsPathConfigs(pathConfigs ...PathConfig) {
|
||||
defaultLabelsPathConfigs = append(defaultLabelsPathConfigs, pathConfigs...)
|
||||
}
|
||||
|
||||
// AddAnnotationsPathConfigs adds extra path configs to the default one
|
||||
func AddAnnotationsPathConfigs(pathConfigs ...PathConfig) {
|
||||
defaultAnnotationsPathConfigs = append(defaultAnnotationsPathConfigs, pathConfigs...)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
)
|
||||
@@ -336,29 +335,3 @@ func TestNameReferenceRun(t *testing.T) {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddNameReferencePathConfigs(t *testing.T) {
|
||||
expected := len(defaultNameReferencePathConfigs) + 1
|
||||
|
||||
pathConfigs := []ReferencePathConfig{
|
||||
{
|
||||
referencedGVK: gvk.Gvk{
|
||||
Kind: "KindA",
|
||||
},
|
||||
pathConfigs: []PathConfig{
|
||||
{
|
||||
GroupVersionKind: &gvk.Gvk{
|
||||
Kind: "KindB",
|
||||
},
|
||||
Path: []string{"path", "to", "a", "field"},
|
||||
CreateIfNotPresent: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
AddNameReferencePathConfigs(pathConfigs)
|
||||
if len(defaultNameReferencePathConfigs) != expected {
|
||||
t.Fatalf("actual %v doesn't match expected: %v", len(defaultAnnotationsPathConfigs), expected)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -918,28 +918,3 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// AddNameReferencePathConfigs adds extra reference path configs to the default one
|
||||
func AddNameReferencePathConfigs(r []ReferencePathConfig) {
|
||||
for _, p := range r {
|
||||
defaultNameReferencePathConfigs = MergeNameReferencePathConfigs(defaultNameReferencePathConfigs, p)
|
||||
}
|
||||
}
|
||||
|
||||
// MergeNameReferencePathConfigs merges one ReferencePathConfig into a slice of ReferencePathConfig
|
||||
func MergeNameReferencePathConfigs(configs []ReferencePathConfig, config ReferencePathConfig) []ReferencePathConfig {
|
||||
var result []ReferencePathConfig
|
||||
found := false
|
||||
for _, c := range configs {
|
||||
if c.referencedGVK == config.referencedGVK {
|
||||
c.pathConfigs = append(c.pathConfigs, config.pathConfigs...)
|
||||
found = true
|
||||
}
|
||||
result = append(result, c)
|
||||
}
|
||||
|
||||
if !found {
|
||||
result = append(result, config)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
@@ -54,14 +54,6 @@ type ReferencePathConfig struct {
|
||||
pathConfigs []PathConfig
|
||||
}
|
||||
|
||||
// NewReferencePathConfig creates a new ReferencePathConfig object
|
||||
func NewReferencePathConfig(k gvk.Gvk, pathconfigs []PathConfig) ReferencePathConfig {
|
||||
return ReferencePathConfig{
|
||||
referencedGVK: k,
|
||||
pathConfigs: pathconfigs,
|
||||
}
|
||||
}
|
||||
|
||||
// GVK returns the Group version kind of a Reference PathConfig
|
||||
func (r ReferencePathConfig) GVK() string {
|
||||
return r.referencedGVK.String()
|
||||
|
||||
@@ -114,8 +114,3 @@ func (o *namePrefixTransformer) addPrefix(in interface{}) (interface{}, error) {
|
||||
}
|
||||
return o.prefix + s, nil
|
||||
}
|
||||
|
||||
// AddPrefixPathConfigs adds extra path configs to the default one
|
||||
func AddPrefixPathConfigs(pathConfigs ...PathConfig) {
|
||||
defaultNamePrefixPathConfigs = append(defaultNamePrefixPathConfigs, pathConfigs...)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"sigs.k8s.io/kustomize/pkg/gvk"
|
||||
"sigs.k8s.io/kustomize/pkg/resmap"
|
||||
"sigs.k8s.io/kustomize/pkg/resource"
|
||||
)
|
||||
@@ -92,19 +91,3 @@ func TestPrefixNameRun(t *testing.T) {
|
||||
t.Fatalf("actual doesn't match expected: %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAddPrefixPathConfigs(t *testing.T) {
|
||||
expected := len(defaultNamePrefixPathConfigs) + 1
|
||||
|
||||
pathConfigs := []PathConfig{
|
||||
{
|
||||
GroupVersionKind: &gvk.Gvk{Group: "GroupA", Kind: "KindB"},
|
||||
Path: []string{"path", "to", "a", "field"},
|
||||
CreateIfNotPresent: true,
|
||||
},
|
||||
}
|
||||
AddPrefixPathConfigs(pathConfigs...)
|
||||
if len(defaultNamePrefixPathConfigs) != expected {
|
||||
t.Fatalf("actual %v doesn't match expected: %v", len(defaultNamePrefixPathConfigs), expected)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user