Merge pull request #75005 from Liujingfang1/vendor

update vendoring of kustomize
This commit is contained in:
Kubernetes Prow Robot 2019-03-06 14:45:29 -08:00 committed by GitHub
commit 9eebfe7a04
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
34 changed files with 453 additions and 258 deletions

88
Godeps/Godeps.json generated
View File

@ -4343,113 +4343,113 @@
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/commands/build", "ImportPath": "sigs.k8s.io/kustomize/pkg/commands/build",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/constants", "ImportPath": "sigs.k8s.io/kustomize/pkg/constants",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/expansion", "ImportPath": "sigs.k8s.io/kustomize/pkg/expansion",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/factory", "ImportPath": "sigs.k8s.io/kustomize/pkg/factory",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/fs", "ImportPath": "sigs.k8s.io/kustomize/pkg/fs",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/git", "ImportPath": "sigs.k8s.io/kustomize/pkg/git",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/gvk", "ImportPath": "sigs.k8s.io/kustomize/pkg/gvk",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/ifc", "ImportPath": "sigs.k8s.io/kustomize/pkg/ifc",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/ifc/transformer", "ImportPath": "sigs.k8s.io/kustomize/pkg/ifc/transformer",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/image", "ImportPath": "sigs.k8s.io/kustomize/pkg/image",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/internal/error", "ImportPath": "sigs.k8s.io/kustomize/pkg/internal/error",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/loader", "ImportPath": "sigs.k8s.io/kustomize/pkg/loader",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/patch", "ImportPath": "sigs.k8s.io/kustomize/pkg/patch",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/patch/transformer", "ImportPath": "sigs.k8s.io/kustomize/pkg/patch/transformer",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resid", "ImportPath": "sigs.k8s.io/kustomize/pkg/resid",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resmap", "ImportPath": "sigs.k8s.io/kustomize/pkg/resmap",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resource", "ImportPath": "sigs.k8s.io/kustomize/pkg/resource",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/target", "ImportPath": "sigs.k8s.io/kustomize/pkg/target",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/types", "ImportPath": "sigs.k8s.io/kustomize/pkg/types",
"Comment": "v2.0.1", "Comment": "v2.0.3",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/structured-merge-diff/fieldpath", "ImportPath": "sigs.k8s.io/structured-merge-diff/fieldpath",

View File

@ -716,91 +716,91 @@
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/commands/build", "ImportPath": "sigs.k8s.io/kustomize/pkg/commands/build",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/constants", "ImportPath": "sigs.k8s.io/kustomize/pkg/constants",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/expansion", "ImportPath": "sigs.k8s.io/kustomize/pkg/expansion",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/factory", "ImportPath": "sigs.k8s.io/kustomize/pkg/factory",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/fs", "ImportPath": "sigs.k8s.io/kustomize/pkg/fs",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/git", "ImportPath": "sigs.k8s.io/kustomize/pkg/git",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/gvk", "ImportPath": "sigs.k8s.io/kustomize/pkg/gvk",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/ifc", "ImportPath": "sigs.k8s.io/kustomize/pkg/ifc",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/ifc/transformer", "ImportPath": "sigs.k8s.io/kustomize/pkg/ifc/transformer",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/image", "ImportPath": "sigs.k8s.io/kustomize/pkg/image",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/internal/error", "ImportPath": "sigs.k8s.io/kustomize/pkg/internal/error",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/loader", "ImportPath": "sigs.k8s.io/kustomize/pkg/loader",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/patch", "ImportPath": "sigs.k8s.io/kustomize/pkg/patch",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/patch/transformer", "ImportPath": "sigs.k8s.io/kustomize/pkg/patch/transformer",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resid", "ImportPath": "sigs.k8s.io/kustomize/pkg/resid",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resmap", "ImportPath": "sigs.k8s.io/kustomize/pkg/resmap",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resource", "ImportPath": "sigs.k8s.io/kustomize/pkg/resource",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/target", "ImportPath": "sigs.k8s.io/kustomize/pkg/target",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/types", "ImportPath": "sigs.k8s.io/kustomize/pkg/types",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/yaml", "ImportPath": "sigs.k8s.io/yaml",

View File

@ -666,7 +666,7 @@ func TestKustomizeDirectoryBuilder(t *testing.T) {
{ {
directory: "../../../artifacts/guestbook", directory: "../../../artifacts/guestbook",
expectErr: true, expectErr: true,
errMsg: "No kustomization file found", errMsg: "unable to find one of 'kustomization.yaml', 'kustomization.yml' or 'Kustomization'",
}, },
{ {
directory: dir, directory: dir,

View File

@ -81,8 +81,8 @@ func (f *ConfigMapFactory) MakeConfigMap(
} }
all = append(all, pairs...) all = append(all, pairs...)
for _, kv := range all { for _, p := range all {
err = addKvToConfigMap(cm, kv.Key, kv.Value) err = addKvToConfigMap(cm, p.Key, p.Value)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -80,8 +80,8 @@ func (f *SecretFactory) MakeSecret(args *types.SecretArgs, options *types.Genera
} }
all = append(all, pairs...) all = append(all, pairs...)
for _, kv := range all { for _, p := range all {
err = addKvToSecret(s, kv.Key, kv.Value) err = addKvToSecret(s, p.Key, p.Value)
if err != nil { if err != nil {
return nil, err return nil, err
} }

View File

@ -108,7 +108,7 @@ func (kf *KunstructuredFactoryImpl) validate(u unstructured.Unstructured) error
kind := u.GetKind() kind := u.GetKind()
if kind == "" { if kind == "" {
return fmt.Errorf("missing kind in object %v", u) return fmt.Errorf("missing kind in object %v", u)
} else if kind == "List" { } else if strings.HasSuffix(kind, "List") {
return nil return nil
} }
if u.GetName() == "" { if u.GetName() == "" {

View File

@ -42,6 +42,15 @@ func TestSliceFromBytes(t *testing.T) {
testConfigMap.Map(), testConfigMap.Map(),
}, },
}) })
testConfigMapList := factory.FromMap(
map[string]interface{}{
"apiVersion": "v1",
"kind": "ConfigMapList",
"items": []interface{}{
testConfigMap.Map(),
testConfigMap.Map(),
},
})
tests := []struct { tests := []struct {
name string name string
@ -151,6 +160,24 @@ items:
expectedOut: []ifc.Kunstructured{testList}, expectedOut: []ifc.Kunstructured{testList},
expectedErr: false, expectedErr: false,
}, },
{
name: "ConfigMapList",
input: []byte(`
apiVersion: v1
kind: ConfigMapList
items:
- apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
- apiVersion: v1
kind: ConfigMap
metadata:
name: winnie
`),
expectedOut: []ifc.Kunstructured{testConfigMapList},
expectedErr: false,
},
} }
for _, test := range tests { for _, test := range tests {

View File

@ -60,7 +60,7 @@ func (pt *patchTransformer) Transform(baseResourceMap resmap.ResMap) error {
for _, patch := range patches { for _, patch := range patches {
// Merge patches with base resource. // Merge patches with base resource.
id := patch.Id() id := patch.Id()
matchedIds := baseResourceMap.FindByGVKN(id) matchedIds := baseResourceMap.GetMatchingIds(id.GvknEquals)
if len(matchedIds) == 0 { if len(matchedIds) == 0 {
return fmt.Errorf("failed to find an object with %s to apply the patch", id.GvknString()) return fmt.Errorf("failed to find an object with %s to apply the patch", id.GvknString())
} }

View File

@ -740,91 +740,91 @@
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/commands/build", "ImportPath": "sigs.k8s.io/kustomize/pkg/commands/build",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/constants", "ImportPath": "sigs.k8s.io/kustomize/pkg/constants",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/expansion", "ImportPath": "sigs.k8s.io/kustomize/pkg/expansion",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/factory", "ImportPath": "sigs.k8s.io/kustomize/pkg/factory",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/fs", "ImportPath": "sigs.k8s.io/kustomize/pkg/fs",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/git", "ImportPath": "sigs.k8s.io/kustomize/pkg/git",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/gvk", "ImportPath": "sigs.k8s.io/kustomize/pkg/gvk",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/ifc", "ImportPath": "sigs.k8s.io/kustomize/pkg/ifc",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/ifc/transformer", "ImportPath": "sigs.k8s.io/kustomize/pkg/ifc/transformer",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/image", "ImportPath": "sigs.k8s.io/kustomize/pkg/image",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/internal/error", "ImportPath": "sigs.k8s.io/kustomize/pkg/internal/error",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/loader", "ImportPath": "sigs.k8s.io/kustomize/pkg/loader",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/patch", "ImportPath": "sigs.k8s.io/kustomize/pkg/patch",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/patch/transformer", "ImportPath": "sigs.k8s.io/kustomize/pkg/patch/transformer",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resid", "ImportPath": "sigs.k8s.io/kustomize/pkg/resid",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resmap", "ImportPath": "sigs.k8s.io/kustomize/pkg/resmap",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/resource", "ImportPath": "sigs.k8s.io/kustomize/pkg/resource",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/target", "ImportPath": "sigs.k8s.io/kustomize/pkg/target",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig", "ImportPath": "sigs.k8s.io/kustomize/pkg/transformers/config/defaultconfig",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/kustomize/pkg/types", "ImportPath": "sigs.k8s.io/kustomize/pkg/types",
"Rev": "ce7e5ee2c30cc5856fea01fe423cf167f2a2d0c3" "Rev": "a6f65144121d1955266b0cd836ce954c04122dc8"
}, },
{ {
"ImportPath": "sigs.k8s.io/yaml", "ImportPath": "sigs.k8s.io/yaml",

View File

@ -108,7 +108,7 @@ func (o *Options) RunBuild(
return err return err
} }
defer ldr.Cleanup() defer ldr.Cleanup()
kt, err := target.NewKustTarget(ldr, fSys, rf, ptf) kt, err := target.NewKustTarget(ldr, rf, ptf)
if err != nil { if err != nil {
return err return err
} }

View File

@ -36,15 +36,17 @@ func syntaxWrap(input string) string {
// implements the expansion semantics defined in the expansion spec; it // implements the expansion semantics defined in the expansion spec; it
// returns the input string wrapped in the expansion syntax if no mapping // returns the input string wrapped in the expansion syntax if no mapping
// for the input is found. // for the input is found.
func MappingFuncFor(context ...map[string]string) func(string) string { func MappingFuncFor(
counts map[string]int,
context ...map[string]string) func(string) string {
return func(input string) string { return func(input string) string {
for _, vars := range context { for _, vars := range context {
val, ok := vars[input] val, ok := vars[input]
if ok { if ok {
counts[input]++
return val return val
} }
} }
return syntaxWrap(input) return syntaxWrap(input)
} }
} }

View File

@ -26,7 +26,7 @@ import (
// that was confirmed to point to an existing directory. // that was confirmed to point to an existing directory.
type ConfirmedDir string type ConfirmedDir string
// Return a temporary dir, else error. // NewTmpConfirmedDir returns a temporary dir, else error.
// The directory is cleaned, no symlinks, etc. so its // The directory is cleaned, no symlinks, etc. so its
// returned as a ConfirmedDir. // returned as a ConfirmedDir.
func NewTmpConfirmedDir() (ConfirmedDir, error) { func NewTmpConfirmedDir() (ConfirmedDir, error) {
@ -34,7 +34,15 @@ func NewTmpConfirmedDir() (ConfirmedDir, error) {
if err != nil { if err != nil {
return "", err return "", err
} }
return ConfirmedDir(n), nil
// In MacOs `ioutil.TempDir` creates a directory
// with root in the `/var` folder, which is in turn a symlinked path
// to `/private/var`.
// Function `filepath.EvalSymlinks`is used to
// resolve the real absolute path.
deLinked, err := filepath.EvalSymlinks(n)
return ConfirmedDir(deLinked), err
} }
// HasPrefix returns true if the directory argument // HasPrefix returns true if the directory argument

View File

@ -24,6 +24,13 @@ import (
"sigs.k8s.io/kustomize/pkg/fs" "sigs.k8s.io/kustomize/pkg/fs"
) )
// Used as a temporary non-empty occupant of the cloneDir
// field, as something distinguishable from the empty string
// in various outputs (especially tests). Not using an
// actual directory name here, as that's a temporary directory
// with a unique name that isn't created until clone time.
const notCloned = fs.ConfirmedDir("/notCloned")
// RepoSpec specifies a git repository and a branch and path therein. // RepoSpec specifies a git repository and a branch and path therein.
type RepoSpec struct { type RepoSpec struct {
// Raw, original spec, used to look for cycles. // Raw, original spec, used to look for cycles.
@ -88,7 +95,7 @@ func NewRepoSpecFromUrl(n string) (*RepoSpec, error) {
} }
return &RepoSpec{ return &RepoSpec{
raw: n, host: host, orgRepo: orgRepo, raw: n, host: host, orgRepo: orgRepo,
path: path, ref: gitRef}, nil cloneDir: notCloned, path: path, ref: gitRef}, nil
} }
const ( const (

View File

@ -73,6 +73,8 @@ var order = []string{
"Namespace", "Namespace",
"StorageClass", "StorageClass",
"CustomResourceDefinition", "CustomResourceDefinition",
"MutatingWebhookConfiguration",
"ValidatingWebhookConfiguration",
"ServiceAccount", "ServiceAccount",
"Role", "Role",
"ClusterRole", "ClusterRole",

View File

@ -5,7 +5,6 @@ go_library(
srcs = [ srcs = [
"factory.go", "factory.go",
"patchjson6902json.go", "patchjson6902json.go",
"util.go",
], ],
importmap = "k8s.io/kubernetes/vendor/sigs.k8s.io/kustomize/pkg/patch/transformer", importmap = "k8s.io/kubernetes/vendor/sigs.k8s.io/kustomize/pkg/patch/transformer",
importpath = "sigs.k8s.io/kustomize/pkg/patch/transformer", importpath = "sigs.k8s.io/kustomize/pkg/patch/transformer",
@ -13,6 +12,7 @@ go_library(
deps = [ deps = [
"//vendor/github.com/evanphx/json-patch:go_default_library", "//vendor/github.com/evanphx/json-patch:go_default_library",
"//vendor/github.com/ghodss/yaml:go_default_library", "//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/gvk:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/gvk:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/ifc:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/ifc:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/patch:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/patch:go_default_library",

View File

@ -21,8 +21,6 @@ import (
"sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resid"
"github.com/evanphx/json-patch"
"github.com/ghodss/yaml"
"sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/patch" "sigs.k8s.io/kustomize/pkg/patch"
"sigs.k8s.io/kustomize/pkg/transformers" "sigs.k8s.io/kustomize/pkg/transformers"
@ -77,19 +75,7 @@ func (f PatchJson6902Factory) makeOnePatchJson6902Transformer(p patch.Json6902)
return nil, err return nil, err
} }
if !isJsonFormat(rawOp) { return newPatchJson6902JSONTransformer(targetId, rawOp)
// if it isn't JSON, try to parse it as YAML
rawOp, err = yaml.YAMLToJSON(rawOp)
if err != nil {
return nil, err
}
}
decodedPatch, err := jsonpatch.DecodePatch(rawOp)
if err != nil {
return nil, err
}
return newPatchJson6902JSONTransformer(targetId, decodedPatch)
} }
func isJsonFormat(data []byte) bool { func isJsonFormat(data []byte) bool {

View File

@ -17,9 +17,14 @@ limitations under the License.
package transformer package transformer
import ( import (
"fmt"
"github.com/evanphx/json-patch" "github.com/evanphx/json-patch"
"github.com/ghodss/yaml"
"github.com/pkg/errors"
"sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
"sigs.k8s.io/kustomize/pkg/transformers" "sigs.k8s.io/kustomize/pkg/transformers"
) )
@ -27,22 +32,37 @@ import (
type patchJson6902JSONTransformer struct { type patchJson6902JSONTransformer struct {
target resid.ResId target resid.ResId
patch jsonpatch.Patch patch jsonpatch.Patch
rawOp []byte
} }
var _ transformers.Transformer = &patchJson6902JSONTransformer{} var _ transformers.Transformer = &patchJson6902JSONTransformer{}
// newPatchJson6902JSONTransformer constructs a PatchJson6902 transformer. // newPatchJson6902JSONTransformer constructs a PatchJson6902 transformer.
func newPatchJson6902JSONTransformer(t resid.ResId, p jsonpatch.Patch) (transformers.Transformer, error) { func newPatchJson6902JSONTransformer(
if len(p) == 0 { id resid.ResId, rawOp []byte) (transformers.Transformer, error) {
op := rawOp
var err error
if !isJsonFormat(op) {
// if it isn't JSON, try to parse it as YAML
op, err = yaml.YAMLToJSON(rawOp)
if err != nil {
return nil, err
}
}
decodedPatch, err := jsonpatch.DecodePatch(op)
if err != nil {
return nil, err
}
if len(decodedPatch) == 0 {
return transformers.NewNoOpTransformer(), nil return transformers.NewNoOpTransformer(), nil
} }
return &patchJson6902JSONTransformer{target: t, patch: p}, nil return &patchJson6902JSONTransformer{target: id, patch: decodedPatch, rawOp: rawOp}, nil
} }
// Transform apply the json patches on top of the base resources. // Transform apply the json patches on top of the base resources.
func (t *patchJson6902JSONTransformer) Transform(baseResourceMap resmap.ResMap) error { func (t *patchJson6902JSONTransformer) Transform(m resmap.ResMap) error {
obj, err := findTargetObj(baseResourceMap, t.target) obj, err := t.findTargetObj(m)
if obj == nil { if err != nil {
return err return err
} }
rawObj, err := obj.MarshalJSON() rawObj, err := obj.MarshalJSON()
@ -51,7 +71,7 @@ func (t *patchJson6902JSONTransformer) Transform(baseResourceMap resmap.ResMap)
} }
modifiedObj, err := t.patch.Apply(rawObj) modifiedObj, err := t.patch.Apply(rawObj)
if err != nil { if err != nil {
return err return errors.Wrapf(err, "failed to apply json patch '%s'", string(t.rawOp))
} }
err = obj.UnmarshalJSON(modifiedObj) err = obj.UnmarshalJSON(modifiedObj)
if err != nil { if err != nil {
@ -59,3 +79,30 @@ func (t *patchJson6902JSONTransformer) Transform(baseResourceMap resmap.ResMap)
} }
return nil return nil
} }
func (t *patchJson6902JSONTransformer) findTargetObj(
m resmap.ResMap) (*resource.Resource, error) {
var matched []resid.ResId
// TODO(monopole): namespace bug in json patch?
// Since introduction in PR #300
// (see pkg/patch/transformer/util.go),
// this code has treated an empty namespace like a wildcard
// rather than like an additional restriction to match
// only the empty namespace. No test coverage to confirm.
// Not sure if desired, keeping it for now.
if t.target.Namespace() != "" {
matched = m.GetMatchingIds(t.target.NsGvknEquals)
} else {
matched = m.GetMatchingIds(t.target.GvknEquals)
}
if len(matched) == 0 {
return nil, fmt.Errorf(
"couldn't find target %v for json patch", t.target)
}
if len(matched) > 1 {
return nil, fmt.Errorf(
"found multiple targets %v matching %v for json patch",
matched, t.target)
}
return m[matched[0]], nil
}

View File

@ -1,46 +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 transformer
import (
"fmt"
"sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/resource"
)
func findTargetObj(m resmap.ResMap, targetId resid.ResId) (*resource.Resource, error) {
matchedIds := m.FindByGVKN(targetId)
if targetId.Namespace() != "" {
var ids []resid.ResId
for _, id := range matchedIds {
if id.Namespace() == targetId.Namespace() {
ids = append(ids, id)
}
}
matchedIds = ids
}
if len(matchedIds) == 0 {
return nil, fmt.Errorf("couldn't find any object to apply the json patch %v", targetId)
}
if len(matchedIds) > 1 {
return nil, fmt.Errorf("found multiple objects that the patch can apply %v", matchedIds)
}
return m[matchedIds[0]], nil
}

View File

@ -22,23 +22,30 @@ import (
"sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/gvk"
) )
// ResId conflates GroupVersionKind with a textual name to uniquely identify a kubernetes resource (object). // ResId is an immutable identifier of a k8s resource object.
type ResId struct { type ResId struct {
// Gvk of the resource. // Gvk of the resource.
gvKind gvk.Gvk gvKind gvk.Gvk
// original name of the resource before transformation.
// name of the resource before transformation.
name string name string
// namePrefix of the resource
// an untransformed resource has no prefix, fully transformed resource has an arbitrary number of prefixes // namePrefix of the resource.
// concatenated together. // An untransformed resource has no prefix.
// A fully transformed resource has an arbitrary
// number of prefixes concatenated together.
prefix string prefix string
// nameSuffix of the resource
// an untransformed resource has no suffix, fully transformed resource has an arbitrary number of suffixes // nameSuffix of the resource.
// concatenated together. // An untransformed resource has no suffix.
// A fully transformed resource has an arbitrary
// number of suffixes concatenated together.
suffix string suffix string
// namespace the resource belongs to
// an untransformed resource has no namespace, fully transformed resource has the namespace from // Namespace the resource belongs to.
// the top most overlay // An untransformed resource has no namespace.
// A fully transformed resource has the namespace
// from the top most overlay.
namespace string namespace string
} }
@ -108,10 +115,16 @@ func (n ResId) GvknString() string {
return n.gvKind.String() + separator + n.name return n.gvKind.String() + separator + n.name
} }
// GvknEquals return if two ResId have the same Group/Version/Kind and name // GvknEquals returns true if the other id matches
// The comparison excludes prefix and suffix // Group/Version/Kind/name.
func (n ResId) GvknEquals(id ResId) bool { func (n ResId) GvknEquals(id ResId) bool {
return n.gvKind.Equals(id.gvKind) && n.name == id.name return n.name == id.name && n.gvKind.Equals(id.gvKind)
}
// NsGvknEquals returns true if the other id matches
// namespace/Group/Version/Kind/name.
func (n ResId) NsGvknEquals(id ResId) bool {
return n.namespace == id.namespace && n.GvknEquals(id)
} }
// Gvk returns Group/Version/Kind of the resource. // Gvk returns Group/Version/Kind of the resource.

View File

@ -50,7 +50,7 @@ func (rmF *Factory) FromFiles(
if err != nil { if err != nil {
return nil, errors.Wrap(err, "Load from path "+path+" failed") return nil, errors.Wrap(err, "Load from path "+path+" failed")
} }
res, err := rmF.newResMapFromBytes(content) res, err := rmF.NewResMapFromBytes(content)
if err != nil { if err != nil {
return nil, internal.Handler(err, path) return nil, internal.Handler(err, path)
} }
@ -60,7 +60,7 @@ func (rmF *Factory) FromFiles(
} }
// newResMapFromBytes decodes a list of objects in byte array format. // newResMapFromBytes decodes a list of objects in byte array format.
func (rmF *Factory) newResMapFromBytes(b []byte) (ResMap, error) { func (rmF *Factory) NewResMapFromBytes(b []byte) (ResMap, error) {
resources, err := rmF.resF.SliceFromBytes(b) resources, err := rmF.resF.SliceFromBytes(b)
if err != nil { if err != nil {
return nil, err return nil, err

View File

@ -32,26 +32,20 @@ import (
// ResMap is a map from ResId to Resource. // ResMap is a map from ResId to Resource.
type ResMap map[resid.ResId]*resource.Resource type ResMap map[resid.ResId]*resource.Resource
// FindByGVKN find the matched ResIds by Group/Version/Kind and Name type IdMatcher func(resid.ResId) bool
func (m ResMap) FindByGVKN(inputId resid.ResId) []resid.ResId {
// GetMatchingIds returns a slice of ResId keys from the map
// that all satisfy the given matcher function.
func (m ResMap) GetMatchingIds(matches IdMatcher) []resid.ResId {
var result []resid.ResId var result []resid.ResId
for id := range m { for id := range m {
if id.GvknEquals(inputId) { if matches(id) {
result = append(result, id) result = append(result, id)
} }
} }
return result return result
} }
// DemandOneMatchForId find the matched resource by Group/Version/Kind and Name
func (m ResMap) DemandOneMatchForId(inputId resid.ResId) (*resource.Resource, bool) {
result := m.FindByGVKN(inputId)
if len(result) == 1 {
return m[result[0]], true
}
return nil, false
}
// EncodeAsYaml encodes a ResMap to YAML; encoded objects separated by `---`. // EncodeAsYaml encodes a ResMap to YAML; encoded objects separated by `---`.
func (m ResMap) EncodeAsYaml() ([]byte, error) { func (m ResMap) EncodeAsYaml() ([]byte, error) {
var ids []resid.ResId var ids []resid.ResId
@ -177,7 +171,7 @@ func MergeWithOverride(maps ...ResMap) (ResMap, error) {
continue continue
} }
for id, r := range m { for id, r := range m {
matchedId := result.FindByGVKN(id) matchedId := result.GetMatchingIds(id.GvknEquals)
if len(matchedId) == 1 { if len(matchedId) == 1 {
id = matchedId[0] id = matchedId[0]
switch r.Behavior() { switch r.Behavior() {

View File

@ -20,6 +20,7 @@ import (
"encoding/json" "encoding/json"
"fmt" "fmt"
"log" "log"
"strings"
"sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/ifc"
internal "sigs.k8s.io/kustomize/pkg/internal/error" internal "sigs.k8s.io/kustomize/pkg/internal/error"
@ -94,10 +95,14 @@ func (rf *Factory) SliceFromBytes(in []byte) ([]*Resource, error) {
for len(kunStructs) > 0 { for len(kunStructs) > 0 {
u := kunStructs[0] u := kunStructs[0]
kunStructs = kunStructs[1:] kunStructs = kunStructs[1:]
if u.GetKind() == "List" { if strings.HasSuffix(u.GetKind(), "List") {
items := u.Map()["items"] items := u.Map()["items"]
itemsSlice, ok := items.([]interface{}) itemsSlice, ok := items.([]interface{})
if !ok { if !ok {
if items == nil {
// an empty list
continue
}
return nil, fmt.Errorf("items in List is type %T, expected array", items) return nil, fmt.Errorf("items in List is type %T, expected array", items)
} }
for _, item := range itemsSlice { for _, item := range itemsSlice {

View File

@ -38,7 +38,7 @@ func (r *Resource) String() string {
if err != nil { if err != nil {
return "<" + err.Error() + ">" return "<" + err.Error() + ">"
} }
return strings.TrimSpace(string(bs)) return strings.TrimSpace(string(bs)) + r.options.String()
} }
// DeepCopy returns a new copy of resource // DeepCopy returns a new copy of resource

View File

@ -13,7 +13,6 @@ go_library(
"//vendor/github.com/ghodss/yaml:go_default_library", "//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library", "//vendor/github.com/pkg/errors:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/constants:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/constants:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/fs:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/ifc:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/ifc:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/ifc/transformer:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/ifc/transformer:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/internal/error:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/internal/error:go_default_library",

View File

@ -26,7 +26,6 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/pkg/errors" "github.com/pkg/errors"
"sigs.k8s.io/kustomize/pkg/constants" "sigs.k8s.io/kustomize/pkg/constants"
"sigs.k8s.io/kustomize/pkg/fs"
"sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/ifc/transformer" "sigs.k8s.io/kustomize/pkg/ifc/transformer"
interror "sigs.k8s.io/kustomize/pkg/internal/error" interror "sigs.k8s.io/kustomize/pkg/internal/error"
@ -42,7 +41,6 @@ import (
type KustTarget struct { type KustTarget struct {
kustomization *types.Kustomization kustomization *types.Kustomization
ldr ifc.Loader ldr ifc.Loader
fSys fs.FileSystem
rFactory *resmap.Factory rFactory *resmap.Factory
tFactory transformer.Factory tFactory transformer.Factory
} }
@ -50,7 +48,6 @@ type KustTarget struct {
// NewKustTarget returns a new instance of KustTarget primed with a Loader. // NewKustTarget returns a new instance of KustTarget primed with a Loader.
func NewKustTarget( func NewKustTarget(
ldr ifc.Loader, ldr ifc.Loader,
fSys fs.FileSystem,
rFactory *resmap.Factory, rFactory *resmap.Factory,
tFactory transformer.Factory) (*KustTarget, error) { tFactory transformer.Factory) (*KustTarget, error) {
content, err := loadKustFile(ldr) content, err := loadKustFile(ldr)
@ -70,12 +67,23 @@ func NewKustTarget(
return &KustTarget{ return &KustTarget{
kustomization: &k, kustomization: &k,
ldr: ldr, ldr: ldr,
fSys: fSys,
rFactory: rFactory, rFactory: rFactory,
tFactory: tFactory, tFactory: tFactory,
}, nil }, nil
} }
func quoted(l []string) []string {
r := make([]string, len(l))
for i, v := range l {
r[i] = "'" + v + "'"
}
return r
}
func commaOr(q []string) string {
return strings.Join(q[:len(q)-1], ", ") + " or " + q[len(q)-1]
}
func loadKustFile(ldr ifc.Loader) ([]byte, error) { func loadKustFile(ldr ifc.Loader) ([]byte, error) {
var content []byte var content []byte
match := 0 match := 0
@ -88,8 +96,9 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) {
} }
switch match { switch match {
case 0: case 0:
return nil, fmt.Errorf("No kustomization file found in %s. Kustomize supports the following kustomization files: %s", return nil, fmt.Errorf(
ldr.Root(), strings.Join(constants.KustomizationFileNames, ", ")) "unable to find one of %v in directory '%s'",
commaOr(quoted(constants.KustomizationFileNames)), ldr.Root())
case 1: case 1:
return content, nil return content, nil
default: default:
@ -110,7 +119,7 @@ func unmarshal(y []byte, o interface{}) error {
// MakeCustomizedResMap creates a ResMap per kustomization instructions. // MakeCustomizedResMap creates a ResMap per kustomization instructions.
// The Resources in the returned ResMap are fully customized. // The Resources in the returned ResMap are fully customized.
func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) { func (kt *KustTarget) MakeCustomizedResMap() (resmap.ResMap, error) {
ra, err := kt.accumulateTarget() ra, err := kt.AccumulateTarget()
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -134,11 +143,11 @@ func (kt *KustTarget) shouldAddHashSuffixesToGeneratedResources() bool {
!kt.kustomization.GeneratorOptions.DisableNameSuffixHash !kt.kustomization.GeneratorOptions.DisableNameSuffixHash
} }
// accumulateTarget returns a new ResAccumulator, // AccumulateTarget returns a new ResAccumulator,
// holding customized resources and the data/rules used // holding customized resources and the data/rules used
// to do so. The name back references and vars are // to do so. The name back references and vars are
// not yet fixed. // not yet fixed.
func (kt *KustTarget) accumulateTarget() ( func (kt *KustTarget) AccumulateTarget() (
ra *ResAccumulator, err error) { ra *ResAccumulator, err error) {
// TODO(monopole): Get rid of the KustomizationErrors accumulator. // TODO(monopole): Get rid of the KustomizationErrors accumulator.
// It's not consistently used, and complicates tests. // It's not consistently used, and complicates tests.
@ -236,15 +245,15 @@ func (kt *KustTarget) accumulateBases() (
continue continue
} }
subKt, err := NewKustTarget( subKt, err := NewKustTarget(
ldr, kt.fSys, kt.rFactory, kt.tFactory) ldr, kt.rFactory, kt.tFactory)
if err != nil { if err != nil {
errs.Append(errors.Wrap(err, "couldn't make target for "+path)) errs.Append(errors.Wrap(err, "couldn't make target for "+path))
ldr.Cleanup() ldr.Cleanup()
continue continue
} }
subRa, err := subKt.accumulateTarget() subRa, err := subKt.AccumulateTarget()
if err != nil { if err != nil {
errs.Append(errors.Wrap(err, "accumulateTarget")) errs.Append(errors.Wrap(err, "AccumulateTarget"))
ldr.Cleanup() ldr.Cleanup()
continue continue
} }

View File

@ -19,6 +19,8 @@ package target
import ( import (
"fmt" "fmt"
"log" "log"
"strings"
"sigs.k8s.io/kustomize/pkg/resid" "sigs.k8s.io/kustomize/pkg/resid"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/transformers" "sigs.k8s.io/kustomize/pkg/transformers"
@ -55,6 +57,11 @@ func (ra *ResAccumulator) ResMap() resmap.ResMap {
return result return result
} }
// Vars returns a copy of underlying vars.
func (ra *ResAccumulator) Vars() []types.Var {
return ra.varSet.Set()
}
func (ra *ResAccumulator) MergeResourcesWithErrorOnIdCollision( func (ra *ResAccumulator) MergeResourcesWithErrorOnIdCollision(
resources resmap.ResMap) (err error) { resources resmap.ResMap) (err error) {
ra.resMap, err = resmap.MergeWithErrorOnIdCollision( ra.resMap, err = resmap.MergeWithErrorOnIdCollision(
@ -96,17 +103,27 @@ func (ra *ResAccumulator) MergeAccumulator(other *ResAccumulator) (err error) {
// for substitution wherever the $(var.Name) occurs. // for substitution wherever the $(var.Name) occurs.
func (ra *ResAccumulator) makeVarReplacementMap() (map[string]string, error) { func (ra *ResAccumulator) makeVarReplacementMap() (map[string]string, error) {
result := map[string]string{} result := map[string]string{}
for _, v := range ra.varSet.Set() { for _, v := range ra.Vars() {
id := resid.NewResId(v.ObjRef.GVK(), v.ObjRef.Name) matched := ra.resMap.GetMatchingIds(
if r, found := ra.resMap.DemandOneMatchForId(id); found { resid.NewResId(v.ObjRef.GVK(), v.ObjRef.Name).GvknEquals)
s, err := r.GetFieldValue(v.FieldRef.FieldPath) if len(matched) > 1 {
return nil, fmt.Errorf(
"found %d resId matches for var %s "+
"(unable to disambiguate)",
len(matched), v)
}
if len(matched) == 1 {
s, err := ra.resMap[matched[0]].GetFieldValue(v.FieldRef.FieldPath)
if err != nil { if err != nil {
return nil, fmt.Errorf("field path err for var: %+v", v) return nil, fmt.Errorf(
"field specified in var '%v' "+
"not found in corresponding resource", v)
} }
result[v.Name] = s result[v.Name] = s
} else { } else {
// Should this be an error? return nil, fmt.Errorf(
log.Printf("var %v defined but not used", v) "var '%v' cannot be mapped to a field "+
"in the set of known resources", v)
} }
} }
return result, nil return result, nil
@ -121,8 +138,18 @@ func (ra *ResAccumulator) ResolveVars() error {
if err != nil { if err != nil {
return err return err
} }
return ra.Transform(transformers.NewRefVarTransformer( if len(replacementMap) == 0 {
replacementMap, ra.tConfig.VarReference)) return nil
}
t := transformers.NewRefVarTransformer(
replacementMap, ra.tConfig.VarReference)
err = ra.Transform(t)
if len(t.UnusedVars()) > 0 {
log.Printf(
"well-defined vars that were never replaced: %s\n",
strings.Join(t.UnusedVars(), ","))
}
return err
} }
func (ra *ResAccumulator) FixBackReferences() (err error) { func (ra *ResAccumulator) FixBackReferences() (err error) {

View File

@ -15,6 +15,7 @@ go_library(
deps = [ deps = [
"//vendor/github.com/ghodss/yaml:go_default_library", "//vendor/github.com/ghodss/yaml:go_default_library",
"//vendor/github.com/go-openapi/spec:go_default_library", "//vendor/github.com/go-openapi/spec:go_default_library",
"//vendor/github.com/pkg/errors:go_default_library",
"//vendor/k8s.io/kube-openapi/pkg/common:go_default_library", "//vendor/k8s.io/kube-openapi/pkg/common:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/gvk:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/gvk:go_default_library",
"//vendor/sigs.k8s.io/kustomize/pkg/ifc:go_default_library", "//vendor/sigs.k8s.io/kustomize/pkg/ifc:go_default_library",

View File

@ -100,10 +100,63 @@ varReference:
- path: spec/containers/env/value - path: spec/containers/env/value
kind: Pod kind: Pod
- path: spec/initContainers/command
kind: Pod
- path: spec/initContainers/args
kind: Pod
- path: spec/initContainers/env/value
kind: Pod
- path: spec/rules/host - path: spec/rules/host
kind: Ingress kind: Ingress
- path: spec/tls/hosts - path: spec/tls/hosts
kind: Ingress kind: Ingress
- path: spec/template/spec/containers/volumeMounts/mountPath
kind: StatefulSet
- path: spec/template/spec/initContainers/volumeMounts/mountPath
kind: StatefulSet
- path: spec/containers/volumeMounts/mountPath
kind: Pod
- path: spec/initContainers/volumeMounts/mountPath
kind: Pod
- path: spec/template/spec/containers/volumeMounts/mountPath
kind: ReplicaSet
- path: spec/template/spec/initContainers/volumeMounts/mountPath
kind: ReplicaSet
- path: spec/template/spec/containers/volumeMounts/mountPath
kind: Job
- path: spec/template/spec/initContainers/volumeMounts/mountPath
kind: Job
- path: spec/template/spec/containers/volumeMounts/mountPath
kind: CronJob
- path: spec/template/spec/initContainers/volumeMounts/mountPath
kind: CronJob
- path: spec/template/spec/containers/volumeMounts/mountPath
kind: DaemonSet
- path: spec/template/spec/initContainers/volumeMounts/mountPath
kind: DaemonSet
- path: spec/template/spec/containers/volumeMounts/mountPath
kind: Deployment
- path: spec/template/spec/initContainers/volumeMounts/mountPath
kind: Deployment
- path: metadata/labels
` `
) )

View File

@ -22,6 +22,7 @@ import (
"github.com/ghodss/yaml" "github.com/ghodss/yaml"
"github.com/go-openapi/spec" "github.com/go-openapi/spec"
"github.com/pkg/errors"
"k8s.io/kube-openapi/pkg/common" "k8s.io/kube-openapi/pkg/common"
"sigs.k8s.io/kustomize/pkg/gvk" "sigs.k8s.io/kustomize/pkg/gvk"
"sigs.k8s.io/kustomize/pkg/ifc" "sigs.k8s.io/kustomize/pkg/ifc"
@ -41,7 +42,7 @@ func LoadConfigFromCRDs(
} }
m, err := makeNameToApiMap(content) m, err := makeNameToApiMap(content)
if err != nil { if err != nil {
return nil, err return nil, errors.Wrapf(err, "unable to parse open API definition from '%s'", path)
} }
otherTc, err := makeConfigFromApiMap(m) otherTc, err := makeConfigFromApiMap(m)
if err != nil { if err != nil {

View File

@ -17,6 +17,7 @@ limitations under the License.
package transformers package transformers
import ( import (
"fmt"
"regexp" "regexp"
"strings" "strings"
@ -75,7 +76,10 @@ func (pt *imageTransformer) findAndReplaceImage(obj map[string]interface{}) erro
} }
func (pt *imageTransformer) updateContainers(obj map[string]interface{}, path string) error { func (pt *imageTransformer) updateContainers(obj map[string]interface{}, path string) error {
containers := obj[path].([]interface{}) containers, ok := obj[path].([]interface{})
if !ok {
return fmt.Errorf("containers path is not of type []interface{} but %T", obj[path])
}
for i := range containers { for i := range containers {
container := containers[i].(map[string]interface{}) container := containers[i].(map[string]interface{})
containerImage, found := container["image"] containerImage, found := container["image"]
@ -85,20 +89,21 @@ func (pt *imageTransformer) updateContainers(obj map[string]interface{}, path st
imageName := containerImage.(string) imageName := containerImage.(string)
for _, img := range pt.images { for _, img := range pt.images {
if isImageMatched(imageName, img.Name) { if !isImageMatched(imageName, img.Name) {
name, tag := split(imageName) continue
if img.NewName != "" {
name = img.NewName
}
if img.NewTag != "" {
tag = ":" + img.NewTag
}
if img.Digest != "" {
tag = "@" + img.Digest
}
container["image"] = name + tag
break
} }
name, tag := split(imageName)
if img.NewName != "" {
name = img.NewName
}
if img.NewTag != "" {
tag = ":" + img.NewTag
}
if img.Digest != "" {
tag = "@" + img.Digest
}
container["image"] = name + tag
break
} }
} }
return nil return nil
@ -138,7 +143,18 @@ func isImageMatched(s, t string) bool {
// from the image string using either colon `:` or at `@` separators. // from the image string using either colon `:` or at `@` separators.
// Note that the returned tag keeps its separator. // Note that the returned tag keeps its separator.
func split(imageName string) (name string, tag string) { func split(imageName string) (name string, tag string) {
ic := strings.LastIndex(imageName, ":") // check if image name contains a domain
// if domain is present, ignore domain and check for `:`
ic := -1
if slashIndex := strings.Index(imageName, "/"); slashIndex < 0 {
ic = strings.LastIndex(imageName, ":")
} else {
lastIc := strings.LastIndex(imageName[slashIndex:], ":")
// set ic only if `:` is present
if lastIc > 0 {
ic = slashIndex + lastIc
}
}
ia := strings.LastIndex(imageName, "@") ia := strings.LastIndex(imageName, "@")
if ic < 0 && ia < 0 { if ic < 0 && ia < 0 {
return imageName, "" return imageName, ""

View File

@ -89,7 +89,7 @@ func (o *nameReferenceTransformer) updateNameReference(
s, _ := in.(string) s, _ := in.(string)
for id, res := range m { for id, res := range m {
if id.Gvk().IsSelected(&backRef) && id.Name() == s { if id.Gvk().IsSelected(&backRef) && id.Name() == s {
matchedIds := m.FindByGVKN(id) matchedIds := m.GetMatchingIds(id.GvknEquals)
// If there's more than one match, there's no way // If there's more than one match, there's no way
// to know which one to pick, so emit error. // to know which one to pick, so emit error.
if len(matchedIds) > 1 { if len(matchedIds) > 1 {
@ -115,7 +115,7 @@ func (o *nameReferenceTransformer) updateNameReference(
for id, res := range m { for id, res := range m {
indexes := indexOf(id.Name(), names) indexes := indexOf(id.Name(), names)
if id.Gvk().IsSelected(&backRef) && len(indexes) > 0 { if id.Gvk().IsSelected(&backRef) && len(indexes) > 0 {
matchedIds := m.FindByGVKN(id) matchedIds := m.GetMatchingIds(id.GvknEquals)
if len(matchedIds) > 1 { if len(matchedIds) > 1 {
return nil, fmt.Errorf( return nil, fmt.Errorf(
"Multiple matches for name %s:\n %v", id, matchedIds) "Multiple matches for name %s:\n %v", id, matchedIds)

View File

@ -2,28 +2,26 @@ package transformers
import ( import (
"fmt" "fmt"
"sigs.k8s.io/kustomize/pkg/expansion" "sigs.k8s.io/kustomize/pkg/expansion"
"sigs.k8s.io/kustomize/pkg/resmap" "sigs.k8s.io/kustomize/pkg/resmap"
"sigs.k8s.io/kustomize/pkg/transformers/config" "sigs.k8s.io/kustomize/pkg/transformers/config"
) )
type refvarTransformer struct { type RefVarTransformer struct {
fieldSpecs []config.FieldSpec varMap map[string]string
mappingFunc func(string) string replacementCounts map[string]int
fieldSpecs []config.FieldSpec
mappingFunc func(string) string
} }
// NewRefVarTransformer returns a Transformer that replaces $(VAR) style // NewRefVarTransformer returns a new RefVarTransformer
// variables with values. // that replaces $(VAR) style variables with values.
// The fieldSpecs are the places to look for occurrences of $(VAR). // The fieldSpecs are the places to look for occurrences of $(VAR).
func NewRefVarTransformer( func NewRefVarTransformer(
varMap map[string]string, fs []config.FieldSpec) Transformer { varMap map[string]string, fs []config.FieldSpec) *RefVarTransformer {
if len(varMap) == 0 { return &RefVarTransformer{
return NewNoOpTransformer() varMap: varMap,
} fieldSpecs: fs,
return &refvarTransformer{
fieldSpecs: fs,
mappingFunc: expansion.MappingFuncFor(varMap),
} }
} }
@ -31,7 +29,7 @@ func NewRefVarTransformer(
// embedded instances of $VAR style variables, e.g. a container command string. // embedded instances of $VAR style variables, e.g. a container command string.
// The function returns the string with the variables expanded to their final // The function returns the string with the variables expanded to their final
// values. // values.
func (rv *refvarTransformer) replaceVars(in interface{}) (interface{}, error) { func (rv *RefVarTransformer) replaceVars(in interface{}) (interface{}, error) {
switch vt := in.(type) { switch vt := in.(type) {
case []interface{}: case []interface{}:
var xs []string var xs []string
@ -39,6 +37,17 @@ func (rv *refvarTransformer) replaceVars(in interface{}) (interface{}, error) {
xs = append(xs, expansion.Expand(a.(string), rv.mappingFunc)) xs = append(xs, expansion.Expand(a.(string), rv.mappingFunc))
} }
return xs, nil return xs, nil
case map[string]interface{}:
inMap := in.(map[string]interface{})
xs := make(map[string]interface{}, len(inMap))
for k, v := range inMap {
s, ok := v.(string)
if !ok {
return nil, fmt.Errorf("%#v is expected to be %T", v, s)
}
xs[k] = expansion.Expand(s, rv.mappingFunc)
}
return xs, nil
case interface{}: case interface{}:
s, ok := in.(string) s, ok := in.(string)
if !ok { if !ok {
@ -52,8 +61,24 @@ func (rv *refvarTransformer) replaceVars(in interface{}) (interface{}, error) {
} }
} }
// UnusedVars returns slice of Var names that were unused
// after a Transform run.
func (rv *RefVarTransformer) UnusedVars() []string {
var unused []string
for k := range rv.varMap {
_, ok := rv.replacementCounts[k]
if !ok {
unused = append(unused, k)
}
}
return unused
}
// Transform replaces $(VAR) style variables with values. // Transform replaces $(VAR) style variables with values.
func (rv *refvarTransformer) Transform(m resmap.ResMap) error { 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 id, res := range m {
for _, fieldSpec := range rv.fieldSpecs { for _, fieldSpec := range rv.fieldSpecs {
if id.Gvk().IsSelected(&fieldSpec.Gvk) { if id.Gvk().IsSelected(&fieldSpec.Gvk) {

View File

@ -16,6 +16,11 @@ limitations under the License.
package types package types
import (
"strconv"
"strings"
)
// GenArgs contains both generator args and options // GenArgs contains both generator args and options
type GenArgs struct { type GenArgs struct {
args *GeneratorArgs args *GeneratorArgs
@ -30,6 +35,18 @@ func NewGenArgs(args *GeneratorArgs, opts *GeneratorOptions) *GenArgs {
} }
} }
func (g *GenArgs) String() string {
if g == nil {
return "{nilGenArgs}"
}
return "{" +
strings.Join([]string{
"nsfx:" + strconv.FormatBool(g.NeedsHashSuffix()),
"beh:" + g.Behavior().String()},
",") +
"}"
}
// NeedHashSuffix returns true if the hash suffix is needed. // NeedHashSuffix returns true if the hash suffix is needed.
// It is needed when the two conditions are both met // It is needed when the two conditions are both met
// 1) GenArgs is not nil // 1) GenArgs is not nil

View File

@ -75,9 +75,11 @@ type VarSet struct {
set []Var set []Var
} }
// Set returns the var set. // Set returns a copy of the var set.
func (vs *VarSet) Set() []Var { func (vs *VarSet) Set() []Var {
return vs.set s := make([]Var, len(vs.set))
copy(s, vs.set)
return s
} }
// MergeSet absorbs other vars with error on name collision. // MergeSet absorbs other vars with error on name collision.