mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
Merge pull request #82243 from jfbai/refactor-kubeadm-calls
refactor: replace all calls to os.Exit() / CheckErr().
This commit is contained in:
commit
01c046836b
@ -27,7 +27,6 @@ go_library(
|
|||||||
"//cmd/kubeadm/app/phases/kubelet:go_default_library",
|
"//cmd/kubeadm/app/phases/kubelet:go_default_library",
|
||||||
"//cmd/kubeadm/app/phases/selfhosting:go_default_library",
|
"//cmd/kubeadm/app/phases/selfhosting:go_default_library",
|
||||||
"//cmd/kubeadm/app/preflight:go_default_library",
|
"//cmd/kubeadm/app/preflight:go_default_library",
|
||||||
"//cmd/kubeadm/app/util:go_default_library",
|
|
||||||
"//cmd/kubeadm/app/util/apiclient:go_default_library",
|
"//cmd/kubeadm/app/util/apiclient:go_default_library",
|
||||||
"//cmd/kubeadm/app/util/config:go_default_library",
|
"//cmd/kubeadm/app/util/config:go_default_library",
|
||||||
"//cmd/kubeadm/app/util/kubeconfig:go_default_library",
|
"//cmd/kubeadm/app/util/kubeconfig:go_default_library",
|
||||||
|
@ -35,7 +35,6 @@ import (
|
|||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal"
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/certs/renewal"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/copycerts"
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/copycerts"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
)
|
)
|
||||||
@ -93,10 +92,13 @@ func NewCmdCertificateKey() *cobra.Command {
|
|||||||
Short: "Generate certificate keys",
|
Short: "Generate certificate keys",
|
||||||
Long: certificateKeyLongDesc,
|
Long: certificateKeyLongDesc,
|
||||||
|
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
key, err := copycerts.CreateCertificateKey()
|
key, err := copycerts.CreateCertificateKey()
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
fmt.Println(key)
|
fmt.Println(key)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -137,10 +139,12 @@ func getRenewSubCommands(kdir string) []*cobra.Command {
|
|||||||
// Get a renewal manager for a generic Cluster configuration, that is used only for getting
|
// Get a renewal manager for a generic Cluster configuration, that is used only for getting
|
||||||
// the list of certificates for building subcommands
|
// the list of certificates for building subcommands
|
||||||
rm, err := renewal.NewManager(&kubeadmapi.ClusterConfiguration{}, "")
|
rm, err := renewal.NewManager(&kubeadmapi.ClusterConfiguration{}, "")
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
cmdList := []*cobra.Command{}
|
cmdList := []*cobra.Command{}
|
||||||
funcList := []func(){}
|
funcList := []func() error{}
|
||||||
|
|
||||||
for _, handler := range rm.Certificates() {
|
for _, handler := range rm.Certificates() {
|
||||||
// get the cobra.Command skeleton for this command
|
// get the cobra.Command skeleton for this command
|
||||||
@ -151,11 +155,13 @@ func getRenewSubCommands(kdir string) []*cobra.Command {
|
|||||||
}
|
}
|
||||||
addRenewFlags(cmd, flags)
|
addRenewFlags(cmd, flags)
|
||||||
// get the implementation of renewing this certificate
|
// get the implementation of renewing this certificate
|
||||||
renewalFunc := func(handler *renewal.CertificateRenewHandler) func() {
|
renewalFunc := func(handler *renewal.CertificateRenewHandler) func() error {
|
||||||
return func() { renewCert(flags, kdir, handler) }
|
return func() error {
|
||||||
|
return renewCert(flags, kdir, handler)
|
||||||
|
}
|
||||||
}(handler)
|
}(handler)
|
||||||
// install the implementation into the command
|
// install the implementation into the command
|
||||||
cmd.Run = func(*cobra.Command, []string) { renewalFunc() }
|
cmd.RunE = func(*cobra.Command, []string) error { return renewalFunc() }
|
||||||
cmdList = append(cmdList, cmd)
|
cmdList = append(cmdList, cmd)
|
||||||
// Collect renewal functions for `renew all`
|
// Collect renewal functions for `renew all`
|
||||||
funcList = append(funcList, renewalFunc)
|
funcList = append(funcList, renewalFunc)
|
||||||
@ -165,10 +171,13 @@ func getRenewSubCommands(kdir string) []*cobra.Command {
|
|||||||
Use: "all",
|
Use: "all",
|
||||||
Short: "Renew all available certificates",
|
Short: "Renew all available certificates",
|
||||||
Long: allLongDesc,
|
Long: allLongDesc,
|
||||||
Run: func(*cobra.Command, []string) {
|
RunE: func(*cobra.Command, []string) error {
|
||||||
for _, f := range funcList {
|
for _, f := range funcList {
|
||||||
f()
|
if err := f(); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
addRenewFlags(allCmd, flags)
|
addRenewFlags(allCmd, flags)
|
||||||
@ -186,23 +195,25 @@ func addRenewFlags(cmd *cobra.Command, flags *renewFlags) {
|
|||||||
cmd.Flags().BoolVar(&flags.useAPI, "use-api", flags.useAPI, "Use the Kubernetes certificate API to renew certificates")
|
cmd.Flags().BoolVar(&flags.useAPI, "use-api", flags.useAPI, "Use the Kubernetes certificate API to renew certificates")
|
||||||
}
|
}
|
||||||
|
|
||||||
func renewCert(flags *renewFlags, kdir string, handler *renewal.CertificateRenewHandler) {
|
func renewCert(flags *renewFlags, kdir string, handler *renewal.CertificateRenewHandler) error {
|
||||||
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(flags.cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, &flags.cfg)
|
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(flags.cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, &flags.cfg)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Get a renewal manager for the given cluster configuration
|
// Get a renewal manager for the given cluster configuration
|
||||||
rm, err := renewal.NewManager(&internalcfg.ClusterConfiguration, kdir)
|
rm, err := renewal.NewManager(&internalcfg.ClusterConfiguration, kdir)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// if the renewal operation is set to generate CSR request only
|
// if the renewal operation is set to generate CSR request only
|
||||||
if flags.csrOnly {
|
if flags.csrOnly {
|
||||||
// checks a path for storing CSR request is given
|
// checks a path for storing CSR request is given
|
||||||
if flags.csrPath == "" {
|
if flags.csrPath == "" {
|
||||||
kubeadmutil.CheckErr(errors.New("please provide a path where CSR request should be stored"))
|
return errors.New("please provide a path where CSR request should be stored")
|
||||||
}
|
}
|
||||||
err := rm.CreateRenewCSR(handler.Name, flags.csrPath)
|
return rm.CreateRenewCSR(handler.Name, flags.csrPath)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// otherwise, the renewal operation has to actually renew a certificate
|
// otherwise, the renewal operation has to actually renew a certificate
|
||||||
@ -212,21 +223,27 @@ func renewCert(flags *renewFlags, kdir string, handler *renewal.CertificateRenew
|
|||||||
// renew using K8s certificate API
|
// renew using K8s certificate API
|
||||||
kubeConfigPath := cmdutil.GetKubeConfigPath(flags.kubeconfigPath)
|
kubeConfigPath := cmdutil.GetKubeConfigPath(flags.kubeconfigPath)
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigPath)
|
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigPath)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = rm.RenewUsingCSRAPI(handler.Name, client)
|
if err := rm.RenewUsingCSRAPI(handler.Name, client); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// renew using local certificate authorities.
|
// renew using local certificate authorities.
|
||||||
// this operation can't complete in case the certificate key is not provided (external CA)
|
// this operation can't complete in case the certificate key is not provided (external CA)
|
||||||
renewed, err := rm.RenewUsingLocalCA(handler.Name)
|
renewed, err := rm.RenewUsingLocalCA(handler.Name)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
if !renewed {
|
if !renewed {
|
||||||
fmt.Printf("Detected external %s, %s can't be renewed\n", handler.CABaseName, handler.LongName)
|
fmt.Printf("Detected external %s, %s can't be renewed\n", handler.CABaseName, handler.LongName)
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fmt.Printf("%s renewed\n", handler.LongName)
|
fmt.Printf("%s renewed\n", handler.LongName)
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// newCmdCertsExpiration creates a new `cert check-expiration` command.
|
// newCmdCertsExpiration creates a new `cert check-expiration` command.
|
||||||
@ -244,13 +261,17 @@ func newCmdCertsExpiration(out io.Writer, kdir string) *cobra.Command {
|
|||||||
Use: "check-expiration",
|
Use: "check-expiration",
|
||||||
Short: "Check certificates expiration for a Kubernetes cluster",
|
Short: "Check certificates expiration for a Kubernetes cluster",
|
||||||
Long: expirationLongDesc,
|
Long: expirationLongDesc,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(flags.cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, &flags.cfg)
|
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(flags.cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, &flags.cfg)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Get a renewal manager for the given cluster configuration
|
// Get a renewal manager for the given cluster configuration
|
||||||
rm, err := renewal.NewManager(&internalcfg.ClusterConfiguration, kdir)
|
rm, err := renewal.NewManager(&internalcfg.ClusterConfiguration, kdir)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Get all the certificate expiration info
|
// Get all the certificate expiration info
|
||||||
yesNo := func(b bool) string {
|
yesNo := func(b bool) string {
|
||||||
@ -264,7 +285,7 @@ func newCmdCertsExpiration(out io.Writer, kdir string) *cobra.Command {
|
|||||||
for _, handler := range rm.Certificates() {
|
for _, handler := range rm.Certificates() {
|
||||||
e, err := rm.GetExpirationInfo(handler.Name)
|
e, err := rm.GetExpirationInfo(handler.Name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
s := fmt.Sprintf("%s\t%s\t%s\t%-8v",
|
s := fmt.Sprintf("%s\t%s\t%s\t%-8v",
|
||||||
@ -277,6 +298,7 @@ func newCmdCertsExpiration(out io.Writer, kdir string) *cobra.Command {
|
|||||||
fmt.Fprintln(w, s)
|
fmt.Fprintln(w, s)
|
||||||
}
|
}
|
||||||
w.Flush()
|
w.Flush()
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
addExpirationFlags(cmd, flags)
|
addExpirationFlags(cmd, flags)
|
||||||
|
@ -26,7 +26,6 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
kubeconfigphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubeconfig"
|
kubeconfigphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubeconfig"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -76,23 +75,24 @@ func newCmdUserKubeConfig(out io.Writer) *cobra.Command {
|
|||||||
Short: "Output a kubeconfig file for an additional user",
|
Short: "Output a kubeconfig file for an additional user",
|
||||||
Long: userKubeconfigLongDesc,
|
Long: userKubeconfigLongDesc,
|
||||||
Example: userKubeconfigExample,
|
Example: userKubeconfigExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if clientName == "" {
|
if clientName == "" {
|
||||||
kubeadmutil.CheckErr(errors.New("missing required argument --client-name"))
|
return errors.New("missing required argument --client-name")
|
||||||
}
|
}
|
||||||
|
|
||||||
// This call returns the ready-to-use configuration based on the defaults populated by flags
|
// This call returns the ready-to-use configuration based on the defaults populated by flags
|
||||||
internalcfg, err := configutil.DefaultedInitConfiguration(initCfg, clusterCfg)
|
internalcfg, err := configutil.DefaultedInitConfiguration(initCfg, clusterCfg)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// if the kubeconfig file for an additional user has to use a token, use it
|
// if the kubeconfig file for an additional user has to use a token, use it
|
||||||
if token != "" {
|
if token != "" {
|
||||||
kubeadmutil.CheckErr(kubeconfigphase.WriteKubeConfigWithToken(out, internalcfg, clientName, token))
|
return kubeconfigphase.WriteKubeConfigWithToken(out, internalcfg, clientName, token)
|
||||||
return
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Otherwise, write a kubeconfig file with a generate client cert
|
// Otherwise, write a kubeconfig file with a generate client cert
|
||||||
kubeadmutil.CheckErr(kubeconfigphase.WriteKubeConfigWithClientCert(out, internalcfg, clientName, organizations))
|
return kubeconfigphase.WriteKubeConfigWithClientCert(out, internalcfg, clientName, organizations)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
kubeletphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet"
|
kubeletphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubelet"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/preflight"
|
"k8s.io/kubernetes/cmd/kubeadm/app/preflight"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
utilsexec "k8s.io/utils/exec"
|
utilsexec "k8s.io/utils/exec"
|
||||||
)
|
)
|
||||||
@ -101,15 +100,18 @@ func newCmdKubeletConfigDownload() *cobra.Command {
|
|||||||
Short: "Download the kubelet configuration from the cluster ConfigMap kubelet-config-1.X, where X is the minor version of the kubelet",
|
Short: "Download the kubelet configuration from the cluster ConfigMap kubelet-config-1.X, where X is the minor version of the kubelet",
|
||||||
Long: kubeletConfigDownloadLongDesc,
|
Long: kubeletConfigDownloadLongDesc,
|
||||||
Example: kubeletConfigDownloadExample,
|
Example: kubeletConfigDownloadExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
kubeletVersion, err := getKubeletVersion(kubeletVersionStr)
|
kubeletVersion, err := getKubeletVersion(kubeletVersionStr)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = kubeletphase.DownloadConfig(client, kubeletVersion, constants.KubeletRunDirectory)
|
return kubeletphase.DownloadConfig(client, kubeletVersion, constants.KubeletRunDirectory)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -136,23 +138,26 @@ func newCmdKubeletConfigEnableDynamic() *cobra.Command {
|
|||||||
Short: "EXPERIMENTAL: Enable or update dynamic kubelet configuration for a Node",
|
Short: "EXPERIMENTAL: Enable or update dynamic kubelet configuration for a Node",
|
||||||
Long: kubeletConfigEnableDynamicLongDesc,
|
Long: kubeletConfigEnableDynamicLongDesc,
|
||||||
Example: kubeletConfigEnableDynamicExample,
|
Example: kubeletConfigEnableDynamicExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(nodeName) == 0 {
|
if len(nodeName) == 0 {
|
||||||
kubeadmutil.CheckErr(errors.New("the --node-name argument is required"))
|
return errors.New("the --node-name argument is required")
|
||||||
}
|
}
|
||||||
if len(kubeletVersionStr) == 0 {
|
if len(kubeletVersionStr) == 0 {
|
||||||
kubeadmutil.CheckErr(errors.New("the --kubelet-version argument is required"))
|
return errors.New("the --kubelet-version argument is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
kubeletVersion, err := version.ParseSemantic(kubeletVersionStr)
|
kubeletVersion, err := version.ParseSemantic(kubeletVersionStr)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = kubeletphase.EnableDynamicConfigForNode(client, nodeName, kubeletVersion)
|
return kubeletphase.EnableDynamicConfigForNode(client, nodeName, kubeletVersion)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,6 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/selfhosting"
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/selfhosting"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
|
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
@ -87,7 +86,7 @@ func getSelfhostingSubCommand(in io.Reader) *cobra.Command {
|
|||||||
Short: "Convert a static Pod-hosted control plane into a self-hosted one",
|
Short: "Convert a static Pod-hosted control plane into a self-hosted one",
|
||||||
Long: selfhostingLongDesc,
|
Long: selfhostingLongDesc,
|
||||||
Example: selfhostingExample,
|
Example: selfhostingExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
@ -97,28 +96,31 @@ func getSelfhostingSubCommand(in io.Reader) *cobra.Command {
|
|||||||
s := bufio.NewScanner(in)
|
s := bufio.NewScanner(in)
|
||||||
s.Scan()
|
s.Scan()
|
||||||
|
|
||||||
err = s.Err()
|
if err = s.Err(); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if strings.ToLower(s.Text()) != "y" {
|
if strings.ToLower(s.Text()) != "y" {
|
||||||
kubeadmutil.CheckErr(errors.New("aborted pivot operation"))
|
return errors.New("aborted pivot operation")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("[pivot] pivoting cluster to self-hosted")
|
fmt.Println("[pivot] pivoting cluster to self-hosted")
|
||||||
|
|
||||||
if cfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString); err != nil {
|
if cfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validation.ValidateMixedArguments(cmd.Flags()); err != nil {
|
if err := validation.ValidateMixedArguments(cmd.Flags()); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gets the Kubernetes client
|
// Gets the Kubernetes client
|
||||||
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// KubernetesVersion is not used, but we set it explicitly to avoid the lookup
|
// KubernetesVersion is not used, but we set it explicitly to avoid the lookup
|
||||||
// of the version from the internet when executing LoadOrDefaultInitConfiguration
|
// of the version from the internet when executing LoadOrDefaultInitConfiguration
|
||||||
@ -126,12 +128,13 @@ func getSelfhostingSubCommand(in io.Reader) *cobra.Command {
|
|||||||
|
|
||||||
// This call returns the ready-to-use configuration based on the configuration file that might or might not exist and the default cfg populated by flags
|
// This call returns the ready-to-use configuration based on the configuration file that might or might not exist and the default cfg populated by flags
|
||||||
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, cfg)
|
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, &kubeadmapiv1beta2.InitConfiguration{}, cfg)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Converts the Static Pod-hosted control plane into a self-hosted one
|
// Converts the Static Pod-hosted control plane into a self-hosted one
|
||||||
waiter := apiclient.NewKubeWaiter(client, 2*time.Minute, os.Stdout)
|
waiter := apiclient.NewKubeWaiter(client, 2*time.Minute, os.Stdout)
|
||||||
err = selfhosting.CreateSelfHostedControlPlane(constants.GetStaticPodDirectory(), constants.KubernetesDir, internalcfg, client, waiter, false, certsInSecrets)
|
return selfhosting.CreateSelfHostedControlPlane(constants.GetStaticPodDirectory(), constants.KubernetesDir, internalcfg, client, waiter, false, certsInSecrets)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -67,7 +67,8 @@ func NewKubeadmCommand(in io.Reader, out, err io.Writer) *cobra.Command {
|
|||||||
You can then repeat the second step on as many other machines as you like.
|
You can then repeat the second step on as many other machines as you like.
|
||||||
|
|
||||||
`),
|
`),
|
||||||
|
SilenceErrors: true,
|
||||||
|
SilenceUsage: true,
|
||||||
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if rootfsPath != "" {
|
if rootfsPath != "" {
|
||||||
if err := kubeadmutil.Chroot(rootfsPath); err != nil {
|
if err := kubeadmutil.Chroot(rootfsPath); err != nil {
|
||||||
|
@ -24,8 +24,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
|
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
const defaultBoilerPlate = `
|
const defaultBoilerPlate = `
|
||||||
@ -105,9 +103,8 @@ func NewCmdCompletion(out io.Writer, boilerPlate string) *cobra.Command {
|
|||||||
Short: "Output shell completion code for the specified shell (bash or zsh)",
|
Short: "Output shell completion code for the specified shell (bash or zsh)",
|
||||||
Long: completionLong,
|
Long: completionLong,
|
||||||
Example: completionExample,
|
Example: completionExample,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
err := RunCompletion(out, boilerPlate, cmd, args)
|
return RunCompletion(out, boilerPlate, cmd, args)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
ValidArgs: GetSupportedShells(),
|
ValidArgs: GetSupportedShells(),
|
||||||
}
|
}
|
||||||
|
@ -42,7 +42,6 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/images"
|
"k8s.io/kubernetes/cmd/kubeadm/app/images"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/uploadconfig"
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/uploadconfig"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
utilruntime "k8s.io/kubernetes/cmd/kubeadm/app/util/runtime"
|
utilruntime "k8s.io/kubernetes/cmd/kubeadm/app/util/runtime"
|
||||||
@ -127,8 +126,8 @@ func newCmdConfigPrintActionDefaults(out io.Writer, action string, configBytesPr
|
|||||||
Note that sensitive values like the Bootstrap Token fields are replaced with placeholder values like %q in order to pass validation but
|
Note that sensitive values like the Bootstrap Token fields are replaced with placeholder values like %q in order to pass validation but
|
||||||
not perform the real computation for creating a token.
|
not perform the real computation for creating a token.
|
||||||
`), action, action, placeholderToken),
|
`), action, action, placeholderToken),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
runConfigPrintActionDefaults(out, componentConfigs, configBytesProc)
|
return runConfigPrintActionDefaults(out, componentConfigs, configBytesProc)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().StringSliceVar(&componentConfigs, "component-configs", componentConfigs,
|
cmd.Flags().StringSliceVar(&componentConfigs, "component-configs", componentConfigs,
|
||||||
@ -136,18 +135,23 @@ func newCmdConfigPrintActionDefaults(out io.Writer, action string, configBytesPr
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func runConfigPrintActionDefaults(out io.Writer, componentConfigs []string, configBytesProc func() ([]byte, error)) {
|
func runConfigPrintActionDefaults(out io.Writer, componentConfigs []string, configBytesProc func() ([]byte, error)) error {
|
||||||
initialConfig, err := configBytesProc()
|
initialConfig, err := configBytesProc()
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
allBytes := [][]byte{initialConfig}
|
allBytes := [][]byte{initialConfig}
|
||||||
for _, componentConfig := range componentConfigs {
|
for _, componentConfig := range componentConfigs {
|
||||||
cfgBytes, err := getDefaultComponentConfigBytes(componentConfig)
|
cfgBytes, err := getDefaultComponentConfigBytes(componentConfig)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
allBytes = append(allBytes, cfgBytes)
|
allBytes = append(allBytes, cfgBytes)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Fprint(out, string(bytes.Join(allBytes, []byte(constants.YAMLDocumentSeparator))))
|
fmt.Fprint(out, string(bytes.Join(allBytes, []byte(constants.YAMLDocumentSeparator))))
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func getDefaultComponentConfigBytes(apiObject string) ([]byte, error) {
|
func getDefaultComponentConfigBytes(apiObject string) ([]byte, error) {
|
||||||
@ -242,24 +246,29 @@ func NewCmdConfigMigrate(out io.Writer) *cobra.Command {
|
|||||||
In other words, the output of this command is what kubeadm actually would read internally if you
|
In other words, the output of this command is what kubeadm actually would read internally if you
|
||||||
submitted this file to "kubeadm init"
|
submitted this file to "kubeadm init"
|
||||||
`), kubeadmapiv1beta2.SchemeGroupVersion, kubeadmapiv1beta2.SchemeGroupVersion),
|
`), kubeadmapiv1beta2.SchemeGroupVersion, kubeadmapiv1beta2.SchemeGroupVersion),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(oldCfgPath) == 0 {
|
if len(oldCfgPath) == 0 {
|
||||||
kubeadmutil.CheckErr(errors.New("the --old-config flag is mandatory"))
|
return errors.New("the --old-config flag is mandatory")
|
||||||
}
|
}
|
||||||
|
|
||||||
oldCfgBytes, err := ioutil.ReadFile(oldCfgPath)
|
oldCfgBytes, err := ioutil.ReadFile(oldCfgPath)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
outputBytes, err := configutil.MigrateOldConfig(oldCfgBytes)
|
outputBytes, err := configutil.MigrateOldConfig(oldCfgBytes)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
if newCfgPath == "" {
|
if newCfgPath == "" {
|
||||||
fmt.Fprint(out, string(outputBytes))
|
fmt.Fprint(out, string(outputBytes))
|
||||||
} else {
|
} else {
|
||||||
if err := ioutil.WriteFile(newCfgPath, outputBytes, 0644); err != nil {
|
if err := ioutil.WriteFile(newCfgPath, outputBytes, 0644); err != nil {
|
||||||
kubeadmutil.CheckErr(errors.Wrapf(err, "failed to write the new configuration to the file %q", newCfgPath))
|
return errors.Wrapf(err, "failed to write the new configuration to the file %q", newCfgPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().StringVar(&oldCfgPath, "old-config", "", "Path to the kubeadm config file that is using an old API version and should be converted. This flag is mandatory.")
|
cmd.Flags().StringVar(&oldCfgPath, "old-config", "", "Path to the kubeadm config file that is using an old API version and should be converted. This flag is mandatory.")
|
||||||
@ -292,13 +301,14 @@ func NewCmdConfigView(out io.Writer, kubeConfigFile *string) *cobra.Command {
|
|||||||
|
|
||||||
The configuration is located in the %q namespace in the %q ConfigMap.
|
The configuration is located in the %q namespace in the %q ConfigMap.
|
||||||
`), metav1.NamespaceSystem, constants.KubeadmConfigConfigMap),
|
`), metav1.NamespaceSystem, constants.KubeadmConfigConfigMap),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
klog.V(1).Infoln("[config] retrieving ClientSet from file")
|
klog.V(1).Infoln("[config] retrieving ClientSet from file")
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(*kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(*kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = RunConfigView(out, client)
|
return RunConfigView(out, client)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -319,23 +329,26 @@ func NewCmdConfigUploadFromFile(out io.Writer, kubeConfigFile *string) *cobra.Co
|
|||||||
|
|
||||||
The configuration is located in the %q namespace in the %q ConfigMap.
|
The configuration is located in the %q namespace in the %q ConfigMap.
|
||||||
`), metav1.NamespaceSystem, constants.KubeadmConfigConfigMap),
|
`), metav1.NamespaceSystem, constants.KubeadmConfigConfigMap),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
if len(cfgPath) == 0 {
|
if len(cfgPath) == 0 {
|
||||||
kubeadmutil.CheckErr(errors.New("the --config flag is mandatory"))
|
return errors.New("the --config flag is mandatory")
|
||||||
}
|
}
|
||||||
|
|
||||||
klog.V(1).Infoln("[config] retrieving ClientSet from file")
|
klog.V(1).Infoln("[config] retrieving ClientSet from file")
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(*kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(*kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Default both statically and dynamically, convert to internal API type, and validate everything
|
// Default both statically and dynamically, convert to internal API type, and validate everything
|
||||||
internalcfg, err := configutil.LoadInitConfigurationFromFile(cfgPath)
|
internalcfg, err := configutil.LoadInitConfigurationFromFile(cfgPath)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Upload the configuration using the file
|
// Upload the configuration using the file
|
||||||
klog.V(1).Infof("[config] uploading configuration")
|
klog.V(1).Infof("[config] uploading configuration")
|
||||||
err = uploadconfig.UploadConfiguration(internalcfg, client)
|
return uploadconfig.UploadConfiguration(internalcfg, client)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
options.AddConfigFlag(cmd.Flags(), &cfgPath)
|
options.AddConfigFlag(cmd.Flags(), &cfgPath)
|
||||||
@ -364,15 +377,17 @@ func NewCmdConfigUploadFromFlags(out io.Writer, kubeConfigFile *string) *cobra.C
|
|||||||
|
|
||||||
The configuration is located in the %q namespace in the %q ConfigMap.
|
The configuration is located in the %q namespace in the %q ConfigMap.
|
||||||
`), metav1.NamespaceSystem, constants.KubeadmConfigConfigMap),
|
`), metav1.NamespaceSystem, constants.KubeadmConfigConfigMap),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
var err error
|
var err error
|
||||||
klog.V(1).Infoln("[config] creating new FeatureGates")
|
klog.V(1).Infoln("[config] creating new FeatureGates")
|
||||||
if clusterCfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString); err != nil {
|
if clusterCfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return nil
|
||||||
}
|
}
|
||||||
klog.V(1).Infoln("[config] retrieving ClientSet from file")
|
klog.V(1).Infoln("[config] retrieving ClientSet from file")
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(*kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(*kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// KubernetesVersion is not used, but we set it explicitly to avoid the lookup
|
// KubernetesVersion is not used, but we set it explicitly to avoid the lookup
|
||||||
// of the version from the internet when executing DefaultedInitConfiguration
|
// of the version from the internet when executing DefaultedInitConfiguration
|
||||||
@ -381,12 +396,13 @@ func NewCmdConfigUploadFromFlags(out io.Writer, kubeConfigFile *string) *cobra.C
|
|||||||
// Default both statically and dynamically, convert to internal API type, and validate everything
|
// Default both statically and dynamically, convert to internal API type, and validate everything
|
||||||
klog.V(1).Infoln("[config] converting to internal API type")
|
klog.V(1).Infoln("[config] converting to internal API type")
|
||||||
internalcfg, err := configutil.DefaultedInitConfiguration(initCfg, clusterCfg)
|
internalcfg, err := configutil.DefaultedInitConfiguration(initCfg, clusterCfg)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Finally, upload the configuration
|
// Finally, upload the configuration
|
||||||
klog.V(1).Infof("[config] uploading configuration")
|
klog.V(1).Infof("[config] uploading configuration")
|
||||||
err = uploadconfig.UploadConfiguration(internalcfg, client)
|
return uploadconfig.UploadConfiguration(internalcfg, client)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
AddInitConfigFlags(cmd.PersistentFlags(), initCfg)
|
AddInitConfigFlags(cmd.PersistentFlags(), initCfg)
|
||||||
@ -431,15 +447,20 @@ func NewCmdConfigImagesPull() *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "pull",
|
Use: "pull",
|
||||||
Short: "Pull images used by kubeadm",
|
Short: "Pull images used by kubeadm",
|
||||||
Run: func(_ *cobra.Command, _ []string) {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
externalClusterCfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString)
|
externalClusterCfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, externalInitCfg, externalClusterCfg)
|
internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, externalInitCfg, externalClusterCfg)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), internalcfg.NodeRegistration.CRISocket)
|
containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), internalcfg.NodeRegistration.CRISocket)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
err = PullControlPlaneImages(containerRuntime, &internalcfg.ClusterConfiguration)
|
return err
|
||||||
kubeadmutil.CheckErr(err)
|
}
|
||||||
|
return PullControlPlaneImages(containerRuntime, &internalcfg.ClusterConfiguration)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
AddImagesCommonConfigFlags(cmd.PersistentFlags(), externalClusterCfg, &cfgPath, &featureGatesString)
|
AddImagesCommonConfigFlags(cmd.PersistentFlags(), externalClusterCfg, &cfgPath, &featureGatesString)
|
||||||
@ -490,12 +511,18 @@ func NewCmdConfigImagesList(out io.Writer, mockK8sVersion *string) *cobra.Comman
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "list",
|
Use: "list",
|
||||||
Short: "Print a list of images kubeadm will use. The configuration file is used in case any images or image repositories are customized",
|
Short: "Print a list of images kubeadm will use. The configuration file is used in case any images or image repositories are customized",
|
||||||
Run: func(_ *cobra.Command, _ []string) {
|
RunE: func(_ *cobra.Command, _ []string) error {
|
||||||
externalcfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString)
|
externalcfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
imagesList, err := NewImagesList(cfgPath, externalcfg)
|
imagesList, err := NewImagesList(cfgPath, externalcfg)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
kubeadmutil.CheckErr(imagesList.Run(out))
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
return imagesList.Run(out)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
AddImagesCommonConfigFlags(cmd.PersistentFlags(), externalcfg, &cfgPath, &featureGatesString)
|
AddImagesCommonConfigFlags(cmd.PersistentFlags(), externalcfg, &cfgPath, &featureGatesString)
|
||||||
|
@ -52,7 +52,9 @@ func TestNewCmdConfigImagesList(t *testing.T) {
|
|||||||
var output bytes.Buffer
|
var output bytes.Buffer
|
||||||
mockK8sVersion := dummyKubernetesVersion
|
mockK8sVersion := dummyKubernetesVersion
|
||||||
images := NewCmdConfigImagesList(&output, &mockK8sVersion)
|
images := NewCmdConfigImagesList(&output, &mockK8sVersion)
|
||||||
images.Run(nil, nil)
|
if err := images.RunE(nil, nil); err != nil {
|
||||||
|
t.Fatalf("Error from running the images command: %v", err)
|
||||||
|
}
|
||||||
actual := strings.Split(output.String(), "\n")
|
actual := strings.Split(output.String(), "\n")
|
||||||
if len(actual) != defaultNumberOfImages {
|
if len(actual) != defaultNumberOfImages {
|
||||||
t.Fatalf("Expected %v but found %v images", defaultNumberOfImages, len(actual))
|
t.Fatalf("Expected %v but found %v images", defaultNumberOfImages, len(actual))
|
||||||
@ -252,7 +254,9 @@ func TestMigrate(t *testing.T) {
|
|||||||
if err := command.Flags().Set("new-config", newConfigPath); err != nil {
|
if err := command.Flags().Set("new-config", newConfigPath); err != nil {
|
||||||
t.Fatalf("failed to set new-config flag")
|
t.Fatalf("failed to set new-config flag")
|
||||||
}
|
}
|
||||||
command.Run(nil, nil)
|
if err := command.RunE(nil, nil); err != nil {
|
||||||
|
t.Fatalf("Error from running the migrate command: %v", err)
|
||||||
|
}
|
||||||
if _, err := configutil.LoadInitConfigurationFromFile(newConfigPath); err != nil {
|
if _, err := configutil.LoadInitConfigurationFromFile(newConfigPath); err != nil {
|
||||||
t.Fatalf("Could not read output back into internal type: %v", err)
|
t.Fatalf("Could not read output back into internal type: %v", err)
|
||||||
}
|
}
|
||||||
@ -347,7 +351,9 @@ func TestNewCmdConfigPrintActionDefaults(t *testing.T) {
|
|||||||
if err := command.Flags().Set("component-configs", test.componentConfigs); err != nil {
|
if err := command.Flags().Set("component-configs", test.componentConfigs); err != nil {
|
||||||
t.Fatalf("failed to set component-configs flag")
|
t.Fatalf("failed to set component-configs flag")
|
||||||
}
|
}
|
||||||
command.Run(nil, nil)
|
if err := command.RunE(nil, nil); err != nil {
|
||||||
|
t.Fatalf("Error from running the print command: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
gvkmap, err := kubeadmutil.SplitYAMLDocuments(output.Bytes())
|
gvkmap, err := kubeadmutil.SplitYAMLDocuments(output.Bytes())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -41,7 +41,6 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
"k8s.io/kubernetes/cmd/kubeadm/app/features"
|
||||||
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
|
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
|
||||||
kubeconfigphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubeconfig"
|
kubeconfigphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/kubeconfig"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
|
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
@ -136,18 +135,20 @@ func NewCmdInit(out io.Writer, initOptions *initOptions) *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
Short: "Run this command in order to set up the Kubernetes control plane",
|
Short: "Run this command in order to set up the Kubernetes control plane",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
c, err := initRunner.InitData(args)
|
c, err := initRunner.InitData(args)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
data := c.(*initData)
|
data := c.(*initData)
|
||||||
fmt.Printf("[init] Using Kubernetes version: %s\n", data.cfg.KubernetesVersion)
|
fmt.Printf("[init] Using Kubernetes version: %s\n", data.cfg.KubernetesVersion)
|
||||||
|
|
||||||
err = initRunner.Run(args)
|
if err := initRunner.Run(args); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = showJoinCommand(data, out)
|
return showJoinCommand(data, out)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ import (
|
|||||||
flag "github.com/spf13/pflag"
|
flag "github.com/spf13/pflag"
|
||||||
"k8s.io/apimachinery/pkg/util/sets"
|
"k8s.io/apimachinery/pkg/util/sets"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
clientcmd "k8s.io/client-go/tools/clientcmd"
|
"k8s.io/client-go/tools/clientcmd"
|
||||||
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
clientcmdapi "k8s.io/client-go/tools/clientcmd/api"
|
||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
@ -41,7 +41,6 @@ import (
|
|||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/discovery"
|
"k8s.io/kubernetes/cmd/kubeadm/app/discovery"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
)
|
)
|
||||||
@ -159,15 +158,18 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
|||||||
Use: "join [api-server-endpoint]",
|
Use: "join [api-server-endpoint]",
|
||||||
Short: "Run this on any machine you wish to join an existing cluster",
|
Short: "Run this on any machine you wish to join an existing cluster",
|
||||||
Long: joinLongDescription,
|
Long: joinLongDescription,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
|
|
||||||
c, err := joinRunner.InitData(args)
|
c, err := joinRunner.InitData(args)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
data := c.(*joinData)
|
data := c.(*joinData)
|
||||||
|
|
||||||
err = joinRunner.Run(args)
|
if err := joinRunner.Run(args); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// if the node is hosting a new control plane instance
|
// if the node is hosting a new control plane instance
|
||||||
if data.cfg.ControlPlane != nil {
|
if data.cfg.ControlPlane != nil {
|
||||||
@ -181,14 +183,17 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
|||||||
"KubeConfigPath": kubeadmconstants.GetAdminKubeConfigPath(),
|
"KubeConfigPath": kubeadmconstants.GetAdminKubeConfigPath(),
|
||||||
"etcdMessage": etcdMessage,
|
"etcdMessage": etcdMessage,
|
||||||
}
|
}
|
||||||
err = joinControPlaneDoneTemp.Execute(data.outputWriter, ctx)
|
if err := joinControPlaneDoneTemp.Execute(data.outputWriter, ctx); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
// otherwise, if the node joined as a worker node;
|
// otherwise, if the node joined as a worker node;
|
||||||
// outputs the join done message and exit
|
// outputs the join done message and exit
|
||||||
fmt.Fprint(data.outputWriter, joinWorkerNodeDoneMsg)
|
fmt.Fprint(data.outputWriter, joinWorkerNodeDoneMsg)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
// We accept the control-plane location as an optional positional argument
|
// We accept the control-plane location as an optional positional argument
|
||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
|
@ -41,7 +41,6 @@ go_library(
|
|||||||
"//cmd/kubeadm/app/phases/patchnode:go_default_library",
|
"//cmd/kubeadm/app/phases/patchnode:go_default_library",
|
||||||
"//cmd/kubeadm/app/phases/uploadconfig:go_default_library",
|
"//cmd/kubeadm/app/phases/uploadconfig:go_default_library",
|
||||||
"//cmd/kubeadm/app/preflight:go_default_library",
|
"//cmd/kubeadm/app/preflight:go_default_library",
|
||||||
"//cmd/kubeadm/app/util:go_default_library",
|
|
||||||
"//cmd/kubeadm/app/util/apiclient:go_default_library",
|
"//cmd/kubeadm/app/util/apiclient:go_default_library",
|
||||||
"//cmd/kubeadm/app/util/dryrun:go_default_library",
|
"//cmd/kubeadm/app/util/dryrun:go_default_library",
|
||||||
"//cmd/kubeadm/app/util/pkiutil:go_default_library",
|
"//cmd/kubeadm/app/util/pkiutil:go_default_library",
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
|
certsphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/certs"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
|
"k8s.io/kubernetes/cmd/kubeadm/app/util/pkiutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -161,11 +160,14 @@ func getSANDescription(certSpec *certsphase.KubeadmCert) string {
|
|||||||
defaultInternalConfig := &kubeadmapi.InitConfiguration{}
|
defaultInternalConfig := &kubeadmapi.InitConfiguration{}
|
||||||
|
|
||||||
kubeadmscheme.Scheme.Default(defaultConfig)
|
kubeadmscheme.Scheme.Default(defaultConfig)
|
||||||
err := kubeadmscheme.Scheme.Convert(defaultConfig, defaultInternalConfig, nil)
|
if err := kubeadmscheme.Scheme.Convert(defaultConfig, defaultInternalConfig, nil); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
certConfig, err := certSpec.GetConfig(defaultInternalConfig)
|
certConfig, err := certSpec.GetConfig(defaultInternalConfig)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
|
||||||
if len(certConfig.AltNames.DNSNames) == 0 && len(certConfig.AltNames.IPs) == 0 {
|
if len(certConfig.AltNames.DNSNames) == 0 && len(certConfig.AltNames.IPs) == 0 {
|
||||||
return ""
|
return ""
|
||||||
|
@ -10,7 +10,6 @@ go_library(
|
|||||||
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow",
|
importpath = "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow",
|
||||||
visibility = ["//visibility:public"],
|
visibility = ["//visibility:public"],
|
||||||
deps = [
|
deps = [
|
||||||
"//cmd/kubeadm/app/util:go_default_library",
|
|
||||||
"//vendor/github.com/pkg/errors:go_default_library",
|
"//vendor/github.com/pkg/errors:go_default_library",
|
||||||
"//vendor/github.com/spf13/cobra:go_default_library",
|
"//vendor/github.com/spf13/cobra:go_default_library",
|
||||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||||
|
@ -23,8 +23,6 @@ import (
|
|||||||
"github.com/pkg/errors"
|
"github.com/pkg/errors"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/spf13/pflag"
|
"github.com/spf13/pflag"
|
||||||
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// phaseSeparator defines the separator to be used when concatenating nested
|
// phaseSeparator defines the separator to be used when concatenating nested
|
||||||
@ -337,17 +335,17 @@ func (e *Runner) BindToCommand(cmd *cobra.Command) {
|
|||||||
Long: p.Long,
|
Long: p.Long,
|
||||||
Example: p.Example,
|
Example: p.Example,
|
||||||
Aliases: p.Aliases,
|
Aliases: p.Aliases,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
// if the phase has subphases, print the help and exits
|
// if the phase has subphases, print the help and exits
|
||||||
if len(p.Phases) > 0 {
|
if len(p.Phases) > 0 {
|
||||||
cmd.Help()
|
cmd.Help()
|
||||||
return
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// overrides the command triggering the Runner using the phaseCmd
|
// overrides the command triggering the Runner using the phaseCmd
|
||||||
e.runCmd = cmd
|
e.runCmd = cmd
|
||||||
e.Options.FilterPhases = []string{phaseSelector}
|
e.Options.FilterPhases = []string{phaseSelector}
|
||||||
util.CheckErr(e.Run(args))
|
return e.Run(args)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -34,7 +34,6 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
utilruntime "k8s.io/kubernetes/cmd/kubeadm/app/util/runtime"
|
utilruntime "k8s.io/kubernetes/cmd/kubeadm/app/util/runtime"
|
||||||
)
|
)
|
||||||
@ -103,7 +102,6 @@ func newResetData(cmd *cobra.Command, options *resetOptions, in io.Reader, out i
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
if cfg != nil {
|
if cfg != nil {
|
||||||
// Also set the union of pre-flight errors to InitConfiguration, to provide a consistent view of the runtime configuration:
|
// Also set the union of pre-flight errors to InitConfiguration, to provide a consistent view of the runtime configuration:
|
||||||
cfg.NodeRegistration.IgnorePreflightErrors = ignorePreflightErrorsSet.List()
|
cfg.NodeRegistration.IgnorePreflightErrors = ignorePreflightErrorsSet.List()
|
||||||
@ -166,12 +164,16 @@ func NewCmdReset(in io.Reader, out io.Writer, resetOptions *resetOptions) *cobra
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "reset",
|
Use: "reset",
|
||||||
Short: "Performs a best effort revert of changes made to this host by 'kubeadm init' or 'kubeadm join'",
|
Short: "Performs a best effort revert of changes made to this host by 'kubeadm init' or 'kubeadm join'",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
c, err := resetRunner.InitData(args)
|
c, err := resetRunner.InitData(args)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = resetRunner.Run(args)
|
err = resetRunner.Run(args)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
// Then clean contents from the stateful kubelet, etcd and cni directories
|
// Then clean contents from the stateful kubelet, etcd and cni directories
|
||||||
data := c.(*resetData)
|
data := c.(*resetData)
|
||||||
@ -179,6 +181,7 @@ func NewCmdReset(in io.Reader, out io.Writer, resetOptions *resetOptions) *cobra
|
|||||||
|
|
||||||
// Output help text instructing user how to remove iptables rules
|
// Output help text instructing user how to remove iptables rules
|
||||||
fmt.Print(iptablesCleanupInstructions)
|
fmt.Print(iptablesCleanupInstructions)
|
||||||
|
return nil
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ import (
|
|||||||
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
tokenphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/node"
|
tokenphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/node"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
|
"k8s.io/kubernetes/cmd/kubeadm/app/util/apiclient"
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
kubeconfigutil "k8s.io/kubernetes/cmd/kubeadm/app/util/kubeconfig"
|
||||||
@ -108,24 +107,27 @@ func NewCmdToken(out io.Writer, errW io.Writer) *cobra.Command {
|
|||||||
This should be a securely generated random token of the form "[a-z0-9]{6}.[a-z0-9]{16}".
|
This should be a securely generated random token of the form "[a-z0-9]{6}.[a-z0-9]{16}".
|
||||||
If no [token] is given, kubeadm will generate a random token instead.
|
If no [token] is given, kubeadm will generate a random token instead.
|
||||||
`),
|
`),
|
||||||
Run: func(tokenCmd *cobra.Command, args []string) {
|
RunE: func(tokenCmd *cobra.Command, args []string) error {
|
||||||
if len(args) > 0 {
|
if len(args) > 0 {
|
||||||
bto.TokenStr = args[0]
|
bto.TokenStr = args[0]
|
||||||
}
|
}
|
||||||
klog.V(1).Infoln("[token] validating mixed arguments")
|
klog.V(1).Infoln("[token] validating mixed arguments")
|
||||||
err := validation.ValidateMixedArguments(tokenCmd.Flags())
|
if err := validation.ValidateMixedArguments(tokenCmd.Flags()); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = bto.ApplyTo(cfg)
|
if err := bto.ApplyTo(cfg); err != nil {
|
||||||
kubeadmutil.CheckErr(err)
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
klog.V(1).Infoln("[token] getting Clientsets from kubeconfig file")
|
klog.V(1).Infoln("[token] getting Clientsets from kubeconfig file")
|
||||||
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
||||||
client, err := getClientset(kubeConfigFile, dryRun)
|
client, err := getClientset(kubeConfigFile, dryRun)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = RunCreateToken(out, client, cfgPath, cfg, printJoinCommand, kubeConfigFile)
|
return RunCreateToken(out, client, cfgPath, cfg, printJoinCommand, kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -146,13 +148,14 @@ func NewCmdToken(out io.Writer, errW io.Writer) *cobra.Command {
|
|||||||
Long: dedent.Dedent(`
|
Long: dedent.Dedent(`
|
||||||
This command will list all bootstrap tokens for you.
|
This command will list all bootstrap tokens for you.
|
||||||
`),
|
`),
|
||||||
Run: func(tokenCmd *cobra.Command, args []string) {
|
RunE: func(tokenCmd *cobra.Command, args []string) error {
|
||||||
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
||||||
client, err := getClientset(kubeConfigFile, dryRun)
|
client, err := getClientset(kubeConfigFile, dryRun)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = RunListTokens(out, errW, client)
|
return RunListTokens(out, errW, client)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tokenCmd.AddCommand(listCmd)
|
tokenCmd.AddCommand(listCmd)
|
||||||
@ -167,16 +170,17 @@ func NewCmdToken(out io.Writer, errW io.Writer) *cobra.Command {
|
|||||||
The [token-value] is the full Token of the form "[a-z0-9]{6}.[a-z0-9]{16}" or the
|
The [token-value] is the full Token of the form "[a-z0-9]{6}.[a-z0-9]{16}" or the
|
||||||
Token ID of the form "[a-z0-9]{6}" to delete.
|
Token ID of the form "[a-z0-9]{6}" to delete.
|
||||||
`),
|
`),
|
||||||
Run: func(tokenCmd *cobra.Command, args []string) {
|
RunE: func(tokenCmd *cobra.Command, args []string) error {
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
kubeadmutil.CheckErr(errors.Errorf("missing subcommand; 'token delete' is missing token of form %q", bootstrapapi.BootstrapTokenIDPattern))
|
return errors.Errorf("missing subcommand; 'token delete' is missing token of form %q", bootstrapapi.BootstrapTokenIDPattern)
|
||||||
}
|
}
|
||||||
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
kubeConfigFile = cmdutil.GetKubeConfigPath(kubeConfigFile)
|
||||||
client, err := getClientset(kubeConfigFile, dryRun)
|
client, err := getClientset(kubeConfigFile, dryRun)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = RunDeleteTokens(out, client, args)
|
return RunDeleteTokens(out, client, args)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
tokenCmd.AddCommand(deleteCmd)
|
tokenCmd.AddCommand(deleteCmd)
|
||||||
@ -200,9 +204,8 @@ func NewCmdTokenGenerate(out io.Writer) *cobra.Command {
|
|||||||
You can also use "kubeadm init" without specifying a token and it will
|
You can also use "kubeadm init" without specifying a token and it will
|
||||||
generate and print one for you.
|
generate and print one for you.
|
||||||
`),
|
`),
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
err := RunGenerateToken(out)
|
return RunGenerateToken(out)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -73,12 +73,13 @@ func NewCmdApply(apf *applyPlanFlags) *cobra.Command {
|
|||||||
Use: "apply [version]",
|
Use: "apply [version]",
|
||||||
DisableFlagsInUseLine: true,
|
DisableFlagsInUseLine: true,
|
||||||
Short: "Upgrade your Kubernetes cluster to the specified version",
|
Short: "Upgrade your Kubernetes cluster to the specified version",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
userVersion, err := getK8sVersionFromUserInput(flags.applyPlanFlags, args, true)
|
userVersion, err := getK8sVersionFromUserInput(flags.applyPlanFlags, args, true)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = runApply(flags, userVersion)
|
return runApply(flags, userVersion)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -65,9 +65,9 @@ func NewCmdDiff(out io.Writer) *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "diff [version]",
|
Use: "diff [version]",
|
||||||
Short: "Show what differences would be applied to existing static pod manifests. See also: kubeadm upgrade apply --dry-run",
|
Short: "Show what differences would be applied to existing static pod manifests. See also: kubeadm upgrade apply --dry-run",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
// TODO: Run preflight checks for diff to check that the manifests already exist.
|
// TODO: Run preflight checks for diff to check that the manifests already exist.
|
||||||
kubeadmutil.CheckErr(runDiff(flags, args))
|
return runDiff(flags, args)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases/workflow"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
kubeadmconstants "k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -70,9 +69,8 @@ func NewCmdNode() *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "node",
|
Use: "node",
|
||||||
Short: "Upgrade commands for a node in the cluster",
|
Short: "Upgrade commands for a node in the cluster",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
err := nodeRunner.Run(args)
|
return nodeRunner.Run(args)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
Args: cobra.NoArgs,
|
Args: cobra.NoArgs,
|
||||||
}
|
}
|
||||||
@ -207,16 +205,15 @@ func NewCmdUpgradeNodeConfig() *cobra.Command {
|
|||||||
Use: "config",
|
Use: "config",
|
||||||
Short: "Download the kubelet configuration from the cluster ConfigMap kubelet-config-1.X, where X is the minor version of the kubelet",
|
Short: "Download the kubelet configuration from the cluster ConfigMap kubelet-config-1.X, where X is the minor version of the kubelet",
|
||||||
Deprecated: "use \"kubeadm upgrade node\" instead",
|
Deprecated: "use \"kubeadm upgrade node\" instead",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
// This is required for preserving the old behavior of `kubeadm upgrade node config`.
|
// This is required for preserving the old behavior of `kubeadm upgrade node config`.
|
||||||
// The new implementation exposed as a phase under `kubeadm upgrade node` infers the target
|
// The new implementation exposed as a phase under `kubeadm upgrade node` infers the target
|
||||||
// kubelet config version from the kubeadm-config ConfigMap
|
// kubelet config version from the kubeadm-config ConfigMap
|
||||||
if len(nodeOptions.kubeletVersion) == 0 {
|
if len(nodeOptions.kubeletVersion) == 0 {
|
||||||
kubeadmutil.CheckErr(errors.New("the --kubelet-version argument is required"))
|
return errors.New("the --kubelet-version argument is required")
|
||||||
}
|
}
|
||||||
|
|
||||||
err := nodeRunner.Run(args)
|
return nodeRunner.Run(args)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +30,6 @@ import (
|
|||||||
"k8s.io/klog"
|
"k8s.io/klog"
|
||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
etcdutil "k8s.io/kubernetes/cmd/kubeadm/app/util/etcd"
|
etcdutil "k8s.io/kubernetes/cmd/kubeadm/app/util/etcd"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -47,12 +46,13 @@ func NewCmdPlan(apf *applyPlanFlags) *cobra.Command {
|
|||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "plan [version] [flags]",
|
Use: "plan [version] [flags]",
|
||||||
Short: "Check which versions are available to upgrade to and validate whether your current cluster is upgradeable. To skip the internet check, pass in the optional [version] parameter",
|
Short: "Check which versions are available to upgrade to and validate whether your current cluster is upgradeable. To skip the internet check, pass in the optional [version] parameter",
|
||||||
Run: func(_ *cobra.Command, args []string) {
|
RunE: func(_ *cobra.Command, args []string) error {
|
||||||
userVersion, err := getK8sVersionFromUserInput(flags.applyPlanFlags, args, false)
|
userVersion, err := getK8sVersionFromUserInput(flags.applyPlanFlags, args, false)
|
||||||
kubeadmutil.CheckErr(err)
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
err = runPlan(flags, userVersion)
|
return runPlan(flags, userVersion)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -27,7 +27,6 @@ import (
|
|||||||
"sigs.k8s.io/yaml"
|
"sigs.k8s.io/yaml"
|
||||||
|
|
||||||
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
apimachineryversion "k8s.io/apimachinery/pkg/version"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/version"
|
"k8s.io/kubernetes/cmd/kubeadm/app/version"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -41,9 +40,8 @@ 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",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
RunE: func(cmd *cobra.Command, args []string) error {
|
||||||
err := RunVersion(out, cmd)
|
return RunVersion(out, cmd)
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
cmd.Flags().StringP("output", "o", "", "Output format; available options are 'yaml', 'json' and 'short'")
|
cmd.Flags().StringP("output", "o", "", "Output format; available options are 'yaml', 'json' and 'short'")
|
||||||
|
Loading…
Reference in New Issue
Block a user