diff --git a/cmd/kubeadm/app/apis/kubeadm/types.go b/cmd/kubeadm/app/apis/kubeadm/types.go index d641ecc6e6..aa2171e2eb 100644 --- a/cmd/kubeadm/app/apis/kubeadm/types.go +++ b/cmd/kubeadm/app/apis/kubeadm/types.go @@ -411,50 +411,3 @@ type HostPathMount struct { // PathType is the type of the HostPath. PathType v1.HostPathType } - -// CommonConfiguration defines the list of common configuration elements and the getter -// methods that must exist for both the InitConfiguration and JoinConfiguration objects. -// This is used internally to deduplicate the kubeadm preflight checks. -type CommonConfiguration interface { - GetCRISocket() string - GetNodeName() string - GetKubernetesVersion() string -} - -// GetCRISocket will return the CRISocket that is defined for the InitConfiguration. -// This is used internally to deduplicate the kubeadm preflight checks. -func (cfg *InitConfiguration) GetCRISocket() string { - return cfg.NodeRegistration.CRISocket -} - -// GetNodeName will return the NodeName that is defined for the InitConfiguration. -// This is used internally to deduplicate the kubeadm preflight checks. -func (cfg *InitConfiguration) GetNodeName() string { - return cfg.NodeRegistration.Name -} - -// GetKubernetesVersion will return the KubernetesVersion that is defined for the InitConfiguration. -// This is used internally to deduplicate the kubeadm preflight checks. -func (cfg *InitConfiguration) GetKubernetesVersion() string { - return cfg.KubernetesVersion -} - -// GetCRISocket will return the CRISocket that is defined for the JoinConfiguration. -// This is used internally to deduplicate the kubeadm preflight checks. -func (cfg *JoinConfiguration) GetCRISocket() string { - return cfg.NodeRegistration.CRISocket -} - -// GetNodeName will return the NodeName that is defined for the JoinConfiguration. -// This is used internally to deduplicate the kubeadm preflight checks. -func (cfg *JoinConfiguration) GetNodeName() string { - return cfg.NodeRegistration.Name -} - -// GetKubernetesVersion will return an empty string since KubernetesVersion is not a -// defined property for JoinConfiguration. This will just cause the regex validation -// of the defined version to be skipped during the preflight checks. -// This is used internally to deduplicate the kubeadm preflight checks. -func (cfg *JoinConfiguration) GetKubernetesVersion() string { - return "" -} diff --git a/cmd/kubeadm/app/cmd/config.go b/cmd/kubeadm/app/cmd/config.go index a87b6cd35c..520f0ff5c2 100644 --- a/cmd/kubeadm/app/cmd/config.go +++ b/cmd/kubeadm/app/cmd/config.go @@ -423,7 +423,7 @@ func NewCmdConfigImagesPull() *cobra.Command { kubeadmutil.CheckErr(err) internalcfg, err := configutil.LoadOrDefaultInitConfiguration(cfgPath, externalcfg) kubeadmutil.CheckErr(err) - containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), internalcfg.GetCRISocket()) + containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), internalcfg.NodeRegistration.CRISocket) kubeadmutil.CheckErr(err) imagesPull := NewImagesPull(containerRuntime, images.GetAllImages(&internalcfg.ClusterConfiguration)) kubeadmutil.CheckErr(imagesPull.PullAll()) diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index f0b652e41c..4f768db2cb 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -901,7 +901,7 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura } if !isSecondaryControlPlane { - checks = addCommonChecks(execer, cfg, checks) + checks = addCommonChecks(execer, cfg.KubernetesVersion, &cfg.NodeRegistration, checks) // Check IVPS required kernel module once we use IVPS kube-proxy mode if cfg.ComponentConfigs.KubeProxy != nil && cfg.ComponentConfigs.KubeProxy.Mode == ipvsutil.IPVSProxyMode { @@ -959,7 +959,7 @@ func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.JoinConfigura FileAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.KubeletKubeConfigFileName)}, FileAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.KubeletBootstrapKubeConfigFileName)}, } - checks = addCommonChecks(execer, cfg, checks) + checks = addCommonChecks(execer, "", &cfg.NodeRegistration, checks) if cfg.ControlPlane == nil { checks = append(checks, FileAvailableCheck{Path: cfg.CACertPath}) } @@ -1006,8 +1006,8 @@ func RunOptionalJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.Clust // addCommonChecks is a helper function to deplicate checks that are common between both the // kubeadm init and join commands -func addCommonChecks(execer utilsexec.Interface, cfg kubeadmapi.CommonConfiguration, checks []Checker) []Checker { - containerRuntime, err := utilruntime.NewContainerRuntime(execer, cfg.GetCRISocket()) +func addCommonChecks(execer utilsexec.Interface, k8sVersion string, nodeReg *kubeadmapi.NodeRegistrationOptions, checks []Checker) []Checker { + containerRuntime, err := utilruntime.NewContainerRuntime(execer, nodeReg.CRISocket) isDocker := false if err != nil { fmt.Printf("[preflight] WARNING: Couldn't create the interface used for talking to the container runtime: %v\n", err) @@ -1044,8 +1044,8 @@ func addCommonChecks(execer utilsexec.Interface, cfg kubeadmapi.CommonConfigurat } checks = append(checks, SystemVerificationCheck{IsDocker: isDocker}, - HostnameCheck{nodeName: cfg.GetNodeName()}, - KubeletVersionCheck{KubernetesVersion: cfg.GetKubernetesVersion(), exec: execer}, + HostnameCheck{nodeName: nodeReg.Name}, + KubeletVersionCheck{KubernetesVersion: k8sVersion, exec: execer}, ServiceCheck{Service: "kubelet", CheckIfActive: false}, PortOpenCheck{port: ports.KubeletPort}) return checks @@ -1062,7 +1062,7 @@ func RunRootCheckOnly(ignorePreflightErrors sets.String) error { // RunPullImagesCheck will pull images kubeadm needs if they are not found on the system func RunPullImagesCheck(execer utilsexec.Interface, cfg *kubeadmapi.InitConfiguration, ignorePreflightErrors sets.String) error { - containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), cfg.GetCRISocket()) + containerRuntime, err := utilruntime.NewContainerRuntime(utilsexec.New(), cfg.NodeRegistration.CRISocket) if err != nil { return err }