@@ -26,8 +26,8 @@ import (
26
26
v1 "k8s.io/api/core/v1"
27
27
"k8s.io/client-go/util/workqueue"
28
28
"k8s.io/utils/clock"
29
- "knative.dev/pkg/logging"
30
29
"sigs.k8s.io/controller-runtime/pkg/client"
30
+ "sigs.k8s.io/controller-runtime/pkg/log"
31
31
"sigs.k8s.io/controller-runtime/pkg/manager"
32
32
"sigs.k8s.io/controller-runtime/pkg/reconcile"
33
33
"sigs.k8s.io/karpenter/pkg/metrics"
@@ -81,9 +81,9 @@ func NewController(kubeClient client.Client, clk clock.Clock, recorder events.Re
81
81
}
82
82
83
83
func (c * Controller ) Reconcile (ctx context.Context , _ reconcile.Request ) (reconcile.Result , error ) {
84
- ctx = logging . WithLogger (ctx , logging .FromContext (ctx ).With ("queue" , c .sqsProvider .Name ()))
84
+ ctx = log . IntoContext (ctx , log .FromContext (ctx ).WithValues ("queue" , c .sqsProvider .Name ()))
85
85
if c .cm .HasChanged (c .sqsProvider .Name (), nil ) {
86
- logging .FromContext (ctx ).Debugf ("watching interruption queue" )
86
+ log .FromContext (ctx ).V ( 1 ). Info ("watching interruption queue" )
87
87
}
88
88
sqsMessages , err := c .sqsProvider .GetSQSMessages (ctx )
89
89
if err != nil {
@@ -105,7 +105,7 @@ func (c *Controller) Reconcile(ctx context.Context, _ reconcile.Request) (reconc
105
105
msg , e := c .parseMessage (sqsMessages [i ])
106
106
if e != nil {
107
107
// If we fail to parse, then we should delete the message but still log the error
108
- logging .FromContext (ctx ).Errorf ( " parsing message, %v" , e )
108
+ log .FromContext (ctx ).Error ( err , "failed parsing interruption message" )
109
109
errs [i ] = c .deleteMessage (ctx , sqsMessages [i ])
110
110
return
111
111
}
@@ -144,7 +144,7 @@ func (c *Controller) parseMessage(raw *sqsapi.Message) (messages.Message, error)
144
144
func (c * Controller ) handleMessage (ctx context.Context , nodeClaimInstanceIDMap map [string ]* v1beta1.NodeClaim ,
145
145
nodeInstanceIDMap map [string ]* v1.Node , msg messages.Message ) (err error ) {
146
146
147
- ctx = logging . WithLogger (ctx , logging .FromContext (ctx ).With ("messageKind" , msg .Kind ()))
147
+ ctx = log . IntoContext (ctx , log .FromContext (ctx ).WithValues ("messageKind" , msg .Kind ()))
148
148
receivedMessages .WithLabelValues (string (msg .Kind ())).Inc ()
149
149
150
150
if msg .Kind () == messages .NoOpKind {
@@ -179,9 +179,9 @@ func (c *Controller) deleteMessage(ctx context.Context, msg *sqsapi.Message) err
179
179
// handleNodeClaim retrieves the action for the message and then performs the appropriate action against the node
180
180
func (c * Controller ) handleNodeClaim (ctx context.Context , msg messages.Message , nodeClaim * v1beta1.NodeClaim , node * v1.Node ) error {
181
181
action := actionForMessage (msg )
182
- ctx = logging . WithLogger (ctx , logging .FromContext (ctx ).With ("nodeclaim" , nodeClaim .Name , "action" , string (action )))
182
+ ctx = log . IntoContext (ctx , log .FromContext (ctx ).WithValues ("nodeclaim" , nodeClaim .Name , "action" , string (action )))
183
183
if node != nil {
184
- ctx = logging . WithLogger (ctx , logging .FromContext (ctx ).With ("node" , node .Name ))
184
+ ctx = log . IntoContext (ctx , log .FromContext (ctx ).WithValues ("node" , node .Name ))
185
185
}
186
186
187
187
// Record metric and event for this action
@@ -215,7 +215,7 @@ func (c *Controller) deleteNodeClaim(ctx context.Context, nodeClaim *v1beta1.Nod
215
215
if err := c .kubeClient .Delete (ctx , nodeClaim ); err != nil {
216
216
return client .IgnoreNotFound (fmt .Errorf ("deleting the node on interruption message, %w" , err ))
217
217
}
218
- logging .FromContext (ctx ).Infof ("initiating delete from interruption message" )
218
+ log .FromContext (ctx ).Info ("initiating delete from interruption message" )
219
219
c .recorder .Publish (interruptionevents .TerminatingOnInterruption (node , nodeClaim )... )
220
220
metrics .NodeClaimsTerminatedCounter .With (prometheus.Labels {
221
221
metrics .ReasonLabel : terminationReasonLabel ,
0 commit comments