diff --git a/k8sdeps/transformer/prune/prune.go b/k8sdeps/transformer/prune/prune.go index 9555a5cee..aea00b802 100644 --- a/k8sdeps/transformer/prune/prune.go +++ b/k8sdeps/transformer/prune/prune.go @@ -58,7 +58,7 @@ func NewPruneTransformer(p *types.Prune, namespace string, append bool) transfor // The prune ConfigMap is used to support the pruning command in the client side tool, // which is proposed in https://github.com/kubernetes/enhancements/pull/810 func (o *pruneTransformer) Transform(m resmap.ResMap) error { - keys := []string{} + var keys []string for _, r := range m { s := r.PruneString() keys = append(keys, s) diff --git a/pkg/commands/build/build.go b/pkg/commands/build/build.go index 9491bff60..b8cc1254d 100644 --- a/pkg/commands/build/build.go +++ b/pkg/commands/build/build.go @@ -96,10 +96,11 @@ func NewCmdBuild( // Validate validates build command. func (o *Options) Validate(args []string) error { if len(args) > 1 { - return errors.New("specify one path to " + pgmconfig.KustomizationFileNames[0]) + return errors.New( + "specify one path to " + pgmconfig.KustomizationFileNames[0]) } if len(args) == 0 { - o.kustomizationPath = "./" + o.kustomizationPath = loader.CWD } else { o.kustomizationPath = args[0] } diff --git a/pkg/commands/build/build_test.go b/pkg/commands/build/build_test.go index 792d95aac..02302a1ed 100644 --- a/pkg/commands/build/build_test.go +++ b/pkg/commands/build/build_test.go @@ -35,7 +35,7 @@ func TestBuildValidate(t *testing.T) { path string erMsg string }{ - {"noargs", []string{}, "./", ""}, + {"noargs", []string{}, ".", ""}, {"file", []string{"beans"}, "beans", ""}, {"path", []string{"a/b/c"}, "a/b/c", ""}, {"path", []string{"too", "many"}, @@ -54,7 +54,7 @@ func TestBuildValidate(t *testing.T) { continue } if e != nil { - t.Errorf("%s: unknown error %v", mycase.name, e) + t.Errorf("%s: unknown error: %v", mycase.name, e) continue } if opts.kustomizationPath != mycase.path { diff --git a/pkg/loader/fileloader.go b/pkg/loader/fileloader.go index 4fa5dca67..8b5c626fe 100644 --- a/pkg/loader/fileloader.go +++ b/pkg/loader/fileloader.go @@ -30,7 +30,7 @@ import ( // fileLoader is a kustomization's interface to files. // // The directory in which a kustomization file sits -// is referred to below as the kustomization's root. +// is referred to below as the kustomization's _root_. // // An instance of fileLoader has an immutable root, // and offers a `New` method returning a new loader @@ -42,12 +42,12 @@ import ( // // `Load` is used to visit these paths. // +// These paths refer to resources, patches, +// data for ConfigMaps and Secrets, etc. +// // They must terminate in or below the root. // -// They hold things like resources, patches, -// data for ConfigMaps, etc. -// -// * bases; other kustomizations +// * bases (other kustomizations) // // `New` is used to load bases. // @@ -82,24 +82,31 @@ type fileLoader struct { // Loader that spawned this loader. // Used to avoid cycles. referrer *fileLoader + // An absolute, cleaned path to a directory. - // The Load function reads from this directory, - // or directories below it. + // The Load function will read non-absolute + // paths relative to this directory. root fs.ConfirmedDir + // If this is non-nil, the files were // obtained from the given repository. repoSpec *git.RepoSpec + // File system utilities. fSys fs.FileSystem + // Used to clone repositories. cloner git.Cloner + // Used to clean up, as needed. cleaner func() error } +const CWD = "." + // NewFileLoaderAtCwd returns a loader that loads from ".". func NewFileLoaderAtCwd(fSys fs.FileSystem) *fileLoader { - return newLoaderOrDie(fSys, ".") + return newLoaderOrDie(fSys, CWD) } // NewFileLoaderAtRoot returns a loader that loads from "/". @@ -279,9 +286,9 @@ func (l *fileLoader) errIfRepoCycle(newRepoSpec *git.RepoSpec) error { return l.referrer.errIfRepoCycle(newRepoSpec) } -// Load returns content of file at the given relative path, -// else an error. The path must refer to a file in or -// below the current root. +// Load returns the content of file at the given path, +// else an error. Relative paths are taken relative +// relative to the root. func (l *fileLoader) Load(path string) ([]byte, error) { if filepath.IsAbs(path) { return nil, l.loadOutOfBounds(path) diff --git a/pkg/plugins/execplugin.go b/pkg/plugins/execplugin.go index e61d5796f..e4a0f88a8 100644 --- a/pkg/plugins/execplugin.go +++ b/pkg/plugins/execplugin.go @@ -159,7 +159,7 @@ func (p *ExecPlugin) Transform(rm resmap.ResMap) error { return err } if len(tmpMap) != 1 { - return fmt.Errorf("Unable to put two resources into one") + return fmt.Errorf("unable to put two resources into one") } for _, v := range tmpMap { rm[id].Kunstructured = v.Kunstructured