mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
Run the root check before the other checks in order to fail fast if non-root to avoid strange errors. Also auto-start the kubelet if inactive
This commit is contained in:
parent
95d97a0e8e
commit
e46d8fef60
@ -22,6 +22,7 @@ import (
|
|||||||
"html/template"
|
"html/template"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/renstrom/dedent"
|
"github.com/renstrom/dedent"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -183,15 +184,26 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, skipPreFlight
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !skipPreFlight {
|
if !skipPreFlight {
|
||||||
fmt.Println("Running pre-flight checks")
|
fmt.Println("[preflight] Running pre-flight checks...")
|
||||||
err := preflight.RunInitMasterChecks(cfg)
|
|
||||||
if err != nil {
|
// First, check if we're root separately from the other preflight checks and fail fast
|
||||||
|
if err := preflight.RunChecks([]preflight.PreFlightCheck{preflight.IsRootCheck{}}, os.Stderr); err != nil {
|
||||||
|
return nil, &preflight.PreFlightError{Msg: err.Error()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then continue with the others...
|
||||||
|
if err := preflight.RunInitMasterChecks(cfg); err != nil {
|
||||||
return nil, &preflight.PreFlightError{Msg: err.Error()}
|
return nil, &preflight.PreFlightError{Msg: err.Error()}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Skipping pre-flight checks")
|
fmt.Println("Skipping pre-flight checks")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to start the kubelet service in case it's inactive
|
||||||
|
if err := preflight.TryStartKubelet(); err != nil {
|
||||||
|
return nil, &preflight.PreFlightError{Msg: err.Error()}
|
||||||
|
}
|
||||||
|
|
||||||
// validate version argument
|
// validate version argument
|
||||||
ver, err := kubeadmutil.KubernetesReleaseVersion(cfg.KubernetesVersion)
|
ver, err := kubeadmutil.KubernetesReleaseVersion(cfg.KubernetesVersion)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/renstrom/dedent"
|
"github.com/renstrom/dedent"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
@ -113,15 +114,26 @@ func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, s
|
|||||||
}
|
}
|
||||||
|
|
||||||
if !skipPreFlight {
|
if !skipPreFlight {
|
||||||
fmt.Println("Running pre-flight checks")
|
fmt.Println("[preflight] Running pre-flight checks...")
|
||||||
err := preflight.RunJoinNodeChecks(cfg)
|
|
||||||
if err != nil {
|
// First, check if we're root separately from the other preflight checks and fail fast
|
||||||
|
if err := preflight.RunChecks([]preflight.PreFlightCheck{preflight.IsRootCheck{}}, os.Stderr); err != nil {
|
||||||
|
return nil, &preflight.PreFlightError{Msg: err.Error()}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Then continue with the others...
|
||||||
|
if err := preflight.RunJoinNodeChecks(cfg); err != nil {
|
||||||
return nil, &preflight.PreFlightError{Msg: err.Error()}
|
return nil, &preflight.PreFlightError{Msg: err.Error()}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("Skipping pre-flight checks")
|
fmt.Println("Skipping pre-flight checks")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Try to start the kubelet service in case it's inactive
|
||||||
|
if err := preflight.TryStartKubelet(); err != nil {
|
||||||
|
return nil, &preflight.PreFlightError{Msg: err.Error()}
|
||||||
|
}
|
||||||
|
|
||||||
ok, err := kubeadmutil.UseGivenTokenIfValid(&cfg.Secrets)
|
ok, err := kubeadmutil.UseGivenTokenIfValid(&cfg.Secrets)
|
||||||
if !ok {
|
if !ok {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -51,7 +51,8 @@ type PreFlightCheck interface {
|
|||||||
// detect a supported init system however, all checks are skipped and a warning is
|
// detect a supported init system however, all checks are skipped and a warning is
|
||||||
// returned.
|
// returned.
|
||||||
type ServiceCheck struct {
|
type ServiceCheck struct {
|
||||||
Service string
|
Service string
|
||||||
|
CheckIfActive bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func (sc ServiceCheck) Check() (warnings, errors []error) {
|
func (sc ServiceCheck) Check() (warnings, errors []error) {
|
||||||
@ -73,7 +74,7 @@ func (sc ServiceCheck) Check() (warnings, errors []error) {
|
|||||||
sc.Service, sc.Service))
|
sc.Service, sc.Service))
|
||||||
}
|
}
|
||||||
|
|
||||||
if !initSystem.ServiceIsActive(sc.Service) {
|
if sc.CheckIfActive && !initSystem.ServiceIsActive(sc.Service) {
|
||||||
errors = append(errors,
|
errors = append(errors,
|
||||||
fmt.Errorf("%s service is not active, please run 'systemctl start %s.service'",
|
fmt.Errorf("%s service is not active, please run 'systemctl start %s.service'",
|
||||||
sc.Service, sc.Service))
|
sc.Service, sc.Service))
|
||||||
@ -128,7 +129,7 @@ func (poc PortOpenCheck) Check() (warnings, errors []error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// IsRootCheck verifies user is root
|
// IsRootCheck verifies user is root
|
||||||
type IsRootCheck struct {}
|
type IsRootCheck struct{}
|
||||||
|
|
||||||
func (irc IsRootCheck) Check() (warnings, errors []error) {
|
func (irc IsRootCheck) Check() (warnings, errors []error) {
|
||||||
errors = []error{}
|
errors = []error{}
|
||||||
@ -260,8 +261,8 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
|
|||||||
SystemVerificationCheck{},
|
SystemVerificationCheck{},
|
||||||
IsRootCheck{},
|
IsRootCheck{},
|
||||||
HostnameCheck{},
|
HostnameCheck{},
|
||||||
ServiceCheck{Service: "kubelet"},
|
ServiceCheck{Service: "kubelet", CheckIfActive: false},
|
||||||
ServiceCheck{Service: "docker"},
|
ServiceCheck{Service: "docker", CheckIfActive: true},
|
||||||
FirewalldCheck{ports: []int{int(cfg.API.BindPort), int(cfg.Discovery.BindPort), 10250}},
|
FirewalldCheck{ports: []int{int(cfg.API.BindPort), int(cfg.Discovery.BindPort), 10250}},
|
||||||
PortOpenCheck{port: int(cfg.API.BindPort)},
|
PortOpenCheck{port: int(cfg.API.BindPort)},
|
||||||
PortOpenCheck{port: 8080},
|
PortOpenCheck{port: 8080},
|
||||||
@ -302,8 +303,8 @@ func RunJoinNodeChecks(cfg *kubeadmapi.NodeConfiguration) error {
|
|||||||
SystemVerificationCheck{},
|
SystemVerificationCheck{},
|
||||||
IsRootCheck{},
|
IsRootCheck{},
|
||||||
HostnameCheck{},
|
HostnameCheck{},
|
||||||
ServiceCheck{Service: "docker"},
|
ServiceCheck{Service: "kubelet", CheckIfActive: false},
|
||||||
ServiceCheck{Service: "kubelet"},
|
ServiceCheck{Service: "docker", CheckIfActive: true},
|
||||||
PortOpenCheck{port: 10250},
|
PortOpenCheck{port: 10250},
|
||||||
HTTPProxyCheck{Proto: "https", Host: cfg.MasterAddresses[0], Port: int(cfg.APIPort)},
|
HTTPProxyCheck{Proto: "https", Host: cfg.MasterAddresses[0], Port: int(cfg.APIPort)},
|
||||||
HTTPProxyCheck{Proto: "http", Host: cfg.MasterAddresses[0], Port: int(cfg.DiscoveryPort)},
|
HTTPProxyCheck{Proto: "http", Host: cfg.MasterAddresses[0], Port: int(cfg.DiscoveryPort)},
|
||||||
@ -346,3 +347,17 @@ func RunChecks(checks []PreFlightCheck, ww io.Writer) error {
|
|||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TryStartKubelet() error {
|
||||||
|
// If we notice that the kubelet service is inactive, try to start it
|
||||||
|
initSystem, err := initsystem.GetInitSystem()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println("[preflight] No supported init system detected, won't check if kubelet is running")
|
||||||
|
} else if !initSystem.ServiceIsActive("kubelet") {
|
||||||
|
fmt.Printf("[preflight] Starting the kubelet service by running %q\n", "systemctl start kubelet")
|
||||||
|
if err := initSystem.ServiceStart("kubelet"); err != nil {
|
||||||
|
return fmt.Errorf("Couldn't start the kubelet service. Please start the kubelet service manually and try again.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user