mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-24 20:24:09 +00:00
Merge pull request #62721 from xiangpengzhao/phase-version
Automatic merge from submit-queue (batch tested with PRs 66984, 67236, 67216, 62721, 67106). If you want to cherry-pick this change to another branch, please follow the instructions <a href="https://github.com/kubernetes/community/blob/master/contributors/devel/cherry-picks.md">here</a>. Set kubeadm version as the default version in phase command. **What this PR does / why we need it**: In some phase commands which don't use kubernetes version, set kubeadm version as the kubernetes version to avoid get it from internet. **Which issue(s) this PR fixes** *(optional, in `fixes #<issue number>(, fixes #<issue_number>, ...)` format, will close the issue(s) when PR gets merged)*: Fixes https://github.com/kubernetes/kubeadm/issues/756 **Special notes for your reviewer**: cc @chrisob **Release note**: ```release-note NONE ```
This commit is contained in:
commit
9fdffd1e57
@ -34,6 +34,7 @@ import (
|
|||||||
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
|
kubeadmscheme "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/scheme"
|
||||||
kubeadmapiv1alpha2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha2"
|
kubeadmapiv1alpha2 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha2"
|
||||||
kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
|
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"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
|
"k8s.io/kubernetes/cmd/kubeadm/app/componentconfigs"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/constants"
|
"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
|
// uploadConfiguration handles the uploading of the configuration internally
|
||||||
func uploadConfiguration(client clientset.Interface, cfgPath string, defaultcfg *kubeadmapiv1alpha3.InitConfiguration) error {
|
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
|
// 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
|
// First argument is unset here as we shouldn't load a config file from disk
|
||||||
|
@ -39,6 +39,7 @@ go_library(
|
|||||||
"//cmd/kubeadm/app/phases/kubelet:go_default_library",
|
"//cmd/kubeadm/app/phases/kubelet:go_default_library",
|
||||||
"//cmd/kubeadm/app/phases/markmaster:go_default_library",
|
"//cmd/kubeadm/app/phases/markmaster:go_default_library",
|
||||||
"//cmd/kubeadm/app/phases/selfhosting:go_default_library",
|
"//cmd/kubeadm/app/phases/selfhosting:go_default_library",
|
||||||
|
"//cmd/kubeadm/app/phases/upgrade: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:go_default_library",
|
||||||
|
@ -107,11 +107,7 @@ func NewCmdBootstrapToken() *cobra.Command {
|
|||||||
|
|
||||||
// NewSubCmdBootstrapTokenAll returns the Cobra command for running the token all sub-phase
|
// NewSubCmdBootstrapTokenAll returns the Cobra command for running the token all sub-phase
|
||||||
func NewSubCmdBootstrapTokenAll(kubeConfigFile *string) *cobra.Command {
|
func NewSubCmdBootstrapTokenAll(kubeConfigFile *string) *cobra.Command {
|
||||||
cfg := &kubeadmapiv1alpha3.InitConfiguration{
|
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",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default values for the cobra help text
|
// Default values for the cobra help text
|
||||||
kubeadmscheme.Scheme.Default(cfg)
|
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
|
// NewSubCmdBootstrapToken returns the Cobra command for running the create token phase
|
||||||
func NewSubCmdBootstrapToken(kubeConfigFile *string) *cobra.Command {
|
func NewSubCmdBootstrapToken(kubeConfigFile *string) *cobra.Command {
|
||||||
cfg := &kubeadmapiv1alpha3.InitConfiguration{
|
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",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default values for the cobra help text
|
// Default values for the cobra help text
|
||||||
kubeadmscheme.Scheme.Default(cfg)
|
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 {
|
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
|
// 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)
|
internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg)
|
||||||
|
@ -150,13 +150,6 @@ func getCertsSubCommands(defaultKubernetesVersion string) []*cobra.Command {
|
|||||||
|
|
||||||
cfg := &kubeadmapiv1alpha3.InitConfiguration{}
|
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
|
// Default values for the cobra help text
|
||||||
kubeadmscheme.Scheme.Default(cfg)
|
kubeadmscheme.Scheme.Default(cfg)
|
||||||
|
|
||||||
@ -252,7 +245,7 @@ func getCertsSubCommands(defaultKubernetesVersion string) []*cobra.Command {
|
|||||||
Short: properties.short,
|
Short: properties.short,
|
||||||
Long: properties.long,
|
Long: properties.long,
|
||||||
Example: properties.examples,
|
Example: properties.examples,
|
||||||
Run: runCmdFunc(properties.cmdFunc, &cfgPath, cfg),
|
Run: runCmdFunc(properties.cmdFunc, &cfgPath, cfg, defaultKubernetesVersion),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add flags to the command
|
// 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)
|
// 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 following statement build a closure that wraps a call to a cmdFunc, binding
|
||||||
// the function itself with the specific parameters of each sub command.
|
// 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)
|
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
|
// 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)
|
internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(*cfgPath, cfg)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
@ -63,13 +63,6 @@ func getEtcdSubCommands(outDir, defaultKubernetesVersion string) []*cobra.Comman
|
|||||||
|
|
||||||
cfg := &kubeadmapiv1alpha3.InitConfiguration{}
|
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
|
// Default values for the cobra help text
|
||||||
kubeadmscheme.Scheme.Default(cfg)
|
kubeadmscheme.Scheme.Default(cfg)
|
||||||
|
|
||||||
@ -96,7 +89,7 @@ func getEtcdSubCommands(outDir, defaultKubernetesVersion string) []*cobra.Comman
|
|||||||
Short: properties.short,
|
Short: properties.short,
|
||||||
Long: properties.long,
|
Long: properties.long,
|
||||||
Example: properties.examples,
|
Example: properties.examples,
|
||||||
Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg),
|
Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg, defaultKubernetesVersion),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add flags to the command
|
// Add flags to the command
|
||||||
|
@ -92,13 +92,6 @@ func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion st
|
|||||||
|
|
||||||
cfg := &kubeadmapiv1alpha3.InitConfiguration{}
|
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
|
// Default values for the cobra help text
|
||||||
kubeadmscheme.Scheme.Default(cfg)
|
kubeadmscheme.Scheme.Default(cfg)
|
||||||
|
|
||||||
@ -172,7 +165,7 @@ func getKubeConfigSubCommands(out io.Writer, outDir, defaultKubernetesVersion st
|
|||||||
Short: properties.short,
|
Short: properties.short,
|
||||||
Long: properties.long,
|
Long: properties.long,
|
||||||
Example: properties.examples,
|
Example: properties.examples,
|
||||||
Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg),
|
Run: runCmdPhase(properties.cmdFunc, &outDir, &cfgPath, cfg, defaultKubernetesVersion),
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add flags to the command
|
// Add flags to the command
|
||||||
|
@ -185,6 +185,7 @@ func NewCmdKubeletConfig() *cobra.Command {
|
|||||||
|
|
||||||
// NewCmdKubeletConfigUpload calls cobra.Command for uploading dynamic kubelet configuration
|
// NewCmdKubeletConfigUpload calls cobra.Command for uploading dynamic kubelet configuration
|
||||||
func NewCmdKubeletConfigUpload() *cobra.Command {
|
func NewCmdKubeletConfigUpload() *cobra.Command {
|
||||||
|
cfg := &kubeadmapiv1alpha3.InitConfiguration{}
|
||||||
var cfgPath string
|
var cfgPath string
|
||||||
kubeConfigFile := constants.GetAdminKubeConfigPath()
|
kubeConfigFile := constants.GetAdminKubeConfigPath()
|
||||||
|
|
||||||
@ -198,8 +199,13 @@ func NewCmdKubeletConfigUpload() *cobra.Command {
|
|||||||
kubeadmutil.CheckErr(fmt.Errorf("The --config argument is required"))
|
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
|
// 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)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
||||||
@ -252,6 +258,7 @@ func getKubeletVersion(kubeletVersionStr string) (*version.Version, error) {
|
|||||||
|
|
||||||
// NewCmdKubeletConfigWriteToDisk calls cobra.Command for writing init kubelet configuration
|
// NewCmdKubeletConfigWriteToDisk calls cobra.Command for writing init kubelet configuration
|
||||||
func NewCmdKubeletConfigWriteToDisk() *cobra.Command {
|
func NewCmdKubeletConfigWriteToDisk() *cobra.Command {
|
||||||
|
cfg := &kubeadmapiv1alpha3.InitConfiguration{}
|
||||||
var cfgPath string
|
var cfgPath string
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "write-to-disk",
|
Use: "write-to-disk",
|
||||||
@ -263,8 +270,13 @@ func NewCmdKubeletConfigWriteToDisk() *cobra.Command {
|
|||||||
kubeadmutil.CheckErr(fmt.Errorf("The --config argument is required"))
|
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
|
// 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)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
err = kubeletphase.WriteConfigToDisk(internalcfg.ComponentConfigs.Kubelet, constants.KubeletRunDirectory)
|
err = kubeletphase.WriteConfigToDisk(internalcfg.ComponentConfigs.Kubelet, constants.KubeletRunDirectory)
|
||||||
|
@ -46,12 +46,7 @@ var (
|
|||||||
|
|
||||||
// NewCmdMarkMaster returns the Cobra command for running the mark-master phase
|
// NewCmdMarkMaster returns the Cobra command for running the mark-master phase
|
||||||
func NewCmdMarkMaster() *cobra.Command {
|
func NewCmdMarkMaster() *cobra.Command {
|
||||||
|
cfg := &kubeadmapiv1alpha3.InitConfiguration{}
|
||||||
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",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default values for the cobra help text
|
// Default values for the cobra help text
|
||||||
kubeadmscheme.Scheme.Default(cfg)
|
kubeadmscheme.Scheme.Default(cfg)
|
||||||
@ -68,11 +63,16 @@ func NewCmdMarkMaster() *cobra.Command {
|
|||||||
kubeadmutil.CheckErr(err)
|
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
|
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
||||||
internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg)
|
|
||||||
kubeadmutil.CheckErr(err)
|
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)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
err = markmasterphase.MarkMaster(client, internalcfg.NodeRegistration.Name, internalcfg.NodeRegistration.Taints)
|
err = markmasterphase.MarkMaster(client, internalcfg.NodeRegistration.Name, internalcfg.NodeRegistration.Taints)
|
||||||
|
@ -93,14 +93,19 @@ func getSelfhostingSubCommand() *cobra.Command {
|
|||||||
kubeadmutil.CheckErr(err)
|
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
|
// Gets the kubernetes client
|
||||||
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
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
|
// 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)
|
err = selfhosting.CreateSelfHostedControlPlane(constants.GetStaticPodDirectory(), constants.KubernetesDir, internalcfg, client, waiter, false)
|
||||||
|
@ -48,7 +48,9 @@ var (
|
|||||||
|
|
||||||
// NewCmdUploadConfig returns the Cobra command for running the uploadconfig phase
|
// NewCmdUploadConfig returns the Cobra command for running the uploadconfig phase
|
||||||
func NewCmdUploadConfig() *cobra.Command {
|
func NewCmdUploadConfig() *cobra.Command {
|
||||||
|
cfg := &kubeadmapiv1alpha3.InitConfiguration{}
|
||||||
var cfgPath, kubeConfigFile string
|
var cfgPath, kubeConfigFile string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "upload-config",
|
Use: "upload-config",
|
||||||
Short: "Uploads the currently used configuration for kubeadm to a ConfigMap",
|
Short: "Uploads the currently used configuration for kubeadm to a ConfigMap",
|
||||||
@ -62,8 +64,12 @@ func NewCmdUploadConfig() *cobra.Command {
|
|||||||
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
client, err := kubeconfigutil.ClientSetFromFile(kubeConfigFile)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
defaultcfg := &kubeadmapiv1alpha3.InitConfiguration{}
|
// KubernetesVersion is not used, but we set it explicitly to avoid the lookup
|
||||||
internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, defaultcfg)
|
// 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)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
err = uploadconfig.UploadConfiguration(internalcfg, client)
|
err = uploadconfig.UploadConfiguration(internalcfg, client)
|
||||||
|
@ -17,17 +17,21 @@ limitations under the License.
|
|||||||
package phases
|
package phases
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
|
|
||||||
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
kubeadmapi "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm"
|
||||||
kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
|
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/apis/kubeadm/validation"
|
||||||
|
"k8s.io/kubernetes/cmd/kubeadm/app/phases/upgrade"
|
||||||
kubeadmutil "k8s.io/kubernetes/cmd/kubeadm/app/util"
|
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
// 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)
|
// 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 following statement build a closure that wraps a call to a cmdFunc, binding
|
||||||
// the function itself with the specific parameters of each sub command.
|
// 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)
|
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
|
// 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)
|
internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(*cfgPath, cfg)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
@ -48,3 +64,18 @@ func runCmdPhase(cmdFunc func(outDir string, cfg *kubeadmapi.InitConfiguration)
|
|||||||
kubeadmutil.CheckErr(err)
|
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
|
||||||
|
}
|
||||||
|
@ -40,6 +40,7 @@ import (
|
|||||||
kubeadmapiv1alpha3 "k8s.io/kubernetes/cmd/kubeadm/app/apis/kubeadm/v1alpha3"
|
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/apis/kubeadm/validation"
|
||||||
"k8s.io/kubernetes/cmd/kubeadm/app/cmd/options"
|
"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"
|
cmdutil "k8s.io/kubernetes/cmd/kubeadm/app/cmd/util"
|
||||||
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"
|
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,
|
tokenCmd.PersistentFlags().BoolVar(&dryRun,
|
||||||
"dry-run", dryRun, "Whether to enable dry-run mode or not")
|
"dry-run", dryRun, "Whether to enable dry-run mode or not")
|
||||||
|
|
||||||
cfg := &kubeadmapiv1alpha3.InitConfiguration{
|
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",
|
|
||||||
}
|
|
||||||
|
|
||||||
// Default values for the cobra help text
|
// Default values for the cobra help text
|
||||||
kubeadmscheme.Scheme.Default(cfg)
|
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.
|
// 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 {
|
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
|
// 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")
|
glog.V(1).Infoln("[token] loading configurations")
|
||||||
internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg)
|
internalcfg, err := configutil.ConfigFileAndDefaultsToInternalConfig(cfgPath, cfg)
|
||||||
|
@ -180,7 +180,7 @@ func TestRunCreateToken(t *testing.T) {
|
|||||||
|
|
||||||
cfg := &kubeadmapiv1alpha3.InitConfiguration{
|
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
|
// the lookup of the version from the internet when executing ConfigFileAndDefaultsToInternalConfig
|
||||||
KubernetesVersion: "v1.10.0",
|
KubernetesVersion: "v1.10.0",
|
||||||
BootstrapTokens: []kubeadmapiv1alpha3.BootstrapToken{
|
BootstrapTokens: []kubeadmapiv1alpha3.BootstrapToken{
|
||||||
|
Loading…
Reference in New Issue
Block a user