Skip to content

Commit bc84b17

Browse files
jonathan-innisengedaam
authored andcommitted
chore: Ensure that NodeClaim is always logged with Node (aws#7750)
1 parent 6e92978 commit bc84b17

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-4
lines changed

pkg/controllers/interruption/controller.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -195,9 +195,9 @@ func (c *Controller) deleteMessage(ctx context.Context, msg *sqstypes.Message) e
195195
// handleNodeClaim retrieves the action for the message and then performs the appropriate action against the node
196196
func (c *Controller) handleNodeClaim(ctx context.Context, msg messages.Message, nodeClaim *karpv1.NodeClaim, node *corev1.Node) error {
197197
action := actionForMessage(msg)
198-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("NodeClaim", klog.KRef("", nodeClaim.Name), "action", string(action)))
198+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("NodeClaim", klog.KObj(nodeClaim), "action", string(action)))
199199
if node != nil {
200-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KRef("", node.Name)))
200+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KObj(node)))
201201
}
202202

203203
// Record metric and event for this action

pkg/controllers/nodeclaim/garbagecollection/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (c *Controller) garbageCollect(ctx context.Context, nodeClaim *karpv1.NodeC
104104
if err := c.kubeClient.Delete(ctx, &node); err != nil {
105105
return client.IgnoreNotFound(err)
106106
}
107-
log.FromContext(ctx).WithValues("Node", klog.KRef("", node.Name)).V(1).Info("garbage collected node")
107+
log.FromContext(ctx).WithValues("Node", klog.KObj(&node)).V(1).Info("garbage collected node")
108108
}
109109
return nil
110110
}

pkg/controllers/nodeclaim/tagging/controller.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"time"
2121

2222
"k8s.io/apimachinery/pkg/api/equality"
23+
"k8s.io/klog/v2"
2324
controllerruntime "sigs.k8s.io/controller-runtime"
2425
"sigs.k8s.io/controller-runtime/pkg/builder"
2526
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -65,7 +66,7 @@ func (c *Controller) Reconcile(ctx context.Context, nodeClaim *karpv1.NodeClaim)
6566
if !isTaggable(nodeClaim) {
6667
return reconcile.Result{}, nil
6768
}
68-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("provider-id", nodeClaim.Status.ProviderID))
69+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KRef("", nodeClaim.Status.NodeName), "provider-id", nodeClaim.Status.ProviderID))
6970
id, err := utils.ParseInstanceID(nodeClaim.Status.ProviderID)
7071
if err != nil {
7172
// We don't throw an error here since we don't want to retry until the ProviderID has been updated.

0 commit comments

Comments
 (0)