diff --git a/cmd/kubeadm/app/cmd/phases/init/preflight.go b/cmd/kubeadm/app/cmd/phases/init/preflight.go index b55f02a1fb1..6fca2a7367c 100644 --- a/cmd/kubeadm/app/cmd/phases/init/preflight.go +++ b/cmd/kubeadm/app/cmd/phases/init/preflight.go @@ -62,6 +62,10 @@ func runPreflight(c workflow.RunData) error { } fmt.Println("[preflight] Running pre-flight checks") + // First, check if we're root separately from the other preflight checks and fail fast. + if err := preflight.RunRootCheckOnly(data.IgnorePreflightErrors()); err != nil { + return err + } if err := preflight.RunInitNodeChecks(utilsexec.New(), data.Cfg(), data.IgnorePreflightErrors(), false, false); err != nil { return err } diff --git a/cmd/kubeadm/app/cmd/phases/join/preflight.go b/cmd/kubeadm/app/cmd/phases/join/preflight.go index c891c85973c..2b155eb36cd 100644 --- a/cmd/kubeadm/app/cmd/phases/join/preflight.go +++ b/cmd/kubeadm/app/cmd/phases/join/preflight.go @@ -91,6 +91,10 @@ func runPreflight(c workflow.RunData) error { // Start with general checks klog.V(1).Infoln("[preflight] Running general checks") + // First, check if we're root separately from the other preflight checks and fail fast. + if err := preflight.RunRootCheckOnly(j.IgnorePreflightErrors()); err != nil { + return err + } if err := preflight.RunJoinNodeChecks(utilsexec.New(), j.Cfg(), j.IgnorePreflightErrors()); err != nil { return err } diff --git a/cmd/kubeadm/app/preflight/checks.go b/cmd/kubeadm/app/preflight/checks.go index ab02e96d264..d5cd1e758d3 100644 --- a/cmd/kubeadm/app/preflight/checks.go +++ b/cmd/kubeadm/app/preflight/checks.go @@ -909,13 +909,6 @@ func (MemCheck) Name() string { // InitNodeChecks returns checks specific to "kubeadm init" func InitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfiguration, ignorePreflightErrors sets.Set[string], isSecondaryControlPlane bool, downloadCerts bool) ([]Checker, 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 nil, err - } - } - manifestsDir := filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.ManifestsSubDirName) checks := []Checker{ NumCPUCheck{NumCPU: kubeadmconstants.ControlPlaneNumCPU}, @@ -1030,11 +1023,6 @@ func RunInitNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.InitConfigura // JoinNodeChecks returns checks specific to "kubeadm join" func JoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.JoinConfiguration, ignorePreflightErrors sets.Set[string]) ([]Checker, error) { - // First, check if we're root separately from the other preflight checks and fail fast - if err := RunRootCheckOnly(ignorePreflightErrors); err != nil { - return nil, err - } - checks := []Checker{ FileAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.KubeletKubeConfigFileName)}, FileAvailableCheck{Path: filepath.Join(kubeadmconstants.KubernetesDir, kubeadmconstants.KubeletBootstrapKubeConfigFileName)}, diff --git a/cmd/kubeadm/app/preflight/checks_test.go b/cmd/kubeadm/app/preflight/checks_test.go index b48833b0186..fcca2a37e99 100644 --- a/cmd/kubeadm/app/preflight/checks_test.go +++ b/cmd/kubeadm/app/preflight/checks_test.go @@ -902,11 +902,6 @@ func TestInitIPCheck(t *testing.T) { if runtime.GOOS != "linux" { t.Skip("unsupported OS") } - // should be a privileged user for the `init` command, otherwise just skip it. - isPrivileged := IsPrivilegedUserCheck{} - if _, err := isPrivileged.Check(); err != nil { - t.Skip("not a privileged user") - } internalcfg, err := configutil.DefaultedStaticInitConfiguration() if err != nil { t.Fatalf("unexpected failure when defaulting InitConfiguration: %v", err) @@ -969,11 +964,6 @@ func TestJoinIPCheck(t *testing.T) { if runtime.GOOS != "linux" { t.Skip("unsupported OS") } - // should be a privileged user for the `join` command, otherwise just skip it. - isPrivileged := IsPrivilegedUserCheck{} - if _, err := isPrivileged.Check(); err != nil { - t.Skip("not a privileged user") - } opts := configutil.LoadOrDefaultConfigurationOptions{ SkipCRIDetect: true,