diff --git a/cmd/kubeadm/app/cmd/config.go b/cmd/kubeadm/app/cmd/config.go index ec4d705c586..89c2c455991 100644 --- a/cmd/kubeadm/app/cmd/config.go +++ b/cmd/kubeadm/app/cmd/config.go @@ -21,7 +21,6 @@ import ( "fmt" "io" "io/ioutil" - "strings" "github.com/lithammer/dedent" "github.com/pkg/errors" @@ -519,7 +518,6 @@ func AddImagesCommonConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.In &cfg.ClusterConfiguration.KubernetesVersion, "kubernetes-version", cfg.ClusterConfiguration.KubernetesVersion, `Choose a specific Kubernetes version for the control plane.`, ) - flagSet.StringVar(featureGatesString, "feature-gates", *featureGatesString, "A set of key=value pairs that describe feature gates for various features. "+ - "Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n")) + options.AddFeatureGatesStringFlag(flagSet, featureGatesString) flagSet.StringVar(cfgPath, "config", *cfgPath, "Path to kubeadm config file.") } diff --git a/cmd/kubeadm/app/cmd/init.go b/cmd/kubeadm/app/cmd/init.go index e279aa8bb7b..28df66a11a8 100644 --- a/cmd/kubeadm/app/cmd/init.go +++ b/cmd/kubeadm/app/cmd/init.go @@ -21,7 +21,6 @@ import ( "io" "os" "path/filepath" - "strings" "text/template" "github.com/lithammer/dedent" @@ -235,8 +234,7 @@ func AddInitConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.InitConfig `Specify the node name.`, ) cmdutil.AddCRISocketFlag(flagSet, &cfg.NodeRegistration.CRISocket) - flagSet.StringVar(featureGatesString, options.FeatureGatesString, *featureGatesString, "A set of key=value pairs that describe feature gates for various features. "+ - "Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n")) + options.AddFeatureGatesStringFlag(flagSet, featureGatesString) } // AddInitOtherFlags adds init flags that are not bound to a configuration file to the given flagset diff --git a/cmd/kubeadm/app/cmd/options/BUILD b/cmd/kubeadm/app/cmd/options/BUILD index 500837b313a..e3b56537020 100644 --- a/cmd/kubeadm/app/cmd/options/BUILD +++ b/cmd/kubeadm/app/cmd/options/BUILD @@ -14,6 +14,7 @@ go_library( deps = [ "//cmd/kubeadm/app/apis/kubeadm/v1beta1:go_default_library", "//cmd/kubeadm/app/constants:go_default_library", + "//cmd/kubeadm/app/features:go_default_library", "//staging/src/k8s.io/cluster-bootstrap/token/api:go_default_library", "//staging/src/k8s.io/component-base/cli/flag:go_default_library", "//vendor/github.com/spf13/pflag:go_default_library", diff --git a/cmd/kubeadm/app/cmd/options/generic.go b/cmd/kubeadm/app/cmd/options/generic.go index fa67fa07ccc..96206b9b645 100644 --- a/cmd/kubeadm/app/cmd/options/generic.go +++ b/cmd/kubeadm/app/cmd/options/generic.go @@ -17,9 +17,12 @@ limitations under the License. package options import ( + "strings" + "github.com/spf13/pflag" cliflag "k8s.io/component-base/cli/flag" "k8s.io/kubernetes/cmd/kubeadm/app/constants" + "k8s.io/kubernetes/cmd/kubeadm/app/features" ) // AddKubeConfigFlag adds the --kubeconfig flag to the given flagset @@ -58,3 +61,14 @@ func AddControlPlanExtraArgsFlags(fs *pflag.FlagSet, apiServerExtraArgs, control func AddImageMetaFlags(fs *pflag.FlagSet, imageRepository *string) { fs.StringVar(imageRepository, ImageRepository, *imageRepository, "Choose a container registry to pull control plane images from") } + +// AddFeatureGatesStringFlag adds the --feature-gates flag to the given flagset +func AddFeatureGatesStringFlag(fs *pflag.FlagSet, featureGatesString *string) { + if knownFeatures := features.KnownFeatures(&features.InitFeatureGates); len(knownFeatures) > 0 { + fs.StringVar(featureGatesString, FeatureGatesString, *featureGatesString, "A set of key=value pairs that describe feature gates for various features. "+ + "Options are:\n"+strings.Join(knownFeatures, "\n")) + } else { + fs.StringVar(featureGatesString, FeatureGatesString, *featureGatesString, "A set of key=value pairs that describe feature gates for various features. "+ + "No feature gates are available in this release.") + } +} diff --git a/cmd/kubeadm/app/cmd/upgrade/upgrade.go b/cmd/kubeadm/app/cmd/upgrade/upgrade.go index 7e89f939317..52e190e2e8e 100644 --- a/cmd/kubeadm/app/cmd/upgrade/upgrade.go +++ b/cmd/kubeadm/app/cmd/upgrade/upgrade.go @@ -18,7 +18,6 @@ package upgrade import ( "io" - "strings" "github.com/spf13/cobra" "github.com/spf13/pflag" @@ -26,7 +25,6 @@ import ( "k8s.io/kubernetes/cmd/kubeadm/app/cmd/options" cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util" kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants" - "k8s.io/kubernetes/cmd/kubeadm/app/features" ) // applyPlanFlags holds the values for the common flags in `kubeadm upgrade apply` and `kubeadm upgrade plan` @@ -73,7 +71,6 @@ func addApplyPlanFlags(fs *pflag.FlagSet, flags *applyPlanFlags) { fs.BoolVar(&flags.allowExperimentalUpgrades, "allow-experimental-upgrades", flags.allowExperimentalUpgrades, "Show unstable versions of Kubernetes as an upgrade alternative and allow upgrading to an alpha/beta/release candidate versions of Kubernetes.") fs.BoolVar(&flags.allowRCUpgrades, "allow-release-candidate-upgrades", flags.allowRCUpgrades, "Show release candidate versions of Kubernetes as an upgrade alternative and allow upgrading to a release candidate versions of Kubernetes.") fs.BoolVar(&flags.printConfig, "print-config", flags.printConfig, "Specifies whether the configuration file that will be used in the upgrade should be printed or not.") - fs.StringVar(&flags.featureGatesString, "feature-gates", flags.featureGatesString, "A set of key=value pairs that describe feature gates for various features. "+ - "Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n")) + options.AddFeatureGatesStringFlag(fs, &flags.featureGatesString) options.AddIgnorePreflightErrorsFlag(fs, &flags.ignorePreflightErrors) }