Skip to content

Commit 478c934

Browse files
authored
Merge pull request kubernetes#121295 from SataQiu/clean-kubeadm-20231017
kubeadm: remove reference to UnknownCRISocket from getInitConfigurationFromCluster
2 parents 2fcddbd + c281c70 commit 478c934

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

cmd/kubeadm/app/util/config/cluster.go

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ func FetchInitConfigurationFromCluster(client clientset.Interface, printer outpu
5959
}
6060

6161
// Apply dynamic defaults
62-
if err := SetInitDynamicDefaults(cfg, false); err != nil {
62+
// NB. skip CRI detection here because it won't be used at all and will be overridden later
63+
if err := SetInitDynamicDefaults(cfg, true); err != nil {
6364
return nil, err
6465
}
6566

@@ -116,15 +117,6 @@ func getInitConfigurationFromCluster(kubeconfigDir string, client clientset.Inte
116117
if err := getAPIEndpoint(client, initcfg.NodeRegistration.Name, &initcfg.LocalAPIEndpoint); err != nil {
117118
return nil, errors.Wrap(err, "failed to getAPIEndpoint")
118119
}
119-
} else {
120-
// In the case where newControlPlane is true we don't go through getNodeRegistration() and initcfg.NodeRegistration.CRISocket is empty.
121-
// This forces DetectCRISocket() to be called later on, and if there is more than one CRI installed on the system, it will error out,
122-
// while asking for the user to provide an override for the CRI socket. Even if the user provides an override, the call to
123-
// DetectCRISocket() can happen too early and thus ignore it (while still erroring out).
124-
// However, if newControlPlane == true, initcfg.NodeRegistration is not used at all and it's overwritten later on.
125-
// Thus it's necessary to supply some default value, that will avoid the call to DetectCRISocket() and as
126-
// initcfg.NodeRegistration is discarded, setting whatever value here is harmless.
127-
initcfg.NodeRegistration.CRISocket = constants.UnknownCRISocket
128120
}
129121
return initcfg, nil
130122
}

cmd/kubeadm/app/util/config/cluster_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,12 @@ func TestGetInitConfigurationFromCluster(t *testing.T) {
646646
if !rt.newControlPlane && (cfg.LocalAPIEndpoint.AdvertiseAddress != "1.2.3.4" || cfg.LocalAPIEndpoint.BindPort != 1234) {
647647
t.Errorf("invalid cfg.LocalAPIEndpoint: %v", cfg.LocalAPIEndpoint)
648648
}
649+
if !rt.newControlPlane && (cfg.NodeRegistration.Name != nodeName || cfg.NodeRegistration.CRISocket != "myCRIsocket" || len(cfg.NodeRegistration.Taints) != 1) {
650+
t.Errorf("invalid cfg.NodeRegistration: %v", cfg.NodeRegistration)
651+
}
652+
if rt.newControlPlane && len(cfg.NodeRegistration.CRISocket) > 0 {
653+
t.Errorf("invalid cfg.NodeRegistration.CRISocket: expected empty CRISocket, but got %v", cfg.NodeRegistration.CRISocket)
654+
}
649655
if _, ok := cfg.ComponentConfigs[componentconfigs.KubeletGroup]; !ok {
650656
t.Errorf("no cfg.ComponentConfigs[%q]", componentconfigs.KubeletGroup)
651657
}

0 commit comments

Comments
 (0)