From 6484259632957ec0ed493ae99fabbffdfd5ebeff Mon Sep 17 00:00:00 2001 From: Phillip Wittrock Date: Wed, 11 Dec 2019 12:23:35 -0800 Subject: [PATCH] Disable alpha kustomize commands by default. - enable alpha commands with env KUSTOMIZE_SHOW_ALPHA_COMMANDS=true --- cmd/config/cmds/cmds.go | 14 +++++++++++++- cmd/config/cmds/example_test.go | 5 +++++ cmd/config/main.go | 3 +++ kustomize/go.mod | 1 + kustomize/internal/commands/config/config.go | 5 ++++- kyaml/commandutil/commandutil.go | 14 ++++++++++++++ 6 files changed, 40 insertions(+), 2 deletions(-) create mode 100644 kyaml/commandutil/commandutil.go diff --git a/cmd/config/cmds/cmds.go b/cmd/config/cmds/cmds.go index c27be0715..dbf772d20 100644 --- a/cmd/config/cmds/cmds.go +++ b/cmd/config/cmds/cmds.go @@ -12,6 +12,7 @@ import ( "sigs.k8s.io/kustomize/cmd/config/cmd" "sigs.k8s.io/kustomize/cmd/config/cmddocs/api" "sigs.k8s.io/kustomize/cmd/config/cmddocs/tutorials" + "sigs.k8s.io/kustomize/kyaml/commandutil" ) var root = &cobra.Command{ @@ -40,7 +41,6 @@ Advanced Documentation Topics: $ kustomize help config docs-fn $ kustomize help config docs-io-annotations `, - Version: "v0.0.1", } // NewConfigCommand returns a new *cobra.Command for the config command group. This may @@ -52,6 +52,18 @@ Advanced Documentation Topics: // "kustomize" and the built-in docs will display "kustomize config" in the examples. // func NewConfigCommand(name string) *cobra.Command { + // config command is alpha + root.Version = "v0.0.0" + + // Only populate the command if Alpha commands are enabled. + if !commandutil.GetAlphaEnabled() { + // return the command because other subcommands are added to it + root.Short = "[Alpha] To enable set KUSTOMIZE_ENABLE_ALPHA_COMMANDS=true" + root.Long = "[Alpha] To enable set KUSTOMIZE_ENABLE_ALPHA_COMMANDS=true" + root.Example = "" + return root + } + root.PersistentFlags().BoolVar(&cmd.StackOnError, "stack-trace", false, "print a stack-trace on failure") diff --git a/cmd/config/cmds/example_test.go b/cmd/config/cmds/example_test.go index 4634a2c02..d7b5a1f96 100644 --- a/cmd/config/cmds/example_test.go +++ b/cmd/config/cmds/example_test.go @@ -4,13 +4,18 @@ package cmds_test import ( + "os" + "github.com/spf13/cobra" "sigs.k8s.io/kustomize/cmd/config/cmds" + "sigs.k8s.io/kustomize/kyaml/commandutil" ) // ExampleNewConfigCommand demonstrates how to embed the config command as a command inside // another group. func ExampleNewConfigCommand() { + // enable the config commands + os.Setenv(commandutil.EnableAlphaCommmandsEnvName, "true") var root = &cobra.Command{ Use: "my-cmd", Short: "My command.", diff --git a/cmd/config/main.go b/cmd/config/main.go index 6fd672c9b..39447ca54 100644 --- a/cmd/config/main.go +++ b/cmd/config/main.go @@ -10,9 +10,12 @@ import ( "os" "sigs.k8s.io/kustomize/cmd/config/cmds" + "sigs.k8s.io/kustomize/kyaml/commandutil" ) func main() { + // enable the config commands + os.Setenv(commandutil.EnableAlphaCommmandsEnvName, "true") if err := cmds.NewConfigCommand("").Execute(); err != nil { os.Exit(1) } diff --git a/kustomize/go.mod b/kustomize/go.mod index 4a7f74843..2297c18db 100644 --- a/kustomize/go.mod +++ b/kustomize/go.mod @@ -8,6 +8,7 @@ require ( github.com/spf13/pflag v1.0.5 sigs.k8s.io/kustomize/api v0.2.0 sigs.k8s.io/kustomize/cmd/config v0.0.0 + sigs.k8s.io/kustomize/kyaml v0.0.0 sigs.k8s.io/yaml v1.1.0 ) diff --git a/kustomize/internal/commands/config/config.go b/kustomize/internal/commands/config/config.go index 93c4ea349..58cf55be9 100644 --- a/kustomize/internal/commands/config/config.go +++ b/kustomize/internal/commands/config/config.go @@ -11,6 +11,7 @@ import ( "sigs.k8s.io/kustomize/api/filesys" "sigs.k8s.io/kustomize/api/konfig/builtinpluginconsts" "sigs.k8s.io/kustomize/cmd/config/cmds" + "sigs.k8s.io/kustomize/kyaml/commandutil" ) // NewCmdConfig returns an instance of 'config' subcommand. @@ -50,7 +51,9 @@ func newCmdSave(fSys filesys.FileSystem) *cobra.Command { } return o.RunSave(fSys) }, - Hidden: true, // Don't display this command, but keep it for backwards compatibility. + // Alpha version of config is very different than the current version. + // If alpha is enabled, don't display this command, but keep it for backwards compatibility. + Hidden: commandutil.GetAlphaEnabled(), Deprecated: `The save command is deprecated and will be removed in a future release. If you require this command file an issue at https://github.com/kubernetes-sigs/kustomize/issues diff --git a/kyaml/commandutil/commandutil.go b/kyaml/commandutil/commandutil.go new file mode 100644 index 000000000..8463c1e8f --- /dev/null +++ b/kyaml/commandutil/commandutil.go @@ -0,0 +1,14 @@ +package commandutil + +import ( + "os" +) + +// EnabkeAlphaCommmandsEnvName is the environment variable used to enable Alpha kustomize commands. +//If set to "true" alpha commands will be enabled. +const EnableAlphaCommmandsEnvName = "KUSTOMIZE_ENABLE_ALPHA_COMMANDS" + +// GetAlphaEnabled returns true if alpha commands should be enabled. +func GetAlphaEnabled() bool { + return os.Getenv(EnableAlphaCommmandsEnvName) == "true" +}