Skip to content

Commit

Permalink
Simplify the condition transition rules (#129)
Browse files Browse the repository at this point in the history
When the cluster is initializing, either a quorum has not yet been
established, so if the sts isn't ready, we don't change the reason for
etcd not ready, or the cluster has initialized, so we set the status
based on the sts state. This reduces the amount of nesting and repeated
code in the condition/reason checks.
  • Loading branch information
lllamnyp committed Apr 10, 2024
1 parent 1f9b5b3 commit 7c5d2d1
Showing 1 changed file with 18 additions and 22 deletions.
40 changes: 18 additions & 22 deletions internal/controller/etcdcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,30 +99,26 @@ func (r *EtcdClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)

// set cluster readiness condition
existingCondition := factory.GetCondition(instance, etcdaenixiov1alpha1.EtcdConditionReady)
if existingCondition.Reason == string(etcdaenixiov1alpha1.EtcdCondTypeWaitingForFirstQuorum) {
// we should change from "waiting for first quorum establishment" to "StatefulSet ready / not ready"
// only after sts gets ready first time
if clusterReady {
factory.SetCondition(instance, factory.NewCondition(etcdaenixiov1alpha1.EtcdConditionReady).
WithStatus(true).
WithReason(string(etcdaenixiov1alpha1.EtcdCondTypeStatefulSetReady)).
WithMessage(string(etcdaenixiov1alpha1.EtcdReadyCondPosMessage)).
Complete())
}
} else {
reason := etcdaenixiov1alpha1.EtcdCondTypeStatefulSetNotReady
message := etcdaenixiov1alpha1.EtcdReadyCondNegMessage
if clusterReady {
reason = etcdaenixiov1alpha1.EtcdCondTypeStatefulSetReady
message = etcdaenixiov1alpha1.EtcdReadyCondPosMessage
}
if existingCondition.Reason == string(etcdaenixiov1alpha1.EtcdCondTypeWaitingForFirstQuorum) && !clusterReady {
// if we are still "waiting for first quorum establishment" and the StatefulSet
// isn't ready yet, don't update the EtcdConditionReady, but circuit-break.
return r.updateStatus(ctx, instance)
}

factory.SetCondition(instance, factory.NewCondition(etcdaenixiov1alpha1.EtcdConditionReady).
WithStatus(clusterReady).
WithReason(string(reason)).
WithMessage(string(message)).
Complete())
// otherwise, EtcdConditionReady is set to true/false with the reason that the
// StatefulSet is or isn't ready.
reason := etcdaenixiov1alpha1.EtcdCondTypeStatefulSetNotReady
message := etcdaenixiov1alpha1.EtcdReadyCondNegMessage
if clusterReady {
reason = etcdaenixiov1alpha1.EtcdCondTypeStatefulSetReady
message = etcdaenixiov1alpha1.EtcdReadyCondPosMessage
}

factory.SetCondition(instance, factory.NewCondition(etcdaenixiov1alpha1.EtcdConditionReady).
WithStatus(clusterReady).
WithReason(string(reason)).
WithMessage(string(message)).
Complete())
return r.updateStatus(ctx, instance)
}

Expand Down

0 comments on commit 7c5d2d1

Please sign in to comment.