Skip to content

Commit a80bc6c

Browse files
authored
Removed any unwanted re-enqueuing of machine objects (#139)
- There were several places where machine objects were re-enqueued unwantedly - This lead to several reconcilation loops and objects being updated frequently - This commit removes any such code
1 parent 4032cc2 commit a80bc6c

File tree

5 files changed

+84
-26
lines changed

5 files changed

+84
-26
lines changed

pkg/controller/deployment_progress.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ package controller
2424

2525
import (
2626
"fmt"
27-
"reflect"
2827
"time"
2928

3029
"github.com/golang/glog"
@@ -108,7 +107,7 @@ func (dc *controller) syncRolloutStatus(allISs []*v1alpha1.MachineSet, newIS *v1
108107
}
109108

110109
// Do not update if there is nothing new to add.
111-
if reflect.DeepEqual(d.Status, newStatus) {
110+
if !statusUpdateRequired(d.Status, newStatus) {
112111
// Requeue the deployment if required.
113112
dc.requeueStuckMachineDeployment(d, newStatus)
114113
return nil

pkg/controller/deployment_util.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ package controller
2424

2525
import (
2626
"fmt"
27+
"reflect"
2728
"sort"
2829
"strconv"
2930
"strings"
@@ -1017,3 +1018,40 @@ func ResolveFenceposts(maxSurge, maxUnavailable *intstrutil.IntOrString, desired
10171018

10181019
return int32(surge), int32(unavailable), nil
10191020
}
1021+
1022+
// statusUpdateRequired checks for if status update is required comparing two MachineDeployment statuses
1023+
func statusUpdateRequired(old v1alpha1.MachineDeploymentStatus, new v1alpha1.MachineDeploymentStatus) bool {
1024+
1025+
if old.AvailableReplicas == new.AvailableReplicas &&
1026+
old.CollisionCount == new.CollisionCount &&
1027+
len(old.FailedMachines) == len(new.FailedMachines) &&
1028+
old.ObservedGeneration == new.ObservedGeneration &&
1029+
old.ReadyReplicas == new.ReadyReplicas &&
1030+
old.Replicas == new.Replicas &&
1031+
old.UpdatedReplicas == new.UpdatedReplicas &&
1032+
reflect.DeepEqual(old.Conditions, new.Conditions) {
1033+
// If all conditions are matching
1034+
1035+
// Iterate through all new failed machines and check if there
1036+
// exists an older machine with same name and description
1037+
for _, newMachine := range new.FailedMachines {
1038+
found := false
1039+
1040+
for _, oldMachine := range old.FailedMachines {
1041+
if oldMachine.Name == newMachine.Name &&
1042+
oldMachine.LastOperation.Description == newMachine.LastOperation.Description {
1043+
found = true
1044+
continue
1045+
}
1046+
}
1047+
1048+
if !found {
1049+
return true
1050+
}
1051+
}
1052+
1053+
return false
1054+
}
1055+
1056+
return true
1057+
}

pkg/controller/machine.go

Lines changed: 28 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (c *controller) addMachine(obj interface{}) {
5858
glog.Errorf("Couldn't get key for object %+v: %v", obj, err)
5959
return
6060
}
61-
glog.V(4).Info("Adding machine object")
61+
glog.V(4).Infof("Add/Update/Delete machine object %q", key)
6262
c.machineQueue.Add(key)
6363
}
6464

@@ -184,7 +184,7 @@ func (c *controller) reconcileClusterMachine(machine *v1alpha1.Machine) error {
184184
}
185185
}
186186

187-
c.enqueueMachineAfter(machine, time.Minute*10)
187+
c.enqueueMachineAfter(machine, 10*time.Minute)
188188
return nil
189189
}
190190

@@ -207,6 +207,7 @@ func (c *controller) addNodeToMachine(obj interface{}) {
207207
return
208208
}
209209

210+
glog.V(4).Infof("Add machine object backing node %q", machine.Name)
210211
c.enqueueMachine(machine)
211212
}
212213

@@ -545,8 +546,9 @@ func (c *controller) updateMachineStatus(
545546
func (c *controller) updateMachineConditions(machine *v1alpha1.Machine, conditions []v1.NodeCondition) (*v1alpha1.Machine, error) {
546547

547548
var (
548-
msg string
549-
lastOperationType v1alpha1.MachineOperationType
549+
msg string
550+
lastOperationType v1alpha1.MachineOperationType
551+
objectRequiresUpdate bool
550552
)
551553

552554
// Get the latest version of the machine so that we can avoid conflicts
@@ -556,12 +558,14 @@ func (c *controller) updateMachineConditions(machine *v1alpha1.Machine, conditio
556558
}
557559

558560
clone := machine.DeepCopy()
559-
clone.Status.Conditions = conditions
560561

561-
//glog.Info(c.isHealthy(clone))
562+
if nodeConditionsHaveChanged(clone.Status.Conditions, conditions) {
563+
clone.Status.Conditions = conditions
564+
objectRequiresUpdate = true
565+
}
562566

563567
if clone.Status.CurrentStatus.Phase == v1alpha1.MachineTerminating {
564-
// If machine is already in terminating state, don't update
568+
// If machine is already in terminating state, don't update health status
565569

566570
} else if !c.isHealthy(clone) && clone.Status.CurrentStatus.Phase == v1alpha1.MachineRunning {
567571
// If machine is not healthy, and current state is running,
@@ -580,6 +584,7 @@ func (c *controller) updateMachineConditions(machine *v1alpha1.Machine, conditio
580584
Type: v1alpha1.MachineOperationHealthCheck,
581585
LastUpdateTime: metav1.Now(),
582586
}
587+
objectRequiresUpdate = true
583588

584589
} else if c.isHealthy(clone) && clone.Status.CurrentStatus.Phase != v1alpha1.MachineRunning {
585590
// If machine is healhy and current machinePhase is not running.
@@ -609,16 +614,22 @@ func (c *controller) updateMachineConditions(machine *v1alpha1.Machine, conditio
609614
TimeoutActive: false,
610615
LastUpdateTime: metav1.Now(),
611616
}
617+
objectRequiresUpdate = true
618+
612619
}
613620

614-
clone, err = c.controlMachineClient.Machines(clone.Namespace).Update(clone)
615-
if err != nil {
616-
// Keep retrying until update goes through
617-
glog.V(2).Infof("Warning: Updated failed, retrying, error: %q", err)
618-
return c.updateMachineConditions(machine, conditions)
621+
if objectRequiresUpdate {
622+
clone, err = c.controlMachineClient.Machines(clone.Namespace).Update(clone)
623+
if err != nil {
624+
// Keep retrying until update goes through
625+
glog.Warningf("Updated failed, retrying, error: %q", err)
626+
return c.updateMachineConditions(machine, conditions)
627+
}
628+
629+
return clone, nil
619630
}
620631

621-
return clone, nil
632+
return machine, nil
622633
}
623634

624635
func (c *controller) updateMachineFinalizers(machine *v1alpha1.Machine, finalizers []string) {
@@ -715,7 +726,7 @@ func (c *controller) checkMachineTimeout(machine *v1alpha1.Machine) {
715726
// Timeout value obtained by subtracting last operation with expected time out period
716727
timeOut := metav1.Now().Add(-timeOutDuration).Sub(machine.Status.CurrentStatus.LastUpdateTime.Time)
717728
if timeOut > 0 {
718-
// If machine health timeout occurs while joining or rejoining of machine
729+
// Machine health timeout occurs while joining or rejoining of machine
719730

720731
if machine.Status.CurrentStatus.Phase == v1alpha1.MachinePending {
721732
// Timeout occurred while machine creation
@@ -748,20 +759,14 @@ func (c *controller) checkMachineTimeout(machine *v1alpha1.Machine) {
748759
// Log the error message for machine failure
749760
glog.Error(description)
750761

762+
// Update the machine status to reflect the changes
763+
c.updateMachineStatus(machine, lastOperation, currentStatus)
764+
751765
} else {
752766
// If timeout has not occurred, re-enqueue the machine
753767
// after a specified sleep time
754768
c.enqueueMachineAfter(machine, sleepTime)
755-
currentStatus = v1alpha1.CurrentStatus{
756-
Phase: machine.Status.CurrentStatus.Phase,
757-
TimeoutActive: true,
758-
LastUpdateTime: machine.Status.CurrentStatus.LastUpdateTime,
759-
}
760-
lastOperation = machine.Status.LastOperation
761769
}
762-
763-
// Update the machine status to reflect the changes
764-
c.updateMachineStatus(machine, lastOperation, currentStatus)
765770
}
766771
}
767772

pkg/controller/machine_util.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,3 +199,19 @@ func (c *controller) validateMachineClass(classSpec *v1alpha1.ClassSpec) (interf
199199

200200
return MachineClass, secretRef, nil
201201
}
202+
203+
// nodeConditionsHaveChanged compares two node statuses to see if any of the statuses have changed
204+
func nodeConditionsHaveChanged(machineConditions []v1.NodeCondition, nodeConditions []v1.NodeCondition) bool {
205+
206+
if len(machineConditions) != len(nodeConditions) {
207+
return true
208+
}
209+
210+
for i := range nodeConditions {
211+
if nodeConditions[i].Status != machineConditions[i].Status {
212+
return true
213+
}
214+
}
215+
216+
return false
217+
}

pkg/controller/machineset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ func (c *controller) machineSetUpdate(old, cur interface{}) {
140140
// that bad as MachineSets that haven't met expectations yet won't
141141
// sync, and all the listing is done using local stores.
142142
if oldMachineSet.Spec.Replicas != currentMachineSet.Spec.Replicas {
143-
glog.V(4).Infof("%v %v updated. Desired machine count change: %d->%d", currentMachineSet.Name, oldMachineSet.Spec.Replicas, currentMachineSet.Spec.Replicas)
143+
glog.V(4).Infof("%v updated. Desired machine count change: %d->%d", currentMachineSet.Name, oldMachineSet.Spec.Replicas, currentMachineSet.Spec.Replicas)
144144
}
145145
c.enqueueMachineSet(currentMachineSet)
146146
}

0 commit comments

Comments
 (0)