Refactor crd package to depend on transformerconfig

This commit is contained in:
Jingfang Liu
2018-09-27 10:39:29 -07:00
parent 20fa90a137
commit 7ab710889c
20 changed files with 204 additions and 217 deletions

View File

@@ -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)
}
}

View File

@@ -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...)
}

View File

@@ -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)
}
}

View File

@@ -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
}

View File

@@ -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()

View File

@@ -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...)
}

View File

@@ -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)
}
}