From c281c70bac396e3b61cc4250881aff42af429224 Mon Sep 17 00:00:00 2001 From: SataQiu Date: Tue, 17 Oct 2023 21:50:05 +0800 Subject: [PATCH] kubeadm: remove reference to UnknownCRISocket from getInitConfigurationFromCluster --- cmd/kubeadm/app/util/config/cluster.go | 12 ++---------- cmd/kubeadm/app/util/config/cluster_test.go | 6 ++++++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/cmd/kubeadm/app/util/config/cluster.go b/cmd/kubeadm/app/util/config/cluster.go index 354af0a16b8..b4b3371dd98 100644 --- a/cmd/kubeadm/app/util/config/cluster.go +++ b/cmd/kubeadm/app/util/config/cluster.go @@ -59,7 +59,8 @@ func FetchInitConfigurationFromCluster(client clientset.Interface, printer outpu } // Apply dynamic defaults - if err := SetInitDynamicDefaults(cfg, false); err != nil { + // NB. skip CRI detection here because it won't be used at all and will be overridden later + if err := SetInitDynamicDefaults(cfg, true); err != nil { return nil, err } @@ -116,15 +117,6 @@ func getInitConfigurationFromCluster(kubeconfigDir string, client clientset.Inte if err := getAPIEndpoint(client, initcfg.NodeRegistration.Name, &initcfg.LocalAPIEndpoint); err != nil { return nil, errors.Wrap(err, "failed to getAPIEndpoint") } - } else { - // In the case where newControlPlane is true we don't go through getNodeRegistration() and initcfg.NodeRegistration.CRISocket is empty. - // This forces DetectCRISocket() to be called later on, and if there is more than one CRI installed on the system, it will error out, - // while asking for the user to provide an override for the CRI socket. Even if the user provides an override, the call to - // DetectCRISocket() can happen too early and thus ignore it (while still erroring out). - // However, if newControlPlane == true, initcfg.NodeRegistration is not used at all and it's overwritten later on. - // Thus it's necessary to supply some default value, that will avoid the call to DetectCRISocket() and as - // initcfg.NodeRegistration is discarded, setting whatever value here is harmless. - initcfg.NodeRegistration.CRISocket = constants.UnknownCRISocket } return initcfg, nil } diff --git a/cmd/kubeadm/app/util/config/cluster_test.go b/cmd/kubeadm/app/util/config/cluster_test.go index 9232aa5e0e5..e31ac4dbe06 100644 --- a/cmd/kubeadm/app/util/config/cluster_test.go +++ b/cmd/kubeadm/app/util/config/cluster_test.go @@ -646,6 +646,12 @@ func TestGetInitConfigurationFromCluster(t *testing.T) { if !rt.newControlPlane && (cfg.LocalAPIEndpoint.AdvertiseAddress != "1.2.3.4" || cfg.LocalAPIEndpoint.BindPort != 1234) { t.Errorf("invalid cfg.LocalAPIEndpoint: %v", cfg.LocalAPIEndpoint) } + if !rt.newControlPlane && (cfg.NodeRegistration.Name != nodeName || cfg.NodeRegistration.CRISocket != "myCRIsocket" || len(cfg.NodeRegistration.Taints) != 1) { + t.Errorf("invalid cfg.NodeRegistration: %v", cfg.NodeRegistration) + } + if rt.newControlPlane && len(cfg.NodeRegistration.CRISocket) > 0 { + t.Errorf("invalid cfg.NodeRegistration.CRISocket: expected empty CRISocket, but got %v", cfg.NodeRegistration.CRISocket) + } if _, ok := cfg.ComponentConfigs[componentconfigs.KubeletGroup]; !ok { t.Errorf("no cfg.ComponentConfigs[%q]", componentconfigs.KubeletGroup) }