Skip to content

Commit

Permalink
Fix review findings
Browse files Browse the repository at this point in the history
  • Loading branch information
sbueringer committed Oct 28, 2024
1 parent 3d25bbd commit 6344197
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 11 deletions.
5 changes: 0 additions & 5 deletions controlplane/kubeadm/internal/controllers/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -490,11 +490,6 @@ func (r *KubeadmControlPlaneReconciler) reconcile(ctx context.Context, controlPl
// Create new Machine w/ init
log.Info("Initializing control plane", "desired", desiredReplicas, "existing", numMachines)
conditions.MarkFalse(controlPlane.KCP, controlplanev1.AvailableCondition, controlplanev1.WaitingForKubeadmInitReason, clusterv1.ConditionSeverityInfo, "")
v1beta2conditions.Set(controlPlane.KCP, metav1.Condition{
Type: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Condition,
Status: metav1.ConditionFalse,
Reason: controlplanev1.KubeadmControlPlaneNotInitializedV1Beta2Reason,
})
return r.initializeControlPlane(ctx, controlPlane)
// We are scaling up
case numMachines < desiredReplicas && numMachines > 0:
Expand Down
23 changes: 18 additions & 5 deletions controlplane/kubeadm/internal/controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,6 @@ func (r *KubeadmControlPlaneReconciler) updateStatus(ctx context.Context, contro
if status.HasKubeadmConfig {
controlPlane.KCP.Status.Initialized = true
conditions.MarkTrue(controlPlane.KCP, controlplanev1.AvailableCondition)
v1beta2conditions.Set(controlPlane.KCP, metav1.Condition{
Type: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Condition,
Status: metav1.ConditionTrue,
Reason: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Reason,
})
}

if controlPlane.KCP.Status.ReadyReplicas > 0 {
Expand Down Expand Up @@ -166,6 +161,7 @@ func (r *KubeadmControlPlaneReconciler) updateV1beta2Status(ctx context.Context,
// any reason those functions are not called before, e.g. an error, this func relies on existing Machine's condition.

setReplicas(ctx, controlPlane.KCP, controlPlane.Machines)
setInitializedCondition(ctx, controlPlane.KCP)
setScalingUpCondition(ctx, controlPlane.KCP, controlPlane.Machines, controlPlane.InfraMachineTemplateIsNotFound, controlPlane.PreflightCheckResults)
setScalingDownCondition(ctx, controlPlane.KCP, controlPlane.Machines, controlPlane.PreflightCheckResults)
setMachinesReadyCondition(ctx, controlPlane.KCP, controlPlane.Machines)
Expand Down Expand Up @@ -198,6 +194,23 @@ func setReplicas(_ context.Context, kcp *controlplanev1.KubeadmControlPlane, mac
kcp.Status.V1Beta2.UpToDateReplicas = ptr.To(upToDateReplicas)
}

func setInitializedCondition(_ context.Context, kcp *controlplanev1.KubeadmControlPlane) {
if kcp.Status.Initialized {
v1beta2conditions.Set(kcp, metav1.Condition{
Type: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Condition,
Status: metav1.ConditionTrue,
Reason: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Reason,
})
return
}

v1beta2conditions.Set(kcp, metav1.Condition{
Type: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Condition,
Status: metav1.ConditionFalse,
Reason: controlplanev1.KubeadmControlPlaneNotInitializedV1Beta2Reason,
})
}

func setScalingUpCondition(_ context.Context, kcp *controlplanev1.KubeadmControlPlane, machines collections.Machines, infrastructureObjectNotFound bool, preflightChecks internal.PreflightCheckResults) {
if kcp.Spec.Replicas == nil {
v1beta2conditions.Set(kcp, metav1.Condition{
Expand Down
45 changes: 44 additions & 1 deletion controlplane/kubeadm/internal/controllers/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,50 @@ func TestSetReplicas(t *testing.T) {
g.Expect(*kcp.Status.V1Beta2.UpToDateReplicas).To(Equal(int32(4)))
}

func Test_setInitializedCondition(t *testing.T) {
tests := []struct {
name string
controlPlane *internal.ControlPlane
expectCondition metav1.Condition
}{
{
name: "KCP not initialized",
controlPlane: &internal.ControlPlane{
KCP: &controlplanev1.KubeadmControlPlane{},
},
expectCondition: metav1.Condition{
Type: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Condition,
Status: metav1.ConditionFalse,
Reason: controlplanev1.KubeadmControlPlaneNotInitializedV1Beta2Reason,
},
},
{
name: "KCP initialized",
controlPlane: &internal.ControlPlane{
KCP: &controlplanev1.KubeadmControlPlane{
Status: controlplanev1.KubeadmControlPlaneStatus{Initialized: true},
},
},
expectCondition: metav1.Condition{
Type: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Condition,
Status: metav1.ConditionTrue,
Reason: controlplanev1.KubeadmControlPlaneInitializedV1Beta2Reason,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
g := NewWithT(t)

setInitializedCondition(ctx, tt.controlPlane.KCP)

condition := v1beta2conditions.Get(tt.controlPlane.KCP, controlplanev1.KubeadmControlPlaneInitializedV1Beta2Condition)
g.Expect(condition).ToNot(BeNil())
g.Expect(*condition).To(v1beta2conditions.MatchCondition(tt.expectCondition, v1beta2conditions.IgnoreLastTransitionTime(true)))
})
}
}

func Test_setScalingUpCondition(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -769,7 +813,6 @@ func TestKubeadmControlPlaneReconciler_updateStatusAllMachinesReady(t *testing.T
g.Expect(kcp.Status.Initialized).To(BeTrue())
g.Expect(conditions.IsTrue(kcp, controlplanev1.AvailableCondition)).To(BeTrue())
g.Expect(conditions.IsTrue(kcp, controlplanev1.MachinesCreatedCondition)).To(BeTrue())
g.Expect(v1beta2conditions.IsTrue(kcp, controlplanev1.KubeadmControlPlaneInitializedV1Beta2Condition)).To(BeTrue())
g.Expect(kcp.Status.Ready).To(BeTrue())
}

Expand Down

0 comments on commit 6344197

Please sign in to comment.