mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-12 13:31:52 +00:00
kubeadm: use the helper NewValidJoin() in join.go
Instead of using kubeadmutil.CheckErr() in every single phase of cmd.Run(), use a new helper function NewValidJoin() that returns a single error. This would improve the unit testing options for this file. Otherwise any error in cmd.Run() will trigger an os.Exit() as kubeadmutil.CheckErr() does that.
This commit is contained in:
parent
3fb88a23d9
commit
01377eeaf6
@ -115,21 +115,7 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
|
|||||||
Short: "Run this on any machine you wish to join an existing cluster",
|
Short: "Run this on any machine you wish to join an existing cluster",
|
||||||
Long: joinLongDescription,
|
Long: joinLongDescription,
|
||||||
Run: func(cmd *cobra.Command, args []string) {
|
Run: func(cmd *cobra.Command, args []string) {
|
||||||
cfg.DiscoveryTokenAPIServers = args
|
j, err := NewValidJoin(cfg, args, skipPreFlight, cfgPath, featureGatesString, ignorePreflightErrors)
|
||||||
|
|
||||||
var err error
|
|
||||||
if cfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString); err != nil {
|
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
legacyscheme.Scheme.Default(cfg)
|
|
||||||
internalcfg := &kubeadmapi.NodeConfiguration{}
|
|
||||||
legacyscheme.Scheme.Convert(cfg, internalcfg, nil)
|
|
||||||
|
|
||||||
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(ignorePreflightErrors, skipPreFlight)
|
|
||||||
kubeadmutil.CheckErr(err)
|
|
||||||
|
|
||||||
j, err := NewJoin(cfgPath, args, internalcfg, ignorePreflightErrorsSet)
|
|
||||||
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))
|
||||||
@ -142,6 +128,27 @@ func NewCmdJoin(out io.Writer) *cobra.Command {
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewValidJoin validates the command line that are passed to the cobra command
|
||||||
|
func NewValidJoin(cfg *kubeadmapiext.NodeConfiguration, args []string, skipPreFlight bool, cfgPath, featureGatesString string, ignorePreflightErrors []string) (*Join, error) {
|
||||||
|
cfg.DiscoveryTokenAPIServers = args
|
||||||
|
|
||||||
|
var err error
|
||||||
|
if cfg.FeatureGates, err = features.NewFeatureGate(&features.InitFeatureGates, featureGatesString); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
legacyscheme.Scheme.Default(cfg)
|
||||||
|
internalcfg := &kubeadmapi.NodeConfiguration{}
|
||||||
|
legacyscheme.Scheme.Convert(cfg, internalcfg, nil)
|
||||||
|
|
||||||
|
ignorePreflightErrorsSet, err := validation.ValidateIgnorePreflightErrors(ignorePreflightErrors, skipPreFlight)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return NewJoin(cfgPath, args, internalcfg, ignorePreflightErrorsSet)
|
||||||
|
}
|
||||||
|
|
||||||
// AddJoinConfigFlags adds join flags bound to the config to the specified flagset
|
// AddJoinConfigFlags adds join flags bound to the config to the specified flagset
|
||||||
func AddJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiext.NodeConfiguration, featureGatesString *string) {
|
func AddJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiext.NodeConfiguration, featureGatesString *string) {
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
|
Loading…
Reference in New Issue
Block a user