Skip to content

Commit

Permalink
Add splitbrain condition, make tests terser
Browse files Browse the repository at this point in the history
  • Loading branch information
lllamnyp committed Jun 25, 2024
1 parent 384893c commit f81648b
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 34 deletions.
3 changes: 3 additions & 0 deletions api/v1alpha1/etcdcluster_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ type EtcdClusterSpec struct {
const (
EtcdConditionInitialized = "Initialized"
EtcdConditionReady = "Ready"
EtcdConditionError = "Error"
)

type EtcdCondType string
Expand All @@ -66,6 +67,7 @@ const (
EtcdCondTypeWaitingForFirstQuorum EtcdCondType = "WaitingForFirstQuorum"
EtcdCondTypeStatefulSetReady EtcdCondType = "StatefulSetReady"
EtcdCondTypeStatefulSetNotReady EtcdCondType = "StatefulSetNotReady"
EtcdCondTypeSplitbrain EtcdCondType = "Splitbrain"
)

const (
Expand All @@ -74,6 +76,7 @@ const (
EtcdReadyCondNegMessage EtcdCondMessage = "Cluster StatefulSet is not Ready"
EtcdReadyCondPosMessage EtcdCondMessage = "Cluster StatefulSet is Ready"
EtcdReadyCondNegWaitingForQuorum EtcdCondMessage = "Waiting for first quorum to be established"
EtcdErrorCondSplitbrainMessage EtcdCondMessage = "Etcd endpoints reporting more than one unique cluster ID"
)

// EtcdClusterStatus defines the observed state of EtcdCluster
Expand Down
8 changes: 7 additions & 1 deletion internal/controller/etcdcluster_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,13 @@ func (r *EtcdClusterReconciler) Reconcile(ctx context.Context, req ctrl.Request)
state.setClusterID()
if state.inSplitbrain() {
log.Error(ctx, fmt.Errorf("etcd cluster in splitbrain"), "etcd cluster in splitbrain, dropping from reconciliation queue")
return ctrl.Result{}, nil
factory.SetCondition(instance, factory.NewCondition(etcdaenixiov1alpha1.EtcdConditionError).
WithStatus(true).
WithReason(string(etcdaenixiov1alpha1.EtcdCondTypeSplitbrain)).
WithMessage(string(etcdaenixiov1alpha1.EtcdErrorCondSplitbrainMessage)).
Complete(),
)
return r.updateStatus(ctx, instance)
}
// fill conditions
if len(instance.Status.Conditions) == 0 {
Expand Down
39 changes: 6 additions & 33 deletions test/e2e/e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,24 +97,15 @@ var _ = Describe("etcd-operator", Ordered, func() {
})

Eventually(func() error {
cmd := exec.Command("kubectl", "get",
"statefulset/test",
"--namespace", namespace,
)
_, err = utils.Run(cmd)
return err
}, time.Second*20, time.Second*2).Should(Succeed())

By("wait for statefulset is ready", func() {
cmd := exec.Command("kubectl", "wait",
"statefulset/test",
"--for", "jsonpath={.status.readyReplicas}=3",
"--namespace", namespace,
"--timeout", "5m",
)
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
})
return err
}, time.Second*20, time.Second*2).Should(Succeed(), "wait for statefulset is ready")

client, err := utils.GetEtcdClient(ctx, client.ObjectKey{Namespace: namespace, Name: "test"})
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -155,24 +146,15 @@ var _ = Describe("etcd-operator", Ordered, func() {
})

Eventually(func() error {
cmd := exec.Command("kubectl", "get",
"statefulset/test",
"--namespace", namespace,
)
_, err = utils.Run(cmd)
return err
}, time.Second*20, time.Second*2).Should(Succeed())

By("wait for statefulset is ready", func() {
cmd := exec.Command("kubectl", "wait",
"statefulset/test",
"--for", "jsonpath={.status.readyReplicas}=3",
"--namespace", namespace,
"--timeout", "5m",
)
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
})
return err
}, time.Second*20, time.Second*2).Should(Succeed(), "wait for statefulset is ready")

client, err := utils.GetEtcdClient(ctx, client.ObjectKey{Namespace: namespace, Name: "test"})
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -212,24 +194,15 @@ var _ = Describe("etcd-operator", Ordered, func() {
})

Eventually(func() error {
cmd := exec.Command("kubectl", "get",
"statefulset/test",
"--namespace", namespace,
)
_, err = utils.Run(cmd)
return err
}, time.Second*20, time.Second*2).Should(Succeed())

By("wait for statefulset is ready", func() {
cmd := exec.Command("kubectl", "wait",
"statefulset/test",
"--for", "jsonpath={.status.availableReplicas}=3",
"--namespace", namespace,
"--timeout", "5m",
)
_, err = utils.Run(cmd)
ExpectWithOffset(1, err).NotTo(HaveOccurred())
})
return err
}, time.Second*20, time.Second*2).Should(Succeed(), "wait for statefulset is ready")

client, err := utils.GetEtcdClient(ctx, client.ObjectKey{Namespace: namespace, Name: "test"})
Expect(err).NotTo(HaveOccurred())
Expand Down

0 comments on commit f81648b

Please sign in to comment.