Skip to content

Commit e7eeec1

Browse files
fix(machinedeployment): misleading log statements and optimized logic
Signed-off-by: Steffen Karlsson <[email protected]>
1 parent a86a82a commit e7eeec1

File tree

1 file changed

+12
-11
lines changed

1 file changed

+12
-11
lines changed

internal/controllers/machinedeployment/machinedeployment_controller.go

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -432,22 +432,23 @@ func (r *Reconciler) getAndAdoptMachineSetsForDeployment(ctx context.Context, s
432432
return err
433433
}
434434

435+
selector, err := metav1.LabelSelectorAsSelector(&md.Spec.Selector)
436+
if err != nil {
437+
log.Error(err, "Skipping MachineDeployment, failed to get label selector from spec selector")
438+
return err
439+
}
440+
441+
// If a MachineDeployment with a nil or empty selector creeps in, it should match nothing, not everything.
442+
if selector.Empty() {
443+
log.Info("Skipping MachineDeployment as the selector is empty")
444+
return nil
445+
}
446+
435447
filtered := make([]*clusterv1.MachineSet, 0, len(machineSets.Items))
436448
for idx := range machineSets.Items {
437449
ms := &machineSets.Items[idx]
438450
log := log.WithValues("MachineSet", klog.KObj(ms))
439451
ctx := ctrl.LoggerInto(ctx, log)
440-
selector, err := metav1.LabelSelectorAsSelector(&md.Spec.Selector)
441-
if err != nil {
442-
log.Error(err, "Skipping MachineSet, failed to get label selector from spec selector")
443-
continue
444-
}
445-
446-
// If a MachineDeployment with a nil or empty selector creeps in, it should match nothing, not everything.
447-
if selector.Empty() {
448-
log.Info("Skipping MachineSet as the selector is empty")
449-
continue
450-
}
451452

452453
// Skip this MachineSet unless either selector matches or it has a controller ref pointing to this MachineDeployment
453454
if !selector.Matches(labels.Set(ms.Labels)) && !metav1.IsControlledBy(ms, md) {

0 commit comments

Comments
 (0)