diff --git a/kustomize/internal/commands/build/build.go b/kustomize/internal/commands/build/build.go index c3a165226..9b68af7c3 100644 --- a/kustomize/internal/commands/build/build.go +++ b/kustomize/internal/commands/build/build.go @@ -67,8 +67,9 @@ func NewCmdBuild( pl := plugins.NewLoader(pluginConfig, rf) cmd := &cobra.Command{ - Use: "build {path}", - Short: "Print configuration per contents of " + pgmconfig.KustomizationFileName0, + Use: "build {path}", + Short: "Print configuration per contents of " + + pgmconfig.DefaultKustomizationFileName(), Example: examples, SilenceUsage: true, RunE: func(cmd *cobra.Command, args []string) error { @@ -96,7 +97,8 @@ func NewCmdBuild( func (o *Options) Validate(args []string) (err error) { if len(args) > 1 { return errors.New( - "specify one path to " + pgmconfig.KustomizationFileName0) + "specify one path to " + + pgmconfig.DefaultKustomizationFileName()) } if len(args) == 0 { o.kustomizationPath = loader.CWD diff --git a/kustomize/internal/commands/build/build_test.go b/kustomize/internal/commands/build/build_test.go index 47c17bca4..0a997d674 100644 --- a/kustomize/internal/commands/build/build_test.go +++ b/kustomize/internal/commands/build/build_test.go @@ -26,7 +26,9 @@ func TestBuildValidate(t *testing.T) { {"file", []string{"beans"}, "beans", ""}, {"path", []string{"a/b/c"}, "a/b/c", ""}, {"path", []string{"too", "many"}, - "", "specify one path to " + pgmconfig.KustomizationFileName0}, + "", + "specify one path to " + + pgmconfig.DefaultKustomizationFileName()}, } for _, mycase := range cases { opts := Options{} diff --git a/kustomize/internal/commands/create/create.go b/kustomize/internal/commands/create/create.go index 6fef7867f..9d12850eb 100644 --- a/kustomize/internal/commands/create/create.go +++ b/kustomize/internal/commands/create/create.go @@ -162,7 +162,7 @@ func detectResources(fSys fs.FileSystem, uf ifc.KunstructuredFactory, base strin } // If a sub-directory contains an existing kustomization file add the // directory as a resource and do not decend into it. - for _, kfilename := range pgmconfig.KustomizationFileNames() { + for _, kfilename := range pgmconfig.RecognizedKustomizationFileNames() { if fSys.Exists(filepath.Join(path, kfilename)) { paths = append(paths, path) return filepath.SkipDir diff --git a/kustomize/internal/commands/edit/add/addmetadata.go b/kustomize/internal/commands/edit/add/addmetadata.go index 97d956b28..4159ab6bf 100644 --- a/kustomize/internal/commands/edit/add/addmetadata.go +++ b/kustomize/internal/commands/edit/add/addmetadata.go @@ -46,8 +46,9 @@ func newCmdAddAnnotation(fSys fs.FileSystem, v func(map[string]string) error) *c o.kind = annotation o.mapValidator = v cmd := &cobra.Command{ - Use: "annotation", - Short: "Adds one or more commonAnnotations to " + pgmconfig.KustomizationFileName0, + Use: "annotation", + Short: "Adds one or more commonAnnotations to " + + pgmconfig.DefaultKustomizationFileName(), Example: ` add annotation {annotationKey1:annotationValue1},{annotationKey2:annotationValue2}`, RunE: func(cmd *cobra.Command, args []string) error { @@ -66,8 +67,9 @@ func newCmdAddLabel(fSys fs.FileSystem, v func(map[string]string) error) *cobra. o.kind = label o.mapValidator = v cmd := &cobra.Command{ - Use: "label", - Short: "Adds one or more commonLabels to " + pgmconfig.KustomizationFileName0, + Use: "label", + Short: "Adds one or more commonLabels to " + + pgmconfig.DefaultKustomizationFileName(), Example: ` add label {labelKey1:labelValue1},{labelKey2:labelValue2}`, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/kustomize/internal/commands/edit/remove/removemetadata.go b/kustomize/internal/commands/edit/remove/removemetadata.go index afd6e84bc..e03759368 100644 --- a/kustomize/internal/commands/edit/remove/removemetadata.go +++ b/kustomize/internal/commands/edit/remove/removemetadata.go @@ -47,7 +47,8 @@ func newCmdRemoveAnnotation(fSys fs.FileSystem, v func([]string) error) *cobra.C o.arrayValidator = v cmd := &cobra.Command{ Use: "annotation", - Short: "Removes one or more commonAnnotations from " + pgmconfig.KustomizationFileName0, + Short: "Removes one or more commonAnnotations from " + + pgmconfig.DefaultKustomizationFileName(), Example: ` remove annotation {annotationKey1},{annotationKey2}`, RunE: func(cmd *cobra.Command, args []string) error { @@ -67,7 +68,8 @@ func newCmdRemoveLabel(fSys fs.FileSystem, v func([]string) error) *cobra.Comman o.arrayValidator = v cmd := &cobra.Command{ Use: "label", - Short: "Removes one or more commonLabels from " + pgmconfig.KustomizationFileName0, + Short: "Removes one or more commonLabels from " + + pgmconfig.DefaultKustomizationFileName(), Example: ` remove label {labelKey1},{labelKey2}`, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/kustomize/internal/commands/edit/remove/removepatch.go b/kustomize/internal/commands/edit/remove/removepatch.go index f211e6770..ab62e90e5 100644 --- a/kustomize/internal/commands/edit/remove/removepatch.go +++ b/kustomize/internal/commands/edit/remove/removepatch.go @@ -25,7 +25,8 @@ func newCmdRemovePatch(fsys fs.FileSystem) *cobra.Command { cmd := &cobra.Command{ Use: "patch", - Short: "Removes one or more patches from " + pgmconfig.KustomizationFileName0, + Short: "Removes one or more patches from " + + pgmconfig.DefaultKustomizationFileName(), Example: ` remove patch {filepath}`, RunE: func(cmd *cobra.Command, args []string) error { diff --git a/kustomize/internal/commands/edit/remove/removeresource.go b/kustomize/internal/commands/edit/remove/removeresource.go index fa49dfd53..e1fd462d9 100644 --- a/kustomize/internal/commands/edit/remove/removeresource.go +++ b/kustomize/internal/commands/edit/remove/removeresource.go @@ -23,7 +23,8 @@ func newCmdRemoveResource(fsys fs.FileSystem) *cobra.Command { cmd := &cobra.Command{ Use: "resource", - Short: "Removes one or more resource file paths from " + pgmconfig.KustomizationFileName0, + Short: "Removes one or more resource file paths from " + + pgmconfig.DefaultKustomizationFileName(), Example: ` remove resource my-resource.yml remove resource resource1.yml resource2.yml resource3.yml diff --git a/kustomize/internal/commands/kustfile/kustomizationfile.go b/kustomize/internal/commands/kustfile/kustomizationfile.go index 3152f0235..61cdf5f7b 100644 --- a/kustomize/internal/commands/kustfile/kustomizationfile.go +++ b/kustomize/internal/commands/kustfile/kustomizationfile.go @@ -119,7 +119,7 @@ func NewKustomizationFile(fSys fs.FileSystem) (*kustomizationFile, error) { // n func (mf *kustomizationFile) validate() error { match := 0 var path []string - for _, kfilename := range pgmconfig.KustomizationFileNames() { + for _, kfilename := range pgmconfig.RecognizedKustomizationFileNames() { if mf.fSys.Exists(kfilename) { match += 1 path = append(path, kfilename) @@ -128,7 +128,9 @@ func (mf *kustomizationFile) validate() error { switch match { case 0: - return fmt.Errorf("Missing kustomization file '%s'.\n", pgmconfig.KustomizationFileName0) + return fmt.Errorf( + "Missing kustomization file '%s'.\n", + pgmconfig.DefaultKustomizationFileName()) case 1: mf.path = path[0] default: @@ -228,7 +230,6 @@ func (mf *kustomizationFile) marshal(kustomization *types.Kustomization) ([]byte return content, nil } output = append(output, content...) - } return output, nil } diff --git a/kustomize/internal/commands/kustfile/kustomizationfile_test.go b/kustomize/internal/commands/kustfile/kustomizationfile_test.go index fbf5fa6c7..065b43c71 100644 --- a/kustomize/internal/commands/kustfile/kustomizationfile_test.go +++ b/kustomize/internal/commands/kustfile/kustomizationfile_test.go @@ -97,7 +97,7 @@ func TestNewNotExist(t *testing.T) { } } -func TestSecondarySuffix(t *testing.T) { +func TestAllKustomizationFileNames(t *testing.T) { kcontent := ` configMapGenerator: - literals: @@ -105,14 +105,16 @@ configMapGenerator: - baz=qux name: my-configmap ` - fSys := fs.MakeFsInMemory() - fSys.WriteFile(pgmconfig.KustomizationFileName1, []byte(kcontent)) - k, err := NewKustomizationFile(fSys) - if err != nil { - t.Fatalf("Unexpected Error: %v", err) - } - if k.path != pgmconfig.KustomizationFileName1 { - t.Fatalf("Load incorrect file path %s", k.path) + for _, n := range pgmconfig.RecognizedKustomizationFileNames() { + fSys := fs.MakeFsInMemory() + fSys.WriteFile(n, []byte(kcontent)) + k, err := NewKustomizationFile(fSys) + if err != nil { + t.Fatalf("Unexpected Error: %v", err) + } + if k.path != n { + t.Fatalf("Load incorrect file path %s", k.path) + } } } diff --git a/kustomize/internal/commands/testutils/testutils.go b/kustomize/internal/commands/testutils/testutils.go index d0004915b..4c27d9bc6 100644 --- a/kustomize/internal/commands/testutils/testutils.go +++ b/kustomize/internal/commands/testutils/testutils.go @@ -38,10 +38,10 @@ func WriteTestKustomization(fSys fs.FileSystem) { // WriteTestKustomizationWith writes content to a well known file name. func WriteTestKustomizationWith(fSys fs.FileSystem, bytes []byte) { - fSys.WriteFile(pgmconfig.KustomizationFileName0, bytes) + fSys.WriteFile(pgmconfig.DefaultKustomizationFileName(), bytes) } // ReadTestKustomization reads content from a well known file name. func ReadTestKustomization(fSys fs.FileSystem) ([]byte, error) { - return fSys.ReadFile(pgmconfig.KustomizationFileName0) + return fSys.ReadFile(pgmconfig.DefaultKustomizationFileName()) } diff --git a/pkg/kusttest/kusttestharness.go b/pkg/kusttest/kusttestharness.go index cf3a2b83e..4eb480c21 100644 --- a/pkg/kusttest/kusttestharness.go +++ b/pkg/kusttest/kusttestharness.go @@ -74,7 +74,10 @@ func (th *KustTestHarness) WriteF(dir string, content string) { } func (th *KustTestHarness) WriteK(dir string, content string) { - th.WriteF(filepath.Join(dir, pgmconfig.KustomizationFileName0), ` + th.WriteF( + filepath.Join( + dir, + pgmconfig.DefaultKustomizationFileName()), ` apiVersion: kustomize.config.k8s.io/v1beta1 kind: Kustomization `+content) diff --git a/pkg/loader/fileloader_test.go b/pkg/loader/fileloader_test.go index abcda6c25..2f8576dd1 100644 --- a/pkg/loader/fileloader_test.go +++ b/pkg/loader/fileloader_test.go @@ -389,7 +389,8 @@ func TestNewLoaderAtGitClone(t *testing.T) { fSys.MkdirAll(coRoot) fSys.MkdirAll(coRoot + "/" + pathInRepo) fSys.WriteFile( - coRoot+"/"+pathInRepo+"/"+pgmconfig.KustomizationFileName0, + coRoot+"/"+pathInRepo+"/"+ + pgmconfig.DefaultKustomizationFileName(), []byte(` whatever `)) diff --git a/pkg/pgmconfig/pgmconfig.go b/pkg/pgmconfig/pgmconfig.go index 83325e400..caad76517 100644 --- a/pkg/pgmconfig/pgmconfig.go +++ b/pkg/pgmconfig/pgmconfig.go @@ -4,22 +4,23 @@ // Package pgmconfig holds global constants for the kustomize tool. package pgmconfig -// KustomizationFileNames is a list of filenames +// RecognizedKustomizationFileNames is a list of file names // that kustomize recognizes. -// To avoid ambiguity, a directory cannot contain -// more than one match to this list. -func KustomizationFileNames() []string { +// To avoid ambiguity, a kustomization directory may not +// contain more than one match to this list. +func RecognizedKustomizationFileNames() []string { return []string{ - KustomizationFileName0, - KustomizationFileName1, - KustomizationFileName2} + "kustomization.yaml", + "kustomization.yml", + "Kustomization", + } +} + +func DefaultKustomizationFileName() string { + return RecognizedKustomizationFileNames()[0] } const ( - KustomizationFileName0 = "kustomization.yaml" - KustomizationFileName1 = "kustomization.yml" - KustomizationFileName2 = "Kustomization" - // An environment variable to consult for kustomization // configuration data. See: // https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html diff --git a/pkg/target/chartinflatorplugin_test.go b/pkg/target/chartinflatorplugin_test.go index 3d6e4ae71..ca17d91b2 100644 --- a/pkg/target/chartinflatorplugin_test.go +++ b/pkg/target/chartinflatorplugin_test.go @@ -11,7 +11,7 @@ import ( "testing" kusttest_test "sigs.k8s.io/kustomize/v3/pkg/kusttest" - "sigs.k8s.io/kustomize/v3/pkg/plugins/testenv" + "sigs.k8s.io/kustomize/v3/pkg/plugins/testenv" ) // This is an example of using a helm chart as a base, diff --git a/pkg/target/kusttarget.go b/pkg/target/kusttarget.go index 55624903b..a35861a91 100644 --- a/pkg/target/kusttarget.go +++ b/pkg/target/kusttarget.go @@ -81,7 +81,7 @@ func commaOr(q []string) string { func loadKustFile(ldr ifc.Loader) ([]byte, error) { var content []byte match := 0 - for _, kf := range pgmconfig.KustomizationFileNames() { + for _, kf := range pgmconfig.RecognizedKustomizationFileNames() { c, err := ldr.Load(kf) if err == nil { match += 1 @@ -92,7 +92,7 @@ func loadKustFile(ldr ifc.Loader) ([]byte, error) { case 0: return nil, fmt.Errorf( "unable to find one of %v in directory '%s'", - commaOr(quoted(pgmconfig.KustomizationFileNames())), + commaOr(quoted(pgmconfig.RecognizedKustomizationFileNames())), ldr.Root()) case 1: return content, nil