Merge pull request #376 from monopole/gvk

Introduce gvk package to isolate apimachinery schema.
This commit is contained in:
k8s-ci-robot
2018-09-26 16:45:15 -07:00
committed by GitHub
38 changed files with 570 additions and 477 deletions

View File

@@ -25,12 +25,12 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/golang/glog" "github.com/golang/glog"
"github.com/pkg/errors" "github.com/pkg/errors"
"sigs.k8s.io/kustomize/pkg/configmapandsecret" "sigs.k8s.io/kustomize/pkg/configmapandsecret"
"sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/constants"
"sigs.k8s.io/kustomize/pkg/crds" "sigs.k8s.io/kustomize/pkg/crds"
"sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/gvk"
interror "sigs.k8s.io/kustomize/pkg/internal/error" interror "sigs.k8s.io/kustomize/pkg/internal/error"
"sigs.k8s.io/kustomize/pkg/loader" "sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/patch" "sigs.k8s.io/kustomize/pkg/patch"
@@ -285,7 +285,8 @@ func (a *Application) resolveRefVars(m resmap.ResMap) (map[string]string, error)
return result, err return result, err
} }
for _, v := range vars { for _, v := range vars {
id := resource.NewResId(v.ObjRef.GroupVersionKind(), v.ObjRef.Name) id := resource.NewResId(
gvk.FromSchemaGvk(v.ObjRef.GroupVersionKind()), v.ObjRef.Name)
if r, found := m.DemandOneMatchForId(id); found { if r, found := m.DemandOneMatchForId(id); found {
s, err := r.GetFieldValue(v.FieldRef.FieldPath) s, err := r.GetFieldValue(v.FieldRef.FieldPath)
if err != nil { if err != nil {

View File

@@ -23,9 +23,9 @@ import (
"testing" "testing"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/constants"
"sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/internal/loadertest"
"sigs.k8s.io/kustomize/pkg/loader" "sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
@@ -106,10 +106,10 @@ func makeLoader1(t *testing.T) loader.Loader {
return ldr return ldr
} }
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
var cmap = schema.GroupVersionKind{Version: "v1", Kind: "ConfigMap"} var cmap = gvk.Gvk{Version: "v1", Kind: "ConfigMap"}
var secret = schema.GroupVersionKind{Version: "v1", Kind: "Secret"} var secret = gvk.Gvk{Version: "v1", Kind: "Secret"}
var ns = schema.GroupVersionKind{Version: "v1", Kind: "Namespace"} var ns = gvk.Gvk{Version: "v1", Kind: "Namespace"}
func TestResources1(t *testing.T) { func TestResources1(t *testing.T) {
expected := resmap.ResMap{ expected := resmap.ResMap{

View File

@@ -145,7 +145,7 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
t.Errorf("unexpected error: %v", err) t.Errorf("unexpected error: %v", err)
} }
if !reflect.DeepEqual(actualBytes, expectedBytes) { if !reflect.DeepEqual(actualBytes, expectedBytes) {
t.Errorf("%s\ndoesn't equal expected:\n%s\n", actualBytes, expectedBytes) t.Errorf("\n**** Actual:\n\n%s\n\n**** doesn't equal expected:\n\n%s\n\n", actualBytes, expectedBytes)
} }
} else { } else {
ioutil.WriteFile(testcase.ExpectedStdout, actualBytes, 0644) ioutil.WriteFile(testcase.ExpectedStdout, actualBytes, 0644)

View File

@@ -5,13 +5,6 @@ kind: Secret
metadata: metadata:
name: test-crdsecret name: test-crdsecret
--- ---
apiVersion: v1beta1
kind: Bee
metadata:
name: test-bee
spec:
action: fly
---
apiVersion: jingfang.example.com/v1beta1 apiVersion: jingfang.example.com/v1beta1
kind: MyKind kind: MyKind
metadata: metadata:
@@ -21,3 +14,10 @@ spec:
name: test-bee name: test-bee
secretRef: secretRef:
name: test-crdsecret name: test-crdsecret
---
apiVersion: v1beta1
kind: Bee
metadata:
name: test-bee
spec:
action: fly

View File

@@ -25,6 +25,7 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"k8s.io/apimachinery/pkg/runtime/schema" "k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kube-openapi/pkg/common" "k8s.io/kube-openapi/pkg/common"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/loader" "sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/transformers" "sigs.k8s.io/kustomize/pkg/transformers"
) )
@@ -100,9 +101,10 @@ func registerCRD(loader loader.Loader, path string) ([]pathConfigs, error) {
} }
crds := getCRDs(types) crds := getCRDs(types)
for crd, gvk := range crds { for crd, k := range crds {
crdPathConfigs := pathConfigs{} crdPathConfigs := pathConfigs{}
err = getCRDPathConfig(types, crd, crd, gvk, []string{}, &crdPathConfigs) err = getCRDPathConfig(
types, crd, crd, gvk.FromSchemaGvk(k), []string{}, &crdPathConfigs)
if err != nil { if err != nil {
return result, err return result, err
} }
@@ -134,7 +136,8 @@ func getCRDs(types map[string]common.OpenAPIDefinition) map[string]schema.GroupV
} }
// getCRDPathConfig gets pathConfigs for one CRD recursively // getCRDPathConfig gets pathConfigs for one CRD recursively
func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, crd string, gvk schema.GroupVersionKind, func getCRDPathConfig(
types map[string]common.OpenAPIDefinition, atype string, crd string, in gvk.Gvk,
path []string, configs *pathConfigs) error { path []string, configs *pathConfigs) error {
if _, ok := types[crd]; !ok { if _, ok := types[crd]; !ok {
return nil return nil
@@ -146,7 +149,7 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
configs.addAnnotationPathConfig( configs.addAnnotationPathConfig(
transformers.PathConfig{ transformers.PathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
GroupVersionKind: &gvk, GroupVersionKind: &in,
Path: append(path, propname), Path: append(path, propname),
}, },
) )
@@ -156,7 +159,7 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
configs.addLabelPathConfig( configs.addLabelPathConfig(
transformers.PathConfig{ transformers.PathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
GroupVersionKind: &gvk, GroupVersionKind: &in,
Path: append(path, propname), Path: append(path, propname),
}, },
) )
@@ -166,7 +169,7 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
configs.addPrefixPathConfig( configs.addPrefixPathConfig(
transformers.PathConfig{ transformers.PathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
GroupVersionKind: &gvk, GroupVersionKind: &in,
Path: append(path, propname), Path: append(path, propname),
}, },
) )
@@ -180,10 +183,10 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
nameKey = "name" nameKey = "name"
} }
configs.addNamereferencePathConfig(transformers.NewReferencePathConfig( configs.addNamereferencePathConfig(transformers.NewReferencePathConfig(
schema.GroupVersionKind{Kind: kind, Version: version}, gvk.Gvk{Kind: kind, Version: version},
[]transformers.PathConfig{ []transformers.PathConfig{
{CreateIfNotPresent: false, {CreateIfNotPresent: false,
GroupVersionKind: &gvk, GroupVersionKind: &in,
Path: append(path, propname, nameKey), Path: append(path, propname, nameKey),
}})) }}))
@@ -191,7 +194,7 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
} }
if property.Ref.GetURL() != nil { if property.Ref.GetURL() != nil {
getCRDPathConfig(types, property.Ref.String(), crd, gvk, append(path, propname), configs) getCRDPathConfig(types, property.Ref.String(), crd, in, append(path, propname), configs)
} }
} }
return nil return nil

View File

@@ -21,7 +21,7 @@ import (
"sort" "sort"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/internal/loadertest"
"sigs.k8s.io/kustomize/pkg/loader" "sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/transformers" "sigs.k8s.io/kustomize/pkg/transformers"
@@ -153,21 +153,21 @@ func makeLoader(t *testing.T) loader.Loader {
func TestRegisterCRD(t *testing.T) { func TestRegisterCRD(t *testing.T) {
refpathconfigs := []transformers.ReferencePathConfig{ refpathconfigs := []transformers.ReferencePathConfig{
transformers.NewReferencePathConfig( transformers.NewReferencePathConfig(
schema.GroupVersionKind{Kind: "Bee", Version: "v1beta1"}, gvk.Gvk{Kind: "Bee", Version: "v1beta1"},
[]transformers.PathConfig{ []transformers.PathConfig{
{ {
CreateIfNotPresent: false, CreateIfNotPresent: false,
GroupVersionKind: &schema.GroupVersionKind{Kind: "MyKind"}, GroupVersionKind: &gvk.Gvk{Kind: "MyKind"},
Path: []string{"spec", "beeRef", "name"}, Path: []string{"spec", "beeRef", "name"},
}, },
}, },
), ),
transformers.NewReferencePathConfig( transformers.NewReferencePathConfig(
schema.GroupVersionKind{Kind: "Secret", Version: "v1"}, gvk.Gvk{Kind: "Secret", Version: "v1"},
[]transformers.PathConfig{ []transformers.PathConfig{
{ {
CreateIfNotPresent: false, CreateIfNotPresent: false,
GroupVersionKind: &schema.GroupVersionKind{Kind: "MyKind"}, GroupVersionKind: &gvk.Gvk{Kind: "MyKind"},
Path: []string{"spec", "secretRef", "name"}, Path: []string{"spec", "secretRef", "name"},
}, },
}, },

132
pkg/gvk/gvk.go Normal file
View File

@@ -0,0 +1,132 @@
/*
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.
*/
package gvk
import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
// Gvk identifies a Kubernetes API type.
// https://github.com/kubernetes/community/blob/master/contributors/design-proposals/api-machinery/api-group.md
type Gvk struct {
Group string `json:"group,omitempty" yaml:"group,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
}
// FromKind makes a Gvk with only the kind specified.
func FromKind(k string) Gvk {
return Gvk{
Kind: k,
}
}
// FromSchemaGvk converts from a schema.GroupVersionKind.
func FromSchemaGvk(x schema.GroupVersionKind) Gvk {
return Gvk{
Group: x.Group,
Version: x.Version,
Kind: x.Kind,
}
}
// ToSchemaGvk converts to a schema.GroupVersionKind.
func (x Gvk) ToSchemaGvk() schema.GroupVersionKind {
return schema.GroupVersionKind{
Group: x.Group,
Version: x.Version,
Kind: x.Kind,
}
}
// String returns a string representation of the GVK.
func (x Gvk) String() string {
if x.Group == "" {
return x.Version + "_" + x.Kind
}
return x.Group + "_" + x.Version + "_" + x.Kind
}
// Equals returns true if the Gvk's have equal fields.
func (x Gvk) Equals(o Gvk) bool {
return x.Group == o.Group && x.Version == o.Version && x.Kind == o.Kind
}
var order = []string{
"Namespace",
"CustomResourceDefinition",
"ServiceAccount",
"Role",
"ClusterRole",
"RoleBinding",
"ClusterRoleBinding",
"ConfigMap",
"Secret",
"Service",
}
var typeOrders = func() map[string]int {
m := map[string]int{}
for i, n := range order {
m[n] = i
}
return m
}()
// IsLessThan returns true if self is less than the argument.
func (x Gvk) IsLessThan(o Gvk) bool {
indexI, foundI := typeOrders[x.Kind]
indexJ, foundJ := typeOrders[o.Kind]
if foundI && foundJ {
return indexI < indexJ
}
if foundI && !foundJ {
return true
}
if !foundI && foundJ {
return false
}
return x.String() < o.String()
}
// IsSelected returns true if `selector` selects `x`; otherwise, false.
// If `selector` and `x` are the same, return true.
// If `selector` is nil, it is considered as a wildcard and always return true.
// e.g. selector <Group: "", Version: "", Kind: "Deployment"> CAN select
// <Group: "extensions", Version: "v1beta1", Kind: "Deployment">.
// selector <Group: "apps", Version: "", Kind: "Deployment"> CANNOT select
// <Group: "extensions", Version: "v1beta1", Kind: "Deployment">.
func (x Gvk) IsSelected(selector *Gvk) bool {
if selector == nil {
return true
}
if len(selector.Group) > 0 {
if x.Group != selector.Group {
return false
}
}
if len(selector.Version) > 0 {
if x.Version != selector.Version {
return false
}
}
if len(selector.Kind) > 0 {
if x.Kind != selector.Kind {
return false
}
}
return true
}

View File

@@ -14,36 +14,90 @@ See the License for the specific language governing permissions and
limitations under the License. limitations under the License.
*/ */
package transformers package gvk
import ( import "testing"
"testing"
"k8s.io/apimachinery/pkg/runtime/schema" var equalsTests = []struct {
) x1 Gvk
x2 Gvk
}{
{Gvk{Group: "a", Version: "b", Kind: "c"},
Gvk{Group: "a", Version: "b", Kind: "c"}},
{Gvk{Version: "b", Kind: "c"},
Gvk{Version: "b", Kind: "c"}},
{Gvk{Kind: "c"},
Gvk{Kind: "c"}},
}
func TestEquals(t *testing.T) {
for _, hey := range equalsTests {
if !hey.x1.Equals(hey.x2) {
t.Fatalf("%v should equal %v", hey.x1, hey.x2)
}
}
}
var lessThanTests = []struct {
x1 Gvk
x2 Gvk
}{
{Gvk{Group: "a", Version: "b", Kind: "CustomResourceDefinition"},
Gvk{Group: "a", Version: "b", Kind: "RoleBinding"}},
{Gvk{Group: "a", Version: "b", Kind: "Namespace"},
Gvk{Group: "a", Version: "b", Kind: "ClusterRole"}},
{Gvk{Group: "a", Version: "b", Kind: "a"},
Gvk{Group: "a", Version: "b", Kind: "b"}},
}
func TestIsLessThan1(t *testing.T) {
for _, hey := range lessThanTests {
if !hey.x1.IsLessThan(hey.x2) {
t.Fatalf("%v should be less than %v", hey.x1, hey.x2)
}
}
}
var stringTests = []struct {
x Gvk
s string
}{
{Gvk{Group: "a", Version: "b", Kind: "c"}, "a_b_c"},
{Gvk{Group: "a", Kind: "c"}, "a__c"},
{Gvk{Kind: "c"}, "_c"},
{Gvk{Version: "b", Kind: "c"}, "b_c"},
}
func TestString(t *testing.T) {
for _, hey := range stringTests {
if hey.x.String() != hey.s {
t.Fatalf("bad string for %v '%s'", hey.x, hey.s)
}
}
}
func TestSelectByGVK(t *testing.T) { func TestSelectByGVK(t *testing.T) {
type testCase struct { type testCase struct {
description string description string
in schema.GroupVersionKind in Gvk
filter *schema.GroupVersionKind filter *Gvk
expected bool expected bool
} }
testCases := []testCase{ testCases := []testCase{
{ {
description: "nil filter", description: "nil filter",
in: schema.GroupVersionKind{}, in: Gvk{},
filter: nil, filter: nil,
expected: true, expected: true,
}, },
{ {
description: "gvk matches", description: "gvk matches",
in: schema.GroupVersionKind{ in: Gvk{
Group: "group1", Group: "group1",
Version: "version1", Version: "version1",
Kind: "kind1", Kind: "kind1",
}, },
filter: &schema.GroupVersionKind{ filter: &Gvk{
Group: "group1", Group: "group1",
Version: "version1", Version: "version1",
Kind: "kind1", Kind: "kind1",
@@ -52,12 +106,12 @@ func TestSelectByGVK(t *testing.T) {
}, },
{ {
description: "group doesn't matches", description: "group doesn't matches",
in: schema.GroupVersionKind{ in: Gvk{
Group: "group1", Group: "group1",
Version: "version1", Version: "version1",
Kind: "kind1", Kind: "kind1",
}, },
filter: &schema.GroupVersionKind{ filter: &Gvk{
Group: "group2", Group: "group2",
Version: "version1", Version: "version1",
Kind: "kind1", Kind: "kind1",
@@ -66,12 +120,12 @@ func TestSelectByGVK(t *testing.T) {
}, },
{ {
description: "version doesn't matches", description: "version doesn't matches",
in: schema.GroupVersionKind{ in: Gvk{
Group: "group1", Group: "group1",
Version: "version1", Version: "version1",
Kind: "kind1", Kind: "kind1",
}, },
filter: &schema.GroupVersionKind{ filter: &Gvk{
Group: "group1", Group: "group1",
Version: "version2", Version: "version2",
Kind: "kind1", Kind: "kind1",
@@ -80,12 +134,12 @@ func TestSelectByGVK(t *testing.T) {
}, },
{ {
description: "kind doesn't matches", description: "kind doesn't matches",
in: schema.GroupVersionKind{ in: Gvk{
Group: "group1", Group: "group1",
Version: "version1", Version: "version1",
Kind: "kind1", Kind: "kind1",
}, },
filter: &schema.GroupVersionKind{ filter: &Gvk{
Group: "group1", Group: "group1",
Version: "version1", Version: "version1",
Kind: "kind2", Kind: "kind2",
@@ -94,12 +148,12 @@ func TestSelectByGVK(t *testing.T) {
}, },
{ {
description: "no version in filter", description: "no version in filter",
in: schema.GroupVersionKind{ in: Gvk{
Group: "group1", Group: "group1",
Version: "version1", Version: "version1",
Kind: "kind1", Kind: "kind1",
}, },
filter: &schema.GroupVersionKind{ filter: &Gvk{
Group: "group1", Group: "group1",
Version: "", Version: "",
Kind: "kind1", Kind: "kind1",
@@ -108,12 +162,12 @@ func TestSelectByGVK(t *testing.T) {
}, },
{ {
description: "only kind is set in filter", description: "only kind is set in filter",
in: schema.GroupVersionKind{ in: Gvk{
Group: "group1", Group: "group1",
Version: "version1", Version: "version1",
Kind: "kind1", Kind: "kind1",
}, },
filter: &schema.GroupVersionKind{ filter: &Gvk{
Group: "", Group: "",
Version: "", Version: "",
Kind: "kind1", Kind: "kind1",
@@ -123,7 +177,7 @@ func TestSelectByGVK(t *testing.T) {
} }
for _, tc := range testCases { for _, tc := range testCases {
filtered := selectByGVK(tc.in, tc.filter) filtered := tc.in.IsSelected(tc.filter)
if filtered != tc.expected { if filtered != tc.expected {
t.Fatalf("unexpected filter result for test case: %v", tc.description) t.Fatalf("unexpected filter result for test case: %v", tc.description)
} }

View File

@@ -16,6 +16,8 @@ limitations under the License.
package patch package patch
import "sigs.k8s.io/kustomize/pkg/gvk"
// PatchJson6902 represents a json patch for an object // PatchJson6902 represents a json patch for an object
// with format documented https://tools.ietf.org/html/rfc6902. // with format documented https://tools.ietf.org/html/rfc6902.
type PatchJson6902 struct { type PatchJson6902 struct {
@@ -32,9 +34,7 @@ type PatchJson6902 struct {
// Target represents the kubernetes object that the patch is applied to // Target represents the kubernetes object that the patch is applied to
type Target struct { type Target struct {
Group string `json:"group,omitempty" yaml:"group,omitempty"` gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"` Namespace string `json:"namespace,omitempty" yaml:"namespace,omitempty"`
Name string `json:"name" yaml:"name"` Name string `json:"name" yaml:"name"`
} }

View File

@@ -21,7 +21,7 @@ import (
"github.com/evanphx/json-patch" "github.com/evanphx/json-patch"
"github.com/krishicks/yaml-patch" "github.com/krishicks/yaml-patch"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/loader" "sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/patch" "sigs.k8s.io/kustomize/pkg/patch"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
@@ -62,7 +62,7 @@ func (f PatchJson6902Factory) makeOnePatchJson6902Transformer(p patch.PatchJson6
} }
targetId := resource.NewResIdWithPrefixNamespace( targetId := resource.NewResIdWithPrefixNamespace(
schema.GroupVersionKind{ gvk.Gvk{
Group: p.Target.Group, Group: p.Target.Group,
Version: p.Target.Version, Version: p.Target.Version,
Kind: p.Target.Kind, Kind: p.Target.Kind,

View File

@@ -22,7 +22,7 @@ import (
"testing" "testing"
"gopkg.in/yaml.v2" "gopkg.in/yaml.v2"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/internal/loadertest"
"sigs.k8s.io/kustomize/pkg/patch" "sigs.k8s.io/kustomize/pkg/patch"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
@@ -179,7 +179,7 @@ func TestNewPatchJson6902FactoryMulti(t *testing.T) {
t.Fatal("the returned transformer should not be nil") t.Fatal("the returned transformer should not be nil")
} }
id := resource.NewResId(schema.GroupVersionKind{Kind: "foo"}, "some-name") id := resource.NewResId(gvk.FromKind("foo"), "some-name")
base := resmap.ResMap{ base := resmap.ResMap{
id: resource.NewResourceFromMap( id: resource.NewResourceFromMap(
map[string]interface{}{ map[string]interface{}{
@@ -293,7 +293,7 @@ func TestNewPatchJson6902FactoryMultiConflict(t *testing.T) {
t.Fatal("the returned transformer should not be nil") t.Fatal("the returned transformer should not be nil")
} }
id := resource.NewResId(schema.GroupVersionKind{Kind: "foo"}, "some-name") id := resource.NewResId(gvk.FromKind("foo"), "some-name")
base := resmap.ResMap{ base := resmap.ResMap{
id: resource.NewResourceFromMap( id: resource.NewResourceFromMap(
map[string]interface{}{ map[string]interface{}{

View File

@@ -21,12 +21,12 @@ import (
"testing" "testing"
"github.com/krishicks/yaml-patch" "github.com/krishicks/yaml-patch"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
) )
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
func TestJsonPatchYAMLTransformer_Transform(t *testing.T) { func TestJsonPatchYAMLTransformer_Transform(t *testing.T) {
id := resource.NewResId(deploy, "deploy1") id := resource.NewResId(deploy, "deploy1")

View File

@@ -20,15 +20,15 @@ import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/configmapandsecret" "sigs.k8s.io/kustomize/pkg/configmapandsecret"
"sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/internal/loadertest"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/types" "sigs.k8s.io/kustomize/pkg/types"
) )
var cmap = schema.GroupVersionKind{Version: "v1", Kind: "ConfigMap"} var cmap = gvk.Gvk{Version: "v1", Kind: "ConfigMap"}
func TestNewFromConfigMaps(t *testing.T) { func TestNewFromConfigMaps(t *testing.T) {
type testCase struct { type testCase struct {

View File

@@ -19,7 +19,6 @@ package resmap
import ( import (
"sort" "sort"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
) )
@@ -31,33 +30,8 @@ var _ sort.Interface = IdSlice{}
func (a IdSlice) Len() int { return len(a) } func (a IdSlice) Len() int { return len(a) }
func (a IdSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] } func (a IdSlice) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a IdSlice) Less(i, j int) bool { func (a IdSlice) Less(i, j int) bool {
if a[i].Gvk().String() != a[j].Gvk().String() { if !a[i].Gvk().Equals(a[j].Gvk()) {
return gvkLess(a[i].Gvk(), a[j].Gvk()) return a[i].Gvk().IsLessThan(a[j].Gvk())
} }
return a[i].String() < a[j].String() return a[i].String() < a[j].String()
} }
var order = []string{"Namespace", "CustomResourceDefinition", "ServiceAccount",
"Role", "ClusterRole", "RoleBinding", "ClusterRoleBinding"}
var typeOrders = func() map[string]int {
m := map[string]int{}
for i, n := range order {
m[n] = i
}
return m
}()
func gvkLess(i, j schema.GroupVersionKind) bool {
indexi, foundi := typeOrders[i.Kind]
indexj, foundj := typeOrders[j.Kind]
if foundi && foundj {
return indexi < indexj
}
if foundi && !foundj {
return true
}
if !foundi && foundj {
return false
}
return i.String() < j.String()
}

View File

@@ -21,30 +21,29 @@ import (
"sort" "sort"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
) )
func TestLess(t *testing.T) { func TestLess(t *testing.T) {
ids := IdSlice{ ids := IdSlice{
resource.NewResId(schema.GroupVersionKind{Kind: "ConfigMap"}, "cm"), resource.NewResIdKindOnly("ConfigMap", "cm"),
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"), resource.NewResIdKindOnly("Pod", "pod"),
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"), resource.NewResIdKindOnly("Namespace", "ns1"),
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"), resource.NewResIdKindOnly("Namespace", "ns2"),
resource.NewResId(schema.GroupVersionKind{Kind: "Role"}, "ro"), resource.NewResIdKindOnly("Role", "ro"),
resource.NewResId(schema.GroupVersionKind{Kind: "RoleBinding"}, "rb"), resource.NewResIdKindOnly("RoleBinding", "rb"),
resource.NewResId(schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, "crd"), resource.NewResIdKindOnly("CustomResourceDefinition", "crd"),
resource.NewResId(schema.GroupVersionKind{Kind: "ServiceAccount"}, "sa"), resource.NewResIdKindOnly("ServiceAccount", "sa"),
} }
expected := IdSlice{ expected := IdSlice{
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"), resource.NewResIdKindOnly("Namespace", "ns1"),
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"), resource.NewResIdKindOnly("Namespace", "ns2"),
resource.NewResId(schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, "crd"), resource.NewResIdKindOnly("CustomResourceDefinition", "crd"),
resource.NewResId(schema.GroupVersionKind{Kind: "ServiceAccount"}, "sa"), resource.NewResIdKindOnly("ServiceAccount", "sa"),
resource.NewResId(schema.GroupVersionKind{Kind: "Role"}, "ro"), resource.NewResIdKindOnly("Role", "ro"),
resource.NewResId(schema.GroupVersionKind{Kind: "RoleBinding"}, "rb"), resource.NewResIdKindOnly("RoleBinding", "rb"),
resource.NewResId(schema.GroupVersionKind{Kind: "ConfigMap"}, "cm"), resource.NewResIdKindOnly("ConfigMap", "cm"),
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"), resource.NewResIdKindOnly("Pod", "pod"),
} }
sort.Sort(ids) sort.Sort(ids)
if !reflect.DeepEqual(ids, expected) { if !reflect.DeepEqual(ids, expected) {

View File

@@ -30,6 +30,7 @@ import (
"github.com/pkg/errors" "github.com/pkg/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
k8syaml "k8s.io/apimachinery/pkg/util/yaml" k8syaml "k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/kustomize/pkg/gvk"
internal "sigs.k8s.io/kustomize/pkg/internal/error" internal "sigs.k8s.io/kustomize/pkg/internal/error"
"sigs.k8s.io/kustomize/pkg/loader" "sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/patch" "sigs.k8s.io/kustomize/pkg/patch"
@@ -129,11 +130,12 @@ func (m ResMap) DeepCopy() ResMap {
func (m ResMap) insert(newName string, obj *unstructured.Unstructured) error { func (m ResMap) insert(newName string, obj *unstructured.Unstructured) error {
oldName := obj.GetName() oldName := obj.GetName()
gvk := obj.GroupVersionKind() gvKind := gvk.FromSchemaGvk(obj.GroupVersionKind())
id := resource.NewResId(gvk, oldName) id := resource.NewResId(gvKind, oldName)
if _, found := m[id]; found { if _, found := m[id]; found {
return fmt.Errorf("the <name: %q, GroupVersionKind: %v> already exists in the map", oldName, gvk) return fmt.Errorf(
"the <name: %q, GroupVersionKind: %v> already exists in the map", oldName, gvKind)
} }
obj.SetName(newName) obj.SetName(newName)
m[id] = resource.NewResourceFromUnstruct(*obj) m[id] = resource.NewResourceFromUnstruct(*obj)

View File

@@ -21,13 +21,13 @@ import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/internal/loadertest" "sigs.k8s.io/kustomize/pkg/internal/loadertest"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
) )
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
var statefulset = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"} var statefulset = gvk.Gvk{Group: "apps", Version: "v1", Kind: "StatefulSet"}
func TestEncodeAsYaml(t *testing.T) { func TestEncodeAsYaml(t *testing.T) {
encoded := []byte(`apiVersion: v1 encoded := []byte(`apiVersion: v1

View File

@@ -22,14 +22,14 @@ import (
"testing" "testing"
corev1 "k8s.io/api/core/v1" corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/configmapandsecret" "sigs.k8s.io/kustomize/pkg/configmapandsecret"
"sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/types" "sigs.k8s.io/kustomize/pkg/types"
) )
var secret = schema.GroupVersionKind{Version: "v1", Kind: "Secret"} var secret = gvk.Gvk{Version: "v1", Kind: "Secret"}
func TestNewResMapFromSecretArgs(t *testing.T) { func TestNewResMapFromSecretArgs(t *testing.T) {
secrets := []types.SecretArgs{ secrets := []types.SecretArgs{

View File

@@ -19,13 +19,13 @@ package resource
import ( import (
"strings" "strings"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
) )
// ResId conflates GroupVersionKind with a textual name to uniquely identify a kubernetes resource (object). // ResId conflates GroupVersionKind with a textual name to uniquely identify a kubernetes resource (object).
type ResId struct { type ResId struct {
// GroupVersionKind of the resource. // Gvk of the resource.
gvk schema.GroupVersionKind gvKind gvk.Gvk
// original name of the resource before transformation. // original name of the resource before transformation.
name string name string
// namePrefix of the resource // namePrefix of the resource
@@ -39,45 +39,46 @@ type ResId struct {
} }
// NewResIdWithPrefixNamespace creates new resource identifier with a prefix and a namespace // NewResIdWithPrefixNamespace creates new resource identifier with a prefix and a namespace
func NewResIdWithPrefixNamespace(g schema.GroupVersionKind, n, p, ns string) ResId { func NewResIdWithPrefixNamespace(k gvk.Gvk, n, p, ns string) ResId {
return ResId{gvk: g, name: n, prefix: p, namespace: ns} return ResId{gvKind: k, name: n, prefix: p, namespace: ns}
} }
// NewResIdWithPrefix creates new resource identifier with a prefix // NewResIdWithPrefix creates new resource identifier with a prefix
func NewResIdWithPrefix(g schema.GroupVersionKind, n, p string) ResId { func NewResIdWithPrefix(k gvk.Gvk, n, p string) ResId {
return ResId{gvk: g, name: n, prefix: p} return ResId{gvKind: k, name: n, prefix: p}
} }
// NewResId creates new resource identifier // NewResId creates new resource identifier
func NewResId(g schema.GroupVersionKind, n string) ResId { func NewResId(k gvk.Gvk, n string) ResId {
return NewResIdWithPrefix(g, n, "") return ResId{gvKind: k, name: n}
}
// NewResIdKindOnly creates new resource identifier
func NewResIdKindOnly(k string, n string) ResId {
return ResId{gvKind: gvk.FromKind(k), name: n}
} }
// String of ResId based on GVK, name and prefix // String of ResId based on GVK, name and prefix
func (n ResId) String() string { func (n ResId) String() string {
fields := []string{n.gvk.Group, n.gvk.Version, n.gvk.Kind, n.namespace, n.prefix, n.name} fields := []string{n.gvKind.Group, n.gvKind.Version, n.gvKind.Kind,
n.namespace, n.prefix, n.name}
return strings.Join(fields, "_") + ".yaml" return strings.Join(fields, "_") + ".yaml"
} }
// GvknString of ResId based on GVK and name // GvknString of ResId based on GVK and name
func (n ResId) GvknString() string { func (n ResId) GvknString() string {
if n.gvk.Group == "" { return n.gvKind.String() + "_" + n.name + ".yaml"
return strings.Join([]string{n.gvk.Version, n.gvk.Kind, n.name}, "_") + ".yaml"
}
return strings.Join([]string{n.gvk.Group, n.gvk.Version, n.gvk.Kind, n.name}, "_") + ".yaml"
} }
// GvknEquals return if two ResId have the same Group/Version/Kind and name // GvknEquals return if two ResId have the same Group/Version/Kind and name
// The comparison excludes prefix // The comparison excludes prefix
func (n ResId) GvknEquals(id ResId) bool { func (n ResId) GvknEquals(id ResId) bool {
return n.gvk.Group == id.gvk.Group && n.gvk.Version == id.gvk.Version && return n.gvKind.Equals(id.gvKind) && n.name == id.name
n.gvk.Kind == id.gvk.Kind && n.name == id.name
} }
// Gvk returns Group/Version/Kind of the resource. // Gvk returns Group/Version/Kind of the resource.
func (n ResId) Gvk() schema.GroupVersionKind { func (n ResId) Gvk() gvk.Gvk {
return n.gvk return n.gvKind
} }
// Name returns resource name. // Name returns resource name.
@@ -97,12 +98,12 @@ func (n ResId) Namespace() string {
// CopyWithNewPrefix make a new copy from current ResId and append a new prefix // CopyWithNewPrefix make a new copy from current ResId and append a new prefix
func (n ResId) CopyWithNewPrefix(p string) ResId { func (n ResId) CopyWithNewPrefix(p string) ResId {
return ResId{gvk: n.gvk, name: n.name, prefix: n.concatPrefix(p), namespace: n.namespace} return ResId{gvKind: n.gvKind, name: n.name, prefix: n.concatPrefix(p), namespace: n.namespace}
} }
// CopyWithNewNamespace make a new copy from current ResId and set a new namespace // CopyWithNewNamespace make a new copy from current ResId and set a new namespace
func (n ResId) CopyWithNewNamespace(ns string) ResId { func (n ResId) CopyWithNewNamespace(ns string) ResId {
return ResId{gvk: n.gvk, name: n.name, prefix: n.prefix, namespace: ns} return ResId{gvKind: n.gvKind, name: n.name, prefix: n.prefix, namespace: ns}
} }
// HasSameLeftmostPrefix check if two ResIds have the same // HasSameLeftmostPrefix check if two ResIds have the same

View File

@@ -3,26 +3,26 @@ package resource
import ( import (
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
) )
var stringTests = []struct { var stringTests = []struct {
x ResId x ResId
s string s string
}{ }{
{ResId{gvk: schema.GroupVersionKind{Group: "g", Version: "v", Kind: "k"}, {ResId{gvKind: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
name: "nm", prefix: "p", namespace: "ns"}, "g_v_k_ns_p_nm.yaml"}, name: "nm", prefix: "p", namespace: "ns"}, "g_v_k_ns_p_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"}, {ResId{gvKind: gvk.Gvk{Version: "v", Kind: "k"},
name: "nm", prefix: "p", namespace: "ns"}, "_v_k_ns_p_nm.yaml"}, name: "nm", prefix: "p", namespace: "ns"}, "_v_k_ns_p_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{Kind: "k"}, {ResId{gvKind: gvk.Gvk{Kind: "k"},
name: "nm", prefix: "p", namespace: "ns"}, "__k_ns_p_nm.yaml"}, name: "nm", prefix: "p", namespace: "ns"}, "__k_ns_p_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}, {ResId{gvKind: gvk.Gvk{},
name: "nm", prefix: "p", namespace: "ns"}, "___ns_p_nm.yaml"}, name: "nm", prefix: "p", namespace: "ns"}, "___ns_p_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}, {ResId{gvKind: gvk.Gvk{},
name: "nm", prefix: "p"}, "____p_nm.yaml"}, name: "nm", prefix: "p"}, "____p_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}, {ResId{gvKind: gvk.Gvk{},
name: "nm"}, "_____nm.yaml"}, name: "nm"}, "_____nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}}, "_____.yaml"}, {ResId{gvKind: gvk.Gvk{}}, "_____.yaml"},
{ResId{}, "_____.yaml"}, {ResId{}, "_____.yaml"},
} }
@@ -38,19 +38,19 @@ var gvknStringTests = []struct {
x ResId x ResId
s string s string
}{ }{
{ResId{gvk: schema.GroupVersionKind{Group: "g", Version: "v", Kind: "k"}, {ResId{gvKind: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
name: "nm", prefix: "p", namespace: "ns"}, "g_v_k_nm.yaml"}, name: "nm", prefix: "p", namespace: "ns"}, "g_v_k_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"}, {ResId{gvKind: gvk.Gvk{Version: "v", Kind: "k"},
name: "nm", prefix: "p", namespace: "ns"}, "v_k_nm.yaml"}, name: "nm", prefix: "p", namespace: "ns"}, "v_k_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{Kind: "k"}, {ResId{gvKind: gvk.Gvk{Kind: "k"},
name: "nm", prefix: "p", namespace: "ns"}, "_k_nm.yaml"}, name: "nm", prefix: "p", namespace: "ns"}, "_k_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}, {ResId{gvKind: gvk.Gvk{},
name: "nm", prefix: "p", namespace: "ns"}, "__nm.yaml"}, name: "nm", prefix: "p", namespace: "ns"}, "__nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}, {ResId{gvKind: gvk.Gvk{},
name: "nm", prefix: "p"}, "__nm.yaml"}, name: "nm", prefix: "p"}, "__nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}, {ResId{gvKind: gvk.Gvk{},
name: "nm"}, "__nm.yaml"}, name: "nm"}, "__nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}}, "__.yaml"}, {ResId{gvKind: gvk.Gvk{}}, "__.yaml"},
{ResId{}, "__.yaml"}, {ResId{}, "__.yaml"},
} }
@@ -66,17 +66,17 @@ var GvknEqualsTest = []struct {
x1 ResId x1 ResId
x2 ResId x2 ResId
}{ }{
{ResId{gvk: schema.GroupVersionKind{Group: "g", Version: "v", Kind: "k"}, {ResId{gvKind: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
name: "nm", prefix: "AA", namespace: "X"}, name: "nm", prefix: "AA", namespace: "X"},
ResId{gvk: schema.GroupVersionKind{Group: "g", Version: "v", Kind: "k"}, ResId{gvKind: gvk.Gvk{Group: "g", Version: "v", Kind: "k"},
name: "nm", prefix: "BB", namespace: "Z"}}, name: "nm", prefix: "BB", namespace: "Z"}},
{ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"}, {ResId{gvKind: gvk.Gvk{Version: "v", Kind: "k"},
name: "nm", prefix: "AA", namespace: "X"}, name: "nm", prefix: "AA", namespace: "X"},
ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"}, ResId{gvKind: gvk.Gvk{Version: "v", Kind: "k"},
name: "nm", prefix: "BB", namespace: "Z"}}, name: "nm", prefix: "BB", namespace: "Z"}},
{ResId{gvk: schema.GroupVersionKind{Kind: "k"}, {ResId{gvKind: gvk.Gvk{Kind: "k"},
name: "nm", prefix: "AA", namespace: "X"}, name: "nm", prefix: "AA", namespace: "X"},
ResId{gvk: schema.GroupVersionKind{Kind: "k"}, ResId{gvKind: gvk.Gvk{Kind: "k"},
name: "nm", prefix: "BB", namespace: "Z"}}, name: "nm", prefix: "BB", namespace: "Z"}},
{ResId{name: "nm", prefix: "AA", namespace: "X"}, {ResId{name: "nm", prefix: "AA", namespace: "X"},
ResId{name: "nm", prefix: "BB", namespace: "Z"}}, ResId{name: "nm", prefix: "BB", namespace: "Z"}},

View File

@@ -20,12 +20,12 @@ package resource
import ( import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"strings" "strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/kustomize/pkg/gvk"
) )
// Resource is an "Unstructured" (json/map form) Kubernetes API resource object // Resource is an "Unstructured" (json/map form) Kubernetes API resource object
@@ -77,7 +77,7 @@ func (r *Resource) IsGenerated() bool {
// Id returns the ResId for the resource. // Id returns the ResId for the resource.
func (r *Resource) Id() ResId { func (r *Resource) Id() ResId {
return NewResId(r.GroupVersionKind(), r.GetName()) return NewResId(gvk.FromSchemaGvk(r.GroupVersionKind()), r.GetName())
} }
// Merge performs merge with other resource. // Merge performs merge with other resource.

View File

@@ -17,29 +17,19 @@ limitations under the License.
package transformerconfig package transformerconfig
import ( import (
"k8s.io/apimachinery/pkg/runtime/schema"
"strings" "strings"
"sigs.k8s.io/kustomize/pkg/gvk"
) )
// PathConfig contains the configuration of a field, including the gvk it ties to, // PathConfig contains the configuration of a field, including the gvk it ties to,
// path to the field, etc. // path to the field, etc.
type PathConfig struct { type PathConfig struct {
Group string `json:"group,omitempty" yaml:"group,omitempty"` gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
Path string `json:"path,omitempty" yaml:"path,omitempty"` Path string `json:"path,omitempty" yaml:"path,omitempty"`
CreateIfNotPresent bool `json:"create,omitempty" yaml:"create,omitempty"` CreateIfNotPresent bool `json:"create,omitempty" yaml:"create,omitempty"`
} }
// Gvk returns GroupVersionKind of the pathConfig
func (p PathConfig) Gvk() *schema.GroupVersionKind {
return &schema.GroupVersionKind{
Group: p.Group,
Version: p.Version,
Kind: p.Kind,
}
}
// PathSlice converts the path string to a slice of strings, separated by "/" // PathSlice converts the path string to a slice of strings, separated by "/"
func (p PathConfig) PathSlice() []string { func (p PathConfig) PathSlice() []string {
return strings.Split(p.Path, "/") return strings.Split(p.Path, "/")

View File

@@ -17,7 +17,7 @@ limitations under the License.
package transformerconfig package transformerconfig
import ( import (
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
) )
// ReferencePathConfig contains the configuration of a field that references // ReferencePathConfig contains the configuration of a field that references
@@ -34,27 +34,16 @@ import (
// }, // },
// } // }
type ReferencePathConfig struct { type ReferencePathConfig struct {
Group string `json:"group,omitempty" yaml:"group,omitempty"` gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
Version string `json:"version,omitempty" yaml:"version,omitempty"`
Kind string `json:"kind,omitempty" yaml:"kind,omitempty"`
// PathConfig is the gvk that is referencing the referencedGVK object's name. // PathConfig is the gvk that is referencing the referencedGVK object's name.
PathConfigs []PathConfig `json:"pathConfigs,omitempty" yaml:"pathConfigs,omitempty"` PathConfigs []PathConfig `json:"pathConfigs,omitempty" yaml:"pathConfigs,omitempty"`
} }
// Gvk returns GroupVersionKind of the reference pathConfig
func (p ReferencePathConfig) Gvk() *schema.GroupVersionKind {
return &schema.GroupVersionKind{
Group: p.Group,
Version: p.Version,
Kind: p.Kind,
}
}
func merge(configs []ReferencePathConfig, config ReferencePathConfig) []ReferencePathConfig { func merge(configs []ReferencePathConfig, config ReferencePathConfig) []ReferencePathConfig {
var result []ReferencePathConfig var result []ReferencePathConfig
found := false found := false
for _, c := range configs { for _, c := range configs {
if c.Gvk() == config.Gvk() { if c.Equals(config.Gvk) {
c.PathConfigs = append(c.PathConfigs, config.PathConfigs...) c.PathConfigs = append(c.PathConfigs, config.PathConfigs...)
found = true found = true
} }

View File

@@ -20,7 +20,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/types" "sigs.k8s.io/kustomize/pkg/types"
@@ -59,7 +59,7 @@ func TestImageTagTransformer(t *testing.T) {
}, },
}, },
}), }),
resource.NewResId(schema.GroupVersionKind{Kind: "randomeKind"}, "random"): resource.NewResourceFromMap( resource.NewResId(gvk.Gvk{Kind: "randomKind"}, "random"): resource.NewResourceFromMap(
map[string]interface{}{ map[string]interface{}{
"spec": map[string]interface{}{ "spec": map[string]interface{}{
"template": map[string]interface{}{ "template": map[string]interface{}{
@@ -127,7 +127,7 @@ func TestImageTagTransformer(t *testing.T) {
}, },
}, },
}), }),
resource.NewResId(schema.GroupVersionKind{Kind: "randomeKind"}, "random"): resource.NewResourceFromMap( resource.NewResId(gvk.Gvk{Kind: "randomKind"}, "random"): resource.NewResourceFromMap(
map[string]interface{}{ map[string]interface{}{
"spec": map[string]interface{}{ "spec": map[string]interface{}{
"template": map[string]interface{}{ "template": map[string]interface{}{

View File

@@ -59,7 +59,7 @@ func (o *mapTransformer) Transform(m resmap.ResMap) error {
for id := range m { for id := range m {
objMap := m[id].UnstructuredContent() objMap := m[id].UnstructuredContent()
for _, path := range o.pathConfigs { for _, path := range o.pathConfigs {
if !selectByGVK(id.Gvk(), path.GroupVersionKind) { if !id.Gvk().IsSelected(path.GroupVersionKind) {
continue continue
} }
err := mutateField(objMap, path.Path, path.CreateIfNotPresent, o.addMap) err := mutateField(objMap, path.Path, path.CreateIfNotPresent, o.addMap)

View File

@@ -20,25 +20,25 @@ import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
) )
var service = schema.GroupVersionKind{Version: "v1", Kind: "Service"} var service = gvk.Gvk{Version: "v1", Kind: "Service"}
var secret = schema.GroupVersionKind{Version: "v1", Kind: "Secret"} var secret = gvk.Gvk{Version: "v1", Kind: "Secret"}
var cmap = schema.GroupVersionKind{Version: "v1", Kind: "ConfigMap"} var cmap = gvk.Gvk{Version: "v1", Kind: "ConfigMap"}
var ns = schema.GroupVersionKind{Version: "v1", Kind: "Namespace"} var ns = gvk.Gvk{Version: "v1", Kind: "Namespace"}
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"} var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
var statefulset = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"} var statefulset = gvk.Gvk{Group: "apps", Version: "v1", Kind: "StatefulSet"}
var foo = schema.GroupVersionKind{Group: "example.com", Version: "v1", Kind: "Foo"} var foo = gvk.Gvk{Group: "example.com", Version: "v1", Kind: "Foo"}
var crd = schema.GroupVersionKind{Group: "apiwctensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"} var crd = gvk.Gvk{Group: "apiwctensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"}
var job = schema.GroupVersionKind{Group: "batch", Version: "v1", Kind: "Job"} var job = gvk.Gvk{Group: "batch", Version: "v1", Kind: "Job"}
var cronjob = schema.GroupVersionKind{Group: "batch", Version: "v1beta1", Kind: "CronJob"} var cronjob = gvk.Gvk{Group: "batch", Version: "v1beta1", Kind: "CronJob"}
var pvc = schema.GroupVersionKind{Version: "v1", Kind: "PersistentVolumeClaim"} var pvc = gvk.Gvk{Version: "v1", Kind: "PersistentVolumeClaim"}
var crb = schema.GroupVersionKind{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"} var crb = gvk.Gvk{Group: "rbac.authorization.k8s.io", Version: "v1", Kind: "ClusterRoleBinding"}
var sa = schema.GroupVersionKind{Version: "v1", Kind: "ServiceAccount"} var sa = gvk.Gvk{Version: "v1", Kind: "ServiceAccount"}
var ingress = schema.GroupVersionKind{Kind: "Ingress"} var ingress = gvk.Gvk{Kind: "Ingress"}
func TestLabelsRun(t *testing.T) { func TestLabelsRun(t *testing.T) {
m := resmap.ResMap{ m := resmap.ResMap{
@@ -568,7 +568,7 @@ func TestAddPathConfigs(t *testing.T) {
lexpected := len(defaultLabelsPathConfigs) + 1 lexpected := len(defaultLabelsPathConfigs) + 1
pathConfigs := []PathConfig{ pathConfigs := []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "GroupA", Kind: "KindB"}, GroupVersionKind: &gvk.Gvk{Group: "GroupA", Kind: "KindB"},
Path: []string{"path", "to", "a", "field"}, Path: []string{"path", "to", "a", "field"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },

View File

@@ -17,7 +17,7 @@ limitations under the License.
package transformers package transformers
import ( import (
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
) )
// defaultLabelsPathConfigs is the default configuration for mutating labels and // defaultLabelsPathConfigs is the default configuration for mutating labels and
@@ -28,149 +28,149 @@ var defaultLabelsPathConfigs = []PathConfig{
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Version: "v1", Kind: "Service"}, GroupVersionKind: &gvk.Gvk{Version: "v1", Kind: "Service"},
Path: []string{"spec", "selector"}, Path: []string{"spec", "selector"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Version: "v1", Kind: "ReplicationController"}, GroupVersionKind: &gvk.Gvk{Version: "v1", Kind: "ReplicationController"},
Path: []string{"spec", "selector"}, Path: []string{"spec", "selector"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Version: "v1", Kind: "ReplicationController"}, GroupVersionKind: &gvk.Gvk{Version: "v1", Kind: "ReplicationController"},
Path: []string{"spec", "template", "metadata", "labels"}, Path: []string{"spec", "template", "metadata", "labels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "selector", "matchLabels"}, Path: []string{"spec", "selector", "matchLabels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "metadata", "labels"}, Path: []string{"spec", "template", "metadata", "labels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "affinity", "podAffinity", Path: []string{"spec", "template", "spec", "affinity", "podAffinity",
"preferredDuringSchedulingIgnoredDuringExecution", "preferredDuringSchedulingIgnoredDuringExecution",
"podAffinityTerm", "labelSelector", "matchLabels"}, "podAffinityTerm", "labelSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "affinity", "podAffinity", Path: []string{"spec", "template", "spec", "affinity", "podAffinity",
"requiredDuringSchedulingIgnoredDuringExecution", "labelSelector", "matchLabels"}, "requiredDuringSchedulingIgnoredDuringExecution", "labelSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "affinity", "podAntiAffinity", Path: []string{"spec", "template", "spec", "affinity", "podAntiAffinity",
"preferredDuringSchedulingIgnoredDuringExecution", "preferredDuringSchedulingIgnoredDuringExecution",
"podAffinityTerm", "labelSelector", "matchLabels"}, "podAffinityTerm", "labelSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "affinity", "podAntiAffinity", Path: []string{"spec", "template", "spec", "affinity", "podAntiAffinity",
"requiredDuringSchedulingIgnoredDuringExecution", "labelSelector", "matchLabels"}, "requiredDuringSchedulingIgnoredDuringExecution", "labelSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "ReplicaSet"}, GroupVersionKind: &gvk.Gvk{Kind: "ReplicaSet"},
Path: []string{"spec", "selector", "matchLabels"}, Path: []string{"spec", "selector", "matchLabels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "ReplicaSet"}, GroupVersionKind: &gvk.Gvk{Kind: "ReplicaSet"},
Path: []string{"spec", "template", "metadata", "labels"}, Path: []string{"spec", "template", "metadata", "labels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "DaemonSet"}, GroupVersionKind: &gvk.Gvk{Kind: "DaemonSet"},
Path: []string{"spec", "selector", "matchLabels"}, Path: []string{"spec", "selector", "matchLabels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "DaemonSet"}, GroupVersionKind: &gvk.Gvk{Kind: "DaemonSet"},
Path: []string{"spec", "template", "metadata", "labels"}, Path: []string{"spec", "template", "metadata", "labels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "StatefulSet"},
Path: []string{"spec", "selector", "matchLabels"}, Path: []string{"spec", "selector", "matchLabels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "StatefulSet"},
Path: []string{"spec", "template", "metadata", "labels"}, Path: []string{"spec", "template", "metadata", "labels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "affinity", "podAffinity", Path: []string{"spec", "template", "spec", "affinity", "podAffinity",
"preferredDuringSchedulingIgnoredDuringExecution", "preferredDuringSchedulingIgnoredDuringExecution",
"podAffinityTerm", "labelSelector", "matchLabels"}, "podAffinityTerm", "labelSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "affinity", "podAffinity", Path: []string{"spec", "template", "spec", "affinity", "podAffinity",
"requiredDuringSchedulingIgnoredDuringExecution", "labelSelector", "matchLabels"}, "requiredDuringSchedulingIgnoredDuringExecution", "labelSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "affinity", "podAntiAffinity", Path: []string{"spec", "template", "spec", "affinity", "podAntiAffinity",
"preferredDuringSchedulingIgnoredDuringExecution", "preferredDuringSchedulingIgnoredDuringExecution",
"podAffinityTerm", "labelSelector", "matchLabels"}, "podAffinityTerm", "labelSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "affinity", "podAntiAffinity", Path: []string{"spec", "template", "spec", "affinity", "podAntiAffinity",
"requiredDuringSchedulingIgnoredDuringExecution", "labelSelector", "matchLabels"}, "requiredDuringSchedulingIgnoredDuringExecution", "labelSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "Job"}, GroupVersionKind: &gvk.Gvk{Group: "batch", Kind: "Job"},
Path: []string{"spec", "selector", "matchLabels"}, Path: []string{"spec", "selector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "Job"}, GroupVersionKind: &gvk.Gvk{Group: "batch", Kind: "Job"},
Path: []string{"spec", "template", "metadata", "labels"}, Path: []string{"spec", "template", "metadata", "labels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "CronJob"}, GroupVersionKind: &gvk.Gvk{Group: "batch", Kind: "CronJob"},
Path: []string{"spec", "jobTemplate", "spec", "selector", "matchLabels"}, Path: []string{"spec", "jobTemplate", "spec", "selector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "CronJob"}, GroupVersionKind: &gvk.Gvk{Group: "batch", Kind: "CronJob"},
Path: []string{"spec", "jobTemplate", "spec", "template", "metadata", "labels"}, Path: []string{"spec", "jobTemplate", "spec", "template", "metadata", "labels"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "policy", Kind: "PodDisruptionBudget"}, GroupVersionKind: &gvk.Gvk{Group: "policy", Kind: "PodDisruptionBudget"},
Path: []string{"spec", "selector", "matchLabels"}, Path: []string{"spec", "selector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "networking.k8s.io", Kind: "NetworkPolicy"}, GroupVersionKind: &gvk.Gvk{Group: "networking.k8s.io", Kind: "NetworkPolicy"},
Path: []string{"spec", "podSelector", "matchLabels"}, Path: []string{"spec", "podSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "networking.k8s.io", Kind: "NetworkPolicy"}, GroupVersionKind: &gvk.Gvk{Group: "networking.k8s.io", Kind: "NetworkPolicy"},
Path: []string{"spec", "ingress", "from", "podSelector", "matchLabels"}, Path: []string{"spec", "ingress", "from", "podSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "networking.k8s.io", Kind: "NetworkPolicy"}, GroupVersionKind: &gvk.Gvk{Group: "networking.k8s.io", Kind: "NetworkPolicy"},
Path: []string{"spec", "egress", "to", "podSelector", "matchLabels"}, Path: []string{"spec", "egress", "to", "podSelector", "matchLabels"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
@@ -184,42 +184,42 @@ var defaultAnnotationsPathConfigs = []PathConfig{
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Version: "v1", Kind: "ReplicationController"}, GroupVersionKind: &gvk.Gvk{Version: "v1", Kind: "ReplicationController"},
Path: []string{"spec", "template", "metadata", "annotations"}, Path: []string{"spec", "template", "metadata", "annotations"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "metadata", "annotations"}, Path: []string{"spec", "template", "metadata", "annotations"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "ReplicaSet"}, GroupVersionKind: &gvk.Gvk{Kind: "ReplicaSet"},
Path: []string{"spec", "template", "metadata", "annotations"}, Path: []string{"spec", "template", "metadata", "annotations"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "DaemonSet"}, GroupVersionKind: &gvk.Gvk{Kind: "DaemonSet"},
Path: []string{"spec", "template", "metadata", "annotations"}, Path: []string{"spec", "template", "metadata", "annotations"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "apps", Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Group: "apps", Kind: "StatefulSet"},
Path: []string{"spec", "template", "metadata", "annotations"}, Path: []string{"spec", "template", "metadata", "annotations"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "Job"}, GroupVersionKind: &gvk.Gvk{Group: "batch", Kind: "Job"},
Path: []string{"spec", "template", "metadata", "annotations"}, Path: []string{"spec", "template", "metadata", "annotations"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "CronJob"}, GroupVersionKind: &gvk.Gvk{Group: "batch", Kind: "CronJob"},
Path: []string{"spec", "jobTemplate", "metadata", "annotations"}, Path: []string{"spec", "jobTemplate", "metadata", "annotations"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "batch", Kind: "CronJob"}, GroupVersionKind: &gvk.Gvk{Group: "batch", Kind: "CronJob"},
Path: []string{"spec", "jobTemplate", "spec", "template", "metadata", "annotations"}, Path: []string{"spec", "jobTemplate", "spec", "template", "metadata", "annotations"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },

View File

@@ -21,7 +21,7 @@ import (
"fmt" "fmt"
"k8s.io/api/core/v1" "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/hash" "sigs.k8s.io/kustomize/pkg/hash"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
@@ -43,13 +43,13 @@ func (o *nameHashTransformer) Transform(m resmap.ResMap) error {
for id, res := range m { for id, res := range m {
if res.IsGenerated() { if res.IsGenerated() {
switch { switch {
case selectByGVK(id.Gvk(), &schema.GroupVersionKind{Version: "v1", Kind: "ConfigMap"}): case id.Gvk().IsSelected(&gvk.Gvk{Version: "v1", Kind: "ConfigMap"}):
err := appendHashForConfigMap(res) err := appendHashForConfigMap(res)
if err != nil { if err != nil {
return err return err
} }
case selectByGVK(id.Gvk(), &schema.GroupVersionKind{Version: "v1", Kind: "Secret"}): case id.Gvk().IsSelected(&gvk.Gvk{Version: "v1", Kind: "Secret"}):
err := appendHashForSecret(res) err := appendHashForSecret(res)
if err != nil { if err != nil {
return err return err

View File

@@ -20,7 +20,7 @@ import (
"errors" "errors"
"fmt" "fmt"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
) )
@@ -55,7 +55,7 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
objMap := m[id].UnstructuredContent() objMap := m[id].UnstructuredContent()
for _, referencePathConfig := range o.pathConfigs { for _, referencePathConfig := range o.pathConfigs {
for _, path := range referencePathConfig.pathConfigs { for _, path := range referencePathConfig.pathConfigs {
if !selectByGVK(id.Gvk(), path.GroupVersionKind) { if !id.Gvk().IsSelected(path.GroupVersionKind) {
continue continue
} }
err := mutateField(objMap, path.Path, path.CreateIfNotPresent, err := mutateField(objMap, path.Path, path.CreateIfNotPresent,
@@ -70,7 +70,7 @@ func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
} }
func (o *nameReferenceTransformer) updateNameReference( func (o *nameReferenceTransformer) updateNameReference(
GVK schema.GroupVersionKind, m resmap.ResMap) func(in interface{}) (interface{}, error) { k gvk.Gvk, m resmap.ResMap) func(in interface{}) (interface{}, error) {
return func(in interface{}) (interface{}, error) { return func(in interface{}) (interface{}, error) {
s, ok := in.(string) s, ok := in.(string)
if !ok { if !ok {
@@ -78,7 +78,7 @@ func (o *nameReferenceTransformer) updateNameReference(
} }
for id, res := range m { for id, res := range m {
if !selectByGVK(id.Gvk(), &GVK) { if !id.Gvk().IsSelected(&k) {
continue continue
} }
if id.Name() == s { if id.Name() == s {

View File

@@ -20,7 +20,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
) )
@@ -342,12 +342,12 @@ func TestAddNameReferencePathConfigs(t *testing.T) {
pathConfigs := []ReferencePathConfig{ pathConfigs := []ReferencePathConfig{
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Kind: "KindA", Kind: "KindA",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "KindB", Kind: "KindB",
}, },
Path: []string{"path", "to", "a", "field"}, Path: []string{"path", "to", "a", "field"},

View File

@@ -17,19 +17,19 @@ limitations under the License.
package transformers package transformers
import ( import (
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
) )
// defaultNameReferencePathConfigs is the default configuration for updating // defaultNameReferencePathConfigs is the default configuration for updating
// the fields reference the name of other resources. // the fields reference the name of other resources.
var defaultNameReferencePathConfigs = []ReferencePathConfig{ var defaultNameReferencePathConfigs = []ReferencePathConfig{
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "HorizontalPodAutoscaler", Kind: "HorizontalPodAutoscaler",
}, },
Path: []string{"spec", "scaleTargetRef", "name"}, Path: []string{"spec", "scaleTargetRef", "name"},
@@ -38,12 +38,12 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Kind: "ReplicationController", Kind: "ReplicationController",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "HorizontalPodAutoscaler", Kind: "HorizontalPodAutoscaler",
}, },
Path: []string{"spec", "scaleTargetRef", "name"}, Path: []string{"spec", "scaleTargetRef", "name"},
@@ -52,12 +52,12 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "HorizontalPodAutoscaler", Kind: "HorizontalPodAutoscaler",
}, },
Path: []string{"spec", "scaleTargetRef", "name"}, Path: []string{"spec", "scaleTargetRef", "name"},
@@ -66,13 +66,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "ConfigMap", Kind: "ConfigMap",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -80,7 +80,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -88,7 +88,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -96,7 +96,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -104,7 +104,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -112,224 +112,224 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"}, Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "volumes", "projected", "sources", "configMap", "name"}, Path: []string{"spec", "template", "spec", "volumes", "projected", "sources", "configMap", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"}, Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"}, Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"}, Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "projected", "sources", "configMap", "name"}, Path: []string{"spec", "template", "spec", "volumes", "projected", "sources", "configMap", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"}, Path: []string{"spec", "template", "spec", "volumes", "configMap", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "volumes", "configMap", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "volumes", "configMap", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "initContainers", "env", "valueFrom", "configMapKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "envFrom", "configMapRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "initContainers", "envFrom", "configMapRef", "name"},
@@ -338,13 +338,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Secret", Kind: "Secret",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -352,7 +352,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -360,7 +360,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -368,7 +368,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -376,7 +376,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -384,7 +384,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Pod", Kind: "Pod",
}, },
@@ -392,308 +392,308 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"}, Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"}, Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"}, Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicaSet", Kind: "ReplicaSet",
}, },
Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"}, Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"}, Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"}, Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"}, Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"}, Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"}, Path: []string{"spec", "template", "spec", "volumes", "secret", "secretName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "containers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"}, Path: []string{"spec", "template", "spec", "imagePullSecrets", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "volumes", "secret", "secretName"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "volumes", "secret", "secretName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "initContainers", "env", "valueFrom", "secretKeyRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "initContainers", "envFrom", "secretRef", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "imagePullSecrets", "name"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "imagePullSecrets", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Ingress", Kind: "Ingress",
}, },
Path: []string{"spec", "tls", "secretName"}, Path: []string{"spec", "tls", "secretName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Ingress", Kind: "Ingress",
}, },
Path: []string{"metadata", "annotations", "ingress.kubernetes.io/auth-secret"}, Path: []string{"metadata", "annotations", "ingress.kubernetes.io/auth-secret"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Ingress", Kind: "Ingress",
}, },
Path: []string{"metadata", "annotations", "nginx.ingress.kubernetes.io/auth-secret"}, Path: []string{"metadata", "annotations", "nginx.ingress.kubernetes.io/auth-secret"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ServiceAccount", Kind: "ServiceAccount",
}, },
Path: []string{"imagePullSecrets", "name"}, Path: []string{"imagePullSecrets", "name"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StorageClass", Kind: "StorageClass",
}, },
Path: []string{"parameters", "secretName"}, // This is for Glusterfs, Path: []string{"parameters", "secretName"}, // This is for Glusterfs,
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StorageClass", Kind: "StorageClass",
}, },
Path: []string{"parameters", "adminSecretName"}, // This is for Quobyte, CephRBD, StorageOS Path: []string{"parameters", "adminSecretName"}, // This is for Quobyte, CephRBD, StorageOS
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StorageClass", Kind: "StorageClass",
}, },
Path: []string{"parameters", "userSecretName"}, // This is for CephRBD Path: []string{"parameters", "userSecretName"}, // This is for CephRBD
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StorageClass", Kind: "StorageClass",
}, },
Path: []string{"parameters", "secretRef"}, // This is for ScaleIO Path: []string{"parameters", "secretRef"}, // This is for ScaleIO
@@ -703,13 +703,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
{ {
// StatefulSet references headless service, so need to update the references. // StatefulSet references headless service, so need to update the references.
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "Service", Kind: "Service",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Group: "apps", Group: "apps",
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
@@ -717,14 +717,14 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Ingress", Kind: "Ingress",
}, },
Path: []string{"spec", "rules", "http", "paths", "backend", "serviceName"}, Path: []string{"spec", "rules", "http", "paths", "backend", "serviceName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Ingress", Kind: "Ingress",
}, },
Path: []string{"spec", "backend", "serviceName"}, Path: []string{"spec", "backend", "serviceName"},
@@ -733,13 +733,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Group: "rbac.authorization.k8s.io", Group: "rbac.authorization.k8s.io",
Kind: "Role", Kind: "Role",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Group: "rbac.authorization.k8s.io", Group: "rbac.authorization.k8s.io",
Kind: "RoleBinding", Kind: "RoleBinding",
}, },
@@ -749,13 +749,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Group: "rbac.authorization.k8s.io", Group: "rbac.authorization.k8s.io",
Kind: "ClusterRole", Kind: "ClusterRole",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Group: "rbac.authorization.k8s.io", Group: "rbac.authorization.k8s.io",
Kind: "RoleBinding", Kind: "RoleBinding",
}, },
@@ -763,7 +763,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Group: "rbac.authorization.k8s.io", Group: "rbac.authorization.k8s.io",
Kind: "ClusterRoleBinding", Kind: "ClusterRoleBinding",
}, },
@@ -773,13 +773,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "ServiceAccount", Kind: "ServiceAccount",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Group: "rbac.authorization.k8s.io", Group: "rbac.authorization.k8s.io",
Kind: "RoleBinding", Kind: "RoleBinding",
}, },
@@ -787,7 +787,7 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Group: "rbac.authorization.k8s.io", Group: "rbac.authorization.k8s.io",
Kind: "ClusterRoleBinding", Kind: "ClusterRoleBinding",
}, },
@@ -795,49 +795,49 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Pod", Kind: "Pod",
}, },
Path: []string{"spec", "serviceAccountName"}, Path: []string{"spec", "serviceAccountName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "serviceAccountName"}, Path: []string{"spec", "template", "spec", "serviceAccountName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "serviceAccountName"}, Path: []string{"spec", "template", "spec", "serviceAccountName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicationController", Kind: "ReplicationController",
}, },
Path: []string{"spec", "template", "spec", "serviceAccountName"}, Path: []string{"spec", "template", "spec", "serviceAccountName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "serviceAccountName"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "serviceAccountName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "serviceAccountName"}, Path: []string{"spec", "template", "spec", "serviceAccountName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "serviceAccountName"}, Path: []string{"spec", "template", "spec", "serviceAccountName"},
@@ -846,55 +846,55 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "PersistentVolumeClaim", Kind: "PersistentVolumeClaim",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Pod", Kind: "Pod",
}, },
Path: []string{"spec", "volumes", "persistentVolumeClaim", "claimName"}, Path: []string{"spec", "volumes", "persistentVolumeClaim", "claimName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "StatefulSet", Kind: "StatefulSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"}, Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Deployment", Kind: "Deployment",
}, },
Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"}, Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ReplicationController", Kind: "ReplicationController",
}, },
Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"}, Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CronJob", Kind: "CronJob",
}, },
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Job", Kind: "Job",
}, },
Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"}, Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"},
CreateIfNotPresent: false, CreateIfNotPresent: false,
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "DaemonSet", Kind: "DaemonSet",
}, },
Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"}, Path: []string{"spec", "template", "spec", "volumes", "persistentVolumeClaim", "claimName"},
@@ -903,13 +903,13 @@ var defaultNameReferencePathConfigs = []ReferencePathConfig{
}, },
}, },
{ {
referencedGVK: schema.GroupVersionKind{ referencedGVK: gvk.Gvk{
Version: "v1", Version: "v1",
Kind: "PersistentVolume", Kind: "PersistentVolume",
}, },
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "PersistentVolumeClaim", Kind: "PersistentVolumeClaim",
}, },
Path: []string{"spec", "volumeName"}, Path: []string{"spec", "volumeName"},

View File

@@ -17,7 +17,7 @@ limitations under the License.
package transformers package transformers
import ( import (
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
) )
@@ -36,22 +36,22 @@ var namespacePathConfigs = []PathConfig{
var skipNamespacePathConfigs = []PathConfig{ var skipNamespacePathConfigs = []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "Namespace", Kind: "Namespace",
}, },
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ClusterRoleBinding", Kind: "ClusterRoleBinding",
}, },
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "ClusterRole", Kind: "ClusterRole",
}, },
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{ GroupVersionKind: &gvk.Gvk{
Kind: "CustomResourceDefinition", Kind: "CustomResourceDefinition",
}, },
}, },
@@ -79,7 +79,7 @@ func (o *namespaceTransformer) Transform(m resmap.ResMap) error {
for id := range m { for id := range m {
found := false found := false
for _, path := range o.skipPathConfigs { for _, path := range o.skipPathConfigs {
if selectByGVK(id.Gvk(), path.GroupVersionKind) { if id.Gvk().IsSelected(path.GroupVersionKind) {
found = true found = true
break break
} }
@@ -93,7 +93,7 @@ func (o *namespaceTransformer) Transform(m resmap.ResMap) error {
for id := range mf { for id := range mf {
objMap := mf[id].UnstructuredContent() objMap := mf[id].UnstructuredContent()
for _, path := range o.pathConfigs { for _, path := range o.pathConfigs {
if !selectByGVK(id.Gvk(), path.GroupVersionKind) { if !id.Gvk().IsSelected(path.GroupVersionKind) {
continue continue
} }
@@ -114,9 +114,8 @@ func (o *namespaceTransformer) Transform(m resmap.ResMap) error {
func (o *namespaceTransformer) updateClusterRoleBinding(m resmap.ResMap) { func (o *namespaceTransformer) updateClusterRoleBinding(m resmap.ResMap) {
saMap := map[string]bool{} saMap := map[string]bool{}
saGVK := schema.GroupVersionKind{Version: "v1", Kind: "ServiceAccount"}
for id := range m { for id := range m {
if id.Gvk().String() == saGVK.String() { if id.Gvk().Equals(gvk.Gvk{Version: "v1", Kind: "ServiceAccount"}) {
saMap[id.Name()] = true saMap[id.Name()] = true
} }
} }

View File

@@ -65,7 +65,7 @@ func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
id = matchedIds[0] id = matchedIds[0]
base := baseResourceMap[id] base := baseResourceMap[id]
merged := map[string]interface{}{} merged := map[string]interface{}{}
versionedObj, err := scheme.Scheme.New(id.Gvk()) versionedObj, err := scheme.Scheme.New(id.Gvk().ToSchemaGvk())
baseName := base.GetName() baseName := base.GetName()
switch { switch {
case runtime.IsNotRegisteredError(err): case runtime.IsNotRegisteredError(err):
@@ -123,7 +123,7 @@ func (pt *patchTransformer) mergePatches() (resmap.ResMap, error) {
continue continue
} }
versionedObj, err := scheme.Scheme.New(id.Gvk()) versionedObj, err := scheme.Scheme.New(id.Gvk().ToSchemaGvk())
if err != nil && !runtime.IsNotRegisteredError(err) { if err != nil && !runtime.IsNotRegisteredError(err) {
return nil, err return nil, err
} }

View File

@@ -17,7 +17,7 @@ limitations under the License.
package transformers package transformers
import ( import (
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
) )
// PathConfig contains the configuration of a field, including the gvk it ties to, // PathConfig contains the configuration of a field, including the gvk it ties to,
@@ -28,7 +28,7 @@ type PathConfig struct {
// The gvk that this path tied to. // The gvk that this path tied to.
// If unset, it applied to any gvk // If unset, it applied to any gvk
// If some fields are set, it applies to all matching gvk. // If some fields are set, it applies to all matching gvk.
GroupVersionKind *schema.GroupVersionKind GroupVersionKind *gvk.Gvk
// Path to the field that will be munged. // Path to the field that will be munged.
Path []string Path []string
} }
@@ -49,15 +49,15 @@ type PathConfig struct {
type ReferencePathConfig struct { type ReferencePathConfig struct {
// referencedGVK is the GroupVersionKind that is referenced by // referencedGVK is the GroupVersionKind that is referenced by
// the PathConfig's gvk in the path of PathConfig.Path. // the PathConfig's gvk in the path of PathConfig.Path.
referencedGVK schema.GroupVersionKind referencedGVK gvk.Gvk
// PathConfig is the gvk that is referencing the referencedGVK object's name. // PathConfig is the gvk that is referencing the referencedGVK object's name.
pathConfigs []PathConfig pathConfigs []PathConfig
} }
// NewReferencePathConfig creates a new ReferencePathConfig object // NewReferencePathConfig creates a new ReferencePathConfig object
func NewReferencePathConfig(gvk schema.GroupVersionKind, pathconfigs []PathConfig) ReferencePathConfig { func NewReferencePathConfig(k gvk.Gvk, pathconfigs []PathConfig) ReferencePathConfig {
return ReferencePathConfig{ return ReferencePathConfig{
referencedGVK: gvk, referencedGVK: k,
pathConfigs: pathconfigs, pathConfigs: pathconfigs,
} }
} }

View File

@@ -21,9 +21,8 @@ import (
"fmt" "fmt"
"log" "log"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"k8s.io/apimachinery/pkg/runtime/schema"
) )
// namePrefixTransformer contains the prefix and the path config for each field that // namePrefixTransformer contains the prefix and the path config for each field that
@@ -45,13 +44,13 @@ var defaultNamePrefixPathConfigs = []PathConfig{
var skipNamePrefixPathConfigs = []PathConfig{ var skipNamePrefixPathConfigs = []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, GroupVersionKind: &gvk.Gvk{Kind: "CustomResourceDefinition"},
}, },
} }
// deprecateNamePrefixPathConfig will be moved into skipNamePrefixPathConfigs in next release // deprecateNamePrefixPathConfig will be moved into skipNamePrefixPathConfigs in next release
var deprecateNamePrefixPathConfig = PathConfig{ var deprecateNamePrefixPathConfig = PathConfig{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Namespace"}, GroupVersionKind: &gvk.Gvk{Kind: "Namespace"},
} }
// NewDefaultingNamePrefixTransformer construct a namePrefixTransformer with defaultNamePrefixPathConfigs. // NewDefaultingNamePrefixTransformer construct a namePrefixTransformer with defaultNamePrefixPathConfigs.
@@ -77,7 +76,7 @@ func (o *namePrefixTransformer) Transform(m resmap.ResMap) error {
for id := range m { for id := range m {
found := false found := false
for _, path := range o.skipPathConfigs { for _, path := range o.skipPathConfigs {
if selectByGVK(id.Gvk(), path.GroupVersionKind) { if id.Gvk().IsSelected(path.GroupVersionKind) {
found = true found = true
break break
} }
@@ -89,12 +88,12 @@ func (o *namePrefixTransformer) Transform(m resmap.ResMap) error {
} }
for id := range mf { for id := range mf {
if selectByGVK(id.Gvk(), deprecateNamePrefixPathConfig.GroupVersionKind) { if id.Gvk().IsSelected(deprecateNamePrefixPathConfig.GroupVersionKind) {
log.Println("Adding nameprefix to Namespace resource will be deprecated in next release.") log.Println("Adding nameprefix to Namespace resource will be deprecated in next release.")
} }
objMap := mf[id].UnstructuredContent() objMap := mf[id].UnstructuredContent()
for _, path := range o.pathConfigs { for _, path := range o.pathConfigs {
if !selectByGVK(id.Gvk(), path.GroupVersionKind) { if !id.Gvk().IsSelected(path.GroupVersionKind) {
continue continue
} }
err := mutateField(objMap, path.Path, path.CreateIfNotPresent, o.addPrefix) err := mutateField(objMap, path.Path, path.CreateIfNotPresent, o.addPrefix)

View File

@@ -20,7 +20,7 @@ import (
"reflect" "reflect"
"testing" "testing"
"k8s.io/apimachinery/pkg/runtime/schema" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource" "sigs.k8s.io/kustomize/pkg/resource"
) )
@@ -98,7 +98,7 @@ func TestAddPrefixPathConfigs(t *testing.T) {
pathConfigs := []PathConfig{ pathConfigs := []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{Group: "GroupA", Kind: "KindB"}, GroupVersionKind: &gvk.Gvk{Group: "GroupA", Kind: "KindB"},
Path: []string{"path", "to", "a", "field"}, Path: []string{"path", "to", "a", "field"},
CreateIfNotPresent: true, CreateIfNotPresent: true,
}, },

View File

@@ -3,8 +3,8 @@ package transformers
import ( import (
"fmt" "fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/expansion" "sigs.k8s.io/kustomize/pkg/expansion"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
) )
@@ -19,87 +19,87 @@ func NewRefVarTransformer(vars map[string]string) (Transformer, error) {
vars: vars, vars: vars,
pathConfigs: []PathConfig{ pathConfigs: []PathConfig{
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "initContainers", "command"}, Path: []string{"spec", "template", "spec", "initContainers", "command"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "containers", "command"}, Path: []string{"spec", "template", "spec", "containers", "command"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "initContainers", "command"}, Path: []string{"spec", "template", "spec", "initContainers", "command"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "containers", "command"}, Path: []string{"spec", "template", "spec", "containers", "command"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Job"}, GroupVersionKind: &gvk.Gvk{Kind: "Job"},
Path: []string{"spec", "template", "spec", "containers", "command"}, Path: []string{"spec", "template", "spec", "containers", "command"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "CronJob"}, GroupVersionKind: &gvk.Gvk{Kind: "CronJob"},
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "command"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "command"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "initContainers", "args"}, Path: []string{"spec", "template", "spec", "initContainers", "args"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "containers", "args"}, Path: []string{"spec", "template", "spec", "containers", "args"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "initContainers", "args"}, Path: []string{"spec", "template", "spec", "initContainers", "args"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "containers", "args"}, Path: []string{"spec", "template", "spec", "containers", "args"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Job"}, GroupVersionKind: &gvk.Gvk{Kind: "Job"},
Path: []string{"spec", "template", "spec", "containers", "args"}, Path: []string{"spec", "template", "spec", "containers", "args"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "CronJob"}, GroupVersionKind: &gvk.Gvk{Kind: "CronJob"},
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "args"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "args"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "initContainers", "env", "value"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "value"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"}, GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "containers", "env", "value"}, Path: []string{"spec", "template", "spec", "containers", "env", "value"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "initContainers", "env", "value"}, Path: []string{"spec", "template", "spec", "initContainers", "env", "value"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"}, GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "containers", "env", "value"}, Path: []string{"spec", "template", "spec", "containers", "env", "value"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Job"}, GroupVersionKind: &gvk.Gvk{Kind: "Job"},
Path: []string{"spec", "template", "spec", "containers", "env", "value"}, Path: []string{"spec", "template", "spec", "containers", "env", "value"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "CronJob"}, GroupVersionKind: &gvk.Gvk{Kind: "CronJob"},
Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "env", "value"}, Path: []string{"spec", "jobTemplate", "spec", "template", "spec", "containers", "env", "value"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Pod"}, GroupVersionKind: &gvk.Gvk{Kind: "Pod"},
Path: []string{"spec", "containers", "command"}, Path: []string{"spec", "containers", "command"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Pod"}, GroupVersionKind: &gvk.Gvk{Kind: "Pod"},
Path: []string{"spec", "containers", "args"}, Path: []string{"spec", "containers", "args"},
}, },
{ {
GroupVersionKind: &schema.GroupVersionKind{Kind: "Pod"}, GroupVersionKind: &gvk.Gvk{Kind: "Pod"},
Path: []string{"spec", "containers", "env", "value"}, Path: []string{"spec", "containers", "env", "value"},
}, },
}, },
@@ -116,10 +116,10 @@ func NewRefVarTransformer(vars map[string]string) (Transformer, error) {
// 2. Create the container's environment in the order variables are declared // 2. Create the container's environment in the order variables are declared
// 3. Add remaining service environment vars // 3. Add remaining service environment vars
func (rv *refvarTransformer) Transform(resources resmap.ResMap) error { func (rv *refvarTransformer) Transform(resources resmap.ResMap) error {
for GVKn := range resources { for resId := range resources {
objMap := resources[GVKn].UnstructuredContent() objMap := resources[resId].UnstructuredContent()
for _, pc := range rv.pathConfigs { for _, pc := range rv.pathConfigs {
if !selectByGVK(GVKn.Gvk(), pc.GroupVersionKind) { if !resId.Gvk().IsSelected(pc.GroupVersionKind) {
continue continue
} }
err := mutateField(objMap, pc.Path, false, func(in interface{}) (interface{}, error) { err := mutateField(objMap, pc.Path, false, func(in interface{}) (interface{}, error) {

View File

@@ -1,50 +0,0 @@
/*
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.
*/
package transformers
import (
"k8s.io/apimachinery/pkg/runtime/schema"
)
// selectByGVK returns true if `selector` selects `in`; otherwise, false.
// If `selector` and `in` are the same, return true.
// If `selector` is nil, it is considered as a wildcard and always return true.
// e.g. selector <Group: "", Version: "", Kind: "Deployment"> CAN select
// <Group: "extensions", Version: "v1beta1", Kind: "Deployment">.
// selector <Group: "apps", Version: "", Kind: "Deployment"> CANNOT select
// <Group: "extensions", Version: "v1beta1", Kind: "Deployment">.
func selectByGVK(in schema.GroupVersionKind, selector *schema.GroupVersionKind) bool {
if selector == nil {
return true
}
if len(selector.Group) > 0 {
if in.Group != selector.Group {
return false
}
}
if len(selector.Version) > 0 {
if in.Version != selector.Version {
return false
}
}
if len(selector.Kind) > 0 {
if in.Kind != selector.Kind {
return false
}
}
return true
}