Skip to content

Commit 508b1ba

Browse files
committed
Address review comments - part 6: Replace function preserveExpiryTimeSet to nil check
1 parent 0a825f8 commit 508b1ba

4 files changed

Lines changed: 8 additions & 15 deletions

File tree

pkg/controller/machineset.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,7 @@ func (c *controller) manageReplicas(ctx context.Context, allMachines []*v1alpha1
495495
// or if it is a candidate for auto-preservation
496496
// TODO@thiyyakat: find more suitable name for function
497497
func (c *controller) isMachineCandidateForPreservation(ctx context.Context, machineSet *v1alpha1.MachineSet, machine *v1alpha1.Machine) (bool, error) {
498-
if machineutils.IsPreserveExpiryTimeSet(machine) && !machineutils.HasPreservationTimedOut(machine) {
498+
if machine.Status.CurrentStatus.PreserveExpiryTime != nil && !machineutils.HasPreservationTimedOut(machine) {
499499
klog.V(3).Infof("Machine %q is preserved until %v, not adding to stale machines", machine.Name, machine.Status.CurrentStatus.PreserveExpiryTime)
500500
return true, nil
501501
}
@@ -508,7 +508,7 @@ func (c *controller) isMachineCandidateForPreservation(ctx context.Context, mach
508508
return false, nil
509509
}
510510
}
511-
if *machineSet.Status.AutoPreserveFailedMachineCount < *machineSet.Spec.AutoPreserveFailedMachineMax {
511+
if machineSet.Status.AutoPreserveFailedMachineCount != nil && machineSet.Spec.AutoPreserveFailedMachineMax != nil && *machineSet.Status.AutoPreserveFailedMachineCount < *machineSet.Spec.AutoPreserveFailedMachineMax {
512512
err := c.annotateMachineForAutoPreservation(ctx, machine)
513513
if err != nil {
514514
return true, err
@@ -729,7 +729,7 @@ func prioritisePreservedMachines(machines []*v1alpha1.Machine) []*v1alpha1.Machi
729729
preservedMachines := make([]*v1alpha1.Machine, 0, len(machines))
730730
otherMachines := make([]*v1alpha1.Machine, 0, len(machines))
731731
for _, mc := range machines {
732-
if machineutils.IsPreserveExpiryTimeSet(mc) {
732+
if mc.Status.CurrentStatus.PreserveExpiryTime != nil {
733733
preservedMachines = append(preservedMachines, mc)
734734
} else {
735735
otherMachines = append(otherMachines, mc)

pkg/util/provider/machinecontroller/machine.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -753,8 +753,7 @@ func (c *controller) handlePreserveAnnotationsChange(oldAnnotations, newAnnotati
753753
return existsInOld != existsInNew || valueOld != valueNew
754754
}
755755
// Special case: annotation changed from 'now' to 'when-failed'
756-
isPreserved := machineutils.IsPreserveExpiryTimeSet(machine)
757-
if !isPreserved {
756+
if machine.Status.CurrentStatus.PreserveExpiryTime == nil {
758757
return true
759758
}
760759
if machineutils.IsMachineFailed(machine) {
@@ -803,7 +802,7 @@ func (c *controller) manageMachinePreservation(ctx context.Context, machine *v1a
803802
if !isPreserveAnnotationValueValid(preserveValue) {
804803
klog.Warningf("Preserve annotation value %q on machine %s is invalid", preserveValue, machine.Name)
805804
return
806-
} else if preserveValue == machineutils.PreserveMachineAnnotationValueFalse || (machineutils.IsPreserveExpiryTimeSet(clone) && machineutils.HasPreservationTimedOut(clone)) {
805+
} else if preserveValue == machineutils.PreserveMachineAnnotationValueFalse || (clone.Status.CurrentStatus.PreserveExpiryTime != nil && machineutils.HasPreservationTimedOut(clone)) {
807806
err = c.stopMachinePreservation(ctx, clone)
808807
return
809808
} else if preserveValue == machineutils.PreserveMachineAnnotationValueWhenFailed {

pkg/util/provider/machinecontroller/machine_util.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,7 @@ func (c *controller) canMarkMachineFailed(machineDeployName, machineName, namesp
21812181
if machine.Status.CurrentStatus.Phase != v1alpha1.MachineUnknown && machine.Status.CurrentStatus.Phase != v1alpha1.MachineRunning {
21822182
// since Preserved Failed machines are not replaced immediately,
21832183
// they need not be considered towards inProgress
2184-
if !machineutils.IsPreserveExpiryTimeSet(machine) {
2184+
if machine.Status.CurrentStatus.PreserveExpiryTime == nil {
21852185
inProgress++
21862186
}
21872187
switch machine.Status.CurrentStatus.Phase {
@@ -2370,9 +2370,8 @@ Utility Functions for Machine Preservation
23702370
// preserveMachine contains logic to start the preservation of a machine and node.
23712371
func (c *controller) preserveMachine(ctx context.Context, machine *v1alpha1.Machine, preserveValue string) error {
23722372
nodeName := machine.Labels[v1alpha1.NodeLabelKey]
2373-
isExpirySet := machineutils.IsPreserveExpiryTimeSet(machine)
23742373
updatedMachine := machine.DeepCopy()
2375-
if !isExpirySet {
2374+
if machine.Status.CurrentStatus.PreserveExpiryTime == nil {
23762375
klog.V(4).Infof("Starting preservation flow for machine %q.", machine.Name)
23772376
// Step 1: Add preserveExpiryTime to machine status
23782377
updatedMachine, err := c.setPreserveExpiryTimeOnMachine(ctx, updatedMachine)
@@ -2526,7 +2525,7 @@ func (c *controller) shouldNodeBeDrained(machine *v1alpha1.Machine, existingCond
25262525
func (c *controller) stopMachinePreservation(ctx context.Context, machine *v1alpha1.Machine) error {
25272526
// removal of preserveExpiryTime is the last step of stopping preservation
25282527
// if preserveExpiryTime is not set, preservation is already stopped
2529-
if !machineutils.IsPreserveExpiryTimeSet(machine) {
2528+
if machine.Status.CurrentStatus.PreserveExpiryTime == nil {
25302529
return nil
25312530
}
25322531
nodeName := machine.Labels[v1alpha1.NodeLabelKey]

pkg/util/provider/machineutils/utils.go

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -153,11 +153,6 @@ func IsMachineTriggeredForDeletion(m *v1alpha1.Machine) bool {
153153
return m.Annotations[MachinePriority] == "1" || m.Annotations[TriggerDeletionByMCM] == "true"
154154
}
155155

156-
// IsPreserveExpiryTimeSet checks if machine is preserved by MCM
157-
func IsPreserveExpiryTimeSet(m *v1alpha1.Machine) bool {
158-
return !m.Status.CurrentStatus.PreserveExpiryTime.IsZero()
159-
}
160-
161156
// HasPreservationTimedOut checks if the Status.CurrentStatus.PreserveExpiryTime has not yet passed
162157
func HasPreservationTimedOut(m *v1alpha1.Machine) bool {
163158
return !m.Status.CurrentStatus.PreserveExpiryTime.After(time.Now())

0 commit comments

Comments
 (0)