Maintain resources in order loaded.

This commit is contained in:
Jeffrey Regan
2019-06-03 11:22:53 -07:00
parent af57fc3ece
commit 4162dbc2d8
39 changed files with 1074 additions and 617 deletions

View File

@@ -44,19 +44,18 @@ func (pt *imageTransformer) Transform(m resmap.ResMap) error {
if len(pt.images) == 0 {
return nil
}
for id := range m {
objMap := m[id].Map()
for _, r := range m.Resources() {
for _, path := range pt.fieldSpecs {
if !id.Gvk().IsSelected(&path.Gvk) {
if !r.Id().Gvk().IsSelected(&path.Gvk) {
continue
}
err := mutateField(objMap, path.PathSlice(), false, pt.mutateImage)
err := mutateField(r.Map(), path.PathSlice(), false, pt.mutateImage)
if err != nil {
return err
}
}
// Kept for backward compatibility
if err := pt.findAndReplaceImage(objMap); err != nil && id.Gvk().Kind != `CustomResourceDefinition` {
if err := pt.findAndReplaceImage(r.Map()); err != nil && r.Id().Kind != `CustomResourceDefinition` {
return err
}
}

View File

@@ -59,13 +59,14 @@ func NewMapTransformer(
// Transform apply each <key, value> pair in the mapTransformer to the
// fields specified in mapTransformer.
func (o *mapTransformer) Transform(m resmap.ResMap) error {
for id := range m {
objMap := m[id].Map()
for _, r := range m.Resources() {
for _, path := range o.fieldSpecs {
if !id.Gvk().IsSelected(&path.Gvk) {
if !r.Id().Gvk().IsSelected(&path.Gvk) {
continue
}
err := mutateField(objMap, path.PathSlice(), path.CreateIfNotPresent, o.addMap)
err := mutateField(
r.Map(), path.PathSlice(),
path.CreateIfNotPresent, o.addMap)
if err != nil {
return err
}

View File

@@ -17,7 +17,6 @@ limitations under the License.
package transformers
import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
@@ -34,7 +33,7 @@ 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 crd = gvk.Gvk{Group: "apiwctensions.k8s.io", Version: "v1beta1", Kind: "CustomResourceDefinition"}
var crd = gvk.Gvk{Group: "apiextensions.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 pv = gvk.Gvk{Version: "v1", Kind: "PersistentVolume"}
@@ -47,7 +46,7 @@ var rf = resource.NewFactory(kunstruct.NewKunstructuredFactoryImpl())
var defaultTransformerConfig = config.MakeDefaultConfig()
func TestLabelsRun(t *testing.T) {
m := resmap.ResMap{
m := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -198,8 +197,8 @@ func TestLabelsRun(t *testing.T) {
},
},
}),
}
expected := resmap.ResMap{
})
expected := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -430,7 +429,7 @@ func TestLabelsRun(t *testing.T) {
},
},
}),
}
})
lt, err := NewLabelsMapTransformer(
map[string]string{"label-key1": "label-value1", "label-key2": "label-value2"},
defaultTransformerConfig.CommonLabels)
@@ -441,14 +440,13 @@ func TestLabelsRun(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(m, expected) {
err = expected.ErrorIfNotEqual(m)
if err = expected.ErrorIfNotEqual(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
}
}
func TestAnnotationsRun(t *testing.T) {
m := resmap.ResMap{
m := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -499,8 +497,8 @@ func TestAnnotationsRun(t *testing.T) {
},
},
}),
}
expected := resmap.ResMap{
})
expected := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -567,7 +565,7 @@ func TestAnnotationsRun(t *testing.T) {
},
},
}),
}
})
at, err := NewAnnotationsMapTransformer(
map[string]string{"anno-key1": "anno-value1", "anno-key2": "anno-value2"},
defaultTransformerConfig.CommonAnnotations)
@@ -578,14 +576,13 @@ func TestAnnotationsRun(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(m, expected) {
err = expected.ErrorIfNotEqual(m)
if err = expected.ErrorIfNotEqual(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
}
}
func TestAnnotaionsRunWithNullValue(t *testing.T) {
m := resmap.ResMap{
m := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -595,9 +592,9 @@ func TestAnnotaionsRunWithNullValue(t *testing.T) {
"annotations": nil,
},
}),
}
})
expected := resmap.ResMap{
expected := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -610,7 +607,7 @@ func TestAnnotaionsRunWithNullValue(t *testing.T) {
},
},
}),
}
})
at, err := NewAnnotationsMapTransformer(
map[string]string{"anno-key1": "anno-value1", "anno-key2": "anno-value2"},
@@ -622,8 +619,7 @@ func TestAnnotaionsRunWithNullValue(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(m, expected) {
err = expected.ErrorIfNotEqual(m)
if err = expected.ErrorIfNotEqual(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
}

View File

@@ -18,8 +18,6 @@ package transformers
import (
"fmt"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/resmap"
)
@@ -27,7 +25,6 @@ import (
type multiTransformer struct {
transformers []Transformer
checkConflictEnabled bool
rf *resource.Factory
}
var _ Transformer = &multiTransformer{}
@@ -71,7 +68,7 @@ func (o *multiTransformer) transform(m resmap.ResMap) error {
// A spot check to perform when the transformations are supposed to be commutative.
// Fail if there's a difference in the result.
func (o *multiTransformer) transformWithCheckConflict(m resmap.ResMap) error {
mcopy := m.DeepCopy(o.rf)
mcopy := m.DeepCopy()
err := o.transform(m)
if err != nil {
return err

View File

@@ -61,17 +61,18 @@ func NewNameReferenceTransformer(br []config.NameBackReferences) Transformer {
// body of the resource object (the value in the ResMap).
func (o *nameReferenceTransformer) Transform(m resmap.ResMap) error {
// TODO: Too much looping.
// Even more hidden loops in FilterBy,
// Even more hidden loops in ResourcesThatCouldReference,
// updateNameReference and FindByGVKN.
for id := range m {
for id, r := range m.AsMap() {
for _, backRef := range o.backRefs {
for _, fSpec := range backRef.FieldSpecs {
if id.Gvk().IsSelected(&fSpec.Gvk) {
err := mutateField(
m[id].Map(), fSpec.PathSlice(),
r.Map(),
fSpec.PathSlice(),
fSpec.CreateIfNotPresent,
o.updateNameReference(
id, backRef.Gvk, m.FilterBy(id)))
id, backRef.Gvk, m.ResourcesThatCouldReference(id)))
if err != nil {
return err
}
@@ -88,7 +89,7 @@ func (o *nameReferenceTransformer) updateNameReference(
switch in.(type) {
case string:
s, _ := in.(string)
for id, res := range m {
for id, res := range m.AsMap() {
if id.Gvk().IsSelected(&backRef) && id.Name() == s {
matchedIds := m.GetMatchingIds(id.GvknEquals)
// If there's more than one match, there's no way
@@ -114,7 +115,7 @@ func (o *nameReferenceTransformer) updateNameReference(
}
names = append(names, name)
}
for id, res := range m {
for id, res := range m.AsMap() {
indexes := indexOf(id.Name(), names)
if id.Gvk().IsSelected(&backRef) && len(indexes) > 0 {
matchedIds := m.GetMatchingIds(id.GvknEquals)

View File

@@ -17,7 +17,6 @@ limitations under the License.
package transformers
import (
"reflect"
"strings"
"testing"
@@ -30,7 +29,7 @@ import (
func TestNameReferenceHappyRun(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmap.ResMap{
m := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -278,14 +277,11 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
},
}),
}
})
expected := resmap.ResMap{}
for k, v := range m {
expected[k] = v
}
expected := m.ShallowCopy()
expected[resid.NewResId(deploy, "deploy1")] = rf.FromMap(
expected.ReplaceResource(resid.NewResId(deploy, "deploy1"), rf.FromMap(
map[string]interface{}{
"group": "apps",
"apiVersion": "v1",
@@ -365,8 +361,8 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
},
},
})
expected[resid.NewResId(statefulset, "statefulset1")] = rf.FromMap(
}))
expected.ReplaceResource(resid.NewResId(statefulset, "statefulset1"), rf.FromMap(
map[string]interface{}{
"group": "apps",
"apiVersion": "v1",
@@ -398,8 +394,8 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
},
},
})
expected[resid.NewResId(ingress, "ingress1")] = rf.FromMap(
}))
expected.ReplaceResource(resid.NewResId(ingress, "ingress1"), rf.FromMap(
map[string]interface{}{
"group": "extensions",
"apiVersion": "v1beta1",
@@ -418,8 +414,8 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
},
},
)
expected[resid.NewResId(crb, "crb")] = rf.FromMap(
))
expected.ReplaceResource(resid.NewResId(crb, "crb"), rf.FromMap(
map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
"kind": "ClusterRoleBinding",
@@ -433,8 +429,8 @@ func TestNameReferenceHappyRun(t *testing.T) {
"namespace": "test",
},
},
})
expected[resid.NewResId(cr, "cr")] = rf.FromMap(
}))
expected.ReplaceResource(resid.NewResId(cr, "cr"), rf.FromMap(
map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
"kind": "ClusterRole",
@@ -453,8 +449,8 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
},
},
})
expected[resid.NewResId(cronjob, "cronjob1")] = rf.FromMap(
}))
expected.ReplaceResource(resid.NewResId(cronjob, "cronjob1"), rf.FromMap(
map[string]interface{}{
"apiVersion": "batch/v1beta1",
"kind": "CronJob",
@@ -490,14 +486,13 @@ func TestNameReferenceHappyRun(t *testing.T) {
},
},
},
})
}))
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
err := nrt.Transform(m)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(m, expected) {
err = expected.ErrorIfNotEqual(m)
if err = expected.ErrorIfNotEqual(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
}
}
@@ -510,7 +505,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
expectedErr string
}{
{
resMap: resmap.ResMap{
resMap: resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cr, "cr"): rf.FromMap(
map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
@@ -529,9 +524,9 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
},
},
}),
},
}),
expectedErr: "is expected to be string"},
{resMap: resmap.ResMap{
{resMap: resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cr, "cr"): rf.FromMap(
map[string]interface{}{
"apiVersion": "rbac.authorization.k8s.io/v1",
@@ -550,7 +545,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
},
},
}),
},
}),
expectedErr: "is expected to be either a string or a []interface{}"},
}
@@ -571,7 +566,7 @@ func TestNameReferenceUnhappyRun(t *testing.T) {
func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmap.ResMap{
m := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(pv, "volume1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -593,9 +588,9 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
"volumeName": "volume1",
},
}),
}
})
expected := resmap.ResMap{
expected := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(pv, "volume1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -617,15 +612,14 @@ func TestNameReferencePersistentVolumeHappyRun(t *testing.T) {
"volumeName": "someprefix-volume1",
},
}),
}
expected[resid.NewResId(pv, "volume1")].AppendRefBy(resid.NewResId(pvc, "claim1"))
})
expected.GetById(resid.NewResId(pv, "volume1")).AppendRefBy(resid.NewResId(pvc, "claim1"))
nrt := NewNameReferenceTransformer(defaultTransformerConfig.NameReference)
err := nrt.Transform(m)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(m, expected) {
err = expected.ErrorIfNotEqual(m)
if err = expected.ErrorIfNotEqual(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
}
}

View File

@@ -50,8 +50,8 @@ func NewNamespaceTransformer(ns string, cf []config.FieldSpec) Transformer {
func (o *namespaceTransformer) Transform(m resmap.ResMap) error {
mf := o.filterResmap(m)
for id := range mf {
objMap := mf[id].Map()
for id, res := range mf.AsMap() {
objMap := res.Map()
for _, path := range o.fieldSpecsToUse {
switch path.Path {
// Special casing .metadata.namespace since it is a common metadata field across all runtime.Object
@@ -88,9 +88,9 @@ func (o *namespaceTransformer) Transform(m resmap.ResMap) error {
if !id.Gvk().IsClusterKind() {
newid := id.CopyWithNewNamespace(o.namespace)
m[newid] = mf[id]
m.AppendWithId(newid, res)
} else {
m[id] = mf[id]
m.AppendWithId(id, res)
}
}
}
@@ -99,19 +99,19 @@ func (o *namespaceTransformer) Transform(m resmap.ResMap) error {
}
func (o *namespaceTransformer) filterResmap(m resmap.ResMap) resmap.ResMap {
mf := resmap.ResMap{}
for id := range m {
mf := resmap.New()
for id, res := range m.AsMap() {
found := false
for _, path := range o.fieldSpecsToSkip {
if id.Gvk().IsSelected(&path.Gvk) {
found = true
mf[id] = m[id]
delete(m, id)
mf.AppendWithId(id, res)
m.Remove(id)
}
}
if !found {
mf[id] = m[id]
delete(m, id)
mf.AppendWithId(id, res)
m.Remove(id)
}
}
return mf
@@ -119,17 +119,17 @@ func (o *namespaceTransformer) filterResmap(m resmap.ResMap) resmap.ResMap {
func (o *namespaceTransformer) updateClusterRoleBinding(m resmap.ResMap) {
saMap := map[string]bool{}
for id := range m {
for id := range m.AsMap() {
if id.Gvk().Equals(gvk.Gvk{Version: "v1", Kind: "ServiceAccount"}) {
saMap[id.Name()] = true
}
}
for id := range m {
for id, res := range m.AsMap() {
if id.Gvk().Kind != "ClusterRoleBinding" && id.Gvk().Kind != "RoleBinding" {
continue
}
objMap := m[id].Map()
objMap := res.Map()
subjects, ok := objMap["subjects"].([]interface{})
if subjects == nil || !ok {
continue

View File

@@ -17,7 +17,6 @@ limitations under the License.
package transformers
import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
@@ -29,7 +28,7 @@ import (
func TestNamespaceRun(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmap.ResMap{
m := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -109,8 +108,8 @@ func TestNamespaceRun(t *testing.T) {
"name": "crd",
},
}),
}
expected := resmap.ResMap{
})
expected := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResIdWithPrefixNamespace(ns, "ns1", "", ""): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -191,15 +190,14 @@ func TestNamespaceRun(t *testing.T) {
"name": "crd",
},
}),
}
})
nst := NewNamespaceTransformer("test", defaultTransformerConfig.NameSpace)
err := nst.Transform(m)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(m, expected) {
err = expected.ErrorIfNotEqual(m)
if err = expected.ErrorIfNotEqual(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
}
}
@@ -207,7 +205,7 @@ func TestNamespaceRun(t *testing.T) {
func TestNamespaceRunForClusterLevelKind(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmap.ResMap{
m := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(ns, "ns1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -245,9 +243,9 @@ func TestNamespaceRunForClusterLevelKind(t *testing.T) {
},
"subjects": []interface{}{},
}),
}
})
expected := m.DeepCopy(rf)
expected := m.DeepCopy()
nst := NewNamespaceTransformer("test", defaultTransformerConfig.NameSpace)
@@ -255,8 +253,7 @@ func TestNamespaceRunForClusterLevelKind(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(m, expected) {
err = expected.ErrorIfNotEqual(m)
if err = expected.ErrorIfNotEqual(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
}
}

View File

@@ -59,12 +59,14 @@ func NewNamePrefixSuffixTransformer(
}
// Transform prepends the name prefix and appends the name suffix.
// TODO: this transformer breaks internal
// ordering and depends on Id hackery. Rewrite completely.
func (o *namePrefixSuffixTransformer) Transform(m resmap.ResMap) error {
// Fill map "mf" with entries subject to name modification, and
// delete these entries from "m", so that for now m retains only
// the entries whose names will not be modified.
mf := resmap.ResMap{}
for id := range m {
mf := resmap.New()
for id, r := range m.AsMap() {
found := false
for _, path := range o.fieldSpecsToSkip {
if id.Gvk().IsSelected(&path.Gvk) {
@@ -73,13 +75,13 @@ func (o *namePrefixSuffixTransformer) Transform(m resmap.ResMap) error {
}
}
if !found {
mf[id] = m[id]
delete(m, id)
mf.AppendWithId(id, r)
m.Remove(id)
}
}
for id := range mf {
objMap := mf[id].Map()
for id, r := range mf.AsMap() {
objMap := r.Map()
for _, path := range o.fieldSpecsToUse {
if !id.Gvk().IsSelected(&path.Gvk) {
continue
@@ -93,7 +95,7 @@ func (o *namePrefixSuffixTransformer) Transform(m resmap.ResMap) error {
return err
}
newId := id.CopyWithNewPrefixSuffix(o.prefix, o.suffix)
m[newId] = mf[id]
m.AppendWithId(newId, r)
}
}
return nil

View File

@@ -17,7 +17,6 @@ limitations under the License.
package transformers
import (
"reflect"
"testing"
"sigs.k8s.io/kustomize/k8sdeps/kunstruct"
@@ -29,7 +28,7 @@ import (
func TestPrefixSuffixNameRun(t *testing.T) {
rf := resource.NewFactory(
kunstruct.NewKunstructuredFactoryImpl())
m := resmap.ResMap{
m := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -54,8 +53,8 @@ func TestPrefixSuffixNameRun(t *testing.T) {
"name": "crd",
},
}),
}
expected := resmap.ResMap{
})
expected := resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResIdWithPrefixSuffix(cmap, "cm1", "someprefix-", "-somesuffix"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -80,7 +79,7 @@ func TestPrefixSuffixNameRun(t *testing.T) {
"name": "crd",
},
}),
}
})
npst, err := NewNamePrefixSuffixTransformer(
"someprefix-", "-somesuffix", defaultTransformerConfig.NamePrefix)
@@ -91,8 +90,7 @@ func TestPrefixSuffixNameRun(t *testing.T) {
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
if !reflect.DeepEqual(m, expected) {
err = expected.ErrorIfNotEqual(m)
if err = expected.ErrorIfNotEqual(m); err != nil {
t.Fatalf("actual doesn't match expected: %v", err)
}
}

View File

@@ -95,9 +95,9 @@ func (rv *RefVarTransformer) Transform(m resmap.ResMap) error {
rv.replacementCounts = make(map[string]int)
rv.mappingFunc = expansion.MappingFuncFor(
rv.replacementCounts, rv.varMap)
for id, res := range m {
for _, res := range m.Resources() {
for _, fieldSpec := range rv.fieldSpecs {
if id.Gvk().IsSelected(&fieldSpec.Gvk) {
if res.Id().Gvk().IsSelected(&fieldSpec.Gvk) {
if err := mutateField(
res.Map(), fieldSpec.PathSlice(),
false, rv.replaceVars); err != nil {

View File

@@ -22,6 +22,7 @@ import (
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformers/config"
)
@@ -50,7 +51,7 @@ func TestVarRef(t *testing.T) {
fs: []config.FieldSpec{
{Gvk: cmap, Path: "data"},
},
res: resmap.ResMap{
res: resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -63,10 +64,10 @@ func TestVarRef(t *testing.T) {
"item2": "bla",
},
}),
},
}),
},
expected: expected{
res: resmap.ResMap{
res: resmap.FromMap(map[resid.ResId]*resource.Resource{
resid.NewResId(cmap, "cm1"): rf.FromMap(
map[string]interface{}{
"apiVersion": "v1",
@@ -79,7 +80,7 @@ func TestVarRef(t *testing.T) {
"item2": "bla",
},
}),
},
}),
unused: []string{"BAR"},
},
},