mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-25 20:53:33 +00:00
Merge pull request #95461 from SataQiu/clean-kubeadm-20201010
kubeadm: make new command functions to keep private when they are not required to be public
This commit is contained in:
commit
7680a85b3b
@ -33,7 +33,7 @@ func NewCmdAlpha(in io.Reader, out io.Writer) *cobra.Command {
|
|||||||
|
|
||||||
const shDeprecatedMessage = "self-hosting support in kubeadm is deprecated " +
|
const shDeprecatedMessage = "self-hosting support in kubeadm is deprecated " +
|
||||||
"and will be removed in a future release"
|
"and will be removed in a future release"
|
||||||
shCommand := NewCmdSelfhosting(in)
|
shCommand := newCmdSelfhosting(in)
|
||||||
shCommand.Deprecated = shDeprecatedMessage
|
shCommand.Deprecated = shDeprecatedMessage
|
||||||
for _, cmd := range shCommand.Commands() {
|
for _, cmd := range shCommand.Commands() {
|
||||||
cmd.Deprecated = shDeprecatedMessage
|
cmd.Deprecated = shDeprecatedMessage
|
||||||
|
@ -100,7 +100,7 @@ func NewCmdCertsUtility(out io.Writer) *cobra.Command {
|
|||||||
|
|
||||||
cmd.AddCommand(newCmdCertsRenewal(out))
|
cmd.AddCommand(newCmdCertsRenewal(out))
|
||||||
cmd.AddCommand(newCmdCertsExpiration(out, constants.KubernetesDir))
|
cmd.AddCommand(newCmdCertsExpiration(out, constants.KubernetesDir))
|
||||||
cmd.AddCommand(NewCmdCertificateKey())
|
cmd.AddCommand(newCmdCertificateKey())
|
||||||
cmd.AddCommand(newCmdGenCSR())
|
cmd.AddCommand(newCmdGenCSR())
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -178,8 +178,8 @@ func runGenCSR(config *genCSRConfig) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdCertificateKey returns cobra.Command for certificate key generate
|
// newCmdCertificateKey returns cobra.Command for certificate key generate
|
||||||
func NewCmdCertificateKey() *cobra.Command {
|
func newCmdCertificateKey() *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "certificate-key",
|
Use: "certificate-key",
|
||||||
Short: "Generate certificate keys",
|
Short: "Generate certificate keys",
|
||||||
|
@ -56,8 +56,8 @@ var (
|
|||||||
`)
|
`)
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdSelfhosting returns the self-hosting Cobra command
|
// newCmdSelfhosting returns the self-hosting Cobra command
|
||||||
func NewCmdSelfhosting(in io.Reader) *cobra.Command {
|
func newCmdSelfhosting(in io.Reader) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "selfhosting",
|
Use: "selfhosting",
|
||||||
Aliases: []string{"selfhosted", "self-hosting"},
|
Aliases: []string{"selfhosted", "self-hosting"},
|
||||||
|
@ -81,13 +81,13 @@ func NewKubeadmCommand(in io.Reader, out, err io.Writer) *cobra.Command {
|
|||||||
|
|
||||||
cmds.ResetFlags()
|
cmds.ResetFlags()
|
||||||
|
|
||||||
cmds.AddCommand(NewCmdCompletion(out, ""))
|
cmds.AddCommand(newCmdCompletion(out, ""))
|
||||||
cmds.AddCommand(NewCmdConfig(out))
|
cmds.AddCommand(newCmdConfig(out))
|
||||||
cmds.AddCommand(NewCmdInit(out, nil))
|
cmds.AddCommand(newCmdInit(out, nil))
|
||||||
cmds.AddCommand(NewCmdJoin(out, nil))
|
cmds.AddCommand(newCmdJoin(out, nil))
|
||||||
cmds.AddCommand(NewCmdReset(in, out, nil))
|
cmds.AddCommand(newCmdReset(in, out, nil))
|
||||||
cmds.AddCommand(NewCmdVersion(out))
|
cmds.AddCommand(newCmdVersion(out))
|
||||||
cmds.AddCommand(NewCmdToken(out, err))
|
cmds.AddCommand(newCmdToken(out, err))
|
||||||
cmds.AddCommand(upgrade.NewCmdUpgrade(out))
|
cmds.AddCommand(upgrade.NewCmdUpgrade(out))
|
||||||
cmds.AddCommand(alpha.NewCmdAlpha(in, out))
|
cmds.AddCommand(alpha.NewCmdAlpha(in, out))
|
||||||
options.AddKubeadmOtherFlags(cmds.PersistentFlags(), &rootfsPath)
|
options.AddKubeadmOtherFlags(cmds.PersistentFlags(), &rootfsPath)
|
||||||
|
@ -96,8 +96,8 @@ func GetSupportedShells() []string {
|
|||||||
return shells
|
return shells
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdCompletion returns the "kubeadm completion" command
|
// newCmdCompletion returns the "kubeadm completion" command
|
||||||
func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command {
|
func newCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "completion SHELL",
|
Use: "completion SHELL",
|
||||||
Short: "Output shell completion code for the specified shell (bash or zsh)",
|
Short: "Output shell completion code for the specified shell (bash or zsh)",
|
||||||
|
@ -31,15 +31,15 @@ func TestNewCmdCompletion(t *testing.T) {
|
|||||||
if len(shells) == 0 {
|
if len(shells) == 0 {
|
||||||
t.Errorf(shellsError)
|
t.Errorf(shellsError)
|
||||||
}
|
}
|
||||||
// test NewCmdCompletion with a valid shell.
|
// test newCmdCompletion with a valid shell.
|
||||||
// use a dummy parent command as NewCmdCompletion needs it.
|
// use a dummy parent command as newCmdCompletion needs it.
|
||||||
parentCmd := &cobra.Command{}
|
parentCmd := &cobra.Command{}
|
||||||
args := []string{"completion", shells[0]}
|
args := []string{"completion", shells[0]}
|
||||||
parentCmd.SetArgs(args)
|
parentCmd.SetArgs(args)
|
||||||
cmd := NewCmdCompletion(&out, "")
|
cmd := newCmdCompletion(&out, "")
|
||||||
parentCmd.AddCommand(cmd)
|
parentCmd.AddCommand(cmd)
|
||||||
if err := parentCmd.Execute(); err != nil {
|
if err := parentCmd.Execute(); err != nil {
|
||||||
t.Errorf("Cannot exectute NewCmdCompletion: %v", err)
|
t.Errorf("Cannot exectute newCmdCompletion: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,8 +63,8 @@ var (
|
|||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdConfig returns cobra.Command for "kubeadm config" command
|
// newCmdConfig returns cobra.Command for "kubeadm config" command
|
||||||
func NewCmdConfig(out io.Writer) *cobra.Command {
|
func newCmdConfig(out io.Writer) *cobra.Command {
|
||||||
var kubeConfigFile string
|
var kubeConfigFile string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@ -87,15 +87,15 @@ func NewCmdConfig(out io.Writer) *cobra.Command {
|
|||||||
options.AddKubeConfigFlag(cmd.PersistentFlags(), &kubeConfigFile)
|
options.AddKubeConfigFlag(cmd.PersistentFlags(), &kubeConfigFile)
|
||||||
|
|
||||||
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
||||||
cmd.AddCommand(NewCmdConfigPrint(out))
|
cmd.AddCommand(newCmdConfigPrint(out))
|
||||||
cmd.AddCommand(NewCmdConfigMigrate(out))
|
cmd.AddCommand(newCmdConfigMigrate(out))
|
||||||
cmd.AddCommand(NewCmdConfigView(out, &kubeConfigFile))
|
cmd.AddCommand(newCmdConfigView(out, &kubeConfigFile))
|
||||||
cmd.AddCommand(NewCmdConfigImages(out))
|
cmd.AddCommand(newCmdConfigImages(out))
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdConfigPrint returns cobra.Command for "kubeadm config print" command
|
// newCmdConfigPrint returns cobra.Command for "kubeadm config print" command
|
||||||
func NewCmdConfigPrint(out io.Writer) *cobra.Command {
|
func newCmdConfigPrint(out io.Writer) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "print",
|
Use: "print",
|
||||||
Short: "Print configuration",
|
Short: "Print configuration",
|
||||||
@ -104,18 +104,18 @@ func NewCmdConfigPrint(out io.Writer) *cobra.Command {
|
|||||||
For details, see: https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2`),
|
For details, see: https://godoc.org/k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1beta2`),
|
||||||
RunE: cmdutil.SubCmdRunE("print"),
|
RunE: cmdutil.SubCmdRunE("print"),
|
||||||
}
|
}
|
||||||
cmd.AddCommand(NewCmdConfigPrintInitDefaults(out))
|
cmd.AddCommand(newCmdConfigPrintInitDefaults(out))
|
||||||
cmd.AddCommand(NewCmdConfigPrintJoinDefaults(out))
|
cmd.AddCommand(newCmdConfigPrintJoinDefaults(out))
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdConfigPrintInitDefaults returns cobra.Command for "kubeadm config print init-defaults" command
|
// newCmdConfigPrintInitDefaults returns cobra.Command for "kubeadm config print init-defaults" command
|
||||||
func NewCmdConfigPrintInitDefaults(out io.Writer) *cobra.Command {
|
func newCmdConfigPrintInitDefaults(out io.Writer) *cobra.Command {
|
||||||
return newCmdConfigPrintActionDefaults(out, "init", getDefaultInitConfigBytes)
|
return newCmdConfigPrintActionDefaults(out, "init", getDefaultInitConfigBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdConfigPrintJoinDefaults returns cobra.Command for "kubeadm config print join-defaults" command
|
// newCmdConfigPrintJoinDefaults returns cobra.Command for "kubeadm config print join-defaults" command
|
||||||
func NewCmdConfigPrintJoinDefaults(out io.Writer) *cobra.Command {
|
func newCmdConfigPrintJoinDefaults(out io.Writer) *cobra.Command {
|
||||||
return newCmdConfigPrintActionDefaults(out, "join", getDefaultNodeConfigBytes)
|
return newCmdConfigPrintActionDefaults(out, "join", getDefaultNodeConfigBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -249,8 +249,8 @@ func getDefaultNodeConfigBytes() ([]byte, error) {
|
|||||||
return configutil.MarshalKubeadmConfigObject(internalcfg)
|
return configutil.MarshalKubeadmConfigObject(internalcfg)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdConfigMigrate returns cobra.Command for "kubeadm config migrate" command
|
// newCmdConfigMigrate returns cobra.Command for "kubeadm config migrate" command
|
||||||
func NewCmdConfigMigrate(out io.Writer) *cobra.Command {
|
func newCmdConfigMigrate(out io.Writer) *cobra.Command {
|
||||||
var oldCfgPath, newCfgPath string
|
var oldCfgPath, newCfgPath string
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "migrate",
|
Use: "migrate",
|
||||||
@ -300,8 +300,8 @@ func NewCmdConfigMigrate(out io.Writer) *cobra.Command {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdConfigView returns cobra.Command for "kubeadm config view" command
|
// newCmdConfigView returns cobra.Command for "kubeadm config view" command
|
||||||
func NewCmdConfigView(out io.Writer, kubeConfigFile *string) *cobra.Command {
|
func newCmdConfigView(out io.Writer, kubeConfigFile *string) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "view",
|
Use: "view",
|
||||||
Short: "View the kubeadm configuration stored inside the cluster",
|
Short: "View the kubeadm configuration stored inside the cluster",
|
||||||
@ -337,20 +337,20 @@ func RunConfigView(out io.Writer, client clientset.Interface) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdConfigImages returns the "kubeadm config images" command
|
// newCmdConfigImages returns the "kubeadm config images" command
|
||||||
func NewCmdConfigImages(out io.Writer) *cobra.Command {
|
func newCmdConfigImages(out io.Writer) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "images",
|
Use: "images",
|
||||||
Short: "Interact with container images used by kubeadm",
|
Short: "Interact with container images used by kubeadm",
|
||||||
RunE: cmdutil.SubCmdRunE("images"),
|
RunE: cmdutil.SubCmdRunE("images"),
|
||||||
}
|
}
|
||||||
cmd.AddCommand(NewCmdConfigImagesList(out, nil))
|
cmd.AddCommand(newCmdConfigImagesList(out, nil))
|
||||||
cmd.AddCommand(NewCmdConfigImagesPull())
|
cmd.AddCommand(newCmdConfigImagesPull())
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdConfigImagesPull returns the `kubeadm config images pull` command
|
// newCmdConfigImagesPull returns the `kubeadm config images pull` command
|
||||||
func NewCmdConfigImagesPull() *cobra.Command {
|
func newCmdConfigImagesPull() *cobra.Command {
|
||||||
externalClusterCfg := &kubeadmapiv1beta2.ClusterConfiguration{}
|
externalClusterCfg := &kubeadmapiv1beta2.ClusterConfiguration{}
|
||||||
kubeadmscheme.Scheme.Default(externalClusterCfg)
|
kubeadmscheme.Scheme.Default(externalClusterCfg)
|
||||||
externalInitCfg := &kubeadmapiv1beta2.InitConfiguration{}
|
externalInitCfg := &kubeadmapiv1beta2.InitConfiguration{}
|
||||||
@ -410,8 +410,8 @@ func PullControlPlaneImages(runtime utilruntime.ContainerRuntime, cfg *kubeadmap
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdConfigImagesList returns the "kubeadm config images list" command
|
// newCmdConfigImagesList returns the "kubeadm config images list" command
|
||||||
func NewCmdConfigImagesList(out io.Writer, mockK8sVersion *string) *cobra.Command {
|
func newCmdConfigImagesList(out io.Writer, mockK8sVersion *string) *cobra.Command {
|
||||||
externalcfg := &kubeadmapiv1beta2.ClusterConfiguration{}
|
externalcfg := &kubeadmapiv1beta2.ClusterConfiguration{}
|
||||||
kubeadmscheme.Scheme.Default(externalcfg)
|
kubeadmscheme.Scheme.Default(externalcfg)
|
||||||
var cfgPath, featureGatesString string
|
var cfgPath, featureGatesString string
|
||||||
|
@ -56,7 +56,7 @@ var (
|
|||||||
func TestNewCmdConfigImagesList(t *testing.T) {
|
func TestNewCmdConfigImagesList(t *testing.T) {
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
mockK8sVersion := dummyKubernetesVersionStr
|
mockK8sVersion := dummyKubernetesVersionStr
|
||||||
images := NewCmdConfigImagesList(&output, &mockK8sVersion)
|
images := newCmdConfigImagesList(&output, &mockK8sVersion)
|
||||||
if err := images.RunE(nil, nil); err != nil {
|
if err := images.RunE(nil, nil); err != nil {
|
||||||
t.Fatalf("Error from running the images command: %v", err)
|
t.Fatalf("Error from running the images command: %v", err)
|
||||||
}
|
}
|
||||||
@ -401,7 +401,7 @@ func TestMigrate(t *testing.T) {
|
|||||||
defer cleanup()
|
defer cleanup()
|
||||||
|
|
||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
command := NewCmdConfigMigrate(&output)
|
command := newCmdConfigMigrate(&output)
|
||||||
if err := command.Flags().Set("old-config", configFile); err != nil {
|
if err := command.Flags().Set("old-config", configFile); err != nil {
|
||||||
t.Fatalf("failed to set old-config flag")
|
t.Fatalf("failed to set old-config flag")
|
||||||
}
|
}
|
||||||
@ -447,7 +447,7 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
|
|||||||
constants.ClusterConfigurationKind,
|
constants.ClusterConfigurationKind,
|
||||||
constants.InitConfigurationKind,
|
constants.InitConfigurationKind,
|
||||||
},
|
},
|
||||||
cmdProc: NewCmdConfigPrintInitDefaults,
|
cmdProc: newCmdConfigPrintInitDefaults,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "InitConfiguration: KubeProxyConfiguration",
|
name: "InitConfiguration: KubeProxyConfiguration",
|
||||||
@ -457,7 +457,7 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
|
|||||||
"KubeProxyConfiguration",
|
"KubeProxyConfiguration",
|
||||||
},
|
},
|
||||||
componentConfigs: "KubeProxyConfiguration",
|
componentConfigs: "KubeProxyConfiguration",
|
||||||
cmdProc: NewCmdConfigPrintInitDefaults,
|
cmdProc: newCmdConfigPrintInitDefaults,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "InitConfiguration: KubeProxyConfiguration and KubeletConfiguration",
|
name: "InitConfiguration: KubeProxyConfiguration and KubeletConfiguration",
|
||||||
@ -468,14 +468,14 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
|
|||||||
"KubeletConfiguration",
|
"KubeletConfiguration",
|
||||||
},
|
},
|
||||||
componentConfigs: "KubeProxyConfiguration,KubeletConfiguration",
|
componentConfigs: "KubeProxyConfiguration,KubeletConfiguration",
|
||||||
cmdProc: NewCmdConfigPrintInitDefaults,
|
cmdProc: newCmdConfigPrintInitDefaults,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "JoinConfiguration: No component configs",
|
name: "JoinConfiguration: No component configs",
|
||||||
expectedKinds: []string{
|
expectedKinds: []string{
|
||||||
constants.JoinConfigurationKind,
|
constants.JoinConfigurationKind,
|
||||||
},
|
},
|
||||||
cmdProc: NewCmdConfigPrintJoinDefaults,
|
cmdProc: newCmdConfigPrintJoinDefaults,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "JoinConfiguration: KubeProxyConfiguration",
|
name: "JoinConfiguration: KubeProxyConfiguration",
|
||||||
@ -484,7 +484,7 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
|
|||||||
"KubeProxyConfiguration",
|
"KubeProxyConfiguration",
|
||||||
},
|
},
|
||||||
componentConfigs: "KubeProxyConfiguration",
|
componentConfigs: "KubeProxyConfiguration",
|
||||||
cmdProc: NewCmdConfigPrintJoinDefaults,
|
cmdProc: newCmdConfigPrintJoinDefaults,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "JoinConfiguration: KubeProxyConfiguration and KubeletConfiguration",
|
name: "JoinConfiguration: KubeProxyConfiguration and KubeletConfiguration",
|
||||||
@ -494,7 +494,7 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
|
|||||||
"KubeletConfiguration",
|
"KubeletConfiguration",
|
||||||
},
|
},
|
||||||
componentConfigs: "KubeProxyConfiguration,KubeletConfiguration",
|
componentConfigs: "KubeProxyConfiguration,KubeletConfiguration",
|
||||||
cmdProc: NewCmdConfigPrintJoinDefaults,
|
cmdProc: newCmdConfigPrintJoinDefaults,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,10 +127,10 @@ type initData struct {
|
|||||||
patchesDir string
|
patchesDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdInit returns "kubeadm init" command.
|
// newCmdInit returns "kubeadm init" command.
|
||||||
// NB. initOptions is exposed as parameter for allowing unit testing of
|
// NB. initOptions is exposed as parameter for allowing unit testing of
|
||||||
// the newInitOptions method, that implements all the command options validation logic
|
// the newInitOptions method, that implements all the command options validation logic
|
||||||
func NewCmdInit(out io.Writer, initOptions *initOptions) *cobra.Command {
|
func newCmdInit(out io.Writer, initOptions *initOptions) *cobra.Command {
|
||||||
if initOptions == nil {
|
if initOptions == nil {
|
||||||
initOptions = newInitOptions()
|
initOptions = newInitOptions()
|
||||||
}
|
}
|
||||||
|
@ -153,7 +153,7 @@ func TestNewInitData(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
// initialize an external init option and inject it to the init cmd
|
// initialize an external init option and inject it to the init cmd
|
||||||
initOptions := newInitOptions()
|
initOptions := newInitOptions()
|
||||||
cmd := NewCmdInit(nil, initOptions)
|
cmd := newCmdInit(nil, initOptions)
|
||||||
|
|
||||||
// sets cmd flags (that will be reflected on the init options)
|
// sets cmd flags (that will be reflected on the init options)
|
||||||
for f, v := range tc.flags {
|
for f, v := range tc.flags {
|
||||||
|
@ -147,10 +147,10 @@ type joinData struct {
|
|||||||
patchesDir string
|
patchesDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdJoin returns "kubeadm join" command.
|
// newCmdJoin returns "kubeadm join" command.
|
||||||
// NB. joinOptions is exposed as parameter for allowing unit testing of
|
// NB. joinOptions is exposed as parameter for allowing unit testing of
|
||||||
// the newJoinData method, that implements all the command options validation logic
|
// the newJoinData method, that implements all the command options validation logic
|
||||||
func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
func newCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
||||||
if joinOptions == nil {
|
if joinOptions == nil {
|
||||||
joinOptions = newJoinOptions()
|
joinOptions = newJoinOptions()
|
||||||
}
|
}
|
||||||
|
@ -255,7 +255,7 @@ func TestNewJoinData(t *testing.T) {
|
|||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
// initialize an external join option and inject it to the join cmd
|
// initialize an external join option and inject it to the join cmd
|
||||||
joinOptions := newJoinOptions()
|
joinOptions := newJoinOptions()
|
||||||
cmd := NewCmdJoin(nil, joinOptions)
|
cmd := newCmdJoin(nil, joinOptions)
|
||||||
|
|
||||||
// sets cmd flags (that will be reflected on the join options)
|
// sets cmd flags (that will be reflected on the join options)
|
||||||
for f, v := range tc.flags {
|
for f, v := range tc.flags {
|
||||||
|
@ -158,8 +158,8 @@ func AddResetFlags(flagSet *flag.FlagSet, resetOptions *resetOptions) {
|
|||||||
cmdutil.AddCRISocketFlag(flagSet, &resetOptions.criSocketPath)
|
cmdutil.AddCRISocketFlag(flagSet, &resetOptions.criSocketPath)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdReset returns the "kubeadm reset" command
|
// newCmdReset returns the "kubeadm reset" command
|
||||||
func NewCmdReset(in io.Reader, out io.Writer, resetOptions *resetOptions) *cobra.Command {
|
func newCmdReset(in io.Reader, out io.Writer, resetOptions *resetOptions) *cobra.Command {
|
||||||
if resetOptions == nil {
|
if resetOptions == nil {
|
||||||
resetOptions = newResetOptions()
|
resetOptions = newResetOptions()
|
||||||
}
|
}
|
||||||
|
@ -54,8 +54,8 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/output"
|
"k8s.io/kubernetes/cmd/kubeadm/app/util/output"
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdToken returns cobra.Command for token management
|
// newCmdToken returns cobra.Command for token management
|
||||||
func NewCmdToken(out io.Writer, errW io.Writer) *cobra.Command {
|
func newCmdToken(out io.Writer, errW io.Writer) *cobra.Command {
|
||||||
var kubeConfigFile string
|
var kubeConfigFile string
|
||||||
var dryRun bool
|
var dryRun bool
|
||||||
tokenCmd := &cobra.Command{
|
tokenCmd := &cobra.Command{
|
||||||
@ -149,7 +149,7 @@ func NewCmdToken(out io.Writer, errW io.Writer) *cobra.Command {
|
|||||||
bto.AddDescriptionFlag(createCmd.Flags())
|
bto.AddDescriptionFlag(createCmd.Flags())
|
||||||
|
|
||||||
tokenCmd.AddCommand(createCmd)
|
tokenCmd.AddCommand(createCmd)
|
||||||
tokenCmd.AddCommand(NewCmdTokenGenerate(out))
|
tokenCmd.AddCommand(newCmdTokenGenerate(out))
|
||||||
|
|
||||||
outputFlags := output.NewOutputFlags(&tokenTextPrintFlags{}).WithTypeSetter(outputapischeme.Scheme).WithDefaultOutput(output.TextOutput)
|
outputFlags := output.NewOutputFlags(&tokenTextPrintFlags{}).WithTypeSetter(outputapischeme.Scheme).WithDefaultOutput(output.TextOutput)
|
||||||
|
|
||||||
@ -208,8 +208,8 @@ func NewCmdToken(out io.Writer, errW io.Writer) *cobra.Command {
|
|||||||
return tokenCmd
|
return tokenCmd
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdTokenGenerate returns cobra.Command to generate new token
|
// newCmdTokenGenerate returns cobra.Command to generate new token
|
||||||
func NewCmdTokenGenerate(out io.Writer) *cobra.Command {
|
func newCmdTokenGenerate(out io.Writer) *cobra.Command {
|
||||||
return &cobra.Command{
|
return &cobra.Command{
|
||||||
Use: "generate",
|
Use: "generate",
|
||||||
Short: "Generate and print a bootstrap token, but do not create it on the server",
|
Short: "Generate and print a bootstrap token, but do not create it on the server",
|
||||||
|
@ -186,7 +186,7 @@ func TestNewCmdTokenGenerate(t *testing.T) {
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
args := []string{}
|
args := []string{}
|
||||||
|
|
||||||
cmd := NewCmdTokenGenerate(&buf)
|
cmd := newCmdTokenGenerate(&buf)
|
||||||
cmd.SetArgs(args)
|
cmd.SetArgs(args)
|
||||||
|
|
||||||
if err := cmd.Execute(); err != nil {
|
if err := cmd.Execute(); err != nil {
|
||||||
@ -242,8 +242,8 @@ func TestNewCmdToken(t *testing.T) {
|
|||||||
for _, tc := range testCases {
|
for _, tc := range testCases {
|
||||||
t.Run(tc.name, func(t *testing.T) {
|
t.Run(tc.name, func(t *testing.T) {
|
||||||
// the command is created for each test so that the kubeConfigFile
|
// the command is created for each test so that the kubeConfigFile
|
||||||
// variable in NewCmdToken() is reset.
|
// variable in newCmdToken() is reset.
|
||||||
cmd := NewCmdToken(&buf, &bufErr)
|
cmd := newCmdToken(&buf, &bufErr)
|
||||||
if _, err = f.WriteString(tc.configToWrite); err != nil {
|
if _, err = f.WriteString(tc.configToWrite); err != nil {
|
||||||
t.Errorf("Unable to write test file %q: %v", fullPath, err)
|
t.Errorf("Unable to write test file %q: %v", fullPath, err)
|
||||||
}
|
}
|
||||||
@ -255,7 +255,7 @@ func TestNewCmdToken(t *testing.T) {
|
|||||||
cmd.SetArgs(tc.args)
|
cmd.SetArgs(tc.args)
|
||||||
err := cmd.Execute()
|
err := cmd.Execute()
|
||||||
if (err != nil) != tc.expectedError {
|
if (err != nil) != tc.expectedError {
|
||||||
t.Errorf("Test case %q: NewCmdToken expected error: %v, saw: %v", tc.name, tc.expectedError, (err != nil))
|
t.Errorf("Test case %q: newCmdToken expected error: %v, saw: %v", tc.name, tc.expectedError, (err != nil))
|
||||||
}
|
}
|
||||||
// restore the environment variable.
|
// restore the environment variable.
|
||||||
os.Setenv(clientcmd.RecommendedConfigPathEnvVar, storedEnv)
|
os.Setenv(clientcmd.RecommendedConfigPathEnvVar, storedEnv)
|
||||||
|
@ -59,8 +59,8 @@ func (f *applyFlags) sessionIsInteractive() bool {
|
|||||||
return !(f.nonInteractiveMode || f.dryRun || f.force)
|
return !(f.nonInteractiveMode || f.dryRun || f.force)
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdApply returns the cobra command for `kubeadm upgrade apply`
|
// newCmdApply returns the cobra command for `kubeadm upgrade apply`
|
||||||
func NewCmdApply(apf *applyPlanFlags) *cobra.Command {
|
func newCmdApply(apf *applyPlanFlags) *cobra.Command {
|
||||||
flags := &applyFlags{
|
flags := &applyFlags{
|
||||||
applyPlanFlags: apf,
|
applyPlanFlags: apf,
|
||||||
imagePullTimeout: defaultImagePullTimeout,
|
imagePullTimeout: defaultImagePullTimeout,
|
||||||
|
@ -54,8 +54,8 @@ var (
|
|||||||
defaultSchedulerManifestPath = constants.GetStaticPodFilepath(constants.KubeScheduler, constants.GetStaticPodDirectory())
|
defaultSchedulerManifestPath = constants.GetStaticPodFilepath(constants.KubeScheduler, constants.GetStaticPodDirectory())
|
||||||
)
|
)
|
||||||
|
|
||||||
// NewCmdDiff returns the cobra command for `kubeadm upgrade diff`
|
// newCmdDiff returns the cobra command for `kubeadm upgrade diff`
|
||||||
func NewCmdDiff(out io.Writer) *cobra.Command {
|
func newCmdDiff(out io.Writer) *cobra.Command {
|
||||||
flags := &diffFlags{
|
flags := &diffFlags{
|
||||||
kubeConfigPath: constants.GetAdminKubeConfigPath(),
|
kubeConfigPath: constants.GetAdminKubeConfigPath(),
|
||||||
out: out,
|
out: out,
|
||||||
|
@ -62,8 +62,8 @@ type nodeData struct {
|
|||||||
ignorePreflightErrors sets.String
|
ignorePreflightErrors sets.String
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdNode returns the cobra command for `kubeadm upgrade node`
|
// newCmdNode returns the cobra command for `kubeadm upgrade node`
|
||||||
func NewCmdNode() *cobra.Command {
|
func newCmdNode() *cobra.Command {
|
||||||
nodeOptions := newNodeOptions()
|
nodeOptions := newNodeOptions()
|
||||||
nodeRunner := workflow.NewRunner()
|
nodeRunner := workflow.NewRunner()
|
||||||
|
|
||||||
|
@ -44,8 +44,8 @@ type planFlags struct {
|
|||||||
*applyPlanFlags
|
*applyPlanFlags
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdPlan returns the cobra command for `kubeadm upgrade plan`
|
// newCmdPlan returns the cobra command for `kubeadm upgrade plan`
|
||||||
func NewCmdPlan(apf *applyPlanFlags) *cobra.Command {
|
func newCmdPlan(apf *applyPlanFlags) *cobra.Command {
|
||||||
flags := &planFlags{
|
flags := &planFlags{
|
||||||
applyPlanFlags: apf,
|
applyPlanFlags: apf,
|
||||||
}
|
}
|
||||||
|
@ -57,10 +57,10 @@ func NewCmdUpgrade(out io.Writer) *cobra.Command {
|
|||||||
RunE: cmdutil.SubCmdRunE("upgrade"),
|
RunE: cmdutil.SubCmdRunE("upgrade"),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.AddCommand(NewCmdApply(flags))
|
cmd.AddCommand(newCmdApply(flags))
|
||||||
cmd.AddCommand(NewCmdPlan(flags))
|
cmd.AddCommand(newCmdPlan(flags))
|
||||||
cmd.AddCommand(NewCmdDiff(out))
|
cmd.AddCommand(newCmdDiff(out))
|
||||||
cmd.AddCommand(NewCmdNode())
|
cmd.AddCommand(newCmdNode())
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,8 +35,8 @@ type Version struct {
|
|||||||
ClientVersion *apimachineryversion.Info `json:"clientVersion"`
|
ClientVersion *apimachineryversion.Info `json:"clientVersion"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdVersion provides the version information of kubeadm.
|
// newCmdVersion provides the version information of kubeadm.
|
||||||
func NewCmdVersion(out io.Writer) *cobra.Command {
|
func newCmdVersion(out io.Writer) *cobra.Command {
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "version",
|
Use: "version",
|
||||||
Short: "Print the version of kubeadm",
|
Short: "Print the version of kubeadm",
|
||||||
|
@ -26,7 +26,7 @@ import (
|
|||||||
|
|
||||||
func TestNewCmdVersion(t *testing.T) {
|
func TestNewCmdVersion(t *testing.T) {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
cmd := NewCmdVersion(&buf)
|
cmd := newCmdVersion(&buf)
|
||||||
if err := cmd.Execute(); err != nil {
|
if err := cmd.Execute(); err != nil {
|
||||||
t.Errorf("Cannot execute version command: %v", err)
|
t.Errorf("Cannot execute version command: %v", err)
|
||||||
}
|
}
|
||||||
@ -36,7 +36,7 @@ func TestRunVersion(t *testing.T) {
|
|||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
iface := make(map[string]interface{})
|
iface := make(map[string]interface{})
|
||||||
flagNameOutput := "output"
|
flagNameOutput := "output"
|
||||||
cmd := NewCmdVersion(&buf)
|
cmd := newCmdVersion(&buf)
|
||||||
|
|
||||||
testCases := []struct {
|
testCases := []struct {
|
||||||
name string
|
name string
|
||||||
|
Loading…
Reference in New Issue
Block a user