diff --git a/cmd/config/internal/commands/cmdcreatesetter.go b/cmd/config/internal/commands/cmdcreatesetter.go index c74992a67..4a9db6a73 100644 --- a/cmd/config/internal/commands/cmdcreatesetter.go +++ b/cmd/config/internal/commands/cmdcreatesetter.go @@ -4,8 +4,6 @@ package commands import ( - "fmt" - "github.com/go-openapi/spec" "github.com/spf13/cobra" "sigs.k8s.io/kustomize/cmd/config/ext" @@ -106,10 +104,11 @@ func (r *CreateSetterRunner) preRunE(c *cobra.Command, args []string) error { return err } - _, err = openapi.Resolve(&ref) - if err == nil { - return errors.Errorf(fmt.Sprintf("substitution with name %s already exists, "+ - "substitution and setter can't have same name", r.CreateSetter.Name)) + subst, _ := openapi.Resolve(&ref) + // if substitution already exists with the input setter name, throw error + if subst != nil { + return errors.Errorf("substitution with name %s already exists, "+ + "substitution and setter can't have same name", r.CreateSetter.Name) } r.CreateSetter.Description = r.Set.SetPartialField.Description diff --git a/cmd/config/internal/commands/cmdcreatesubstitution.go b/cmd/config/internal/commands/cmdcreatesubstitution.go index a51d7d9db..b4cb47988 100644 --- a/cmd/config/internal/commands/cmdcreatesubstitution.go +++ b/cmd/config/internal/commands/cmdcreatesubstitution.go @@ -76,8 +76,9 @@ func (r *CreateSubstitutionRunner) preRunE(c *cobra.Command, args []string) erro return err } - _, err = openapi.Resolve(&ref) // resolve the setter to its openAPI def - if err == nil { + setter, _ := openapi.Resolve(&ref) + // if setter already exists with input substitution name, throw error + if setter != nil { return errors.Errorf(fmt.Sprintf("setter with name %s already exists, "+ "substitution and setter can't have same name", r.CreateSubstitution.Name)) }