@@ -435,6 +435,18 @@ var _ = Describe("Orchestrator reconciler", func() {
435435 Expect (insts ).To (HaveLen (1 ))
436436 })
437437
438+ It ("should remove nodes from cluster status at scale down" , func () {
439+ // scale down the cluster
440+ cluster .Spec .Replicas = & one
441+ cluster .Status .ReadyNodes = 1
442+
443+ // call the function
444+ insts , _ := orcClient .Cluster (cluster .GetClusterAlias ())
445+ updater .removeNodeConditionNotInOrc (insts )
446+
447+ Expect (cluster .Status .Nodes ).To (ConsistOf (hasNodeWithStatus (cluster .GetPodHostname (0 ))))
448+ })
449+
438450 When ("cluster is not ready" , func () {
439451 BeforeEach (func () {
440452 cluster .Spec .Replicas = & two
@@ -488,6 +500,53 @@ var _ = Describe("Orchestrator reconciler", func() {
488500 })
489501
490502 })
503+
504+ // NOTE: this test sute should be deleted in next major version
505+ Describe ("status updater unit tests at upgrade" , func () {
506+ var (
507+ updater * orcUpdater
508+ )
509+
510+ BeforeEach (func () {
511+ updater = & orcUpdater {
512+ cluster : cluster ,
513+ recorder : rec ,
514+ orcClient : orcClient ,
515+ }
516+ // set cluster on readonly, master should be in read only state
517+ orcClient .AddInstance (orc.Instance {
518+ ClusterName : cluster .GetClusterAlias (),
519+ Key : orc.InstanceKey {Hostname : oldPodHostname (cluster , 0 )},
520+ ReadOnly : false , // mark node as master
521+ // mark instance as uptodate
522+ IsUpToDate : true ,
523+ IsLastCheckValid : true ,
524+ })
525+ orcClient .AddInstance (orc.Instance {
526+ ClusterName : cluster .GetClusterAlias (),
527+ Key : orc.InstanceKey {Hostname : oldPodHostname (cluster , 1 )},
528+ MasterKey : orc.InstanceKey {Hostname : oldPodHostname (cluster , 0 )},
529+ })
530+
531+ // update cluster nodes status
532+ insts , _ := orcClient .Cluster (cluster .GetClusterAlias ())
533+ master , _ := orcClient .Master (cluster .GetClusterAlias ())
534+ updater .updateStatusFromOrc (insts , master )
535+ })
536+
537+ It ("should not remove nodes from cluster when upgrading" , func () {
538+ // scale down the cluster
539+ cluster .Spec .Replicas = & one
540+ cluster .Status .ReadyNodes = 1
541+
542+ // call the function
543+ insts , _ := orcClient .Cluster (cluster .GetClusterAlias ())
544+ updater .removeNodeConditionNotInOrc (insts )
545+
546+ // nothing should be remove
547+ Expect (cluster .Status .Nodes ).To (ConsistOf (hasNodeWithStatus (oldPodHostname (cluster , 0 ))))
548+ })
549+ })
491550})
492551
493552// haveNodeCondWithStatus is a helper func that returns a matcher to check for an existing condition in a ClusterCondition list.
@@ -510,5 +569,15 @@ func haveCondWithStatus(condType api.ClusterConditionType, status core.Condition
510569 "Reason" : Equal (reason ),
511570 })),
512571 })
572+ }
573+
574+ func hasNodeWithStatus (host string ) gomegatypes.GomegaMatcher {
575+ return MatchFields (IgnoreExtras , Fields {
576+ "Name" : Equal (host ),
577+ })
578+ }
513579
580+ func oldPodHostname (cluster * mysqlcluster.MysqlCluster , index int ) string {
581+ return fmt .Sprintf ("%s-mysql-%d.%s.%s" , cluster .Name , index , cluster .GetNameForResource (mysqlcluster .OldHeadlessSVC ),
582+ cluster .Namespace )
514583}
0 commit comments