From 5cf9291e025baf3efa13e8ef73dcfa7fb46ee925 Mon Sep 17 00:00:00 2001 From: xiangpengzhao Date: Tue, 17 Apr 2018 16:23:39 +0800 Subject: [PATCH] Set kubeadm version as the default version in phase command. --- cmd/kubeadm/app/cmd/config.go | 7 +++++ cmd/kubeadm/app/cmd/phases/bootstraptoken.go | 18 +++++------ cmd/kubeadm/app/cmd/phases/certs.go | 23 ++++++++------ cmd/kubeadm/app/cmd/phases/etcd.go | 9 +----- cmd/kubeadm/app/cmd/phases/kubeconfig.go | 9 +----- cmd/kubeadm/app/cmd/phases/kubelet.go | 16 ++++++++-- cmd/kubeadm/app/cmd/phases/markmaster.go | 18 +++++------ cmd/kubeadm/app/cmd/phases/selfhosting.go | 13 +++++--- cmd/kubeadm/app/cmd/phases/uploadconfig.go | 10 ++++-- cmd/kubeadm/app/cmd/phases/util.go | 33 +++++++++++++++++++- cmd/kubeadm/app/cmd/token.go | 13 +++++--- cmd/kubeadm/app/cmd/token_test.go | 2 +- 12 files changed, 112 insertions(+), 59 deletions(-) diff --git a/cmd/kubeadm/app/cmd/config.go b/cmd/kubeadm/app/cmd/config.go index 9c5fd1f030e69..80a76bd3cf959 100644 --- a/cmd/kubeadm/app/cmd/config.go +++ b/cmd/kubeadm/app/cmd/config.go @@ -34,6 +34,7 @@ import ( kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme" kubeadmapiv1alpha2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha2" kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3" + phaseutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases" cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util" "k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs" "k8s.io/kubernetes/cmd/kubeadm/app/constants" @@ -368,6 +369,12 @@ func RunConfigView(out io.Writer, client clientset.Interface) error { // uploadConfiguration handles the uploading of the configuration internally func uploadConfiguration(client clientset.Interface, cfgPath string, defaultcfg *kubeadmapiv1alpha3.InitConfiguration) error { + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err := phaseutil.SetKubernetesVersion(client, defaultcfg) + if err != nil { + return err + } // Default both statically and dynamically, convert to internal API type, and validate everything // First argument is unset here as we shouldn't load a config file from disk diff --git a/cmd/kubeadm/app/cmd/phases/bootstraptoken.go b/cmd/kubeadm/app/cmd/phases/bootstraptoken.go index 53fbd6e57a25c..f9ff7412ce6b2 100644 --- a/cmd/kubeadm/app/cmd/phases/bootstraptoken.go +++ b/cmd/kubeadm/app/cmd/phases/bootstraptoken.go @@ -107,11 +107,7 @@ func NewCmdBootstrapToken() *cobra.Command { // NewSubCmdBootstrapTokenAll returns the Cobra command for running the token all sub-phase func NewSubCmdBootstrapTokenAll(kubeConfigFile *string) *cobra.Command { - cfg := &kubeadmapiv1alpha3.InitConfiguration{ - // KubernetesVersion is not used by bootstrap-token, but we set this explicitly to avoid - // the lookup of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig - KubernetesVersion: "v1.10.0", - } + cfg := &kubeadmapiv1alpha3.InitConfiguration{} // Default values for the cobra help text kubeadmscheme.Scheme.Default(cfg) @@ -174,11 +170,7 @@ func NewSubCmdBootstrapTokenAll(kubeConfigFile *string) *cobra.Command { // NewSubCmdBootstrapToken returns the Cobra command for running the create token phase func NewSubCmdBootstrapToken(kubeConfigFile *string) *cobra.Command { - cfg := &kubeadmapiv1alpha3.InitConfiguration{ - // KubernetesVersion is not used by bootstrap-token, but we set this explicitly to avoid - // the lookup of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig - KubernetesVersion: "v1.10.0", - } + cfg := &kubeadmapiv1alpha3.InitConfiguration{} // Default values for the cobra help text kubeadmscheme.Scheme.Default(cfg) @@ -307,6 +299,12 @@ func addGenericFlags(flagSet *pflag.FlagSet, cfgPath *string, skipTokenPrint *bo } func createBootstrapToken(kubeConfigFile string, client clientset.Interface, cfgPath string, cfg *kubeadmapiv1alpha3.InitConfiguration, skipTokenPrint bool) error { + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err := SetKubernetesVersion(client, cfg) + if err != nil { + return err + } // 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.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) diff --git a/cmd/kubeadm/app/cmd/phases/certs.go b/cmd/kubeadm/app/cmd/phases/certs.go index c7391506e16fa..8a3681adc966d 100644 --- a/cmd/kubeadm/app/cmd/phases/certs.go +++ b/cmd/kubeadm/app/cmd/phases/certs.go @@ -150,13 +150,6 @@ func getCertsSubCommands(defaultKubernetesVersion string) []*cobra.Command { cfg := &kubeadmapiv1alpha3.InitConfiguration{} - // This is used for unit testing only... - // If we wouldn't set this to something, the code would dynamically look up the version from the internet - // By setting this explicitly for tests workarounds that - if defaultKubernetesVersion != "" { - cfg.KubernetesVersion = defaultKubernetesVersion - } - // Default values for the cobra help text kubeadmscheme.Scheme.Default(cfg) @@ -252,7 +245,7 @@ func getCertsSubCommands(defaultKubernetesVersion string) []*cobra.Command { Short: properties.short, Long: properties.long, Example: properties.examples, - Run: runCmdFunc(properties.cmdFunc, &cfgPath, cfg), + Run: runCmdFunc(properties.cmdFunc, &cfgPath, cfg, defaultKubernetesVersion), } // Add flags to the command @@ -272,7 +265,7 @@ func getCertsSubCommands(defaultKubernetesVersion string) []*cobra.Command { } // runCmdFunc creates a cobra.Command Run function, by composing the call to the given cmdFunc with necessary additional steps (e.g preparation of input parameters) -func runCmdFunc(cmdFunc func(cfg *kubeadmapi.InitConfiguration) error, cfgPath *string, cfg *kubeadmapiv1alpha3.InitConfiguration) func(cmd *cobra.Command, args []string) { +func runCmdFunc(cmdFunc func(cfg *kubeadmapi.InitConfiguration) error, cfgPath *string, cfg *kubeadmapiv1alpha3.InitConfiguration, defaultKubernetesVersion string) func(cmd *cobra.Command, args []string) { // the following statement build a closure that wraps a call to a cmdFunc, binding // the function itself with the specific parameters of each sub command. @@ -284,6 +277,18 @@ func runCmdFunc(cmdFunc func(cfg *kubeadmapi.InitConfiguration) error, cfgPath * kubeadmutil.CheckErr(err) } + // This is used for unit testing only... + // If we wouldn't set this to something, the code would dynamically look up the version from the internet + // By setting this explicitly for tests workarounds that + if defaultKubernetesVersion != "" { + cfg.KubernetesVersion = defaultKubernetesVersion + } else { + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err := SetKubernetesVersion(nil, cfg) + kubeadmutil.CheckErr(err) + } + // 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.ConfigFileAndDefaultsToInternalConfig(*cfgPath, cfg) kubeadmutil.CheckErr(err) diff --git a/cmd/kubeadm/app/cmd/phases/etcd.go b/cmd/kubeadm/app/cmd/phases/etcd.go index 02c2ef0fc648f..74121a06aacba 100644 --- a/cmd/kubeadm/app/cmd/phases/etcd.go +++ b/cmd/kubeadm/app/cmd/phases/etcd.go @@ -63,13 +63,6 @@ func getEtcdSubCommands(outDir, defaultKubernetesVersion string) []*cobra.Comman cfg := &kubeadmapiv1alpha3.InitConfiguration{} - // This is used for unit testing only... - // If we wouldn't set this to something, the code would dynamically look up the version from the internet - // By setting this explicitly for tests workarounds that - if defaultKubernetesVersion != "" { - cfg.KubernetesVersion = defaultKubernetesVersion - } - // Default values for the cobra help text kubeadmscheme.Scheme.Default(cfg) @@ -96,7 +89,7 @@ func getEtcdSubCommands(outDir, defaultKubernetesVersion string) []*cobra.Comman Short: properties.short, Long: properties.long, Example: properties.examples, - Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg), + Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg, defaultKubernetesVersion), } // Add flags to the command diff --git a/cmd/kubeadm/app/cmd/phases/kubeconfig.go b/cmd/kubeadm/app/cmd/phases/kubeconfig.go index 351a1adcac625..f349872d54c54 100644 --- a/cmd/kubeadm/app/cmd/phases/kubeconfig.go +++ b/cmd/kubeadm/app/cmd/phases/kubeconfig.go @@ -92,13 +92,6 @@ func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion st cfg := &kubeadmapiv1alpha3.InitConfiguration{} - // This is used for unit testing only... - // If we wouldn't set this to something, the code would dynamically look up the version from the internet - // By setting this explicitly for tests workarounds that - if defaultKubernetesVersion != "" { - cfg.KubernetesVersion = defaultKubernetesVersion - } - // Default values for the cobra help text kubeadmscheme.Scheme.Default(cfg) @@ -172,7 +165,7 @@ func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion st Short: properties.short, Long: properties.long, Example: properties.examples, - Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg), + Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg, defaultKubernetesVersion), } // Add flags to the command diff --git a/cmd/kubeadm/app/cmd/phases/kubelet.go b/cmd/kubeadm/app/cmd/phases/kubelet.go index 91c87dd855c45..1bb6127a01ddb 100644 --- a/cmd/kubeadm/app/cmd/phases/kubelet.go +++ b/cmd/kubeadm/app/cmd/phases/kubelet.go @@ -181,6 +181,7 @@ func NewCmdKubeletConfig() *cobra.Command { // NewCmdKubeletConfigUpload calls cobra.Command for uploading dynamic kubelet configuration func NewCmdKubeletConfigUpload() *cobra.Command { + cfg := &kubeadmapiv1alpha3.InitConfiguration{} var cfgPath string kubeConfigFile := constants.GetAdminKubeConfigPath() @@ -194,8 +195,13 @@ func NewCmdKubeletConfigUpload() *cobra.Command { kubeadmutil.CheckErr(fmt.Errorf("The --config argument is required")) } + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err := SetKubernetesVersion(nil, cfg) + kubeadmutil.CheckErr(err) + // This call returns the ready-to-use configuration based on the configuration file - internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, &kubeadmapiv1alpha3.InitConfiguration{}) + internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) kubeadmutil.CheckErr(err) client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) @@ -248,6 +254,7 @@ func getKubeletVersion(kubeletVersionStr string) (*version.Version, error) { // NewCmdKubeletConfigWriteToDisk calls cobra.Command for writing init kubelet configuration func NewCmdKubeletConfigWriteToDisk() *cobra.Command { + cfg := &kubeadmapiv1alpha3.InitConfiguration{} var cfgPath string cmd := &cobra.Command{ Use: "write-to-disk", @@ -259,8 +266,13 @@ func NewCmdKubeletConfigWriteToDisk() *cobra.Command { kubeadmutil.CheckErr(fmt.Errorf("The --config argument is required")) } + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err := SetKubernetesVersion(nil, cfg) + kubeadmutil.CheckErr(err) + // This call returns the ready-to-use configuration based on the configuration file - internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, &kubeadmapiv1alpha3.InitConfiguration{}) + internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) kubeadmutil.CheckErr(err) err = kubeletphase.WriteConfigToDisk(internalcfg.ComponentConfigs.Kubelet, constants.KubeletRunDirectory) diff --git a/cmd/kubeadm/app/cmd/phases/markmaster.go b/cmd/kubeadm/app/cmd/phases/markmaster.go index dd569365d1001..2780830734de8 100644 --- a/cmd/kubeadm/app/cmd/phases/markmaster.go +++ b/cmd/kubeadm/app/cmd/phases/markmaster.go @@ -46,12 +46,7 @@ var ( // NewCmdMarkMaster returns the Cobra command for running the mark-master phase func NewCmdMarkMaster() *cobra.Command { - - cfg := &kubeadmapiv1alpha3.InitConfiguration{ - // KubernetesVersion is not used by mark master, but we set this explicitly to avoid - // the lookup of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig - KubernetesVersion: "v1.10.0", - } + cfg := &kubeadmapiv1alpha3.InitConfiguration{} // Default values for the cobra help text kubeadmscheme.Scheme.Default(cfg) @@ -68,11 +63,16 @@ func NewCmdMarkMaster() *cobra.Command { kubeadmutil.CheckErr(err) } - // 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.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) + client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) kubeadmutil.CheckErr(err) - client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err = SetKubernetesVersion(client, cfg) + kubeadmutil.CheckErr(err) + + // 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.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) kubeadmutil.CheckErr(err) err = markmasterphase.MarkMaster(client, internalcfg.NodeRegistration.Name, internalcfg.NodeRegistration.Taints) diff --git a/cmd/kubeadm/app/cmd/phases/selfhosting.go b/cmd/kubeadm/app/cmd/phases/selfhosting.go index 6176e08ddd849..d627436f19cf5 100644 --- a/cmd/kubeadm/app/cmd/phases/selfhosting.go +++ b/cmd/kubeadm/app/cmd/phases/selfhosting.go @@ -93,14 +93,19 @@ func getSelfhostingSubCommand() *cobra.Command { kubeadmutil.CheckErr(err) } - // 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.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) - kubeadmutil.CheckErr(err) - // Gets the kubernetes client client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) kubeadmutil.CheckErr(err) + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err = SetKubernetesVersion(client, cfg) + kubeadmutil.CheckErr(err) + + // 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.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) + kubeadmutil.CheckErr(err) + // Converts the Static Pod-hosted control plane into a self-hosted one waiter := apiclient.NewKubeWaiter(client, 2*time.Minute, os.Stdout) err = selfhosting.CreateSelfHostedControlPlane(constants.GetStaticPodDirectory(), constants.KubernetesDir, internalcfg, client, waiter, false) diff --git a/cmd/kubeadm/app/cmd/phases/uploadconfig.go b/cmd/kubeadm/app/cmd/phases/uploadconfig.go index e496a1b079954..9a8c1b8f2475b 100644 --- a/cmd/kubeadm/app/cmd/phases/uploadconfig.go +++ b/cmd/kubeadm/app/cmd/phases/uploadconfig.go @@ -48,7 +48,9 @@ var ( // NewCmdUploadConfig returns the Cobra command for running the uploadconfig phase func NewCmdUploadConfig() *cobra.Command { + cfg := &kubeadmapiv1alpha3.InitConfiguration{} var cfgPath, kubeConfigFile string + cmd := &cobra.Command{ Use: "upload-config", Short: "Uploads the currently used configuration for kubeadm to a ConfigMap", @@ -62,8 +64,12 @@ func NewCmdUploadConfig() *cobra.Command { client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile) kubeadmutil.CheckErr(err) - defaultcfg := &kubeadmapiv1alpha3.InitConfiguration{} - internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, defaultcfg) + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err = SetKubernetesVersion(client, cfg) + kubeadmutil.CheckErr(err) + + internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) kubeadmutil.CheckErr(err) err = uploadconfig.UploadConfiguration(internalcfg, client) diff --git a/cmd/kubeadm/app/cmd/phases/util.go b/cmd/kubeadm/app/cmd/phases/util.go index 1886be311b9a4..efa5c0acd8165 100644 --- a/cmd/kubeadm/app/cmd/phases/util.go +++ b/cmd/kubeadm/app/cmd/phases/util.go @@ -17,17 +17,21 @@ limitations under the License. package phases import ( + "os" + "github.com/spf13/cobra" + clientset "k8s.io/client-go/kubernetes" kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm" kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3" "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation" + "k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade" kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" configutil "k8s.io/kubernetes/cmd/kubeadm/app/util/config" ) // runCmdPhase creates a cobra.Command Run function, by composing the call to the given cmdFunc with necessary additional steps (e.g preparation of input parameters) -func runCmdPhase(cmdFunc func(outDir string, cfg *kubeadmapi.InitConfiguration) error, outDir, cfgPath *string, cfg *kubeadmapiv1alpha3.InitConfiguration) func(cmd *cobra.Command, args []string) { +func runCmdPhase(cmdFunc func(outDir string, cfg *kubeadmapi.InitConfiguration) error, outDir, cfgPath *string, cfg *kubeadmapiv1alpha3.InitConfiguration, defaultKubernetesVersion string) func(cmd *cobra.Command, args []string) { // the following statement build a closure that wraps a call to a cmdFunc, binding // the function itself with the specific parameters of each sub command. @@ -39,6 +43,18 @@ func runCmdPhase(cmdFunc func(outDir string, cfg *kubeadmapi.InitConfiguration) kubeadmutil.CheckErr(err) } + // This is used for unit testing only... + // If we wouldn't set this to something, the code would dynamically look up the version from the internet + // By setting this explicitly for tests workarounds that + if defaultKubernetesVersion != "" { + cfg.KubernetesVersion = defaultKubernetesVersion + } else { + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err := SetKubernetesVersion(nil, cfg) + kubeadmutil.CheckErr(err) + } + // 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.ConfigFileAndDefaultsToInternalConfig(*cfgPath, cfg) kubeadmutil.CheckErr(err) @@ -48,3 +64,18 @@ func runCmdPhase(cmdFunc func(outDir string, cfg *kubeadmapi.InitConfiguration) kubeadmutil.CheckErr(err) } } + +// SetKubernetesVersion gets current Kubeadm version and sets it as Kubernetes version of master configuration if not set. +func SetKubernetesVersion(client clientset.Interface, cfg *kubeadmapiv1alpha3.InitConfiguration) error { + if cfg.KubernetesVersion != "" { + return nil + } + + kubeadmVer, _, err := upgrade.NewKubeVersionGetter(client, os.Stdout).KubeadmVersion() + if err != nil { + return err + } + cfg.KubernetesVersion = kubeadmVer + + return nil +} diff --git a/cmd/kubeadm/app/cmd/token.go b/cmd/kubeadm/app/cmd/token.go index d3f99cb541d78..61330e02da755 100644 --- a/cmd/kubeadm/app/cmd/token.go +++ b/cmd/kubeadm/app/cmd/token.go @@ -40,6 +40,7 @@ import ( kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3" "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/validation" "k8s.io/kubernetes/cmd/kubeadm/app/cmd/options" + phaseutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/phases" cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util" tokenphase "k8s.io/kubernetes/cmd/kubeadm/app/phases/bootstraptoken/node" kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util" @@ -89,11 +90,7 @@ func NewCmdToken(out io.Writer, errW io.Writer) *cobra.Command { tokenCmd.PersistentFlags().BoolVar(&dryRun, "dry-run", dryRun, "Whether to enable dry-run mode or not") - cfg := &kubeadmapiv1alpha3.InitConfiguration{ - // KubernetesVersion is not used by bootstrap-token, but we set this explicitly to avoid - // the lookup of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig - KubernetesVersion: "v1.10.0", - } + cfg := &kubeadmapiv1alpha3.InitConfiguration{} // Default values for the cobra help text kubeadmscheme.Scheme.Default(cfg) @@ -215,6 +212,12 @@ func NewCmdTokenGenerate(out io.Writer) *cobra.Command { // RunCreateToken generates a new bootstrap token and stores it as a secret on the server. func RunCreateToken(out io.Writer, client clientset.Interface, cfgPath string, cfg *kubeadmapiv1alpha3.InitConfiguration, printJoinCommand bool, kubeConfigFile string) error { + // KubernetesVersion is not used, but we set it explicitly to avoid the lookup + // of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig + err := phaseutil.SetKubernetesVersion(client, cfg) + if err != nil { + return err + } // 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 glog.V(1).Infoln("[token] loading configurations") internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg) diff --git a/cmd/kubeadm/app/cmd/token_test.go b/cmd/kubeadm/app/cmd/token_test.go index 692e8ba4f307c..16517e1e331ae 100644 --- a/cmd/kubeadm/app/cmd/token_test.go +++ b/cmd/kubeadm/app/cmd/token_test.go @@ -180,7 +180,7 @@ func TestRunCreateToken(t *testing.T) { cfg := &kubeadmapiv1alpha3.InitConfiguration{ - // KubernetesVersion is not used by bootstrap-token, but we set this explicitly to avoid + // KubernetesVersion is not used, but we set this explicitly to avoid // the lookup of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig KubernetesVersion: "v1.10.0", BootstrapTokens: []kubeadmapiv1alpha3.BootstrapToken{