Skip to content

Commit 6aff2da

Browse files
committed
Fix flaky test and when scaled to 0 mark cluster ready.
1 parent f0e9896 commit 6aff2da

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

pkg/controller/orchestrator/orchestrator_controller_test.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -204,12 +204,10 @@ var _ = Describe("Orchestrator controller", func() {
204204
})
205205

206206
It("should update the status after a sync", func() {
207-
orcClient.AddInstance(orc.Instance{
208-
ClusterName: cluster.GetClusterAlias(),
209-
Key: orc.InstanceKey{Hostname: cluster.GetPodHostname(0)},
210-
})
211-
212-
// wait reconciliation request
207+
// wait reconciliation requests those requests should ensure that the cluster node
208+
// status is updated as master
209+
By("wait two reconcile requests")
210+
Eventually(requests, noReconcileTime+reconcileTimeout).Should(Receive(Equal(expectedRequest)))
213211
Eventually(requests, noReconcileTime+reconcileTimeout).Should(Receive(Equal(expectedRequest)))
214212

215213
// get latest cluster values

pkg/controller/orchestrator/orchestrator_reconcile.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ func (ou *orcUpdater) Sync(ctx context.Context) (syncer.SyncResult, error) {
8585
log.Error(err, "orchestrator is not reachable", "cluster_alias", ou.cluster.GetClusterAlias())
8686
return syncer.SyncResult{}, err
8787
}
88+
} else if master != nil {
89+
log.V(1).Info("cluster master", "master", master.Key.Hostname, "cluster", ou.cluster.GetClusterAlias())
8890
}
8991

9092
// register nodes in orchestrator if needed, or remove nodes from status
@@ -150,7 +152,7 @@ func (ou *orcUpdater) updateClusterReadyStatus() {
150152
}
151153
}
152154

153-
if !hasMaster && !ou.cluster.Spec.ReadOnly {
155+
if !hasMaster && !ou.cluster.Spec.ReadOnly && int(*ou.cluster.Spec.Replicas) > 0 {
154156
ou.cluster.UpdateStatusCondition(api.ClusterConditionReady, core.ConditionFalse, "NoMaster",
155157
"Cluster has no designated master")
156158
return

pkg/orchestrator/fake/client.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,17 @@ func (o *OrcFakeClient) Discover(host string, port int) error {
192192
Port: port,
193193
})
194194

195+
readOnly := true
196+
if strings.Contains(host, "-0") {
197+
// make node-0 as master alywas
198+
readOnly = false
199+
}
200+
195201
cluster := o.getHostClusterAlias(host)
196202
o.AddInstance(Instance{
197203
ClusterName: cluster,
198204
Key: InstanceKey{Hostname: host},
199-
ReadOnly: false,
205+
ReadOnly: readOnly,
200206
SlaveLagSeconds: sql.NullInt64{
201207
Valid: false,
202208
Int64: 0,

0 commit comments

Comments
 (0)