Skip to content

Commit a6d5e66

Browse files
authored
Merge pull request #12540 from fabriziopandini/stop-requiring-init-or-cluster-configuration
✨ Stop requiring init or cluster configuration for first CP machine
2 parents 2157a8d + 922d926 commit a6d5e66

File tree

10 files changed

+26
-23
lines changed

10 files changed

+26
-23
lines changed

api/bootstrap/kubeadm/v1beta2/kubeadm_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ const (
7373

7474
// InitConfiguration contains a list of elements that is specific "kubeadm init"-only runtime
7575
// information.
76+
// +kubebuilder:validation:MinProperties=1
7677
type InitConfiguration struct {
7778
// bootstrapTokens is respected at `kubeadm init` time and describes a set of Bootstrap Tokens to create.
7879
// This information IS NOT uploaded to the kubeadm cluster configmap, partly because of its sensitive nature
@@ -119,6 +120,7 @@ type InitConfiguration struct {
119120
}
120121

121122
// ClusterConfiguration contains cluster-wide configuration for a kubeadm cluster.
123+
// +kubebuilder:validation:MinProperties=1
122124
type ClusterConfiguration struct {
123125
// etcd holds configuration for etcd.
124126
// NB: This value defaults to a Local (stacked) etcd
@@ -545,6 +547,7 @@ type ExternalEtcd struct {
545547
}
546548

547549
// JoinConfiguration contains elements describing a particular node.
550+
// +kubebuilder:validation:MinProperties=1
548551
type JoinConfiguration struct {
549552
// nodeRegistration holds fields that relate to registering the new control-plane node to the cluster.
550553
// When used in the context of control plane nodes, NodeRegistration should remain consistent

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigs.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/config/crd/bases/bootstrap.cluster.x-k8s.io_kubeadmconfigtemplates.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,6 @@ func (r *KubeadmConfigReconciler) handleClusterNotInitialized(ctx context.Contex
494494
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
495495
}
496496

497-
// if the machine has not ClusterConfiguration and InitConfiguration, requeue
498-
if scope.Config.Spec.InitConfiguration == nil && scope.Config.Spec.ClusterConfiguration == nil {
499-
scope.Info("Control plane is not ready, requeuing joining control planes until ready.")
500-
return ctrl.Result{RequeueAfter: 30 * time.Second}, nil
501-
}
502-
503497
machine := &clusterv1.Machine{}
504498
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(scope.ConfigOwner.Object, machine); err != nil {
505499
return ctrl.Result{}, errors.Wrapf(err, "cannot convert %s to Machine", scope.ConfigOwner.GetKind())

bootstrap/kubeadm/internal/controllers/kubeadmconfig_controller_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,7 @@ func TestKubeadmConfigReconciler_Reconcile_RequeueJoiningNodesIfControlPlaneNotI
426426
name string
427427
request ctrl.Request
428428
objects []client.Object
429+
lock bool
429430
}{
430431
{
431432
name: "requeue worker when control plane is not yet initialized",
@@ -454,6 +455,7 @@ func TestKubeadmConfigReconciler_Reconcile_RequeueJoiningNodesIfControlPlaneNotI
454455
controlPlaneJoinMachine,
455456
controlPlaneJoinConfig,
456457
},
458+
lock: true,
457459
},
458460
}
459461
for _, tc := range testcases {
@@ -468,6 +470,10 @@ func TestKubeadmConfigReconciler_Reconcile_RequeueJoiningNodesIfControlPlaneNotI
468470
KubeadmInitLock: &myInitLocker{},
469471
}
470472

473+
if tc.lock {
474+
k.KubeadmInitLock.Lock(ctx, nil, nil)
475+
}
476+
471477
result, err := k.Reconcile(ctx, tc.request)
472478
g.Expect(err).ToNot(HaveOccurred())
473479
g.Expect(result.Requeue).To(BeFalse())
@@ -1944,6 +1950,7 @@ func TestKubeadmConfigReconciler_Reconcile_AlwaysCheckCAVerificationUnlessReques
19441950
}
19451951

19461952
wc := newWorkerJoinKubeadmConfig(metav1.NamespaceDefault, "worker-join-cfg")
1953+
wc.Spec.JoinConfiguration = &bootstrapv1.JoinConfiguration{}
19471954
wc.Spec.JoinConfiguration.Discovery.BootstrapToken = tc.discovery
19481955
key := client.ObjectKey{Namespace: wc.Namespace, Name: wc.Name}
19491956
err := myclient.Create(ctx, wc)
@@ -2576,11 +2583,7 @@ func newKubeadmConfig(namespace, name string) *bootstrapv1.KubeadmConfig {
25762583

25772584
// newKubeadmConfig return a CABPK KubeadmConfig object with a worker JoinConfiguration.
25782585
func newWorkerJoinKubeadmConfig(namespace, name string) *bootstrapv1.KubeadmConfig {
2579-
return bootstrapbuilder.KubeadmConfig(namespace, name).
2580-
WithJoinConfig(&bootstrapv1.JoinConfiguration{
2581-
ControlPlane: nil,
2582-
}).
2583-
Build()
2586+
return bootstrapbuilder.KubeadmConfig(namespace, name).Build()
25842587
}
25852588

25862589
// newKubeadmConfig returns a CABPK KubeadmConfig object with a ControlPlane JoinConfiguration.
@@ -2594,10 +2597,7 @@ func newControlPlaneJoinKubeadmConfig(namespace, name string) *bootstrapv1.Kubea
25942597

25952598
// newControlPlaneJoinConfig returns a CABPK KubeadmConfig object with a ControlPlane InitConfiguration and ClusterConfiguration.
25962599
func newControlPlaneInitKubeadmConfig(namespace, name string) *bootstrapv1.KubeadmConfig {
2597-
return bootstrapbuilder.KubeadmConfig(namespace, name).
2598-
WithInitConfig(&bootstrapv1.InitConfiguration{}).
2599-
WithClusterConfig(&bootstrapv1.ClusterConfiguration{}).
2600-
Build()
2600+
return bootstrapbuilder.KubeadmConfig(namespace, name).Build()
26012601
}
26022602

26032603
// addKubeadmConfigToMachine adds the config details to the passed Machine, and adds the Machine to the KubeadmConfig as an ownerReference.

controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanes.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/kubeadm/config/crd/bases/controlplane.cluster.x-k8s.io_kubeadmcontrolplanetemplates.yaml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

controlplane/kubeadm/internal/control_plane.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,6 @@ func getGetFailureDomainIDs(failureDomains []clusterv1.FailureDomain) []string {
223223
// InitialControlPlaneConfig returns a new KubeadmConfigSpec that is to be used for an initializing control plane.
224224
func (c *ControlPlane) InitialControlPlaneConfig() *bootstrapv1.KubeadmConfigSpec {
225225
bootstrapSpec := c.KCP.Spec.KubeadmConfigSpec.DeepCopy()
226-
if bootstrapSpec.InitConfiguration == nil {
227-
bootstrapSpec.InitConfiguration = &bootstrapv1.InitConfiguration{}
228-
}
229226
bootstrapSpec.JoinConfiguration = nil
230227
return bootstrapSpec
231228
}

controlplane/kubeadm/internal/controllers/controller_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1740,8 +1740,7 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
17401740

17411741
// Existing KubeadmConfig
17421742
bootstrapSpec := &bootstrapv1.KubeadmConfigSpec{
1743-
Users: []bootstrapv1.User{{Name: "test-user"}},
1744-
JoinConfiguration: &bootstrapv1.JoinConfiguration{},
1743+
Users: []bootstrapv1.User{{Name: "test-user"}},
17451744
}
17461745
existingKubeadmConfig := &bootstrapv1.KubeadmConfig{
17471746
TypeMeta: metav1.TypeMeta{

controlplane/kubeadm/internal/controllers/helpers_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -372,9 +372,7 @@ func TestCloneConfigsAndGenerateMachine(t *testing.T) {
372372
recorder: record.NewFakeRecorder(32),
373373
}
374374

375-
bootstrapSpec := &bootstrapv1.KubeadmConfigSpec{
376-
JoinConfiguration: &bootstrapv1.JoinConfiguration{},
377-
}
375+
bootstrapSpec := &bootstrapv1.KubeadmConfigSpec{}
378376
_, err := r.cloneConfigsAndGenerateMachine(ctx, cluster, kcp, bootstrapSpec, "")
379377
g.Expect(err).To(Succeed())
380378

0 commit comments

Comments
 (0)