Skip to content

Commit

Permalink
Account for machine healthiness during reconciliation
Browse files Browse the repository at this point in the history
Signed-off-by: Rahul Ganesh <[email protected]>
  • Loading branch information
rahulbabu95 committed Sep 5, 2024
1 parent 6afd038 commit 3f271ec
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 3 deletions.
12 changes: 9 additions & 3 deletions controllers/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,20 @@ func (r *EtcdadmClusterReconciler) updateStatus(ctx context.Context, ec *etcdv1.

desiredReplicas := *ec.Spec.Replicas

ec.Status.ReadyReplicas = int32(len(ownedMachines))
// Only consider a healthy machine as a ready replica
// This will prevent an owned machine being deleted due to a catastrophic event from being considered ready.
readyReplicas := int32(0)
for _, m := range ownedMachines {
if m.healthy() {
readyReplicas++
}
}
ec.Status.ReadyReplicas = readyReplicas

if !ec.DeletionTimestamp.IsZero() {
return nil
}

readyReplicas := ec.Status.ReadyReplicas

if readyReplicas < desiredReplicas {
conditions.MarkFalse(ec, etcdv1.EtcdClusterResizeCompleted, etcdv1.EtcdScaleUpInProgressReason, clusterv1.ConditionSeverityWarning, "Scaling up etcd cluster to %d replicas (actual %d)", desiredReplicas, readyReplicas)
ec.Status.Ready = false
Expand Down
49 changes: 49 additions & 0 deletions controllers/status_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,55 @@ func TestUpdateStatusResizeIncomplete(t *testing.T) {
g.Expect(conditions.IsTrue(etcdadmCluster, etcdv1.EtcdClusterResizeCompleted)).To(BeFalse())
}

func TestUpdateStatusMachineUnhealthy(t *testing.T) {
g := NewWithT(t)

cluster := newClusterWithExternalEtcd()
etcdadmCluster := newEtcdadmCluster(cluster)

machine1 := newEtcdMachine(etcdadmCluster, cluster)
machine2 := newEtcdMachine(etcdadmCluster, cluster)

etcdMachine1 := etcdMachine{
Machine: machine1,
endpoint: "1.1.1.1",
listening: true,
healthError: nil,
}
etcdMachine2 := etcdMachine{
Machine: machine2,
endpoint: "1.1.1.1",
listening: false,
healthError: nil,
}

ownedMachines := map[string]etcdMachine{
"machine1": etcdMachine1,
"machine2": etcdMachine2,
}

objects := []client.Object{
cluster,
etcdadmCluster,
infraTemplate.DeepCopy(),
machine1,
machine2,
}

fakeClient := fake.NewClientBuilder().WithScheme(setupScheme()).WithObjects(objects...).Build()

r := &EtcdadmClusterReconciler{
Client: fakeClient,
uncachedClient: fakeClient,
Log: log.Log,
}

err := r.updateStatus(ctx, etcdadmCluster, cluster, ownedMachines)
g.Expect(etcdadmCluster.Status.ReadyReplicas).To(Equal(int32(1)))
g.Expect(err).NotTo(HaveOccurred())
g.Expect(conditions.IsTrue(etcdadmCluster, etcdv1.EtcdClusterResizeCompleted)).To(BeFalse())
}

func TestUpdateStatusResizeComplete(t *testing.T) {
g := NewWithT(t)

Expand Down

0 comments on commit 3f271ec

Please sign in to comment.