mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-26 05:03:09 +00:00
kubeadm: updated preflight types to avoid stutter
PreFlightError and PreFlightCheck to Error and Checker to avoid preflight.PreFlightError and preflight.PreFlightCheck stutter.
This commit is contained in:
parent
add3a08a6d
commit
8f0f09c0fe
@ -37,17 +37,17 @@ import (
|
|||||||
|
|
||||||
const bridgenf string = "/proc/sys/net/bridge/bridge-nf-call-iptables"
|
const bridgenf string = "/proc/sys/net/bridge/bridge-nf-call-iptables"
|
||||||
|
|
||||||
type PreFlightError struct {
|
type Error struct {
|
||||||
Msg string
|
Msg string
|
||||||
}
|
}
|
||||||
|
|
||||||
func (e *PreFlightError) Error() string {
|
func (e *Error) Error() string {
|
||||||
return fmt.Sprintf("[preflight] Some fatal errors occurred:\n%s%s", e.Msg, "[preflight] If you know what you are doing, you can skip pre-flight checks with `--skip-preflight-checks`")
|
return fmt.Sprintf("[preflight] Some fatal errors occurred:\n%s%s", e.Msg, "[preflight] If you know what you are doing, you can skip pre-flight checks with `--skip-preflight-checks`")
|
||||||
}
|
}
|
||||||
|
|
||||||
// PreFlightCheck validates the state of the system to ensure kubeadm will be
|
// Checker validates the state of the system to ensure kubeadm will be
|
||||||
// successful as often as possilble.
|
// successful as often as possilble.
|
||||||
type PreFlightCheck interface {
|
type Checker interface {
|
||||||
Check() (warnings, errors []error)
|
Check() (warnings, errors []error)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,7 +304,7 @@ func (sysver SystemVerificationCheck) Check() (warnings, errors []error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
|
func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
|
||||||
checks := []PreFlightCheck{
|
checks := []Checker{
|
||||||
SystemVerificationCheck{},
|
SystemVerificationCheck{},
|
||||||
IsRootCheck{},
|
IsRootCheck{},
|
||||||
HostnameCheck{},
|
HostnameCheck{},
|
||||||
@ -346,7 +346,7 @@ func RunInitMasterChecks(cfg *kubeadmapi.MasterConfiguration) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RunJoinNodeChecks(cfg *kubeadmapi.NodeConfiguration) error {
|
func RunJoinNodeChecks(cfg *kubeadmapi.NodeConfiguration) error {
|
||||||
checks := []PreFlightCheck{
|
checks := []Checker{
|
||||||
SystemVerificationCheck{},
|
SystemVerificationCheck{},
|
||||||
IsRootCheck{},
|
IsRootCheck{},
|
||||||
HostnameCheck{},
|
HostnameCheck{},
|
||||||
@ -372,7 +372,7 @@ func RunJoinNodeChecks(cfg *kubeadmapi.NodeConfiguration) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func RunRootCheckOnly() error {
|
func RunRootCheckOnly() error {
|
||||||
checks := []PreFlightCheck{
|
checks := []Checker{
|
||||||
IsRootCheck{},
|
IsRootCheck{},
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -381,7 +381,7 @@ func RunRootCheckOnly() error {
|
|||||||
|
|
||||||
// RunChecks runs each check, displays it's warnings/errors, and once all
|
// RunChecks runs each check, displays it's warnings/errors, and once all
|
||||||
// are processed will exit if any errors occurred.
|
// are processed will exit if any errors occurred.
|
||||||
func RunChecks(checks []PreFlightCheck, ww io.Writer) error {
|
func RunChecks(checks []Checker, ww io.Writer) error {
|
||||||
found := []error{}
|
found := []error{}
|
||||||
for _, c := range checks {
|
for _, c := range checks {
|
||||||
warnings, errs := c.Check()
|
warnings, errs := c.Check()
|
||||||
@ -395,7 +395,7 @@ func RunChecks(checks []PreFlightCheck, ww io.Writer) error {
|
|||||||
for _, i := range found {
|
for _, i := range found {
|
||||||
errs.WriteString("\t" + i.Error() + "\n")
|
errs.WriteString("\t" + i.Error() + "\n")
|
||||||
}
|
}
|
||||||
return &PreFlightError{Msg: errs.String()}
|
return &Error{Msg: errs.String()}
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
@ -38,14 +38,14 @@ func (pfct preflightCheckTest) Check() (warning, errors []error) {
|
|||||||
|
|
||||||
func TestRunChecks(t *testing.T) {
|
func TestRunChecks(t *testing.T) {
|
||||||
var tokenTest = []struct {
|
var tokenTest = []struct {
|
||||||
p []PreFlightCheck
|
p []Checker
|
||||||
expected bool
|
expected bool
|
||||||
output string
|
output string
|
||||||
}{
|
}{
|
||||||
{[]PreFlightCheck{}, true, ""},
|
{[]Checker{}, true, ""},
|
||||||
{[]PreFlightCheck{preflightCheckTest{"warning"}}, true, "[preflight] WARNING: warning\n"}, // should just print warning
|
{[]Checker{preflightCheckTest{"warning"}}, true, "[preflight] WARNING: warning\n"}, // should just print warning
|
||||||
{[]PreFlightCheck{preflightCheckTest{"error"}}, false, ""},
|
{[]Checker{preflightCheckTest{"error"}}, false, ""},
|
||||||
{[]PreFlightCheck{preflightCheckTest{"test"}}, false, ""},
|
{[]Checker{preflightCheckTest{"test"}}, false, ""},
|
||||||
}
|
}
|
||||||
for _, rt := range tokenTest {
|
for _, rt := range tokenTest {
|
||||||
buf := new(bytes.Buffer)
|
buf := new(bytes.Buffer)
|
||||||
|
@ -61,7 +61,7 @@ func checkErr(prefix string, err error, handleErr func(string, int)) {
|
|||||||
switch err.(type) {
|
switch err.(type) {
|
||||||
case nil:
|
case nil:
|
||||||
return
|
return
|
||||||
case *preflight.PreFlightError:
|
case *preflight.Error:
|
||||||
handleErr(err.Error(), PreFlightExitCode)
|
handleErr(err.Error(), PreFlightExitCode)
|
||||||
default:
|
default:
|
||||||
handleErr(err.Error(), DefaultErrorExitCode)
|
handleErr(err.Error(), DefaultErrorExitCode)
|
||||||
|
@ -35,7 +35,7 @@ func TestCheckErr(t *testing.T) {
|
|||||||
}{
|
}{
|
||||||
{nil, 0},
|
{nil, 0},
|
||||||
{fmt.Errorf(""), DefaultErrorExitCode},
|
{fmt.Errorf(""), DefaultErrorExitCode},
|
||||||
{&preflight.PreFlightError{}, PreFlightExitCode},
|
{&preflight.Error{}, PreFlightExitCode},
|
||||||
}
|
}
|
||||||
|
|
||||||
for _, rt := range tokenTest {
|
for _, rt := range tokenTest {
|
||||||
|
Loading…
Reference in New Issue
Block a user