kubeadm: avoid CRI detection for phase subcommand when it's --cri-socket flag is not set

This commit is contained in:
SataQiu 2022-12-14 12:00:49 +08:00
parent 6b9035513b
commit 2501a46b80
6 changed files with 17 additions and 1 deletions

View File

@ -150,6 +150,11 @@ func newCmdInit(out io.Writer, initOptions *initOptions) *cobra.Command {
// sets the data builder function, that will be used by the runner
// both when running the entire workflow or single phases
initRunner.SetDataInitializer(func(cmd *cobra.Command, args []string) (workflow.RunData, error) {
if cmd.Flags().Lookup(options.NodeCRISocket) == nil {
// avoid CRI detection
// assume that the command execution does not depend on CRISocket when --cri-socket flag is not set
initOptions.externalInitCfg.NodeRegistration.CRISocket = kubeadmconstants.UnknownCRISocket
}
data, err := newInitData(cmd, args, initOptions, out)
if err != nil {
return nil, err

View File

@ -221,6 +221,11 @@ func newCmdJoin(out io.Writer, joinOptions *joinOptions) *cobra.Command {
// sets the data builder function, that will be used by the runner
// both when running the entire workflow or single phases
joinRunner.SetDataInitializer(func(cmd *cobra.Command, args []string) (workflow.RunData, error) {
if cmd.Flags().Lookup(options.NodeCRISocket) == nil {
// avoid CRI detection
// assume that the command execution does not depend on CRISocket when --cri-socket flag is not set
joinOptions.externalcfg.NodeRegistration.CRISocket = kubeadmconstants.UnknownCRISocket
}
data, err := newJoinData(cmd, args, joinOptions, out, kubeadmconstants.GetAdminKubeConfigPath())
if err != nil {
return nil, err

View File

@ -46,6 +46,7 @@ func NewPreflightPhase() workflow.Phase {
Run: runPreflight,
InheritFlags: []string{
options.CfgPath,
options.NodeCRISocket,
options.IgnorePreflightErrors,
options.DryRun,
},

View File

@ -36,7 +36,6 @@ func NewUploadCertsPhase() workflow.Phase {
Run: runUploadCerts,
InheritFlags: []string{
options.CfgPath,
options.NodeCRISocket,
options.KubeconfigPath,
options.UploadCerts,
options.CertificateKey,

View File

@ -96,6 +96,7 @@ func NewUploadConfigPhase() workflow.Phase {
func getUploadConfigPhaseFlags() []string {
return []string{
options.CfgPath,
options.NodeCRISocket,
options.KubeconfigPath,
options.DryRun,
}

View File

@ -203,6 +203,11 @@ func newCmdReset(in io.Reader, out io.Writer, resetOptions *resetOptions) *cobra
// sets the data builder function, that will be used by the runner
// both when running the entire workflow or single phases
resetRunner.SetDataInitializer(func(cmd *cobra.Command, args []string) (workflow.RunData, error) {
if cmd.Flags().Lookup(options.NodeCRISocket) == nil {
// avoid CRI detection
// assume that the command execution does not depend on CRISocket when --cri-socket flag is not set
resetOptions.criSocketPath = kubeadmconstants.UnknownCRISocket
}
return newResetData(cmd, resetOptions, in, out)
})