From 6aff2da38f00991ce4269e21adb8008ca86e7c68 Mon Sep 17 00:00:00 2001 From: amecea Date: Wed, 13 Feb 2019 13:24:47 +0200 Subject: [PATCH] Fix flaky test and when scaled to 0 mark cluster ready. --- .../orchestrator/orchestrator_controller_test.go | 10 ++++------ pkg/controller/orchestrator/orchestrator_reconcile.go | 4 +++- pkg/orchestrator/fake/client.go | 8 +++++++- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/pkg/controller/orchestrator/orchestrator_controller_test.go b/pkg/controller/orchestrator/orchestrator_controller_test.go index c79634825..f571128ce 100644 --- a/pkg/controller/orchestrator/orchestrator_controller_test.go +++ b/pkg/controller/orchestrator/orchestrator_controller_test.go @@ -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 diff --git a/pkg/controller/orchestrator/orchestrator_reconcile.go b/pkg/controller/orchestrator/orchestrator_reconcile.go index 9b1a26c12..f29f16f2f 100644 --- a/pkg/controller/orchestrator/orchestrator_reconcile.go +++ b/pkg/controller/orchestrator/orchestrator_reconcile.go @@ -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 @@ -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 diff --git a/pkg/orchestrator/fake/client.go b/pkg/orchestrator/fake/client.go index f0668b6d7..59d8fac85 100644 --- a/pkg/orchestrator/fake/client.go +++ b/pkg/orchestrator/fake/client.go @@ -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,