diff --git a/cmd/config/internal/commands/cmdcreatesetter.go b/cmd/config/internal/commands/cmdcreatesetter.go index 38df7f96c..7f21fdafb 100644 --- a/cmd/config/internal/commands/cmdcreatesetter.go +++ b/cmd/config/internal/commands/cmdcreatesetter.go @@ -214,7 +214,6 @@ func (r *CreateSetterRunner) set(c *cobra.Command, args []string) error { if err := openapi.AddSchemaFromFile(r.CreateSetter.OpenAPIPath); err != nil { return err } - err := r.CreateSetter.Create() if err != nil { // return err if there is only package @@ -222,10 +221,10 @@ func (r *CreateSetterRunner) set(c *cobra.Command, args []string) error { return err } else { // print error message and continue if there are multiple packages to set - fmt.Fprintf(c.OutOrStdout(), "%s in package %q\n", err.Error(), r.CreateSetter.ResourcesPath) + fmt.Fprintf(c.OutOrStdout(), "%s in package %q\n\n", err.Error(), r.CreateSetter.ResourcesPath) } } else { - fmt.Fprintf(c.OutOrStdout(), "created setter %q in package %q\n", r.CreateSetter.Name, r.CreateSetter.ResourcesPath) + fmt.Fprintf(c.OutOrStdout(), "created setter %q in package %q\n\n", r.CreateSetter.Name, r.CreateSetter.ResourcesPath) } // Delete schema present in openAPI file for current package diff --git a/cmd/config/internal/commands/cmdcreatesetter_test.go b/cmd/config/internal/commands/cmdcreatesetter_test.go index 048ddf721..a6a21c05b 100644 --- a/cmd/config/internal/commands/cmdcreatesetter_test.go +++ b/cmd/config/internal/commands/cmdcreatesetter_test.go @@ -855,6 +855,7 @@ func TestCreateSetterSubPackages(t *testing.T) { args: []string{"namespace", "myspace", "-R"}, expected: ` created setter "namespace" in package "${baseDir}/mysql" + created setter "namespace" in package "${baseDir}/mysql/storage" `, }, @@ -878,7 +879,9 @@ created setter "namespace" in package "${baseDir}/mysql/storage" packagePath: "mysql", args: []string{"namespace", "myspace", "-R"}, expected: `setter with name "namespace" already exists, if you want to modify it, please delete the existing setter and recreate it in package "${baseDir}/mysql" + created setter "namespace" in package "${baseDir}/mysql/nosetters" + setter with name "namespace" already exists, if you want to modify it, please delete the existing setter and recreate it in package "${baseDir}/mysql/storage"`, }, } diff --git a/cmd/config/internal/commands/cmdcreatesubstitution.go b/cmd/config/internal/commands/cmdcreatesubstitution.go index e7a112ce7..269002af4 100644 --- a/cmd/config/internal/commands/cmdcreatesubstitution.go +++ b/cmd/config/internal/commands/cmdcreatesubstitution.go @@ -89,10 +89,10 @@ func (r *CreateSubstitutionRunner) runE(c *cobra.Command, args []string) error { return err } else { // print error message and continue if there are multiple packages to set - fmt.Fprintf(c.OutOrStdout(), "%s in package %q\n", err.Error(), r.CreateSubstitution.ResourcesPath) + fmt.Fprintf(c.OutOrStdout(), "%s in package %q\n\n", err.Error(), r.CreateSubstitution.ResourcesPath) } } else { - fmt.Fprintf(c.OutOrStdout(), "created substitution %q in package %q\n", r.CreateSubstitution.Name, r.CreateSubstitution.ResourcesPath) + fmt.Fprintf(c.OutOrStdout(), "created substitution %q in package %q\n\n", r.CreateSubstitution.Name, r.CreateSubstitution.ResourcesPath) } // Delete schema present in openAPI file for current package diff --git a/cmd/config/internal/commands/cmdcreatesubstitution_test.go b/cmd/config/internal/commands/cmdcreatesubstitution_test.go index f996488f3..142f38a7d 100644 --- a/cmd/config/internal/commands/cmdcreatesubstitution_test.go +++ b/cmd/config/internal/commands/cmdcreatesubstitution_test.go @@ -441,6 +441,7 @@ func TestCreateSubstSubPackages(t *testing.T) { args: []string{"image-tag", "--field-value", "mysql:1.7.9", "--pattern", "${image}:${tag}", "-R"}, expected: ` created substitution "image-tag" in package "${baseDir}/mysql" + created substitution "image-tag" in package "${baseDir}/mysql/storage" `, }, @@ -464,7 +465,9 @@ created substitution "image-tag" in package "${baseDir}/mysql/storage" packagePath: "mysql", args: []string{"image-tag", "--field-value", "mysql:1.7.9", "--pattern", "${image}:${tag}", "-R"}, expected: `substitution with name "image-tag" already exists in package "${baseDir}/mysql" + created substitution "image-tag" in package "${baseDir}/mysql/nosetters" + created substitution "image-tag" in package "${baseDir}/mysql/storage"`, }, } diff --git a/cmd/config/internal/commands/cmdlistsetters.go b/cmd/config/internal/commands/cmdlistsetters.go index 2080a1bb6..bbdaefa8c 100644 --- a/cmd/config/internal/commands/cmdlistsetters.go +++ b/cmd/config/internal/commands/cmdlistsetters.go @@ -37,6 +37,8 @@ func NewListSettersRunner(parent string) *ListSettersRunner { "output as github markdown") c.Flags().BoolVar(&r.IncludeSubst, "include-subst", false, "include substitutions in the output") + c.Flags().BoolVarP(&r.RecurseSubPackages, "recurse-subpackages", "R", true, + "list setters recursively in all the nested subpackages") fixDocs(parent, c) r.Command = c return r @@ -47,11 +49,12 @@ func ListSettersCommand(parent string) *cobra.Command { } type ListSettersRunner struct { - Command *cobra.Command - Lookup setters.LookupSetters - List setters2.List - Markdown bool - IncludeSubst bool + Command *cobra.Command + Lookup setters.LookupSetters + List setters2.List + Markdown bool + IncludeSubst bool + RecurseSubPackages bool } func (r *ListSettersRunner) preRunE(c *cobra.Command, args []string) error { @@ -71,7 +74,7 @@ func (r *ListSettersRunner) runE(c *cobra.Command, args []string) error { return err } - resourcePaths, err := pathutil.DirsWithFile(args[0], openAPIFileName, true) + resourcePaths, err := pathutil.DirsWithFile(args[0], openAPIFileName, r.RecurseSubPackages) if err != nil { return err } @@ -86,7 +89,7 @@ func (r *ListSettersRunner) runE(c *cobra.Command, args []string) error { OpenAPIFileName: openAPIFileName, } openAPIPath := filepath.Join(resourcePath, openAPIFileName) - fmt.Fprintf(c.OutOrStdout(), "%s\n", resourcePath) + fmt.Fprintf(c.OutOrStdout(), "\n%s/\n", resourcePath) if err := r.ListSetters(c, openAPIPath, resourcePath); err != nil { return err } diff --git a/cmd/config/internal/commands/cmdlistsetters_test.go b/cmd/config/internal/commands/cmdlistsetters_test.go index 921b4fdcf..28a3a08d7 100644 --- a/cmd/config/internal/commands/cmdlistsetters_test.go +++ b/cmd/config/internal/commands/cmdlistsetters_test.go @@ -474,7 +474,8 @@ func TestListSettersSubPackages(t *testing.T) { dataset: "dataset-with-setters", args: []string{"--include-subst"}, expected: ` -test/testdata/dataset-with-setters/mysql + +test/testdata/dataset-with-setters/mysql/ NAME VALUE SET BY DESCRIPTION COUNT REQUIRED image mysql 1 No namespace myspace 1 No @@ -482,11 +483,26 @@ test/testdata/dataset-with-setters/mysql --------------- ----------------- -------------- SUBSTITUTION PATTERN REFERENCES image-tag ${image}:${tag} [image,tag] -test/testdata/dataset-with-setters/mysql/nosetters + +test/testdata/dataset-with-setters/mysql/nosetters/ NAME VALUE SET BY DESCRIPTION COUNT REQUIRED -test/testdata/dataset-with-setters/mysql/storage + +test/testdata/dataset-with-setters/mysql/storage/ NAME VALUE SET BY DESCRIPTION COUNT REQUIRED namespace myspace 1 No +`, + }, + { + name: "list-replicas", + dataset: "dataset-with-setters/mysql", + args: []string{"--recurse-subpackages=false"}, + expected: ` + +test/testdata/dataset-with-setters/mysql/ + NAME VALUE SET BY DESCRIPTION COUNT REQUIRED + image mysql 1 No + namespace myspace 1 No + tag 1.7.9 1 No `, }, } diff --git a/cmd/config/internal/commands/e2e/list_setters_test.go b/cmd/config/internal/commands/e2e/list_setters_test.go index 6f5f78fd5..0d73132a3 100644 --- a/cmd/config/internal/commands/e2e/list_setters_test.go +++ b/cmd/config/internal/commands/e2e/list_setters_test.go @@ -34,7 +34,7 @@ openAPI: `, }, expectedStdOut: ` -. +./ NAME VALUE SET BY DESCRIPTION COUNT REQUIRED replicas 3 1 No `, diff --git a/kyaml/setters2/settersutil/settercreator.go b/kyaml/setters2/settersutil/settercreator.go index 9d8e04311..5974e1111 100644 --- a/kyaml/setters2/settersutil/settercreator.go +++ b/kyaml/setters2/settersutil/settercreator.go @@ -87,7 +87,7 @@ func (c SetterCreator) Create() error { }.Execute() if a.Count == 0 { fmt.Printf("setter %q doesn't match any field in resource configs, "+ - "but creating setter definition\n", c.Name) + "but creating setter definition in package %q\n", c.Name, c.ResourcesPath) } if err != nil { return err diff --git a/kyaml/setters2/settersutil/substitutioncreator.go b/kyaml/setters2/settersutil/substitutioncreator.go index 53ace3a57..9b898e1ee 100644 --- a/kyaml/setters2/settersutil/substitutioncreator.go +++ b/kyaml/setters2/settersutil/substitutioncreator.go @@ -138,7 +138,7 @@ func (c SubstitutionCreator) Create() error { } // Update the resources with the substitution reference - inout := &kio.LocalPackageReadWriter{PackagePath: c.ResourcesPath} + inout := &kio.LocalPackageReadWriter{PackagePath: c.ResourcesPath, PackageFileName: c.OpenAPIFileName} err = kio.Pipeline{ Inputs: []kio.Reader{inout}, Filters: []kio.Filter{kio.FilterAll(a)}, @@ -147,7 +147,7 @@ func (c SubstitutionCreator) Create() error { if a.Count == 0 { fmt.Printf("substitution %s doesn't match any field value in resource configs, "+ - "but creating substitution definition\n", c.Name) + "but creating substitution definition in package %q\n", c.Name, c.ResourcesPath) } return err }