diff --git a/app/application.go b/app/application.go index cc4a27851..cf38dba05 100644 --- a/app/application.go +++ b/app/application.go @@ -213,13 +213,13 @@ func (a *applicationImpl) getTransformer(patches []*resource.Resource) (transfor } ts = append(ts, npt) - lt, err := transformers.NewDefaultingLabelsMapTransformer(a.kustomization.LabelsToAdd) + lt, err := transformers.NewDefaultingLabelsMapTransformer(a.kustomization.CommonLabels) if err != nil { return nil, err } ts = append(ts, lt) - at, err := transformers.NewDefaultingAnnotationsMapTransformer(a.kustomization.AnnotationsToAdd) + at, err := transformers.NewDefaultingAnnotationsMapTransformer(a.kustomization.CommonAnnotations) if err != nil { return nil, err } diff --git a/app/application_test.go b/app/application_test.go index e3025d9aa..97b919e5d 100644 --- a/app/application_test.go +++ b/app/application_test.go @@ -25,6 +25,7 @@ import ( corev1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" "k8s.io/apimachinery/pkg/runtime/schema" + "k8s.io/kubectl/pkg/kustomize/constants" "k8s.io/kubectl/pkg/kustomize/resource" "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/loader" @@ -34,9 +35,9 @@ import ( func setupTest(t *testing.T) loader.Loader { kustomizationContent := []byte(` namePrefix: foo- -labelsToAdd: +commonLabels: app: nginx -annotationsToAdd: +commonAnnotations: note: This is a test annotation resources: - deployment.yaml @@ -59,7 +60,7 @@ metadata: `) loader := loadertest.NewFakeLoader("/testpath") - err := loader.AddFile("/testpath/kustomize.yaml", kustomizationContent) + err := loader.AddFile("/testpath/"+constants.KustomizationFileName, kustomizationContent) if err != nil { t.Fatalf("Failed to setup fake loader.") } diff --git a/commands/build.go b/commands/build.go index deb025a82..3f0a0b3dc 100644 --- a/commands/build.go +++ b/commands/build.go @@ -44,9 +44,8 @@ func newCmdBuild(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command { cmd := &cobra.Command{ Use: "build [path]", Short: "Print current configuration per contents of " + constants.KustomizationFileName, - Example: ` - # Use the kustomize.yaml file under somedir/ to generate a set of api resources. - build somedir/`, + Example: "Use the file somedir/" + constants.KustomizationFileName + + " to generate a set of api resources:\nbuild somedir/", Run: func(cmd *cobra.Command, args []string) { err := o.Validate(args) if err != nil { @@ -66,7 +65,7 @@ func newCmdBuild(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command { // Validate validates build command. func (o *buildOptions) Validate(args []string) error { if len(args) > 1 { - return errors.New("specify one path to kustomization file") + return errors.New("specify one path to " + constants.KustomizationFileName) } if len(args) == 0 { o.kustomizationPath = "./" diff --git a/commands/build_test.go b/commands/build_test.go index 173d0a66b..0de59be0a 100644 --- a/commands/build_test.go +++ b/commands/build_test.go @@ -28,6 +28,7 @@ import ( "github.com/ghodss/yaml" "k8s.io/apimachinery/pkg/util/sets" + "k8s.io/kubectl/pkg/kustomize/constants" "k8s.io/kubectl/pkg/kustomize/util/fs" ) @@ -50,7 +51,8 @@ func TestBuildValidate(t *testing.T) { {"noargs", []string{}, "./", ""}, {"file", []string{"beans"}, "beans", ""}, {"path", []string{"a/b/c"}, "a/b/c", ""}, - {"path", []string{"too", "many"}, "", "specify one path to kustomization file"}, + {"path", []string{"too", "many"}, + "", "specify one path to " + constants.KustomizationFileName}, } for _, mycase := range cases { opts := buildOptions{} diff --git a/commands/diff.go b/commands/diff.go index 78d3935d0..85c8babae 100644 --- a/commands/diff.go +++ b/commands/diff.go @@ -24,6 +24,7 @@ import ( "github.com/spf13/cobra" "k8s.io/kubectl/pkg/kustomize/app" + "k8s.io/kubectl/pkg/kustomize/constants" "k8s.io/kubectl/pkg/kustomize/util" "k8s.io/kubectl/pkg/kustomize/util/fs" "k8s.io/kubectl/pkg/loader" @@ -56,7 +57,12 @@ func newCmdDiff(out, errOut io.Writer, fs fs.FileSystem) *cobra.Command { }, } - cmd.Flags().StringVarP(&o.kustomizationPath, "filename", "f", "", "Pass in a kustomize.yaml file or a directory that contains the file.") + cmd.Flags().StringVarP( + &o.kustomizationPath, + "filename", + "f", + "", + "Specify a directory containing "+constants.KustomizationFileName) cmd.MarkFlagRequired("filename") return cmd } diff --git a/commands/init.go b/commands/init.go index 21a5d371e..40840b091 100644 --- a/commands/init.go +++ b/commands/init.go @@ -32,9 +32,9 @@ namePrefix: some-prefix # Labels to add to all objects and selectors. # These labels would also be used to form the selector for apply --prune # Named differently than “labels” to avoid confusion with metadata for this object -labelsToAdd: +commonLabels: app: helloworld -annotationsToAdd: +commonAnnotations: note: This is an example annotation resources: [] #- service.yaml diff --git a/commands/testdata/testcase-base-only/in/kustomize.yaml b/commands/testdata/testcase-base-only/in/kustomization.yaml similarity index 81% rename from commands/testdata/testcase-base-only/in/kustomize.yaml rename to commands/testdata/testcase-base-only/in/kustomization.yaml index cb3189160..eb8201580 100644 --- a/commands/testdata/testcase-base-only/in/kustomize.yaml +++ b/commands/testdata/testcase-base-only/in/kustomization.yaml @@ -1,9 +1,9 @@ namePrefix: team-foo- -labelsToAdd: +commonLabels: app: mynginx org: example.com team: foo -annotationsToAdd: +commonAnnotations: note: This is a test annotation resources: - deployment.yaml diff --git a/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomize.yaml b/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml similarity index 93% rename from commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomize.yaml rename to commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml index 7bbccd1e2..173d1b050 100644 --- a/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomize.yaml +++ b/commands/testdata/testcase-multiple-patches-conflict/in/overlay/kustomization.yaml @@ -1,5 +1,5 @@ namePrefix: staging- -labelsToAdd: +commonLabels: env: staging patches: - deployment-patch2.yaml diff --git a/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomize.yaml b/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml similarity index 87% rename from commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomize.yaml rename to commands/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml index 877f034f2..30603cf68 100644 --- a/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomize.yaml +++ b/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomization.yaml @@ -1,9 +1,9 @@ namePrefix: team-foo- -labelsToAdd: +commonLabels: app: mynginx org: example.com team: foo -annotationsToAdd: +commonAnnotations: note: This is a test annotation resources: - deployment.yaml diff --git a/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomize.yaml b/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml similarity index 93% rename from commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomize.yaml rename to commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml index ed636a56e..2ffc41519 100644 --- a/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomize.yaml +++ b/commands/testdata/testcase-multiple-patches-noconflict/in/overlay/kustomization.yaml @@ -1,5 +1,5 @@ namePrefix: staging- -labelsToAdd: +commonLabels: env: staging patches: - deployment-patch1.yaml diff --git a/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomize.yaml b/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml similarity index 87% rename from commands/testdata/testcase-multiple-patches-conflict/in/package/kustomize.yaml rename to commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml index 877f034f2..30603cf68 100644 --- a/commands/testdata/testcase-multiple-patches-conflict/in/package/kustomize.yaml +++ b/commands/testdata/testcase-multiple-patches-noconflict/in/package/kustomization.yaml @@ -1,9 +1,9 @@ namePrefix: team-foo- -labelsToAdd: +commonLabels: app: mynginx org: example.com team: foo -annotationsToAdd: +commonAnnotations: note: This is a test annotation resources: - deployment.yaml diff --git a/commands/testdata/testcase-single-overlay/in/overlay/kustomize.yaml b/commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml similarity index 96% rename from commands/testdata/testcase-single-overlay/in/overlay/kustomize.yaml rename to commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml index 9d12ad3a2..42f80b67c 100644 --- a/commands/testdata/testcase-single-overlay/in/overlay/kustomize.yaml +++ b/commands/testdata/testcase-single-overlay/in/overlay/kustomization.yaml @@ -1,5 +1,5 @@ namePrefix: staging- -labelsToAdd: +commonLabels: env: staging team: override-foo patches: diff --git a/commands/testdata/testcase-single-overlay/in/package/kustomize.yaml b/commands/testdata/testcase-single-overlay/in/package/kustomization.yaml similarity index 91% rename from commands/testdata/testcase-single-overlay/in/package/kustomize.yaml rename to commands/testdata/testcase-single-overlay/in/package/kustomization.yaml index aca0ab306..b84575522 100644 --- a/commands/testdata/testcase-single-overlay/in/package/kustomize.yaml +++ b/commands/testdata/testcase-single-overlay/in/package/kustomization.yaml @@ -1,9 +1,9 @@ namePrefix: team-foo- -labelsToAdd: +commonLabels: app: mynginx org: example.com team: foo -annotationsToAdd: +commonAnnotations: note: This is a test annotation resources: - deployment.yaml diff --git a/commands/util_test.go b/commands/util_test.go index c9369231e..501eb4c21 100644 --- a/commands/util_test.go +++ b/commands/util_test.go @@ -21,6 +21,7 @@ import ( "strings" "testing" + "k8s.io/kubectl/pkg/kustomize/constants" "k8s.io/kubectl/pkg/kustomize/types" "k8s.io/kubectl/pkg/kustomize/util/fs" ) @@ -31,8 +32,8 @@ func TestWriteAndRead(t *testing.T) { } fsys := fs.MakeFakeFS() - fsys.Create("kustomize.yaml") - mf, err := newKustomizationFile("kustomize.yaml", fsys) + fsys.Create(constants.KustomizationFileName) + mf, err := newKustomizationFile(constants.KustomizationFileName, fsys) if err != nil { t.Fatalf("Unexpected Error: %v", err) } @@ -63,7 +64,7 @@ func TestNewNotExist(t *testing.T) { fakeFS := fs.MakeFakeFS() fakeFS.Mkdir(".", 0644) fakeFS.Create(badSuffix) - _, err := newKustomizationFile("kustomize.yaml", fakeFS) + _, err := newKustomizationFile(constants.KustomizationFileName, fakeFS) if err == nil { t.Fatalf("expect an error") } @@ -71,7 +72,7 @@ func TestNewNotExist(t *testing.T) { if !strings.Contains(err.Error(), contained) { t.Fatalf("expect an error contains %q, but got %v", contained, err) } - _, err = newKustomizationFile("kustomize.yaml", fakeFS) + _, err = newKustomizationFile(constants.KustomizationFileName, fakeFS) if err == nil { t.Fatalf("expect an error") } diff --git a/constants/constants.go b/constants/constants.go index 40b4cd326..3b6d73fdb 100644 --- a/constants/constants.go +++ b/constants/constants.go @@ -18,8 +18,8 @@ package constants const KustomizationSuffix = ".yaml" -// KustomizationFileName is the Well-Known File Name for a kustomize configuration file -const KustomizationFileName = "kustomize" + KustomizationSuffix +// KustomizationFileName is the Well-Known File Name for a kustomize configuration file. +const KustomizationFileName = "kustomization" + KustomizationSuffix // Configmap behaviors const CreateBehavior = "create" diff --git a/examples/simple/instances/exampleinstance/kustomize.yaml b/examples/simple/instances/exampleinstance/kustomization.yaml similarity index 92% rename from examples/simple/instances/exampleinstance/kustomize.yaml rename to examples/simple/instances/exampleinstance/kustomization.yaml index a3a20c030..3a184178d 100644 --- a/examples/simple/instances/exampleinstance/kustomize.yaml +++ b/examples/simple/instances/exampleinstance/kustomization.yaml @@ -1,9 +1,9 @@ namePrefix: test-infra- -labelsToAdd: +commonLabels: app: mungebot org: kubernetes repo: test-infra -annotationsToAdd: +commonAnnotations: note: This is a test annotation bases: - ../../package/ diff --git a/examples/simple/package/kustomize.yaml b/examples/simple/package/kustomization.yaml similarity index 80% rename from examples/simple/package/kustomize.yaml rename to examples/simple/package/kustomization.yaml index c041d68c2..31fed42c4 100644 --- a/examples/simple/package/kustomize.yaml +++ b/examples/simple/package/kustomization.yaml @@ -1,7 +1,7 @@ namePrefix: baseprefix- -labelsToAdd: +commonLabels: foo: bar -annotationsToAdd: +commonAnnotations: baseAnno: This is an base annotation resources: - deployment/deployment.yaml diff --git a/internal/error/configmaperror_test.go b/internal/error/configmaperror_test.go index 5119dfb8d..31d1f5f34 100644 --- a/internal/error/configmaperror_test.go +++ b/internal/error/configmaperror_test.go @@ -19,10 +19,12 @@ package error import ( "strings" "testing" + + "k8s.io/kubectl/pkg/kustomize/constants" ) func TestConfigmapError_Error(t *testing.T) { - filepath := "/path/to/kustomize.yaml" + filepath := "/path/to/" + constants.KustomizationFileName errorMsg := "configmap name is missing" me := ConfigmapError{Path: filepath, ErrorMsg: errorMsg} diff --git a/internal/error/kustomizationerror_test.go b/internal/error/kustomizationerror_test.go index eabaf0107..05a7fb6f9 100644 --- a/internal/error/kustomizationerror_test.go +++ b/internal/error/kustomizationerror_test.go @@ -20,10 +20,12 @@ import ( "fmt" "strings" "testing" + + "k8s.io/kubectl/pkg/kustomize/constants" ) func TestKustomizationError_Error(t *testing.T) { - filepath := "/path/to/kustomize.yaml" + filepath := "/path/to/" + constants.KustomizationFileName errorMsg := "Kustomization not found" me := KustomizationError{KustomizationPath: filepath, ErrorMsg: errorMsg} diff --git a/internal/error/patcherror_test.go b/internal/error/patcherror_test.go index 0157f6e8c..73b0e6756 100644 --- a/internal/error/patcherror_test.go +++ b/internal/error/patcherror_test.go @@ -19,10 +19,12 @@ package error import ( "strings" "testing" + + "k8s.io/kubectl/pkg/kustomize/constants" ) func TestPatchError_Error(t *testing.T) { - filepath := "/path/to/kustomize.yaml" + filepath := "/path/to/" + constants.KustomizationFileName patchfilepath := "/path/to/patch/patch.yaml" errorMsg := "file not found" me := PatchError{KustomizationPath: filepath, PatchFilepath: patchfilepath, ErrorMsg: errorMsg} diff --git a/internal/error/resourceerror_test.go b/internal/error/resourceerror_test.go index b1b241b4f..5cdf4b2ce 100644 --- a/internal/error/resourceerror_test.go +++ b/internal/error/resourceerror_test.go @@ -19,10 +19,12 @@ package error import ( "strings" "testing" + + "k8s.io/kubectl/pkg/kustomize/constants" ) func TestResourceError_Error(t *testing.T) { - filepath := "/path/to/kustomize.yaml" + filepath := "/path/to/" + constants.KustomizationFileName resourcefilepath := "/path/to/resource/deployment.yaml" errorMsg := "file not found" me := ResourceError{KustomizationPath: filepath, ResourceFilepath: resourcefilepath, ErrorMsg: errorMsg} diff --git a/types/kustomization.go b/types/kustomization.go index aea43dda3..c3354baea 100644 --- a/types/kustomization.go +++ b/types/kustomization.go @@ -26,14 +26,13 @@ type Kustomization struct { // These labels would also be used to form the selector for apply --prune // Named differently than “labels” to avoid confusion with metadata for // this object - LabelsToAdd map[string]string `json:"labelsToAdd,omitempty" yaml:"labelsToAdd,omitempty"` + CommonLabels map[string]string `json:"commonLabels,omitempty" yaml:"commonLabels,omitempty"` // Annotations to add to all objects. - AnnotationsToAdd map[string]string `json:"annotationsToAdd,omitempty" yaml:"annotationsToAdd,omitempty"` + CommonAnnotations map[string]string `json:"commonAnnotations,omitempty" yaml:"commonAnnotations,omitempty"` - // Bases contain the paths to other packages that this kustomization depends on. - // Each path should be either a path to a kustomize.yaml or a path of - // a directory that contains a kustomize.yaml file. + // Each entry should be either a path to a file with a name matching the value of + // constants.KustomizationFileName, or a path to a directory containing a file with that name. Bases []string `json:"bases,omitempty" yaml:"bases,omitempty"` // Resources specifies the relative paths within the package.