kubeadm: cleanup the code about cobra

This commit is contained in:
SataQiu 2019-07-10 18:45:28 +08:00
parent abe94ce9b3
commit b837f8d96f
3 changed files with 11 additions and 11 deletions

View File

@ -21,8 +21,8 @@ import (
"github.com/lithammer/dedent"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/alpha"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/upgrade"
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
// Register the kubeadm configuration types because CLI flag generation
@ -90,15 +90,7 @@ func NewKubeadmCommand(in io.Reader, out, err io.Writer) *cobra.Command {
cmds.AddCommand(upgrade.NewCmdUpgrade(out))
cmds.AddCommand(alpha.NewCmdAlpha(in, out))
AddKubeadmOtherFlags(cmds.PersistentFlags(), &rootfsPath)
options.AddKubeadmOtherFlags(cmds.PersistentFlags(), &rootfsPath)
return cmds
}
// AddKubeadmOtherFlags adds flags that are not bound to a configuration file to the given flagset
func AddKubeadmOtherFlags(flagSet *pflag.FlagSet, rootfsPath *string) {
flagSet.StringVar(
rootfsPath, "rootfs", *rootfsPath,
"[EXPERIMENTAL] The path to the 'real' host root filesystem.",
)
}

View File

@ -538,5 +538,5 @@ func AddImagesCommonConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta2.Cl
options.AddKubernetesVersionFlag(flagSet, &cfg.KubernetesVersion)
options.AddFeatureGatesStringFlag(flagSet, featureGatesString)
options.AddImageMetaFlags(flagSet, &cfg.ImageRepository)
flagSet.StringVar(cfgPath, "config", *cfgPath, "Path to kubeadm config file.")
options.AddConfigFlag(flagSet, cfgPath)
}

View File

@ -80,3 +80,11 @@ func AddKubernetesVersionFlag(fs *pflag.FlagSet, kubernetesVersion *string) {
`Choose a specific Kubernetes version for the control plane.`,
)
}
// AddKubeadmOtherFlags adds flags that are not bound to a configuration file to the given flagset
func AddKubeadmOtherFlags(flagSet *pflag.FlagSet, rootfsPath *string) {
flagSet.StringVar(
rootfsPath, "rootfs", *rootfsPath,
"[EXPERIMENTAL] The path to the 'real' host root filesystem.",
)
}