From 108b3e497b6a96d20934241ab2b1032543723b20 Mon Sep 17 00:00:00 2001 From: Jeffrey Regan Date: Fri, 7 Dec 2018 10:46:35 -0800 Subject: [PATCH] Require relocatable kustomizations and fix some nits. --- k8sdeps/kunstruct/factory.go | 4 ++-- k8sdeps/kunstruct/helper.go | 2 +- pkg/loader/fileloader.go | 17 ++++------------- pkg/resid/resid.go | 10 ---------- 4 files changed, 7 insertions(+), 26 deletions(-) diff --git a/k8sdeps/kunstruct/factory.go b/k8sdeps/kunstruct/factory.go index c62018ea9..de058f07c 100644 --- a/k8sdeps/kunstruct/factory.go +++ b/k8sdeps/kunstruct/factory.go @@ -103,10 +103,10 @@ func (kf *KunstructuredFactoryImpl) Set(fs fs.FileSystem, ldr ifc.Loader) { // validate validates that u has kind and name func (kf *KunstructuredFactoryImpl) validate(u unstructured.Unstructured) error { if u.GetName() == "" { - return fmt.Errorf("Missing metadata.name in object %v", u) + return fmt.Errorf("missing metadata.name in object %v", u) } if u.GetKind() == "" { - return fmt.Errorf("Missing kind in object %v", u) + return fmt.Errorf("missing kind in object %v", u) } return nil } diff --git a/k8sdeps/kunstruct/helper.go b/k8sdeps/kunstruct/helper.go index e0b2f3775..0675b961d 100644 --- a/k8sdeps/kunstruct/helper.go +++ b/k8sdeps/kunstruct/helper.go @@ -55,7 +55,7 @@ func parseFields(path string) ([]string, error) { start = i + 1 insideParentheses = false } else { - return nil, fmt.Errorf("Invalid field path %s", path) + return nil, fmt.Errorf("invalid field path %s", path) } } } diff --git a/pkg/loader/fileloader.go b/pkg/loader/fileloader.go index fcf3dc8c3..9ed39af49 100644 --- a/pkg/loader/fileloader.go +++ b/pkg/loader/fileloader.go @@ -26,11 +26,6 @@ import ( "sigs.k8s.io/kustomize/pkg/ifc" ) -// TODO: 2018/Nov/20 remove this before next release. -// Leave only the true path. Retaining only for -// quick revert. -const enforceRelocatable = true - // fileLoader loads files, returning an array of bytes. // It also enforces two kustomization requirements: // @@ -153,7 +148,7 @@ func (l *fileLoader) New(root string) (ifc.Loader, error) { } return newGitLoader(root, l.fSys, l.roots, l.cloner) } - if enforceRelocatable && filepath.IsAbs(root) { + if filepath.IsAbs(root) { return nil, fmt.Errorf("new root '%s' cannot be absolute", root) } // Get absolute path to squeeze out "..", ".", etc. @@ -208,14 +203,10 @@ func (l *fileLoader) seenBefore(path string) error { // Load returns content of file at the given relative path. func (l *fileLoader) Load(path string) ([]byte, error) { if filepath.IsAbs(path) { - if enforceRelocatable { - return nil, fmt.Errorf( - "must use relative path; '%s' is absolute", path) - } - } else { - path = filepath.Join(l.Root(), path) + return nil, fmt.Errorf( + "must use relative path; '%s' is absolute", path) } - return l.fSys.ReadFile(path) + return l.fSys.ReadFile(filepath.Join(l.Root(), path)) } // Cleanup runs the cleaner. diff --git a/pkg/resid/resid.go b/pkg/resid/resid.go index 47df4efc6..e76f9b887 100644 --- a/pkg/resid/resid.go +++ b/pkg/resid/resid.go @@ -63,16 +63,6 @@ func NewResIdWithPrefixSuffix(k gvk.Gvk, n, p, s string) ResId { return ResId{gvKind: k, name: n, prefix: p, suffix: s} } -// NewResIdWithPrefix creates new resource identifier with a prefix -func NewResIdWithPrefix(k gvk.Gvk, n, p string) ResId { - return ResId{gvKind: k, name: n, prefix: p} -} - -// NewResIdWithSuffix creates new resource identifier with a suffix -func NewResIdWithSuffix(k gvk.Gvk, n, s string) ResId { - return ResId{gvKind: k, name: n, suffix: s} -} - // NewResId creates new resource identifier func NewResId(k gvk.Gvk, n string) ResId { return ResId{gvKind: k, name: n}