Skip to content

Commit 7944bcb

Browse files
chuckhaArvinderpal
authored andcommitted
Improve delete logging
Signed-off-by: Chuck Ha <[email protected]>
1 parent 5b67782 commit 7944bcb

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

controllers/cluster_controller.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"context"
2121
"fmt"
2222
"path"
23+
"strings"
2324
"sync"
2425
"time"
2526

@@ -209,7 +210,7 @@ func (r *ClusterReconciler) reconcileDelete(ctx context.Context, cluster *cluste
209210
if cluster.Spec.ControlPlaneRef != nil {
210211
obj, err := external.Get(ctx, r.Client, cluster.Spec.ControlPlaneRef, cluster.Namespace)
211212
switch {
212-
case apierrors.IsNotFound(err):
213+
case apierrors.IsNotFound(errors.Cause(err)):
213214
case err != nil:
214215
return reconcile.Result{}, err
215216
case obj.GetDeletionTimestamp().IsZero():
@@ -267,7 +268,7 @@ func (r *ClusterReconciler) reconcileDelete(ctx context.Context, cluster *cluste
267268

268269
if descendantCount := descendants.length(); descendantCount > 0 {
269270
indirect := descendantCount - len(children)
270-
logger.Info("Cluster still has descendants - need to requeue", "direct", len(children), "indirect", indirect)
271+
logger.Info("Cluster still has descendants - need to requeue", "descendants", descendants.descendantNames(), "indirect descendants count", indirect)
271272
// Requeue so we can check the next time to see if there are still any descendants left.
272273
return ctrl.Result{RequeueAfter: deleteRequeueAfter}, nil
273274
}
@@ -314,6 +315,39 @@ func (c *clusterDescendants) length() int {
314315
len(c.workerMachines.Items)
315316
}
316317

318+
func (c *clusterDescendants) descendantNames() string {
319+
descendants := make([]string, 0)
320+
controlPlaneMachineNames := make([]string, len(c.controlPlaneMachines.Items))
321+
for i, controlPlaneMachine := range c.controlPlaneMachines.Items {
322+
controlPlaneMachineNames[i] = controlPlaneMachine.Name
323+
}
324+
if len(controlPlaneMachineNames) > 0 {
325+
descendants = append(descendants, "Control plane machines: "+strings.Join(controlPlaneMachineNames, ","))
326+
}
327+
machineDeploymentNames := make([]string, len(c.machineDeployments.Items))
328+
for i, machineDeployment := range c.machineDeployments.Items {
329+
machineDeploymentNames[i] = machineDeployment.Name
330+
}
331+
if len(machineDeploymentNames) > 0 {
332+
descendants = append(descendants, "Machine deployments: "+strings.Join(machineDeploymentNames, ","))
333+
}
334+
machineSetNames := make([]string, len(c.machineSets.Items))
335+
for i, machineSet := range c.machineSets.Items {
336+
machineSetNames[i] = machineSet.Name
337+
}
338+
if len(machineSetNames) > 0 {
339+
descendants = append(descendants, "Machine sets: "+strings.Join(machineSetNames, ","))
340+
}
341+
workerMachineNames := make([]string, len(c.workerMachines.Items))
342+
for i, workerMachine := range c.workerMachines.Items {
343+
workerMachineNames[i] = workerMachine.Name
344+
}
345+
if len(workerMachineNames) > 0 {
346+
descendants = append(descendants, "Worker machines: "+strings.Join(workerMachineNames, ","))
347+
}
348+
return strings.Join(descendants, ";")
349+
}
350+
317351
// listDescendants returns a list of all MachineDeployments, MachineSets, and Machines for the cluster.
318352
func (r *ClusterReconciler) listDescendants(ctx context.Context, cluster *clusterv1.Cluster) (clusterDescendants, error) {
319353
var descendants clusterDescendants

0 commit comments

Comments
 (0)