Skip to content

Commit

Permalink
Improve MachineSet create and delete logs
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Büringer [email protected]
  • Loading branch information
sbueringer committed Jan 24, 2025
1 parent 29905d5 commit 2ad4307
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -337,10 +337,13 @@ func (r *Reconciler) reconcileDelete(ctx context.Context, s *scope) error {
// else delete owned machinesets.
for _, ms := range s.machineSets {
if ms.DeletionTimestamp.IsZero() {

Check failure on line 339 in internal/controllers/machinedeployment/machinedeployment_controller.go

View workflow job for this annotation

GitHub Actions / lint

unnecessary leading newline (whitespace)
log.Info("Deleting MachineSet", "MachineSet", klog.KObj(ms))

if err := r.Client.Delete(ctx, ms); err != nil && !apierrors.IsNotFound(err) {
return errors.Wrapf(err, "failed to delete MachineSet %s", klog.KObj(ms))
}
// Note: We intentionally log after Delete because we want this log line to show up only after DeletionTimestamp has been set.
// Also, setting DeletionTimestamp doesn't mean the MachineSet is actually deleted (deletion takes some time).
log.Info("Deleting MachineSet (MachineDeployment deleted)", "MachineSet", klog.KObj(ms))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,12 @@ func (r *Reconciler) createMachineSetAndWait(ctx context.Context, deployment *cl
log = log.WithValues("MachineSet", klog.KObj(newMS))
ctx = ctrl.LoggerInto(ctx, log)

log.Info(fmt.Sprintf("Creating new MachineSet, %s", createReason))

// Create the MachineSet.
if err := ssa.Patch(ctx, r.Client, machineDeploymentManagerName, newMS); err != nil {
r.recorder.Eventf(deployment, corev1.EventTypeWarning, "FailedCreate", "Failed to create MachineSet %s: %v", klog.KObj(newMS), err)
return nil, errors.Wrapf(err, "failed to create new MachineSet %s", klog.KObj(newMS))
}
log.V(4).Info("Created new MachineSet")
log.Info(fmt.Sprintf("MachineSet created (%s)", createReason))
r.recorder.Eventf(deployment, corev1.EventTypeNormal, "SuccessfulCreate", "Created MachineSet %s", klog.KObj(newMS))

// Keep trying to get the MachineSet. This will force the cache to update and prevent any future reconciliation of
Expand Down Expand Up @@ -647,6 +645,8 @@ func (r *Reconciler) cleanupDeployment(ctx context.Context, oldMSs []*clusterv1.
r.recorder.Eventf(deployment, corev1.EventTypeWarning, "FailedDelete", "Failed to delete MachineSet %q: %v", ms.Name, err)
return err
}
// Note: We intentionally log after Delete because we want this log line to show up only after DeletionTimestamp has been set.
log.Info("Deleting MachineSet (cleanup of old MachineSet)", "MachineSet", klog.KObj(ms))
r.recorder.Eventf(deployment, corev1.EventTypeNormal, "SuccessfulDelete", "Deleted MachineSet %q", ms.Name)
}

Expand Down

0 comments on commit 2ad4307

Please sign in to comment.