mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 11:50:44 +00:00
kubeadm: rename flag to --ignore-preflight-errors
Improves user experience by using name that is more descriptive.
This commit is contained in:
parent
ba09291ba7
commit
3a0aa06fc9
@ -331,25 +331,22 @@ func ValidateAPIEndpoint(c *kubeadm.MasterConfiguration, fldPath *field.Path) fi
|
|||||||
return allErrs
|
return allErrs
|
||||||
}
|
}
|
||||||
|
|
||||||
// ValidateIgnoreChecksErrors validates duplicates in ignore-checks-errors flag.
|
// ValidateIgnorePreflightErrors validates duplicates in ignore-preflight-errors flag.
|
||||||
func ValidateIgnoreChecksErrors(ignoreChecksErrors []string, skipPreflightChecks bool) (sets.String, error) {
|
func ValidateIgnorePreflightErrors(ignorePreflightErrors []string, skipPreflightChecks bool) (sets.String, error) {
|
||||||
ignoreErrors := sets.NewString()
|
ignoreErrors := sets.NewString()
|
||||||
allErrs := field.ErrorList{}
|
allErrs := field.ErrorList{}
|
||||||
|
|
||||||
for _, item := range ignoreChecksErrors {
|
for _, item := range ignorePreflightErrors {
|
||||||
ignoreErrors.Insert(strings.ToLower(item)) // parameters are case insensitive
|
ignoreErrors.Insert(strings.ToLower(item)) // parameters are case insensitive
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: remove once deprecated flag --skip-preflight-checks is removed.
|
// TODO: remove once deprecated flag --skip-preflight-checks is removed.
|
||||||
if skipPreflightChecks {
|
if skipPreflightChecks {
|
||||||
if ignoreErrors.Has("all") {
|
|
||||||
allErrs = append(allErrs, field.Invalid(field.NewPath("ignore-checks-errors"), strings.Join(ignoreErrors.List(), ","), "'all' is used together with deprecated flag --skip-preflight-checks. Remove deprecated flag"))
|
|
||||||
}
|
|
||||||
ignoreErrors.Insert("all")
|
ignoreErrors.Insert("all")
|
||||||
}
|
}
|
||||||
|
|
||||||
if ignoreErrors.Has("all") && ignoreErrors.Len() > 1 {
|
if ignoreErrors.Has("all") && ignoreErrors.Len() > 1 {
|
||||||
allErrs = append(allErrs, field.Invalid(field.NewPath("ignore-checks-errors"), strings.Join(ignoreErrors.List(), ","), "don't specify individual checks if 'all' is used"))
|
allErrs = append(allErrs, field.Invalid(field.NewPath("ignore-preflight-errors"), strings.Join(ignoreErrors.List(), ","), "don't specify individual checks if 'all' is used"))
|
||||||
}
|
}
|
||||||
|
|
||||||
return ignoreErrors, allErrs.ToAggregate()
|
return ignoreErrors, allErrs.ToAggregate()
|
||||||
|
@ -459,12 +459,12 @@ func TestValidateFeatureGates(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValidateIgnoreChecksErrors(t *testing.T) {
|
func TestValidateIgnorePreflightErrors(t *testing.T) {
|
||||||
var tests = []struct {
|
var tests = []struct {
|
||||||
ignoreChecksErrors []string
|
ignorePreflightErrors []string
|
||||||
skipPreflightChecks bool
|
skipPreflightChecks bool
|
||||||
expectedLen int
|
expectedLen int
|
||||||
expectedError bool
|
expectedError bool
|
||||||
}{
|
}{
|
||||||
{[]string{}, false, 0, false}, // empty list, no old skip-preflight-checks
|
{[]string{}, false, 0, false}, // empty list, no old skip-preflight-checks
|
||||||
{[]string{}, true, 1, false}, // empty list, old skip-preflight-checks
|
{[]string{}, true, 1, false}, // empty list, old skip-preflight-checks
|
||||||
@ -473,17 +473,17 @@ func TestValidateIgnoreChecksErrors(t *testing.T) {
|
|||||||
{[]string{"check1", "check2", "check1"}, false, 2, false}, // duplicates
|
{[]string{"check1", "check2", "check1"}, false, 2, false}, // duplicates
|
||||||
{[]string{"check1", "check2", "all"}, false, 3, true}, // non-duplicate, but 'all' present together wth individual checks
|
{[]string{"check1", "check2", "all"}, false, 3, true}, // non-duplicate, but 'all' present together wth individual checks
|
||||||
{[]string{"all"}, false, 1, false}, // skip all checks by using new flag
|
{[]string{"all"}, false, 1, false}, // skip all checks by using new flag
|
||||||
{[]string{"all"}, true, 1, true}, // skip all checks by using both old and new flags at the same time
|
{[]string{"all"}, true, 1, false}, // skip all checks by using both old and new flags at the same time
|
||||||
}
|
}
|
||||||
for _, rt := range tests {
|
for _, rt := range tests {
|
||||||
result, err := ValidateIgnoreChecksErrors(rt.ignoreChecksErrors, rt.skipPreflightChecks)
|
result, err := ValidateIgnorePreflightErrors(rt.ignorePreflightErrors, rt.skipPreflightChecks)
|
||||||
switch {
|
switch {
|
||||||
case err != nil && !rt.expectedError:
|
case err != nil && !rt.expectedError:
|
||||||
t.Errorf("ValidateIgnoreChecksErrors: unexpected error for input (%s, %v), error: %v", rt.ignoreChecksErrors, rt.skipPreflightChecks, err)
|
t.Errorf("ValidateIgnorePreflightErrors: unexpected error for input (%s, %v), error: %v", rt.ignorePreflightErrors, rt.skipPreflightChecks, err)
|
||||||
case err == nil && rt.expectedError:
|
case err == nil && rt.expectedError:
|
||||||
t.Errorf("ValidateIgnoreChecksErrors: expected error for input (%s, %v) but got: %v", rt.ignoreChecksErrors, rt.skipPreflightChecks, result)
|
t.Errorf("ValidateIgnorePreflightErrors: expected error for input (%s, %v) but got: %v", rt.ignorePreflightErrors, rt.skipPreflightChecks, result)
|
||||||
case result.Len() != rt.expectedLen:
|
case result.Len() != rt.expectedLen:
|
||||||
t.Errorf("ValidateIgnoreChecksErrors: expected Len = %d for input (%s, %v) but got: %v, %v", rt.expectedLen, rt.ignoreChecksErrors, rt.skipPreflightChecks, result.Len(), result)
|
t.Errorf("ValidateIgnorePreflightErrors: expected Len = %d for input (%s, %v) but got: %v, %v", rt.expectedLen, rt.ignorePreflightErrors, rt.skipPreflightChecks, result.Len(), result)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,7 +113,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
|
|||||||
var dryRun bool
|
var dryRun bool
|
||||||
var featureGatesString string
|
var featureGatesString string
|
||||||
var criSocket string
|
var criSocket string
|
||||||
var ignoreChecksErrors []string
|
var ignorePreflightErrors []string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "init",
|
Use: "init",
|
||||||
@ -128,10 +128,10 @@ func NewCmdInit(out io.Writer) *cobra.Command {
|
|||||||
internalcfg := &kubeadmapi.MasterConfiguration{}
|
internalcfg := &kubeadmapi.MasterConfiguration{}
|
||||||
legacyscheme.Scheme.Convert(cfg, internalcfg, nil)
|
legacyscheme.Scheme.Convert(cfg, internalcfg, nil)
|
||||||
|
|
||||||
ignoreChecksErrorsSet, err := validation.ValidateIgnoreChecksErrors(ignoreChecksErrors, skipPreFlight)
|
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(ignorePreflightErrors, skipPreFlight)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
i, err := NewInit(cfgPath, internalcfg, ignoreChecksErrorsSet, skipTokenPrint, dryRun, criSocket)
|
i, err := NewInit(cfgPath, internalcfg, ignorePreflightErrorsSet, skipTokenPrint, dryRun, criSocket)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
kubeadmutil.CheckErr(i.Validate(cmd))
|
kubeadmutil.CheckErr(i.Validate(cmd))
|
||||||
kubeadmutil.CheckErr(i.Run(out))
|
kubeadmutil.CheckErr(i.Run(out))
|
||||||
@ -139,7 +139,7 @@ func NewCmdInit(out io.Writer) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddInitConfigFlags(cmd.PersistentFlags(), cfg, &featureGatesString)
|
AddInitConfigFlags(cmd.PersistentFlags(), cfg, &featureGatesString)
|
||||||
AddInitOtherFlags(cmd.PersistentFlags(), &cfgPath, &skipPreFlight, &skipTokenPrint, &dryRun, &criSocket, &ignoreChecksErrors)
|
AddInitOtherFlags(cmd.PersistentFlags(), &cfgPath, &skipPreFlight, &skipTokenPrint, &dryRun, &criSocket, &ignorePreflightErrors)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -195,13 +195,13 @@ func AddInitConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiext.MasterConfigur
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddInitOtherFlags adds init flags that are not bound to a configuration file to the given flagset
|
// AddInitOtherFlags adds init flags that are not bound to a configuration file to the given flagset
|
||||||
func AddInitOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight, skipTokenPrint, dryRun *bool, criSocket *string, ignoreChecksErrors *[]string) {
|
func AddInitOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight, skipTokenPrint, dryRun *bool, criSocket *string, ignorePreflightErrors *[]string) {
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
cfgPath, "config", *cfgPath,
|
cfgPath, "config", *cfgPath,
|
||||||
"Path to kubeadm config file. WARNING: Usage of a configuration file is experimental.",
|
"Path to kubeadm config file. WARNING: Usage of a configuration file is experimental.",
|
||||||
)
|
)
|
||||||
flagSet.StringSliceVar(
|
flagSet.StringSliceVar(
|
||||||
ignoreChecksErrors, "ignore-checks-errors", *ignoreChecksErrors,
|
ignorePreflightErrors, "ignore-preflight-errors", *ignorePreflightErrors,
|
||||||
"A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.",
|
"A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.",
|
||||||
)
|
)
|
||||||
// Note: All flags that are not bound to the cfg object should be whitelisted in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
|
// Note: All flags that are not bound to the cfg object should be whitelisted in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
|
||||||
@ -209,7 +209,7 @@ func AddInitOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight, sk
|
|||||||
skipPreFlight, "skip-preflight-checks", *skipPreFlight,
|
skipPreFlight, "skip-preflight-checks", *skipPreFlight,
|
||||||
"Skip preflight checks which normally run before modifying the system.",
|
"Skip preflight checks which normally run before modifying the system.",
|
||||||
)
|
)
|
||||||
flagSet.MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-checks-errors=all")
|
flagSet.MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-preflight-errors=all")
|
||||||
// Note: All flags that are not bound to the cfg object should be whitelisted in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
|
// Note: All flags that are not bound to the cfg object should be whitelisted in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
|
||||||
flagSet.BoolVar(
|
flagSet.BoolVar(
|
||||||
skipTokenPrint, "skip-token-print", *skipTokenPrint,
|
skipTokenPrint, "skip-token-print", *skipTokenPrint,
|
||||||
@ -227,7 +227,7 @@ func AddInitOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight, sk
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewInit validates given arguments and instantiates Init struct with provided information.
|
// NewInit validates given arguments and instantiates Init struct with provided information.
|
||||||
func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, ignoreChecksErrors sets.String, skipTokenPrint, dryRun bool, criSocket string) (*Init, error) {
|
func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, ignorePreflightErrors sets.String, skipTokenPrint, dryRun bool, criSocket string) (*Init, error) {
|
||||||
fmt.Println("[kubeadm] WARNING: kubeadm is currently in beta")
|
fmt.Println("[kubeadm] WARNING: kubeadm is currently in beta")
|
||||||
|
|
||||||
if cfgPath != "" {
|
if cfgPath != "" {
|
||||||
@ -261,12 +261,12 @@ func NewInit(cfgPath string, cfg *kubeadmapi.MasterConfiguration, ignoreChecksEr
|
|||||||
|
|
||||||
fmt.Println("[preflight] Running pre-flight checks.")
|
fmt.Println("[preflight] Running pre-flight checks.")
|
||||||
|
|
||||||
if err := preflight.RunInitMasterChecks(utilsexec.New(), cfg, criSocket, ignoreChecksErrors); err != nil {
|
if err := preflight.RunInitMasterChecks(utilsexec.New(), cfg, criSocket, ignorePreflightErrors); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to start the kubelet service in case it's inactive
|
// Try to start the kubelet service in case it's inactive
|
||||||
preflight.TryStartKubelet(ignoreChecksErrors)
|
preflight.TryStartKubelet(ignorePreflightErrors)
|
||||||
|
|
||||||
return &Init{cfg: cfg, skipTokenPrint: skipTokenPrint, dryRun: dryRun}, nil
|
return &Init{cfg: cfg, skipTokenPrint: skipTokenPrint, dryRun: dryRun}, nil
|
||||||
}
|
}
|
||||||
|
@ -108,7 +108,7 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
|
|||||||
var cfgPath string
|
var cfgPath string
|
||||||
var criSocket string
|
var criSocket string
|
||||||
var featureGatesString string
|
var featureGatesString string
|
||||||
var ignoreChecksErrors []string
|
var ignorePreflightErrors []string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "join [flags]",
|
Use: "join [flags]",
|
||||||
@ -126,10 +126,10 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
|
|||||||
internalcfg := &kubeadmapi.NodeConfiguration{}
|
internalcfg := &kubeadmapi.NodeConfiguration{}
|
||||||
legacyscheme.Scheme.Convert(cfg, internalcfg, nil)
|
legacyscheme.Scheme.Convert(cfg, internalcfg, nil)
|
||||||
|
|
||||||
ignoreChecksErrorsSet, err := validation.ValidateIgnoreChecksErrors(ignoreChecksErrors, skipPreFlight)
|
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(ignorePreflightErrors, skipPreFlight)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
j, err := NewJoin(cfgPath, args, internalcfg, ignoreChecksErrorsSet, criSocket)
|
j, err := NewJoin(cfgPath, args, internalcfg, ignorePreflightErrorsSet, criSocket)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
kubeadmutil.CheckErr(j.Validate(cmd))
|
kubeadmutil.CheckErr(j.Validate(cmd))
|
||||||
kubeadmutil.CheckErr(j.Run(out))
|
kubeadmutil.CheckErr(j.Run(out))
|
||||||
@ -137,7 +137,7 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
AddJoinConfigFlags(cmd.PersistentFlags(), cfg, &featureGatesString)
|
AddJoinConfigFlags(cmd.PersistentFlags(), cfg, &featureGatesString)
|
||||||
AddJoinOtherFlags(cmd.PersistentFlags(), &cfgPath, &skipPreFlight, &criSocket, &ignoreChecksErrors)
|
AddJoinOtherFlags(cmd.PersistentFlags(), &cfgPath, &skipPreFlight, &criSocket, &ignorePreflightErrors)
|
||||||
|
|
||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
@ -172,20 +172,20 @@ func AddJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiext.NodeConfigurat
|
|||||||
}
|
}
|
||||||
|
|
||||||
// AddJoinOtherFlags adds join flags that are not bound to a configuration file to the given flagset
|
// AddJoinOtherFlags adds join flags that are not bound to a configuration file to the given flagset
|
||||||
func AddJoinOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight *bool, criSocket *string, ignoreChecksErrors *[]string) {
|
func AddJoinOtherFlags(flagSet *flag.FlagSet, cfgPath *string, skipPreFlight *bool, criSocket *string, ignorePreflightErrors *[]string) {
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
cfgPath, "config", *cfgPath,
|
cfgPath, "config", *cfgPath,
|
||||||
"Path to kubeadm config file.")
|
"Path to kubeadm config file.")
|
||||||
|
|
||||||
flagSet.StringSliceVar(
|
flagSet.StringSliceVar(
|
||||||
ignoreChecksErrors, "ignore-checks-errors", *ignoreChecksErrors,
|
ignorePreflightErrors, "ignore-preflight-errors", *ignorePreflightErrors,
|
||||||
"A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.",
|
"A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.",
|
||||||
)
|
)
|
||||||
flagSet.BoolVar(
|
flagSet.BoolVar(
|
||||||
skipPreFlight, "skip-preflight-checks", false,
|
skipPreFlight, "skip-preflight-checks", false,
|
||||||
"Skip preflight checks which normally run before modifying the system.",
|
"Skip preflight checks which normally run before modifying the system.",
|
||||||
)
|
)
|
||||||
flagSet.MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-checks-errors=all")
|
flagSet.MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-preflight-errors=all")
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
criSocket, "cri-socket", "/var/run/dockershim.sock",
|
criSocket, "cri-socket", "/var/run/dockershim.sock",
|
||||||
`Specify the CRI socket to connect to.`,
|
`Specify the CRI socket to connect to.`,
|
||||||
@ -198,7 +198,7 @@ type Join struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewJoin instantiates Join struct with given arguments
|
// NewJoin instantiates Join struct with given arguments
|
||||||
func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, ignoreChecksErrors sets.String, criSocket string) (*Join, error) {
|
func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, ignorePreflightErrors sets.String, criSocket string) (*Join, error) {
|
||||||
fmt.Println("[kubeadm] WARNING: kubeadm is currently in beta")
|
fmt.Println("[kubeadm] WARNING: kubeadm is currently in beta")
|
||||||
|
|
||||||
if cfg.NodeName == "" {
|
if cfg.NodeName == "" {
|
||||||
@ -218,12 +218,12 @@ func NewJoin(cfgPath string, args []string, cfg *kubeadmapi.NodeConfiguration, i
|
|||||||
fmt.Println("[preflight] Running pre-flight checks.")
|
fmt.Println("[preflight] Running pre-flight checks.")
|
||||||
|
|
||||||
// Then continue with the others...
|
// Then continue with the others...
|
||||||
if err := preflight.RunJoinNodeChecks(utilsexec.New(), cfg, criSocket, ignoreChecksErrors); err != nil {
|
if err := preflight.RunJoinNodeChecks(utilsexec.New(), cfg, criSocket, ignorePreflightErrors); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try to start the kubelet service in case it's inactive
|
// Try to start the kubelet service in case it's inactive
|
||||||
preflight.TryStartKubelet(ignoreChecksErrors)
|
preflight.TryStartKubelet(ignorePreflightErrors)
|
||||||
|
|
||||||
return &Join{cfg: cfg}, nil
|
return &Join{cfg: cfg}, nil
|
||||||
}
|
}
|
||||||
|
@ -47,30 +47,30 @@ func NewCmdReset(out io.Writer) *cobra.Command {
|
|||||||
var skipPreFlight bool
|
var skipPreFlight bool
|
||||||
var certsDir string
|
var certsDir string
|
||||||
var criSocketPath string
|
var criSocketPath string
|
||||||
var ignoreChecksErrors []string
|
var ignorePreflightErrors []string
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
Use: "reset",
|
Use: "reset",
|
||||||
Short: "Run this to revert any changes made to this host by 'kubeadm init' or 'kubeadm join'.",
|
Short: "Run this to revert any changes made to this host by 'kubeadm init' or 'kubeadm join'.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
ignoreChecksErrorsSet, err := validation.ValidateIgnoreChecksErrors(ignoreChecksErrors, skipPreFlight)
|
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(ignorePreflightErrors, skipPreFlight)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
r, err := NewReset(ignoreChecksErrorsSet, certsDir, criSocketPath)
|
r, err := NewReset(ignorePreflightErrorsSet, certsDir, criSocketPath)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
kubeadmutil.CheckErr(r.Run(out))
|
kubeadmutil.CheckErr(r.Run(out))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd.PersistentFlags().StringSliceVar(
|
cmd.PersistentFlags().StringSliceVar(
|
||||||
&ignoreChecksErrors, "ignore-checks-errors", ignoreChecksErrors,
|
&ignorePreflightErrors, "ignore-preflight-errors", ignorePreflightErrors,
|
||||||
"A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.",
|
"A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.",
|
||||||
)
|
)
|
||||||
cmd.PersistentFlags().BoolVar(
|
cmd.PersistentFlags().BoolVar(
|
||||||
&skipPreFlight, "skip-preflight-checks", false,
|
&skipPreFlight, "skip-preflight-checks", false,
|
||||||
"Skip preflight checks which normally run before modifying the system.",
|
"Skip preflight checks which normally run before modifying the system.",
|
||||||
)
|
)
|
||||||
cmd.PersistentFlags().MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-checks-errors=all")
|
cmd.PersistentFlags().MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-preflight-errors=all")
|
||||||
|
|
||||||
cmd.PersistentFlags().StringVar(
|
cmd.PersistentFlags().StringVar(
|
||||||
&certsDir, "cert-dir", kubeadmapiext.DefaultCertificatesDir,
|
&certsDir, "cert-dir", kubeadmapiext.DefaultCertificatesDir,
|
||||||
@ -92,10 +92,10 @@ type Reset struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// NewReset instantiate Reset struct
|
// NewReset instantiate Reset struct
|
||||||
func NewReset(ignoreChecksErrors sets.String, certsDir, criSocketPath string) (*Reset, error) {
|
func NewReset(ignorePreflightErrors sets.String, certsDir, criSocketPath string) (*Reset, error) {
|
||||||
fmt.Println("[preflight] Running pre-flight checks.")
|
fmt.Println("[preflight] Running pre-flight checks.")
|
||||||
|
|
||||||
if err := preflight.RunRootCheckOnly(ignoreChecksErrors); err != nil {
|
if err := preflight.RunRootCheckOnly(ignorePreflightErrors); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -72,11 +72,11 @@ func NewCmdApply(parentFlags *cmdUpgradeFlags) *cobra.Command {
|
|||||||
Short: "Upgrade your Kubernetes cluster to the specified version.",
|
Short: "Upgrade your Kubernetes cluster to the specified version.",
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
var err error
|
var err error
|
||||||
flags.parent.ignoreChecksErrorsSet, err = validation.ValidateIgnoreChecksErrors(flags.parent.ignoreChecksErrors, flags.parent.skipPreFlight)
|
flags.parent.ignorePreflightErrorsSet, err = validation.ValidateIgnorePreflightErrors(flags.parent.ignorePreflightErrors, flags.parent.skipPreFlight)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
// Ensure the user is root
|
// Ensure the user is root
|
||||||
err = runPreflightChecks(flags.parent.ignoreChecksErrorsSet)
|
err = runPreflightChecks(flags.parent.ignorePreflightErrorsSet)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
err = cmdutil.ValidateExactArgNumber(args, []string{"version"})
|
err = cmdutil.ValidateExactArgNumber(args, []string{"version"})
|
||||||
|
@ -107,9 +107,9 @@ func printConfiguration(cfg *kubeadmapiext.MasterConfiguration, w io.Writer) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// runPreflightChecks runs the root preflight check
|
// runPreflightChecks runs the root preflight check
|
||||||
func runPreflightChecks(ignoreChecksErrors sets.String) error {
|
func runPreflightChecks(ignorePreflightErrors sets.String) error {
|
||||||
fmt.Println("[preflight] Running pre-flight checks.")
|
fmt.Println("[preflight] Running pre-flight checks.")
|
||||||
return preflight.RunRootCheckOnly(ignoreChecksErrors)
|
return preflight.RunRootCheckOnly(ignorePreflightErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// getClient gets a real or fake client depending on whether the user is dry-running or not
|
// getClient gets a real or fake client depending on whether the user is dry-running or not
|
||||||
|
@ -38,10 +38,10 @@ func NewCmdPlan(parentFlags *cmdUpgradeFlags) *cobra.Command {
|
|||||||
Short: "Check which versions are available to upgrade to and validate whether your current cluster is upgradeable.",
|
Short: "Check which versions are available to upgrade to and validate whether your current cluster is upgradeable.",
|
||||||
Run: func(_ *cobra.Command, _ []string) {
|
Run: func(_ *cobra.Command, _ []string) {
|
||||||
var err error
|
var err error
|
||||||
parentFlags.ignoreChecksErrorsSet, err = validation.ValidateIgnoreChecksErrors(parentFlags.ignoreChecksErrors, parentFlags.skipPreFlight)
|
parentFlags.ignorePreflightErrorsSet, err = validation.ValidateIgnorePreflightErrors(parentFlags.ignorePreflightErrors, parentFlags.skipPreFlight)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
// Ensure the user is root
|
// Ensure the user is root
|
||||||
err = runPreflightChecks(parentFlags.ignoreChecksErrorsSet)
|
err = runPreflightChecks(parentFlags.ignorePreflightErrorsSet)
|
||||||
kubeadmutil.CheckErr(err)
|
kubeadmutil.CheckErr(err)
|
||||||
|
|
||||||
err = RunPlan(parentFlags)
|
err = RunPlan(parentFlags)
|
||||||
|
@ -35,8 +35,8 @@ type cmdUpgradeFlags struct {
|
|||||||
allowRCUpgrades bool
|
allowRCUpgrades bool
|
||||||
printConfig bool
|
printConfig bool
|
||||||
skipPreFlight bool
|
skipPreFlight bool
|
||||||
ignoreChecksErrors []string
|
ignorePreflightErrors []string
|
||||||
ignoreChecksErrorsSet sets.String
|
ignorePreflightErrorsSet sets.String
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCmdUpgrade returns the cobra command for `kubeadm upgrade`
|
// NewCmdUpgrade returns the cobra command for `kubeadm upgrade`
|
||||||
@ -49,7 +49,7 @@ func NewCmdUpgrade(out io.Writer) *cobra.Command {
|
|||||||
allowRCUpgrades: false,
|
allowRCUpgrades: false,
|
||||||
printConfig: false,
|
printConfig: false,
|
||||||
skipPreFlight: false,
|
skipPreFlight: false,
|
||||||
ignoreChecksErrorsSet: sets.NewString(),
|
ignorePreflightErrorsSet: sets.NewString(),
|
||||||
}
|
}
|
||||||
|
|
||||||
cmd := &cobra.Command{
|
cmd := &cobra.Command{
|
||||||
@ -63,9 +63,9 @@ func NewCmdUpgrade(out io.Writer) *cobra.Command {
|
|||||||
cmd.PersistentFlags().BoolVar(&flags.allowExperimentalUpgrades, "allow-experimental-upgrades", flags.allowExperimentalUpgrades, "Show unstable versions of Kubernetes as an upgrade alternative and allow upgrading to an alpha/beta/release candidate versions of Kubernetes.")
|
cmd.PersistentFlags().BoolVar(&flags.allowExperimentalUpgrades, "allow-experimental-upgrades", flags.allowExperimentalUpgrades, "Show unstable versions of Kubernetes as an upgrade alternative and allow upgrading to an alpha/beta/release candidate versions of Kubernetes.")
|
||||||
cmd.PersistentFlags().BoolVar(&flags.allowRCUpgrades, "allow-release-candidate-upgrades", flags.allowRCUpgrades, "Show release candidate versions of Kubernetes as an upgrade alternative and allow upgrading to a release candidate versions of Kubernetes.")
|
cmd.PersistentFlags().BoolVar(&flags.allowRCUpgrades, "allow-release-candidate-upgrades", flags.allowRCUpgrades, "Show release candidate versions of Kubernetes as an upgrade alternative and allow upgrading to a release candidate versions of Kubernetes.")
|
||||||
cmd.PersistentFlags().BoolVar(&flags.printConfig, "print-config", flags.printConfig, "Specifies whether the configuration file that will be used in the upgrade should be printed or not.")
|
cmd.PersistentFlags().BoolVar(&flags.printConfig, "print-config", flags.printConfig, "Specifies whether the configuration file that will be used in the upgrade should be printed or not.")
|
||||||
cmd.PersistentFlags().StringSliceVar(&flags.ignoreChecksErrors, "ignore-checks-errors", flags.ignoreChecksErrors, "A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.")
|
cmd.PersistentFlags().StringSliceVar(&flags.ignorePreflightErrors, "ignore-preflight-errors", flags.ignorePreflightErrors, "A list of checks whose errors will be shown as warnings. Example: 'IsPrivilegedUser,Swap'. Value 'all' ignores errors from all checks.")
|
||||||
cmd.PersistentFlags().BoolVar(&flags.skipPreFlight, "skip-preflight-checks", flags.skipPreFlight, "Skip preflight checks that normally run before modifying the system.")
|
cmd.PersistentFlags().BoolVar(&flags.skipPreFlight, "skip-preflight-checks", flags.skipPreFlight, "Skip preflight checks that normally run before modifying the system.")
|
||||||
cmd.PersistentFlags().MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-checks-errors=all")
|
cmd.PersistentFlags().MarkDeprecated("skip-preflight-checks", "it is now equivalent to --ignore-preflight-errors=all")
|
||||||
cmd.PersistentFlags().StringVar(&flags.featureGatesString, "feature-gates", flags.featureGatesString, "A set of key=value pairs that describe feature gates for various features."+
|
cmd.PersistentFlags().StringVar(&flags.featureGatesString, "feature-gates", flags.featureGatesString, "A set of key=value pairs that describe feature gates for various features."+
|
||||||
"Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n"))
|
"Options are:\n"+strings.Join(features.KnownFeatures(&features.InitFeatureGates), "\n"))
|
||||||
|
|
||||||
|
@ -75,7 +75,7 @@ type Error struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (e *Error) 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 make a check non-fatal with `--ignore-checks-errors=...`")
|
return fmt.Sprintf("[preflight] Some fatal errors occurred:\n%s%s", e.Msg, "[preflight] If you know what you are doing, you can make a check non-fatal with `--ignore-preflight-errors=...`")
|
||||||
}
|
}
|
||||||
|
|
||||||
// Checker validates the state of the system to ensure kubeadm will be
|
// Checker validates the state of the system to ensure kubeadm will be
|
||||||
@ -837,9 +837,9 @@ func getEtcdVersionResponse(client *http.Client, url string, target interface{})
|
|||||||
}
|
}
|
||||||
|
|
||||||
// RunInitMasterChecks executes all individual, applicable to Master node checks.
|
// RunInitMasterChecks executes all individual, applicable to Master node checks.
|
||||||
func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.MasterConfiguration, criSocket string, ignoreChecksErrors sets.String) error {
|
func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.MasterConfiguration, criSocket string, ignorePreflightErrors sets.String) error {
|
||||||
// First, check if we're root separately from the other preflight checks and fail fast
|
// First, check if we're root separately from the other preflight checks and fail fast
|
||||||
if err := RunRootCheckOnly(ignoreChecksErrors); err != nil {
|
if err := RunRootCheckOnly(ignorePreflightErrors); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -929,13 +929,13 @@ func RunInitMasterChecks(execer utilsexec.Interface, cfg *kubeadmapi.MasterConfi
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RunChecks(checks, os.Stderr, ignoreChecksErrors)
|
return RunChecks(checks, os.Stderr, ignorePreflightErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunJoinNodeChecks executes all individual, applicable to node checks.
|
// RunJoinNodeChecks executes all individual, applicable to node checks.
|
||||||
func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.NodeConfiguration, criSocket string, ignoreChecksErrors sets.String) error {
|
func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.NodeConfiguration, criSocket string, ignorePreflightErrors sets.String) error {
|
||||||
// First, check if we're root separately from the other preflight checks and fail fast
|
// First, check if we're root separately from the other preflight checks and fail fast
|
||||||
if err := RunRootCheckOnly(ignoreChecksErrors); err != nil {
|
if err := RunRootCheckOnly(ignorePreflightErrors); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -987,21 +987,21 @@ func RunJoinNodeChecks(execer utilsexec.Interface, cfg *kubeadmapi.NodeConfigura
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return RunChecks(checks, os.Stderr, ignoreChecksErrors)
|
return RunChecks(checks, os.Stderr, ignorePreflightErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RunRootCheckOnly initializes checks slice of structs and call RunChecks
|
// RunRootCheckOnly initializes checks slice of structs and call RunChecks
|
||||||
func RunRootCheckOnly(ignoreChecksErrors sets.String) error {
|
func RunRootCheckOnly(ignorePreflightErrors sets.String) error {
|
||||||
checks := []Checker{
|
checks := []Checker{
|
||||||
IsPrivilegedUserCheck{},
|
IsPrivilegedUserCheck{},
|
||||||
}
|
}
|
||||||
|
|
||||||
return RunChecks(checks, os.Stderr, ignoreChecksErrors)
|
return RunChecks(checks, os.Stderr, ignorePreflightErrors)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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 []Checker, ww io.Writer, ignoreChecksErrors sets.String) error {
|
func RunChecks(checks []Checker, ww io.Writer, ignorePreflightErrors sets.String) error {
|
||||||
type checkErrors struct {
|
type checkErrors struct {
|
||||||
Name string
|
Name string
|
||||||
Errors []error
|
Errors []error
|
||||||
@ -1012,7 +1012,7 @@ func RunChecks(checks []Checker, ww io.Writer, ignoreChecksErrors sets.String) e
|
|||||||
name := c.Name()
|
name := c.Name()
|
||||||
warnings, errs := c.Check()
|
warnings, errs := c.Check()
|
||||||
|
|
||||||
if setHasItemOrAll(ignoreChecksErrors, name) {
|
if setHasItemOrAll(ignorePreflightErrors, name) {
|
||||||
// Decrease severity of errors to warnings for this check
|
// Decrease severity of errors to warnings for this check
|
||||||
warnings = append(warnings, errs...)
|
warnings = append(warnings, errs...)
|
||||||
errs = []error{}
|
errs = []error{}
|
||||||
@ -1038,8 +1038,8 @@ func RunChecks(checks []Checker, ww io.Writer, ignoreChecksErrors sets.String) e
|
|||||||
}
|
}
|
||||||
|
|
||||||
// TryStartKubelet attempts to bring up kubelet service
|
// TryStartKubelet attempts to bring up kubelet service
|
||||||
func TryStartKubelet(ignoreChecksErrors sets.String) {
|
func TryStartKubelet(ignorePreflightErrors sets.String) {
|
||||||
if setHasItemOrAll(ignoreChecksErrors, "StartKubelet") {
|
if setHasItemOrAll(ignorePreflightErrors, "StartKubelet") {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// If we notice that the kubelet service is inactive, try to start it
|
// If we notice that the kubelet service is inactive, try to start it
|
||||||
|
@ -619,3 +619,30 @@ func TestKubeletVersionCheck(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestSetHasItemOrAll(t *testing.T) {
|
||||||
|
var tests = []struct {
|
||||||
|
ignoreSet sets.String
|
||||||
|
testString string
|
||||||
|
expectedResult bool
|
||||||
|
}{
|
||||||
|
{sets.NewString(), "foo", false},
|
||||||
|
{sets.NewString("all"), "foo", true},
|
||||||
|
{sets.NewString("all", "bar"), "foo", true},
|
||||||
|
{sets.NewString("bar"), "foo", false},
|
||||||
|
{sets.NewString("baz", "foo", "bar"), "foo", true},
|
||||||
|
{sets.NewString("baz", "bar", "foo"), "Foo", true},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, rt := range tests {
|
||||||
|
result := setHasItemOrAll(rt.ignoreSet, rt.testString)
|
||||||
|
if result != rt.expectedResult {
|
||||||
|
t.Errorf(
|
||||||
|
"setHasItemOrAll: expected: %v actual: %v (arguments: %q, %q)",
|
||||||
|
rt.expectedResult, result,
|
||||||
|
rt.ignoreSet,
|
||||||
|
rt.testString,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user