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/golang/glog"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/pkg/configmapandsecret"
"sigs.k8s.io/kustomize/pkg/constants"
"sigs.k8s.io/kustomize/pkg/crds"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/gvk"
interror "sigs.k8s.io/kustomize/pkg/internal/error"
"sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/patch"
@@ -285,7 +285,8 @@ func (a *Application) resolveRefVars(m resmap.ResMap) (map[string]string, error)
return result, err
}
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 {
s, err := r.GetFieldValue(v.FieldRef.FieldPath)
if err != nil {

View File

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

View File

@@ -145,7 +145,7 @@ func runBuildTestCase(t *testing.T, testcaseName string, updateKustomizeExpected
t.Errorf("unexpected error: %v", err)
}
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 {
ioutil.WriteFile(testcase.ExpectedStdout, actualBytes, 0644)

View File

@@ -5,13 +5,6 @@ kind: Secret
metadata:
name: test-crdsecret
---
apiVersion: v1beta1
kind: Bee
metadata:
name: test-bee
spec:
action: fly
---
apiVersion: jingfang.example.com/v1beta1
kind: MyKind
metadata:
@@ -21,3 +14,10 @@ spec:
name: test-bee
secretRef:
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"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/kube-openapi/pkg/common"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/loader"
"sigs.k8s.io/kustomize/pkg/transformers"
)
@@ -100,9 +101,10 @@ func registerCRD(loader loader.Loader, path string) ([]pathConfigs, error) {
}
crds := getCRDs(types)
for crd, gvk := range crds {
for crd, k := range crds {
crdPathConfigs := pathConfigs{}
err = getCRDPathConfig(types, crd, crd, gvk, []string{}, &crdPathConfigs)
err = getCRDPathConfig(
types, crd, crd, gvk.FromSchemaGvk(k), []string{}, &crdPathConfigs)
if err != nil {
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
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 {
if _, ok := types[crd]; !ok {
return nil
@@ -146,7 +149,7 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
configs.addAnnotationPathConfig(
transformers.PathConfig{
CreateIfNotPresent: false,
GroupVersionKind: &gvk,
GroupVersionKind: &in,
Path: append(path, propname),
},
)
@@ -156,7 +159,7 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
configs.addLabelPathConfig(
transformers.PathConfig{
CreateIfNotPresent: false,
GroupVersionKind: &gvk,
GroupVersionKind: &in,
Path: append(path, propname),
},
)
@@ -166,7 +169,7 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
configs.addPrefixPathConfig(
transformers.PathConfig{
CreateIfNotPresent: false,
GroupVersionKind: &gvk,
GroupVersionKind: &in,
Path: append(path, propname),
},
)
@@ -180,10 +183,10 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
nameKey = "name"
}
configs.addNamereferencePathConfig(transformers.NewReferencePathConfig(
schema.GroupVersionKind{Kind: kind, Version: version},
gvk.Gvk{Kind: kind, Version: version},
[]transformers.PathConfig{
{CreateIfNotPresent: false,
GroupVersionKind: &gvk,
GroupVersionKind: &in,
Path: append(path, propname, nameKey),
}}))
@@ -191,7 +194,7 @@ func getCRDPathConfig(types map[string]common.OpenAPIDefinition, atype string, c
}
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

View File

@@ -21,7 +21,7 @@ import (
"sort"
"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/loader"
"sigs.k8s.io/kustomize/pkg/transformers"
@@ -153,21 +153,21 @@ func makeLoader(t *testing.T) loader.Loader {
func TestRegisterCRD(t *testing.T) {
refpathconfigs := []transformers.ReferencePathConfig{
transformers.NewReferencePathConfig(
schema.GroupVersionKind{Kind: "Bee", Version: "v1beta1"},
gvk.Gvk{Kind: "Bee", Version: "v1beta1"},
[]transformers.PathConfig{
{
CreateIfNotPresent: false,
GroupVersionKind: &schema.GroupVersionKind{Kind: "MyKind"},
GroupVersionKind: &gvk.Gvk{Kind: "MyKind"},
Path: []string{"spec", "beeRef", "name"},
},
},
),
transformers.NewReferencePathConfig(
schema.GroupVersionKind{Kind: "Secret", Version: "v1"},
gvk.Gvk{Kind: "Secret", Version: "v1"},
[]transformers.PathConfig{
{
CreateIfNotPresent: false,
GroupVersionKind: &schema.GroupVersionKind{Kind: "MyKind"},
GroupVersionKind: &gvk.Gvk{Kind: "MyKind"},
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.
*/
package transformers
package gvk
import (
"testing"
import "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) {
type testCase struct {
description string
in schema.GroupVersionKind
filter *schema.GroupVersionKind
in Gvk
filter *Gvk
expected bool
}
testCases := []testCase{
{
description: "nil filter",
in: schema.GroupVersionKind{},
in: Gvk{},
filter: nil,
expected: true,
},
{
description: "gvk matches",
in: schema.GroupVersionKind{
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &schema.GroupVersionKind{
filter: &Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
@@ -52,12 +106,12 @@ func TestSelectByGVK(t *testing.T) {
},
{
description: "group doesn't matches",
in: schema.GroupVersionKind{
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &schema.GroupVersionKind{
filter: &Gvk{
Group: "group2",
Version: "version1",
Kind: "kind1",
@@ -66,12 +120,12 @@ func TestSelectByGVK(t *testing.T) {
},
{
description: "version doesn't matches",
in: schema.GroupVersionKind{
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &schema.GroupVersionKind{
filter: &Gvk{
Group: "group1",
Version: "version2",
Kind: "kind1",
@@ -80,12 +134,12 @@ func TestSelectByGVK(t *testing.T) {
},
{
description: "kind doesn't matches",
in: schema.GroupVersionKind{
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &schema.GroupVersionKind{
filter: &Gvk{
Group: "group1",
Version: "version1",
Kind: "kind2",
@@ -94,12 +148,12 @@ func TestSelectByGVK(t *testing.T) {
},
{
description: "no version in filter",
in: schema.GroupVersionKind{
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &schema.GroupVersionKind{
filter: &Gvk{
Group: "group1",
Version: "",
Kind: "kind1",
@@ -108,12 +162,12 @@ func TestSelectByGVK(t *testing.T) {
},
{
description: "only kind is set in filter",
in: schema.GroupVersionKind{
in: Gvk{
Group: "group1",
Version: "version1",
Kind: "kind1",
},
filter: &schema.GroupVersionKind{
filter: &Gvk{
Group: "",
Version: "",
Kind: "kind1",
@@ -123,7 +177,7 @@ func TestSelectByGVK(t *testing.T) {
}
for _, tc := range testCases {
filtered := selectByGVK(tc.in, tc.filter)
filtered := tc.in.IsSelected(tc.filter)
if filtered != tc.expected {
t.Fatalf("unexpected filter result for test case: %v", tc.description)
}

View File

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

View File

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

View File

@@ -22,7 +22,7 @@ import (
"testing"
"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/patch"
"sigs.k8s.io/kustomize/pkg/resmap"
@@ -179,7 +179,7 @@ func TestNewPatchJson6902FactoryMulti(t *testing.T) {
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{
id: resource.NewResourceFromMap(
map[string]interface{}{
@@ -293,7 +293,7 @@ func TestNewPatchJson6902FactoryMultiConflict(t *testing.T) {
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{
id: resource.NewResourceFromMap(
map[string]interface{}{

View File

@@ -21,12 +21,12 @@ import (
"testing"
"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/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) {
id := resource.NewResId(deploy, "deploy1")

View File

@@ -20,15 +20,15 @@ import (
"reflect"
"testing"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/configmapandsecret"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/internal/loadertest"
"sigs.k8s.io/kustomize/pkg/resource"
"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) {
type testCase struct {

View File

@@ -19,7 +19,6 @@ package resmap
import (
"sort"
"k8s.io/apimachinery/pkg/runtime/schema"
"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) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a IdSlice) Less(i, j int) bool {
if a[i].Gvk().String() != a[j].Gvk().String() {
return gvkLess(a[i].Gvk(), a[j].Gvk())
if !a[i].Gvk().Equals(a[j].Gvk()) {
return a[i].Gvk().IsLessThan(a[j].Gvk())
}
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"
"testing"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/resource"
)
func TestLess(t *testing.T) {
ids := IdSlice{
resource.NewResId(schema.GroupVersionKind{Kind: "ConfigMap"}, "cm"),
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"),
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"),
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"),
resource.NewResId(schema.GroupVersionKind{Kind: "Role"}, "ro"),
resource.NewResId(schema.GroupVersionKind{Kind: "RoleBinding"}, "rb"),
resource.NewResId(schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, "crd"),
resource.NewResId(schema.GroupVersionKind{Kind: "ServiceAccount"}, "sa"),
resource.NewResIdKindOnly("ConfigMap", "cm"),
resource.NewResIdKindOnly("Pod", "pod"),
resource.NewResIdKindOnly("Namespace", "ns1"),
resource.NewResIdKindOnly("Namespace", "ns2"),
resource.NewResIdKindOnly("Role", "ro"),
resource.NewResIdKindOnly("RoleBinding", "rb"),
resource.NewResIdKindOnly("CustomResourceDefinition", "crd"),
resource.NewResIdKindOnly("ServiceAccount", "sa"),
}
expected := IdSlice{
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns1"),
resource.NewResId(schema.GroupVersionKind{Kind: "Namespace"}, "ns2"),
resource.NewResId(schema.GroupVersionKind{Kind: "CustomResourceDefinition"}, "crd"),
resource.NewResId(schema.GroupVersionKind{Kind: "ServiceAccount"}, "sa"),
resource.NewResId(schema.GroupVersionKind{Kind: "Role"}, "ro"),
resource.NewResId(schema.GroupVersionKind{Kind: "RoleBinding"}, "rb"),
resource.NewResId(schema.GroupVersionKind{Kind: "ConfigMap"}, "cm"),
resource.NewResId(schema.GroupVersionKind{Kind: "Pod"}, "pod"),
resource.NewResIdKindOnly("Namespace", "ns1"),
resource.NewResIdKindOnly("Namespace", "ns2"),
resource.NewResIdKindOnly("CustomResourceDefinition", "crd"),
resource.NewResIdKindOnly("ServiceAccount", "sa"),
resource.NewResIdKindOnly("Role", "ro"),
resource.NewResIdKindOnly("RoleBinding", "rb"),
resource.NewResIdKindOnly("ConfigMap", "cm"),
resource.NewResIdKindOnly("Pod", "pod"),
}
sort.Sort(ids)
if !reflect.DeepEqual(ids, expected) {

View File

@@ -30,6 +30,7 @@ import (
"github.com/pkg/errors"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
k8syaml "k8s.io/apimachinery/pkg/util/yaml"
"sigs.k8s.io/kustomize/pkg/gvk"
internal "sigs.k8s.io/kustomize/pkg/internal/error"
"sigs.k8s.io/kustomize/pkg/loader"
"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 {
oldName := obj.GetName()
gvk := obj.GroupVersionKind()
id := resource.NewResId(gvk, oldName)
gvKind := gvk.FromSchemaGvk(obj.GroupVersionKind())
id := resource.NewResId(gvKind, oldName)
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)
m[id] = resource.NewResourceFromUnstruct(*obj)

View File

@@ -21,13 +21,13 @@ import (
"reflect"
"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/resource"
)
var deploy = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "Deployment"}
var statefulset = schema.GroupVersionKind{Group: "apps", Version: "v1", Kind: "StatefulSet"}
var deploy = gvk.Gvk{Group: "apps", Version: "v1", Kind: "Deployment"}
var statefulset = gvk.Gvk{Group: "apps", Version: "v1", Kind: "StatefulSet"}
func TestEncodeAsYaml(t *testing.T) {
encoded := []byte(`apiVersion: v1

View File

@@ -22,14 +22,14 @@ import (
"testing"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/configmapandsecret"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resource"
"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) {
secrets := []types.SecretArgs{

View File

@@ -19,13 +19,13 @@ package resource
import (
"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).
type ResId struct {
// GroupVersionKind of the resource.
gvk schema.GroupVersionKind
// Gvk of the resource.
gvKind gvk.Gvk
// original name of the resource before transformation.
name string
// namePrefix of the resource
@@ -39,45 +39,46 @@ type ResId struct {
}
// NewResIdWithPrefixNamespace creates new resource identifier with a prefix and a namespace
func NewResIdWithPrefixNamespace(g schema.GroupVersionKind, n, p, ns string) ResId {
return ResId{gvk: g, name: n, prefix: p, namespace: ns}
func NewResIdWithPrefixNamespace(k gvk.Gvk, n, p, ns string) ResId {
return ResId{gvKind: k, name: n, prefix: p, namespace: ns}
}
// NewResIdWithPrefix creates new resource identifier with a prefix
func NewResIdWithPrefix(g schema.GroupVersionKind, n, p string) ResId {
return ResId{gvk: g, name: n, prefix: p}
func NewResIdWithPrefix(k gvk.Gvk, n, p string) ResId {
return ResId{gvKind: k, name: n, prefix: p}
}
// NewResId creates new resource identifier
func NewResId(g schema.GroupVersionKind, n string) ResId {
return NewResIdWithPrefix(g, n, "")
func NewResId(k gvk.Gvk, n string) ResId {
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
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"
}
// GvknString of ResId based on GVK and name
func (n ResId) GvknString() string {
if n.gvk.Group == "" {
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"
return n.gvKind.String() + "_" + n.name + ".yaml"
}
// GvknEquals return if two ResId have the same Group/Version/Kind and name
// The comparison excludes prefix
func (n ResId) GvknEquals(id ResId) bool {
return n.gvk.Group == id.gvk.Group && n.gvk.Version == id.gvk.Version &&
n.gvk.Kind == id.gvk.Kind && n.name == id.name
return n.gvKind.Equals(id.gvKind) && n.name == id.name
}
// Gvk returns Group/Version/Kind of the resource.
func (n ResId) Gvk() schema.GroupVersionKind {
return n.gvk
func (n ResId) Gvk() gvk.Gvk {
return n.gvKind
}
// 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
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
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

View File

@@ -3,26 +3,26 @@ package resource
import (
"testing"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/gvk"
)
var stringTests = []struct {
x ResId
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"},
{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"},
{ResId{gvk: schema.GroupVersionKind{Kind: "k"},
{ResId{gvKind: gvk.Gvk{Kind: "k"},
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"},
{ResId{gvk: schema.GroupVersionKind{},
{ResId{gvKind: gvk.Gvk{},
name: "nm", prefix: "p"}, "____p_nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{},
{ResId{gvKind: gvk.Gvk{},
name: "nm"}, "_____nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}}, "_____.yaml"},
{ResId{gvKind: gvk.Gvk{}}, "_____.yaml"},
{ResId{}, "_____.yaml"},
}
@@ -38,19 +38,19 @@ var gvknStringTests = []struct {
x ResId
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"},
{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"},
{ResId{gvk: schema.GroupVersionKind{Kind: "k"},
{ResId{gvKind: gvk.Gvk{Kind: "k"},
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"},
{ResId{gvk: schema.GroupVersionKind{},
{ResId{gvKind: gvk.Gvk{},
name: "nm", prefix: "p"}, "__nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{},
{ResId{gvKind: gvk.Gvk{},
name: "nm"}, "__nm.yaml"},
{ResId{gvk: schema.GroupVersionKind{}}, "__.yaml"},
{ResId{gvKind: gvk.Gvk{}}, "__.yaml"},
{ResId{}, "__.yaml"},
}
@@ -66,17 +66,17 @@ var GvknEqualsTest = []struct {
x1 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"},
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"}},
{ResId{gvk: schema.GroupVersionKind{Version: "v", Kind: "k"},
{ResId{gvKind: gvk.Gvk{Version: "v", Kind: "k"},
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"}},
{ResId{gvk: schema.GroupVersionKind{Kind: "k"},
{ResId{gvKind: gvk.Gvk{Kind: "k"},
name: "nm", prefix: "AA", namespace: "X"},
ResId{gvk: schema.GroupVersionKind{Kind: "k"},
ResId{gvKind: gvk.Gvk{Kind: "k"},
name: "nm", prefix: "BB", namespace: "Z"}},
{ResId{name: "nm", prefix: "AA", namespace: "X"},
ResId{name: "nm", prefix: "BB", namespace: "Z"}},

View File

@@ -20,12 +20,12 @@ package resource
import (
"encoding/json"
"fmt"
"strings"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
"sigs.k8s.io/kustomize/pkg/gvk"
)
// 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.
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.

View File

@@ -17,29 +17,19 @@ limitations under the License.
package transformerconfig
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"strings"
"sigs.k8s.io/kustomize/pkg/gvk"
)
// PathConfig contains the configuration of a field, including the gvk it ties to,
// path to the field, etc.
type PathConfig 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"`
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
Path string `json:"path,omitempty" yaml:"path,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 "/"
func (p PathConfig) PathSlice() []string {
return strings.Split(p.Path, "/")

View File

@@ -17,7 +17,7 @@ limitations under the License.
package transformerconfig
import (
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/gvk"
)
// ReferencePathConfig contains the configuration of a field that references
@@ -34,27 +34,16 @@ import (
// },
// }
type ReferencePathConfig 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"`
gvk.Gvk `json:",inline,omitempty" yaml:",inline,omitempty"`
// PathConfig is the gvk that is referencing the referencedGVK object's name.
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 {
var result []ReferencePathConfig
found := false
for _, c := range configs {
if c.Gvk() == config.Gvk() {
if c.Equals(config.Gvk) {
c.PathConfigs = append(c.PathConfigs, config.PathConfigs...)
found = true
}

View File

@@ -20,7 +20,7 @@ import (
"reflect"
"testing"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
"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{}{
"spec": 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{}{
"spec": 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 {
objMap := m[id].UnstructuredContent()
for _, path := range o.pathConfigs {
if !selectByGVK(id.Gvk(), path.GroupVersionKind) {
if !id.Gvk().IsSelected(path.GroupVersionKind) {
continue
}
err := mutateField(objMap, path.Path, path.CreateIfNotPresent, o.addMap)

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@@ -17,7 +17,7 @@ limitations under the License.
package transformers
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,
@@ -28,7 +28,7 @@ type PathConfig struct {
// The gvk that this path tied to.
// If unset, it applied to any 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 []string
}
@@ -49,15 +49,15 @@ type PathConfig struct {
type ReferencePathConfig struct {
// referencedGVK is the GroupVersionKind that is referenced by
// 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.
pathConfigs []PathConfig
}
// NewReferencePathConfig creates a new ReferencePathConfig object
func NewReferencePathConfig(gvk schema.GroupVersionKind, pathconfigs []PathConfig) ReferencePathConfig {
func NewReferencePathConfig(k gvk.Gvk, pathconfigs []PathConfig) ReferencePathConfig {
return ReferencePathConfig{
referencedGVK: gvk,
referencedGVK: k,
pathConfigs: pathconfigs,
}
}

View File

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

View File

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

View File

@@ -3,8 +3,8 @@ package transformers
import (
"fmt"
"k8s.io/apimachinery/pkg/runtime/schema"
"sigs.k8s.io/kustomize/pkg/expansion"
"sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/resmap"
)
@@ -19,87 +19,87 @@ func NewRefVarTransformer(vars map[string]string) (Transformer, error) {
vars: vars,
pathConfigs: []PathConfig{
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"},
GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "initContainers", "command"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"},
GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "containers", "command"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"},
GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "initContainers", "command"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"},
GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "containers", "command"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Job"},
GroupVersionKind: &gvk.Gvk{Kind: "Job"},
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"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"},
GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "initContainers", "args"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"},
GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
Path: []string{"spec", "template", "spec", "containers", "args"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"},
GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "initContainers", "args"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"},
GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
Path: []string{"spec", "template", "spec", "containers", "args"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Job"},
GroupVersionKind: &gvk.Gvk{Kind: "Job"},
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"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "StatefulSet"},
GroupVersionKind: &gvk.Gvk{Kind: "StatefulSet"},
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"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Deployment"},
GroupVersionKind: &gvk.Gvk{Kind: "Deployment"},
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"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Job"},
GroupVersionKind: &gvk.Gvk{Kind: "Job"},
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"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Pod"},
GroupVersionKind: &gvk.Gvk{Kind: "Pod"},
Path: []string{"spec", "containers", "command"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Pod"},
GroupVersionKind: &gvk.Gvk{Kind: "Pod"},
Path: []string{"spec", "containers", "args"},
},
{
GroupVersionKind: &schema.GroupVersionKind{Kind: "Pod"},
GroupVersionKind: &gvk.Gvk{Kind: "Pod"},
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
// 3. Add remaining service environment vars
func (rv *refvarTransformer) Transform(resources resmap.ResMap) error {
for GVKn := range resources {
objMap := resources[GVKn].UnstructuredContent()
for resId := range resources {
objMap := resources[resId].UnstructuredContent()
for _, pc := range rv.pathConfigs {
if !selectByGVK(GVKn.Gvk(), pc.GroupVersionKind) {
if !resId.Gvk().IsSelected(pc.GroupVersionKind) {
continue
}
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
}