Skip to content

Commit

Permalink
🌱 kcp: ensure ReadinessGates for v1beta2 conditions get set (#11335)
Browse files Browse the repository at this point in the history
* kcp: ensure ReadinessGates for v1beta2 conditions get set

* review fixes
  • Loading branch information
chrischdi authored Oct 25, 2024
1 parent 7957510 commit 80e26b4
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1567,6 +1567,7 @@ func TestKubeadmControlPlaneReconciler_syncMachines(t *testing.T) {
NodeDrainTimeout: duration5s,
NodeVolumeDetachTimeout: duration5s,
NodeDeletionTimeout: duration5s,
ReadinessGates: mandatoryMachineReadinessGates,
},
}
g.Expect(env.Create(ctx, deletingMachine, client.FieldOwner(classicManager))).To(Succeed())
Expand Down
31 changes: 31 additions & 0 deletions controlplane/kubeadm/internal/controllers/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ import (
"sigs.k8s.io/cluster-api/util/secret"
)

// mandatoryMachineReadinessGates are readinessGates KCP enforces to be set on machine it owns.
var mandatoryMachineReadinessGates = []clusterv1.MachineReadinessGate{
{ConditionType: string(controlplanev1.KubeadmControlPlaneMachineAPIServerPodHealthyV1Beta2Condition)},
{ConditionType: string(controlplanev1.KubeadmControlPlaneMachineControllerManagerPodHealthyV1Beta2Condition)},
{ConditionType: string(controlplanev1.KubeadmControlPlaneMachineSchedulerPodHealthyV1Beta2Condition)},
{ConditionType: string(controlplanev1.KubeadmControlPlaneMachineEtcdPodHealthyV1Beta2Condition)},
{ConditionType: string(controlplanev1.KubeadmControlPlaneMachineEtcdMemberHealthyV1Beta2Condition)},
}

func (r *KubeadmControlPlaneReconciler) reconcileKubeconfig(ctx context.Context, controlPlane *internal.ControlPlane) (ctrl.Result, error) {
log := ctrl.LoggerFrom(ctx)

Expand Down Expand Up @@ -443,7 +452,29 @@ func (r *KubeadmControlPlaneReconciler) computeDesiredMachine(kcp *controlplanev
if existingMachine != nil {
desiredMachine.Spec.InfrastructureRef = existingMachine.Spec.InfrastructureRef
desiredMachine.Spec.Bootstrap.ConfigRef = existingMachine.Spec.Bootstrap.ConfigRef
desiredMachine.Spec.ReadinessGates = existingMachine.Spec.ReadinessGates
}
ensureMandatoryReadinessGates(desiredMachine)

return desiredMachine, nil
}

func ensureMandatoryReadinessGates(m *clusterv1.Machine) {
if m.Spec.ReadinessGates == nil {
m.Spec.ReadinessGates = mandatoryMachineReadinessGates
return
}

for _, want := range mandatoryMachineReadinessGates {
found := false
for _, got := range m.Spec.ReadinessGates {
if got.ConditionType == want.ConditionType {
found = true
break
}
}
if !found {
m.Spec.ReadinessGates = append(m.Spec.ReadinessGates, want)
}
}
}
3 changes: 3 additions & 0 deletions controlplane/kubeadm/internal/controllers/helpers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ func TestKubeadmControlPlaneReconciler_computeDesiredMachine(t *testing.T) {
NodeDrainTimeout: kcp.Spec.MachineTemplate.NodeDrainTimeout,
NodeDeletionTimeout: kcp.Spec.MachineTemplate.NodeDeletionTimeout,
NodeVolumeDetachTimeout: kcp.Spec.MachineTemplate.NodeVolumeDetachTimeout,
ReadinessGates: mandatoryMachineReadinessGates,
}
g.Expect(createdMachine.Name).To(HavePrefix(kcp.Name))
g.Expect(createdMachine.Namespace).To(Equal(kcp.Namespace))
Expand Down Expand Up @@ -601,6 +602,7 @@ func TestKubeadmControlPlaneReconciler_computeDesiredMachine(t *testing.T) {
ConfigRef: bootstrapRef,
},
InfrastructureRef: *infraRef,
ReadinessGates: []clusterv1.MachineReadinessGate{{ConditionType: "Foo"}},
},
}

Expand All @@ -621,6 +623,7 @@ func TestKubeadmControlPlaneReconciler_computeDesiredMachine(t *testing.T) {
NodeDrainTimeout: kcp.Spec.MachineTemplate.NodeDrainTimeout,
NodeDeletionTimeout: kcp.Spec.MachineTemplate.NodeDeletionTimeout,
NodeVolumeDetachTimeout: kcp.Spec.MachineTemplate.NodeVolumeDetachTimeout,
ReadinessGates: append([]clusterv1.MachineReadinessGate{{ConditionType: "Foo"}}, mandatoryMachineReadinessGates...),
}
g.Expect(updatedMachine.Namespace).To(Equal(kcp.Namespace))
g.Expect(updatedMachine.OwnerReferences).To(HaveLen(1))
Expand Down

0 comments on commit 80e26b4

Please sign in to comment.