kubeadm: remove misleading warning on kubeadm join
If the user does not provide --config or --control-plane but provides some other flags such as --certificate-key kubeadm is supposed to print a warning. The logic around printing the warning is bogus. Implement proper checks of when to print the warning.
This commit is contained in:
@@ -20,6 +20,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"text/template"
|
"text/template"
|
||||||
|
|
||||||
"github.com/lithammer/dedent"
|
"github.com/lithammer/dedent"
|
||||||
@@ -127,6 +128,7 @@ type joinOptions struct {
|
|||||||
controlPlane bool
|
controlPlane bool
|
||||||
ignorePreflightErrors []string
|
ignorePreflightErrors []string
|
||||||
externalcfg *kubeadmapiv1beta2.JoinConfiguration
|
externalcfg *kubeadmapiv1beta2.JoinConfiguration
|
||||||
|
joinControlPlane *kubeadmapiv1beta2.JoinControlPlane
|
||||||
kustomizeDir string
|
kustomizeDir string
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -199,7 +201,7 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
|||||||
Args: cobra.MaximumNArgs(1),
|
Args: cobra.MaximumNArgs(1),
|
||||||
}
|
}
|
||||||
|
|
||||||
addJoinConfigFlags(cmd.Flags(), joinOptions.externalcfg)
|
addJoinConfigFlags(cmd.Flags(), joinOptions.externalcfg, joinOptions.joinControlPlane)
|
||||||
addJoinOtherFlags(cmd.Flags(), joinOptions)
|
addJoinOtherFlags(cmd.Flags(), joinOptions)
|
||||||
|
|
||||||
joinRunner.AppendPhase(phases.NewPreflightPhase())
|
joinRunner.AppendPhase(phases.NewPreflightPhase())
|
||||||
@@ -222,22 +224,22 @@ func NewCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 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 *kubeadmapiv1beta2.JoinConfiguration) {
|
func addJoinConfigFlags(flagSet *flag.FlagSet, cfg *kubeadmapiv1beta2.JoinConfiguration, jcp *kubeadmapiv1beta2.JoinControlPlane) {
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
&cfg.NodeRegistration.Name, options.NodeName, cfg.NodeRegistration.Name,
|
&cfg.NodeRegistration.Name, options.NodeName, cfg.NodeRegistration.Name,
|
||||||
`Specify the node name.`,
|
`Specify the node name.`,
|
||||||
)
|
)
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
&cfg.ControlPlane.CertificateKey, options.CertificateKey, "",
|
&jcp.CertificateKey, options.CertificateKey, jcp.CertificateKey,
|
||||||
"Use this key to decrypt the certificate secrets uploaded by init.",
|
"Use this key to decrypt the certificate secrets uploaded by init.",
|
||||||
)
|
)
|
||||||
// add control plane endpoint flags to the specified flagset
|
// add control plane endpoint flags to the specified flagset
|
||||||
flagSet.StringVar(
|
flagSet.StringVar(
|
||||||
&cfg.ControlPlane.LocalAPIEndpoint.AdvertiseAddress, options.APIServerAdvertiseAddress, cfg.ControlPlane.LocalAPIEndpoint.AdvertiseAddress,
|
&jcp.LocalAPIEndpoint.AdvertiseAddress, options.APIServerAdvertiseAddress, jcp.LocalAPIEndpoint.AdvertiseAddress,
|
||||||
"If the node should host a new control plane instance, the IP address the API Server will advertise it's listening on. If not set the default network interface will be used.",
|
"If the node should host a new control plane instance, the IP address the API Server will advertise it's listening on. If not set the default network interface will be used.",
|
||||||
)
|
)
|
||||||
flagSet.Int32Var(
|
flagSet.Int32Var(
|
||||||
&cfg.ControlPlane.LocalAPIEndpoint.BindPort, options.APIServerBindPort, cfg.ControlPlane.LocalAPIEndpoint.BindPort,
|
&jcp.LocalAPIEndpoint.BindPort, options.APIServerBindPort, jcp.LocalAPIEndpoint.BindPort,
|
||||||
"If the node should host a new control plane instance, the port for the API Server to bind to.",
|
"If the node should host a new control plane instance, the port for the API Server to bind to.",
|
||||||
)
|
)
|
||||||
// adds bootstrap token specific discovery flags to the specified flagset
|
// adds bootstrap token specific discovery flags to the specified flagset
|
||||||
@@ -297,11 +299,16 @@ func newJoinOptions() *joinOptions {
|
|||||||
externalcfg.Discovery.BootstrapToken = &kubeadmapiv1beta2.BootstrapTokenDiscovery{}
|
externalcfg.Discovery.BootstrapToken = &kubeadmapiv1beta2.BootstrapTokenDiscovery{}
|
||||||
externalcfg.ControlPlane = &kubeadmapiv1beta2.JoinControlPlane{}
|
externalcfg.ControlPlane = &kubeadmapiv1beta2.JoinControlPlane{}
|
||||||
|
|
||||||
|
// This object is used for storage of control-plane flags.
|
||||||
|
joinControlPlane := &kubeadmapiv1beta2.JoinControlPlane{}
|
||||||
|
|
||||||
// Apply defaults
|
// Apply defaults
|
||||||
kubeadmscheme.Scheme.Default(externalcfg)
|
kubeadmscheme.Scheme.Default(externalcfg)
|
||||||
|
kubeadmapiv1beta2.SetDefaults_JoinControlPlane(joinControlPlane)
|
||||||
|
|
||||||
return &joinOptions{
|
return &joinOptions{
|
||||||
externalcfg: externalcfg,
|
externalcfg: externalcfg,
|
||||||
|
joinControlPlane: joinControlPlane,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,6 +316,12 @@ func newJoinOptions() *joinOptions {
|
|||||||
// This func takes care of validating joinOptions passed to the command, and then it converts
|
// This func takes care of validating joinOptions passed to the command, and then it converts
|
||||||
// options into the internal JoinConfiguration type that is used as input all the phases in the kubeadm join workflow
|
// options into the internal JoinConfiguration type that is used as input all the phases in the kubeadm join workflow
|
||||||
func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Writer) (*joinData, error) {
|
func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Writer) (*joinData, error) {
|
||||||
|
|
||||||
|
// Validate the mixed arguments with --config and return early on errors
|
||||||
|
if err := validation.ValidateMixedArguments(cmd.Flags()); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
// Re-apply defaults to the public kubeadm API (this will set only values not exposed/not set as a flags)
|
// Re-apply defaults to the public kubeadm API (this will set only values not exposed/not set as a flags)
|
||||||
kubeadmscheme.Scheme.Default(opt.externalcfg)
|
kubeadmscheme.Scheme.Default(opt.externalcfg)
|
||||||
|
|
||||||
@@ -340,10 +353,26 @@ func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Wri
|
|||||||
opt.externalcfg.Discovery.BootstrapToken.APIServerEndpoint = args[0]
|
opt.externalcfg.Discovery.BootstrapToken.APIServerEndpoint = args[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
// if not joining a control plane, unset the ControlPlane object
|
// Include the JoinControlPlane with user flags
|
||||||
|
opt.externalcfg.ControlPlane = opt.joinControlPlane
|
||||||
|
|
||||||
|
// If not passing --control-plane, unset the ControlPlane object
|
||||||
if !opt.controlPlane {
|
if !opt.controlPlane {
|
||||||
if opt.externalcfg.ControlPlane != nil {
|
// Use a defaulted JoinControlPlane object to detect if the user has passed
|
||||||
klog.Warningf("[preflight] WARNING: JoinControlPane.controlPlane settings will be ignored when %s flag is not set.", options.ControlPlane)
|
// other control-plane related flags.
|
||||||
|
defaultJCP := &kubeadmapiv1beta2.JoinControlPlane{}
|
||||||
|
kubeadmapiv1beta2.SetDefaults_JoinControlPlane(defaultJCP)
|
||||||
|
|
||||||
|
// This list must match the JCP flags in addJoinConfigFlags()
|
||||||
|
joinControlPlaneFlags := []string{
|
||||||
|
options.CertificateKey,
|
||||||
|
options.APIServerAdvertiseAddress,
|
||||||
|
options.APIServerBindPort,
|
||||||
|
}
|
||||||
|
|
||||||
|
if *opt.joinControlPlane != *defaultJCP {
|
||||||
|
klog.Warningf("[preflight] WARNING: --%s is also required when passing control-plane "+
|
||||||
|
"related flags such as [%s]", options.ControlPlane, strings.Join(joinControlPlaneFlags, ", "))
|
||||||
}
|
}
|
||||||
opt.externalcfg.ControlPlane = nil
|
opt.externalcfg.ControlPlane = nil
|
||||||
}
|
}
|
||||||
@@ -361,10 +390,6 @@ func newJoinData(cmd *cobra.Command, args []string, opt *joinOptions, out io.Wri
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := validation.ValidateMixedArguments(cmd.Flags()); err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
// Either use the config file if specified, or convert public kubeadm API to the internal JoinConfiguration
|
// Either use the config file if specified, or convert public kubeadm API to the internal JoinConfiguration
|
||||||
// and validates JoinConfiguration
|
// and validates JoinConfiguration
|
||||||
if opt.externalcfg.NodeRegistration.Name == "" {
|
if opt.externalcfg.NodeRegistration.Name == "" {
|
||||||
|
|||||||
Reference in New Issue
Block a user