Skip to content

Commit

Permalink
Fix flaky test and when scaled to 0 mark cluster ready.
Browse files Browse the repository at this point in the history
  • Loading branch information
AMecea committed Feb 13, 2019
1 parent f0e9896 commit 6aff2da
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 4 additions & 6 deletions pkg/controller/orchestrator/orchestrator_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,12 +204,10 @@ var _ = Describe("Orchestrator controller", func() {
})

It("should update the status after a sync", func() {
orcClient.AddInstance(orc.Instance{
ClusterName: cluster.GetClusterAlias(),
Key: orc.InstanceKey{Hostname: cluster.GetPodHostname(0)},
})

// wait reconciliation request
// wait reconciliation requests those requests should ensure that the cluster node
// status is updated as master
By("wait two reconcile requests")
Eventually(requests, noReconcileTime+reconcileTimeout).Should(Receive(Equal(expectedRequest)))
Eventually(requests, noReconcileTime+reconcileTimeout).Should(Receive(Equal(expectedRequest)))

// get latest cluster values
Expand Down
4 changes: 3 additions & 1 deletion pkg/controller/orchestrator/orchestrator_reconcile.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ func (ou *orcUpdater) Sync(ctx context.Context) (syncer.SyncResult, error) {
log.Error(err, "orchestrator is not reachable", "cluster_alias", ou.cluster.GetClusterAlias())
return syncer.SyncResult{}, err
}
} else if master != nil {
log.V(1).Info("cluster master", "master", master.Key.Hostname, "cluster", ou.cluster.GetClusterAlias())
}

// register nodes in orchestrator if needed, or remove nodes from status
Expand Down Expand Up @@ -150,7 +152,7 @@ func (ou *orcUpdater) updateClusterReadyStatus() {
}
}

if !hasMaster && !ou.cluster.Spec.ReadOnly {
if !hasMaster && !ou.cluster.Spec.ReadOnly && int(*ou.cluster.Spec.Replicas) > 0 {
ou.cluster.UpdateStatusCondition(api.ClusterConditionReady, core.ConditionFalse, "NoMaster",
"Cluster has no designated master")
return
Expand Down
8 changes: 7 additions & 1 deletion pkg/orchestrator/fake/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,17 @@ func (o *OrcFakeClient) Discover(host string, port int) error {
Port: port,
})

readOnly := true
if strings.Contains(host, "-0") {
// make node-0 as master alywas
readOnly = false
}

cluster := o.getHostClusterAlias(host)
o.AddInstance(Instance{
ClusterName: cluster,
Key: InstanceKey{Hostname: host},
ReadOnly: false,
ReadOnly: readOnly,
SlaveLagSeconds: sql.NullInt64{
Valid: false,
Int64: 0,
Expand Down

0 comments on commit 6aff2da

Please sign in to comment.