mirror of https://github.com/k3s-io/k3s
kubeadm: add a flag to RunInitNodeChecks to indicate sec. control-plane
Add an extra flag isSecondaryControlPlane to RunInitNodeChecks which can be used to indicate that the node we are checking is a secondary control-plane. In such a case we skip some tests that are already covered by RunJoinNodeChecks and RunOptionalJoinNodeChecks.pull/564/head
parent
feb0937fa4
commit
af9e3fcfaa
|
@ -57,7 +57,7 @@ func runPreflight(c workflow.RunData) error {
|
|||
}
|
||||
|
||||
fmt.Println("[preflight] Running pre-flight checks")
|
||||
if err := preflight.RunInitNodeChecks(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors()); err != nil {
|
||||
if err := preflight.RunInitNodeChecks(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors(), false); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ func runPreflight(c workflow.RunData) error {
|
|||
|
||||
// run kubeadm init preflight checks for checking all the prequisites
|
||||
fmt.Println("[preflight] Running pre-flight checks before initializing the new control plane instance")
|
||||
if err := preflight.RunInitNodeChecks(utilsexec.New(), initCfg, j.IgnorePreflightErrors()); err != nil {
|
||||
if err := preflight.RunInitNodeChecks(utilsexec.New(), initCfg, j.IgnorePreflightErrors(), true); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -873,10 +873,14 @@ func (ncc NumCPUCheck) Check() (warnings, errorList []error) {
|
|||
}
|
||||
|
||||
// RunInitNodeChecks executes all individual, applicable to control-plane node checks.
|
||||
func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfiguration, ignorePreflightErrors sets.String) error {
|
||||
// First, check if we're root separately from the other preflight checks and fail fast
|
||||
if err := RunRootCheckOnly(ignorePreflightErrors); err != nil {
|
||||
return err
|
||||
// The boolean flag 'isSecondaryControlPlane' controls whether we are running checks in a --join-control-plane scenario.
|
||||
// If the flag is set to true we should skip checks already executed by RunJoinNodeChecks and RunOptionalJoinNodeChecks.
|
||||
func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfiguration, ignorePreflightErrors sets.String, isSecondaryControlPlane bool) error {
|
||||
if !isSecondaryControlPlane {
|
||||
// First, check if we're root separately from the other preflight checks and fail fast
|
||||
if err := RunRootCheckOnly(ignorePreflightErrors); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
manifestsDir := filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ManifestsSubDirName)
|
||||
|
@ -895,13 +899,26 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura
|
|||
HTTPProxyCIDRCheck{Proto: "https", CIDR: cfg.Networking.ServiceSubnet},
|
||||
HTTPProxyCIDRCheck{Proto: "https", CIDR: cfg.Networking.PodSubnet},
|
||||
}
|
||||
checks = addCommonChecks(execer, cfg, checks)
|
||||
|
||||
// Check ipvs required kernel module once we use ipvs kube-proxy mode
|
||||
if cfg.ComponentConfigs.KubeProxy != nil && cfg.ComponentConfigs.KubeProxy.Mode == ipvsutil.IPVSProxyMode {
|
||||
checks = append(checks,
|
||||
ipvsutil.RequiredIPVSKernelModulesAvailableCheck{Executor: execer},
|
||||
)
|
||||
if !isSecondaryControlPlane {
|
||||
checks = addCommonChecks(execer, cfg, checks)
|
||||
|
||||
// Check IVPS required kernel module once we use IVPS kube-proxy mode
|
||||
if cfg.ComponentConfigs.KubeProxy != nil && cfg.ComponentConfigs.KubeProxy.Mode == ipvsutil.IPVSProxyMode {
|
||||
checks = append(checks,
|
||||
ipvsutil.RequiredIPVSKernelModulesAvailableCheck{Executor: execer},
|
||||
)
|
||||
}
|
||||
|
||||
// Check if Bridge-netfilter and IPv6 relevant flags are set
|
||||
if ip := net.ParseIP(cfg.LocalAPIEndpoint.AdvertiseAddress); ip != nil {
|
||||
if ip.To4() == nil && ip.To16() != nil {
|
||||
checks = append(checks,
|
||||
FileContentCheck{Path: bridgenf6, Content: []byte{'1'}},
|
||||
FileContentCheck{Path: ipv6DefaultForwarding, Content: []byte{'1'}},
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.Etcd.Local != nil {
|
||||
|
@ -927,14 +944,6 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura
|
|||
checks = append(checks, ExternalEtcdVersionCheck{Etcd: cfg.Etcd})
|
||||
}
|
||||
|
||||
if ip := net.ParseIP(cfg.LocalAPIEndpoint.AdvertiseAddress); ip != nil {
|
||||
if ip.To4() == nil && ip.To16() != nil {
|
||||
checks = append(checks,
|
||||
FileContentCheck{Path: bridgenf6, Content: []byte{'1'}},
|
||||
FileContentCheck{Path: ipv6DefaultForwarding, Content: []byte{'1'}},
|
||||
)
|
||||
}
|
||||
}
|
||||
return RunChecks(checks, os.Stderr, ignorePreflightErrors)
|
||||
}
|
||||
|
||||
|
|
|
@ -232,7 +232,7 @@ func TestRunInitNodeChecks(t *testing.T) {
|
|||
}
|
||||
for _, rt := range tests {
|
||||
// TODO: Make RunInitNodeChecks accept a ClusterConfiguration object instead of InitConfiguration
|
||||
actual := RunInitNodeChecks(exec.New(), rt.cfg, sets.NewString())
|
||||
actual := RunInitNodeChecks(exec.New(), rt.cfg, sets.NewString(), false)
|
||||
if (actual == nil) != rt.expected {
|
||||
t.Errorf(
|
||||
"failed RunInitNodeChecks:\n\texpected: %t\n\t actual: %t\n\t error: %v",
|
||||
|
|
Loading…
Reference in New Issue