mirror of https://github.com/k3s-io/k3s
kubeadm: reduce some functions number of parameters
parent
ba34591627
commit
f600348006
|
@ -140,7 +140,7 @@ func NewCmdInit(out io.Writer, initOptions *initOptions) *cobra.Command {
|
||||||
// adds flags to the init command
|
// adds flags to the init command
|
||||||
// init command local flags could be eventually inherited by the sub-commands automatically generated for phases
|
// init command local flags could be eventually inherited by the sub-commands automatically generated for phases
|
||||||
AddInitConfigFlags(cmd.Flags(), initOptions.externalcfg, &initOptions.featureGatesString)
|
AddInitConfigFlags(cmd.Flags(), initOptions.externalcfg, &initOptions.featureGatesString)
|
||||||
AddInitOtherFlags(cmd.Flags(), &initOptions.cfgPath, &initOptions.skipTokenPrint, &initOptions.dryRun, &initOptions.uploadCerts, &initOptions.ignorePreflightErrors)
|
AddInitOtherFlags(cmd.Flags(), initOptions)
|
||||||
initOptions.bto.AddTokenFlag(cmd.Flags())
|
initOptions.bto.AddTokenFlag(cmd.Flags())
|
||||||
initOptions.bto.AddTTLFlag(cmd.Flags())
|
initOptions.bto.AddTTLFlag(cmd.Flags())
|
||||||
options.AddImageMetaFlags(cmd.Flags(), &initOptions.externalcfg.ImageRepository)
|
options.AddImageMetaFlags(cmd.Flags(), &initOptions.externalcfg.ImageRepository)
|
||||||
|
@ -225,27 +225,22 @@ func AddInitConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.InitConfig
|
||||||
|
|
||||||
// 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
|
||||||
// Note: All flags that are not bound to the cfg object should be allowed in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
|
// Note: All flags that are not bound to the cfg object should be allowed in cmd/kubeadm/app/apis/kubeadm/validation/validation.go
|
||||||
func AddInitOtherFlags(
|
func AddInitOtherFlags(flagSet *flag.FlagSet, initOptions *initOptions) {
|
||||||
flagSet *flag.FlagSet,
|
options.AddConfigFlag(flagSet, &initOptions.cfgPath)
|
||||||
cfgPath *string,
|
|
||||||
skipTokenPrint, dryRun, uploadCerts *bool,
|
|
||||||
ignorePreflightErrors *[]string,
|
|
||||||
) {
|
|
||||||
options.AddConfigFlag(flagSet, cfgPath)
|
|
||||||
flagSet.StringSliceVar(
|
flagSet.StringSliceVar(
|
||||||
ignorePreflightErrors, options.IgnorePreflightErrors, *ignorePreflightErrors,
|
&initOptions.ignorePreflightErrors, options.IgnorePreflightErrors, initOptions.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(
|
||||||
skipTokenPrint, options.SkipTokenPrint, *skipTokenPrint,
|
&initOptions.skipTokenPrint, options.SkipTokenPrint, initOptions.skipTokenPrint,
|
||||||
"Skip printing of the default bootstrap token generated by 'kubeadm init'.",
|
"Skip printing of the default bootstrap token generated by 'kubeadm init'.",
|
||||||
)
|
)
|
||||||
flagSet.BoolVar(
|
flagSet.BoolVar(
|
||||||
dryRun, options.DryRun, *dryRun,
|
&initOptions.dryRun, options.DryRun, initOptions.dryRun,
|
||||||
"Don't apply any changes; just output what would be done.",
|
"Don't apply any changes; just output what would be done.",
|
||||||
)
|
)
|
||||||
flagSet.BoolVar(
|
flagSet.BoolVar(
|
||||||
uploadCerts, options.UploadCerts, *uploadCerts,
|
&initOptions.uploadCerts, options.UploadCerts, initOptions.uploadCerts,
|
||||||
"Upload certfificates to kubeadm-certs secret.",
|
"Upload certfificates to kubeadm-certs secret.",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -476,8 +471,8 @@ func (d *initData) Tokens() []string {
|
||||||
return tokens
|
return tokens
|
||||||
}
|
}
|
||||||
|
|
||||||
func printJoinCommand(out io.Writer, adminKubeConfigPath, token, key string, skipTokenPrint, uploadCerts bool) error {
|
func printJoinCommand(out io.Writer, adminKubeConfigPath, token string, i *initData) error {
|
||||||
joinCommand, err := cmdutil.GetJoinCommand(adminKubeConfigPath, token, key, skipTokenPrint, uploadCerts)
|
joinCommand, err := cmdutil.GetJoinCommand(adminKubeConfigPath, token, i.certificateKey, i.skipTokenPrint, i.uploadCerts)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -496,7 +491,7 @@ func showJoinCommand(i *initData, out io.Writer) error {
|
||||||
|
|
||||||
// Prints the join command, multiple times in case the user has multiple tokens
|
// Prints the join command, multiple times in case the user has multiple tokens
|
||||||
for _, token := range i.Tokens() {
|
for _, token := range i.Tokens() {
|
||||||
if err := printJoinCommand(out, adminKubeConfigPath, token, i.certificateKey, i.skipTokenPrint, i.uploadCerts); err != nil {
|
if err := printJoinCommand(out, adminKubeConfigPath, token, i); err != nil {
|
||||||
return errors.Wrap(err, "failed to print join command")
|
return errors.Wrap(err, "failed to print join command")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -194,7 +194,7 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
||||||
}
|
}
|
||||||
|
|
||||||
addJoinConfigFlags(cmd.Flags(), joinOptions.externalcfg)
|
addJoinConfigFlags(cmd.Flags(), joinOptions.externalcfg)
|
||||||
addJoinOtherFlags(cmd.Flags(), &joinOptions.cfgPath, &joinOptions.ignorePreflightErrors, &joinOptions.controlPlane, &joinOptions.token, &joinOptions.certificateKey)
|
addJoinOtherFlags(cmd.Flags(), joinOptions)
|
||||||
|
|
||||||
joinRunner.AppendPhase(phases.NewPreflightPhase())
|
joinRunner.AppendPhase(phases.NewPreflightPhase())
|
||||||
joinRunner.AppendPhase(phases.NewControlPlanePreparePhase())
|
joinRunner.AppendPhase(phases.NewControlPlanePreparePhase())
|
||||||
|
@ -256,32 +256,25 @@ func addJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta1.JoinConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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(
|
func addJoinOtherFlags(flagSet *flag.FlagSet, joinOptions *joinOptions) {
|
||||||
flagSet *flag.FlagSet,
|
|
||||||
cfgPath *string,
|
|
||||||
ignorePreflightErrors *[]string,
|
|
||||||
controlPlane *bool,
|
|
||||||
token *string,
|
|
||||||
certificateKey *string,
|
|
||||||
) {
|
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
cfgPath, options.CfgPath, *cfgPath,
|
&joinOptions.cfgPath, options.CfgPath, joinOptions.cfgPath,
|
||||||
"Path to kubeadm config file.",
|
"Path to kubeadm config file.",
|
||||||
)
|
)
|
||||||
flagSet.StringSliceVar(
|
flagSet.StringSliceVar(
|
||||||
ignorePreflightErrors, options.IgnorePreflightErrors, *ignorePreflightErrors,
|
&joinOptions.ignorePreflightErrors, options.IgnorePreflightErrors, joinOptions.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.StringVar(
|
flagSet.StringVar(
|
||||||
token, options.TokenStr, "",
|
&joinOptions.token, options.TokenStr, "",
|
||||||
"Use this token for both discovery-token and tls-bootstrap-token when those values are not provided.",
|
"Use this token for both discovery-token and tls-bootstrap-token when those values are not provided.",
|
||||||
)
|
)
|
||||||
flagSet.BoolVar(
|
flagSet.BoolVar(
|
||||||
controlPlane, options.ControlPlane, *controlPlane,
|
&joinOptions.controlPlane, options.ControlPlane, joinOptions.controlPlane,
|
||||||
"Create a new control plane instance on this node",
|
"Create a new control plane instance on this node",
|
||||||
)
|
)
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
certificateKey, options.CertificateKey, "",
|
&joinOptions.certificateKey, options.CertificateKey, "",
|
||||||
"Use this key to decrypt the certificate secrets uploaded by init.",
|
"Use this key to decrypt the certificate secrets uploaded by init.",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue