Refactor switchActiveReplicas to consolidate loops
@@ -1790,14 +1790,8 @@ func (vc *VolumeController) switchActiveReplicas(rs map[string]*longhorn.Replica
// delete the volume data on the disk.
// Set `active` at last to prevent data loss
for _, r := range rs {
- if !activeCondFunc(r, obj) && r.Spec.Active != false {
- r.Spec.Active = false
- rs[r.Name] = r
- }
- }
- for _, r := range rs {
- if activeCondFunc(r, obj) && r.Spec.Active != true {
- r.Spec.Active = true
+ if activeCondFunc(r, obj) != r.Spec.Active {
+ r.Spec.Active = activeCondFunc(r, obj)
rs[r.Name] = r
}
}
