Merge pull request #95 from Liujingfang1/crdsupport

Add skeleton for CRD support
This commit is contained in:
Jeff Regan
2018-06-12 09:21:10 -07:00
committed by GitHub
8 changed files with 114 additions and 1 deletions

View File

@@ -312,3 +312,23 @@ 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: &schema.GroupVersionKind{Group: "GroupA", Kind: "KindB"},
Path: []string{"path", "to", "a", "field"},
CreateIfNotPresent: true,
},
}
AddLabelsPathConfigs(pathConfigs)
AddAnnotationsPathConfigs(pathConfigs)
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

@@ -162,3 +162,13 @@ 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

@@ -22,6 +22,7 @@ import (
"github.com/kubernetes-sigs/kustomize/pkg/resmap"
"github.com/kubernetes-sigs/kustomize/pkg/resource"
"k8s.io/apimachinery/pkg/runtime/schema"
)
func TestNameReferenceRun(t *testing.T) {
@@ -199,3 +200,29 @@ 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: schema.GroupVersionKind{
Kind: "KindA",
},
pathConfigs: []PathConfig{
{
GroupVersionKind: &schema.GroupVersionKind{
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

@@ -733,3 +733,8 @@ var defaultNameReferencePathConfigs = []referencePathConfig{
},
},
}
// AddNameReferencePathConfigs adds extra reference path configs to the default one
func AddNameReferencePathConfigs(r []referencePathConfig) {
defaultNameReferencePathConfigs = append(defaultNameReferencePathConfigs, r...)
}