Skip to content

Commit 2542084

Browse files
Ensure we use structured logging when returning disruption commands
1 parent 9fe41b8 commit 2542084

File tree

19 files changed

+100
-86
lines changed

19 files changed

+100
-86
lines changed

go.mod

+7-6
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ require (
6464
github.com/prometheus/procfs v0.15.1 // indirect
6565
github.com/robfig/cron/v3 v3.0.1
6666
github.com/spf13/cobra v1.8.1 // indirect
67-
github.com/spf13/pflag v1.0.5 // indirect
67+
github.com/spf13/pflag v1.0.6 // indirect
6868
github.com/x448/float16 v0.8.4 // indirect
69-
golang.org/x/net v0.33.0 // indirect
69+
golang.org/x/net v0.35.0 // indirect
7070
golang.org/x/oauth2 v0.23.0 // indirect
71-
golang.org/x/sys v0.28.0 // indirect
72-
golang.org/x/term v0.27.0 // indirect
73-
golang.org/x/tools v0.28.0 // indirect
71+
golang.org/x/sys v0.30.0 // indirect
72+
golang.org/x/term v0.29.0 // indirect
73+
golang.org/x/tools v0.30.0 // indirect
7474
gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect
75-
google.golang.org/protobuf v1.36.1 // indirect
75+
google.golang.org/protobuf v1.36.4 // indirect
7676
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
7777
gopkg.in/inf.v0 v0.9.1 // indirect
7878
gopkg.in/yaml.v3 v3.0.1 // indirect
@@ -85,6 +85,7 @@ require (
8585
require (
8686
github.com/fsnotify/fsnotify v1.7.0 // indirect
8787
github.com/google/btree v1.1.3 // indirect
88+
github.com/rogpeppe/go-internal v1.13.1 // indirect
8889
golang.org/x/sync v0.11.0 // indirect
8990
)
9091

go.sum

+14-13
Original file line numberDiff line numberDiff line change
@@ -111,15 +111,16 @@ github.com/prometheus/procfs v0.15.1 h1:YagwOFzUgYfKKHX6Dr+sHT7km/hxC76UB0leargg
111111
github.com/prometheus/procfs v0.15.1/go.mod h1:fB45yRUv8NstnjriLhBQLuOUt+WW4BsoGhij/e3PBqk=
112112
github.com/robfig/cron/v3 v3.0.1 h1:WdRxkvbJztn8LMz/QEvLN5sBU+xKpSqwwUO1Pjr4qDs=
113113
github.com/robfig/cron/v3 v3.0.1/go.mod h1:eQICP3HwyT7UooqI/z+Ov+PtYAWygg1TEWWzGIFLtro=
114-
github.com/rogpeppe/go-internal v1.12.0 h1:exVL4IDcn6na9z1rAb56Vxr+CgyK3nn3O+epU5NdKM8=
115-
github.com/rogpeppe/go-internal v1.12.0/go.mod h1:E+RYuTGaKKdloAfM02xzb0FW3Paa99yedzYV+kq4uf4=
114+
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
115+
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
116116
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
117117
github.com/samber/lo v1.49.1 h1:4BIFyVfuQSEpluc7Fua+j1NolZHiEHEpaSEKdsH0tew=
118118
github.com/samber/lo v1.49.1/go.mod h1:dO6KHFzUKXgP8LDhU0oI8d2hekjXnGOu0DB8Jecxd6o=
119119
github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM=
120120
github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y=
121-
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
122121
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
122+
github.com/spf13/pflag v1.0.6 h1:jFzHGLGAlb3ruxLB8MhbI6A8+AQX/2eW4qeyNZXNp2o=
123+
github.com/spf13/pflag v1.0.6/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
123124
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
124125
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
125126
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
@@ -148,8 +149,8 @@ golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn
148149
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
149150
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
150151
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
151-
golang.org/x/net v0.33.0 h1:74SYHlV8BIgHIFC/LrYkOGIwL19eTYXQ5wc6TBuO36I=
152-
golang.org/x/net v0.33.0/go.mod h1:HXLR5J+9DxmrqMwG9qjGCxZ+zKXxBru04zlTvWlWuN4=
152+
golang.org/x/net v0.35.0 h1:T5GQRQb2y08kTAByq9L4/bz8cipCdA8FbRTXewonqY8=
153+
golang.org/x/net v0.35.0/go.mod h1:EglIi67kWsHKlRzzVMUD93VMSWGFOMSZgxFjparz1Qk=
153154
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
154155
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
155156
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
@@ -160,10 +161,10 @@ golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
160161
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
161162
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
162163
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
163-
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
164-
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
165-
golang.org/x/term v0.27.0 h1:WP60Sv1nlK1T6SupCHbXzSaN0b9wUmsPoRS9b61A23Q=
166-
golang.org/x/term v0.27.0/go.mod h1:iMsnZpn0cago0GOrHO2+Y7u7JPn5AylBrcoWkElMTSM=
164+
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
165+
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
166+
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
167+
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
167168
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
168169
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
169170
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
@@ -174,16 +175,16 @@ golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGm
174175
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
175176
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
176177
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
177-
golang.org/x/tools v0.28.0 h1:WuB6qZ4RPCQo5aP3WdKZS7i595EdWqWR8vqJTlwTVK8=
178-
golang.org/x/tools v0.28.0/go.mod h1:dcIOrVd3mfQKTgrDVQHqCPMWy6lnhfhtX3hLXYVLfRw=
178+
golang.org/x/tools v0.30.0 h1:BgcpHewrV5AUp2G9MebG4XPFI1E2W41zU1SaqVA9vJY=
179+
golang.org/x/tools v0.30.0/go.mod h1:c347cR/OJfw5TI+GfX7RUPNMdDRRbjvYTS0jPyvsVtY=
179180
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
180181
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
181182
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
182183
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
183184
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
184185
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
185-
google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk=
186-
google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
186+
google.golang.org/protobuf v1.36.4 h1:6A3ZDJHn/eNqc1i+IdefRzy/9PokBTPvcqMySR7NNIM=
187+
google.golang.org/protobuf v1.36.4/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE=
187188
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
188189
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
189190
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=

pkg/controllers/disruption/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func (c *Controller) disrupt(ctx context.Context, disruption Method) (bool, erro
202202
// 3. Add Command to orchestration.Queue to wait to delete the candiates.
203203
func (c *Controller) executeCommand(ctx context.Context, m Method, cmd Command, schedulingResults scheduling.Results) error {
204204
commandID := uuid.NewUUID()
205-
log.FromContext(ctx).WithValues("command-id", commandID, "reason", strings.ToLower(string(m.Reason()))).Info(fmt.Sprintf("disrupting nodeclaim(s) via %s", cmd))
205+
log.FromContext(ctx).WithValues(append([]any{"command-id", string(commandID), "reason", strings.ToLower(string(m.Reason()))}, cmd.LogValues()...)...).Info("disrupting node(s)")
206206

207207
// Cordon the old nodes before we launch the replacements to prevent new pods from scheduling to the old nodes
208208
if err := c.MarkDisrupted(ctx, m, cmd.candidates...); err != nil {

pkg/controllers/disruption/emptiness.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func (e *Emptiness) ComputeCommand(ctx context.Context, disruptionBudgetMapping
104104
validatedCandidates, err := v.ValidateCandidates(ctx, cmd.candidates...)
105105
if err != nil {
106106
if IsValidationError(err) {
107-
log.FromContext(ctx).V(1).Info(fmt.Sprintf("abandoning empty node consolidation attempt due to pod churn, command is no longer valid, %s", cmd))
107+
log.FromContext(ctx).V(1).WithValues(cmd.LogValues()...).Info("abandoning empty node consolidation attempt due to pod churn, command is no longer valid")
108108
return Command{}, scheduling.Results{}, nil
109109
}
110110
return Command{}, scheduling.Results{}, err
@@ -114,7 +114,7 @@ func (e *Emptiness) ComputeCommand(ctx context.Context, disruptionBudgetMapping
114114
if lo.ContainsBy(validatedCandidates, func(c *Candidate) bool {
115115
return len(c.reschedulablePods) != 0
116116
}) {
117-
log.FromContext(ctx).V(1).Info(fmt.Sprintf("abandoning empty node consolidation attempt due to pod churn, command is no longer valid, %s", cmd))
117+
log.FromContext(ctx).V(1).WithValues(cmd.LogValues()...).Info("abandoning empty node consolidation attempt due to pod churn, command is no longer valid")
118118
return Command{}, scheduling.Results{}, nil
119119
}
120120

pkg/controllers/disruption/multinodeconsolidation.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ func (m *MultiNodeConsolidation) ComputeCommand(ctx context.Context, disruptionB
9797

9898
if err := NewValidation(m.clock, m.cluster, m.kubeClient, m.provisioner, m.cloudProvider, m.recorder, m.queue, m.Reason()).IsValid(ctx, cmd, consolidationTTL); err != nil {
9999
if IsValidationError(err) {
100-
log.FromContext(ctx).V(1).Info(fmt.Sprintf("abandoning multi-node consolidation attempt due to pod churn, command is no longer valid, %s", cmd))
100+
log.FromContext(ctx).V(1).WithValues(cmd.LogValues()...).Info("abandoning multi-node consolidation attempt due to pod churn, command is no longer valid")
101101
return Command{}, scheduling.Results{}, nil
102102
}
103103
return Command{}, scheduling.Results{}, fmt.Errorf("validating consolidation, %w", err)
@@ -128,7 +128,7 @@ func (m *MultiNodeConsolidation) firstNConsolidationOption(ctx context.Context,
128128
if lastSavedCommand.candidates == nil {
129129
log.FromContext(ctx).V(1).Info(fmt.Sprintf("failed to find a multi-node consolidation after timeout, last considered batch had %d", (min+max)/2))
130130
} else {
131-
log.FromContext(ctx).V(1).Info(fmt.Sprintf("stopping multi-node consolidation after timeout, returning last valid command %s", lastSavedCommand))
131+
log.FromContext(ctx).V(1).WithValues(lastSavedCommand.LogValues()...).Info("stopping multi-node consolidation after timeout, returning last valid command")
132132
}
133133
return lastSavedCommand, lastSavedResults, nil
134134
}

pkg/controllers/disruption/orchestration/queue.go

+26-1
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import (
2727
"github.com/awslabs/operatorpkg/singleton"
2828
"github.com/samber/lo"
2929
"go.uber.org/multierr"
30+
corev1 "k8s.io/api/core/v1"
3031
apierrors "k8s.io/apimachinery/pkg/api/errors"
3132
"k8s.io/apimachinery/pkg/types"
3233
"k8s.io/client-go/util/workqueue"
34+
"k8s.io/klog/v2"
3335
"k8s.io/utils/clock"
3436
controllerruntime "sigs.k8s.io/controller-runtime"
3537
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -63,6 +65,29 @@ type Command struct {
6365
lastError error
6466
}
6567

68+
func (c *Command) LogValues() []any {
69+
candidateNodes := lo.Map(c.candidates, func(candidate *state.StateNode, _ int) interface{} {
70+
m := map[string]interface{}{}
71+
m["Node"] = klog.KObj(candidate.Node)
72+
m["NodeClaim"] = klog.KObj(candidate.NodeClaim)
73+
m["instance-type"] = candidate.Labels()[corev1.LabelInstanceTypeStable]
74+
m["capacity-type"] = candidate.Labels()[v1.CapacityTypeLabelKey]
75+
return m
76+
})
77+
replacementNodes := lo.Map(c.Replacements, func(replacement Replacement, _ int) interface{} {
78+
m := map[string]interface{}{}
79+
m["NodeClaim"] = klog.KRef("", replacement.name)
80+
return m
81+
})
82+
return []any{
83+
"command-id", c.id,
84+
"reason", c.reason,
85+
"decision", c.Decision(),
86+
"candidate-nodes", candidateNodes,
87+
"replacement-nodes", replacementNodes,
88+
}
89+
}
90+
6691
// Replacement wraps a NodeClaim name with an initialized field to save on readiness checks and identify
6792
// when a NodeClaim is first initialized for metrics and events.
6893
type Replacement struct {
@@ -175,7 +200,7 @@ func (q *Queue) Reconcile(ctx context.Context) (reconcile.Result, error) {
175200
if shutdown {
176201
panic("unexpected failure, disruption queue has shut down")
177202
}
178-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("command-id", string(cmd.id)))
203+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues(cmd.LogValues()...))
179204

180205
if err := q.waitOrTerminate(ctx, cmd); err != nil {
181206
// If recoverable, re-queue and try again.

pkg/controllers/disruption/singlenodeconsolidation.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ func (s *SingleNodeConsolidation) ComputeCommand(ctx context.Context, disruption
8484
}
8585
if err := v.IsValid(ctx, cmd, consolidationTTL); err != nil {
8686
if IsValidationError(err) {
87-
log.FromContext(ctx).V(1).Info(fmt.Sprintf("abandoning single-node consolidation attempt due to pod churn, command is no longer valid, %s", cmd))
87+
log.FromContext(ctx).V(1).WithValues(cmd.LogValues()...).Info("abandoning single-node consolidation attempt due to pod churn, command is no longer valid")
8888
return Command{}, scheduling.Results{}, nil
8989
}
9090
return Command{}, scheduling.Results{}, fmt.Errorf("validating consolidation, %w", err)

pkg/controllers/disruption/types.go

+27-40
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ limitations under the License.
1717
package disruption
1818

1919
import (
20-
"bytes"
2120
"context"
2221
"fmt"
2322

2423
"github.com/samber/lo"
2524
corev1 "k8s.io/api/core/v1"
25+
"k8s.io/klog/v2"
2626
"k8s.io/utils/clock"
2727
"sigs.k8s.io/controller-runtime/pkg/client"
2828

@@ -140,46 +140,33 @@ func (c Command) Decision() Decision {
140140
}
141141
}
142142

143-
func (c Command) String() string {
144-
var buf bytes.Buffer
143+
func (c Command) LogValues() []any {
145144
podCount := lo.Reduce(c.candidates, func(_ int, cd *Candidate, _ int) int { return len(cd.reschedulablePods) }, 0)
146-
fmt.Fprintf(&buf, "%s, terminating %d nodes (%d pods) ", c.Decision(), len(c.candidates), podCount)
147-
for i, old := range c.candidates {
148-
if i != 0 {
149-
fmt.Fprint(&buf, ", ")
150-
}
151-
fmt.Fprintf(&buf, "%s", old.Name())
152-
fmt.Fprintf(&buf, "/%s", old.Labels()[corev1.LabelInstanceTypeStable])
153-
fmt.Fprintf(&buf, "/%s", old.Labels()[v1.CapacityTypeLabelKey])
154-
}
155-
if len(c.replacements) == 0 {
156-
return buf.String()
157-
}
158-
odNodeClaims := 0
159-
spotNodeClaims := 0
160-
for _, nodeClaim := range c.replacements {
161-
ct := nodeClaim.Requirements.Get(v1.CapacityTypeLabelKey)
162-
if ct.Has(v1.CapacityTypeOnDemand) {
163-
odNodeClaims++
164-
}
165-
if ct.Has(v1.CapacityTypeSpot) {
166-
spotNodeClaims++
145+
146+
candidateNodes := lo.Map(c.candidates, func(candidate *Candidate, _ int) interface{} {
147+
m := map[string]interface{}{}
148+
m["Node"] = klog.KObj(candidate.Node)
149+
m["NodeClaim"] = klog.KObj(candidate.NodeClaim)
150+
m["instance-type"] = candidate.Labels()[corev1.LabelInstanceTypeStable]
151+
m["capacity-type"] = candidate.Labels()[v1.CapacityTypeLabelKey]
152+
return m
153+
})
154+
replacementNodes := lo.Map(c.replacements, func(replacement *scheduling.NodeClaim, _ int) interface{} {
155+
m := map[string]interface{}{}
156+
ct := replacement.Requirements.Get(v1.CapacityTypeLabelKey)
157+
m["capacity-type"] = lo.Ternary(ct.Has(v1.CapacityTypeSpot), v1.CapacityTypeSpot, v1.CapacityTypeOnDemand)
158+
if len(c.replacements) == 1 {
159+
m["instance-types"] = scheduling.InstanceTypeList(replacement.InstanceTypeOptions)
167160
}
161+
return m
162+
})
163+
164+
return []any{
165+
"decision", c.Decision(),
166+
"candidate-count", len(candidateNodes),
167+
"replacement-count", len(replacementNodes),
168+
"pod-count", podCount,
169+
"candidate-nodes", candidateNodes,
170+
"replacement-nodes", replacementNodes,
168171
}
169-
// Print list of instance types for the first replacements.
170-
if len(c.replacements) > 1 {
171-
fmt.Fprintf(&buf, " and replacing with %d spot and %d on-demand, from types %s",
172-
spotNodeClaims, odNodeClaims,
173-
scheduling.InstanceTypeList(c.replacements[0].InstanceTypeOptions))
174-
return buf.String()
175-
}
176-
ct := c.replacements[0].Requirements.Get(v1.CapacityTypeLabelKey)
177-
nodeDesc := "node"
178-
if ct.Len() == 1 {
179-
nodeDesc = fmt.Sprintf("%s node", ct.Any())
180-
}
181-
fmt.Fprintf(&buf, " and replacing with %s from types %s",
182-
nodeDesc,
183-
scheduling.InstanceTypeList(c.replacements[0].InstanceTypeOptions))
184-
return buf.String()
185172
}

pkg/controllers/node/health/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ func (c *Controller) Register(_ context.Context, m manager.Manager) error {
7474

7575
func (c *Controller) Reconcile(ctx context.Context, node *corev1.Node) (reconcile.Result, error) {
7676
ctx = injection.WithControllerName(ctx, "node.health")
77-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KRef(node.Namespace, node.Name)))
77+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KObj(node)))
7878

7979
// Validate that the node is owned by us
8080
nodeClaim, err := nodeutils.NodeClaimForNode(ctx, c.kubeClient, node)

pkg/controllers/node/hydration/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ func NewController(kubeClient client.Client, cloudProvider cloudprovider.CloudPr
5656

5757
func (c *Controller) Reconcile(ctx context.Context, n *corev1.Node) (reconcile.Result, error) {
5858
ctx = injection.WithControllerName(ctx, c.Name())
59-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KRef(n.Namespace, n.Name)))
59+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KObj(n)))
6060

6161
nc, err := nodeutils.NodeClaimForNode(ctx, c.kubeClient, n)
6262
if err != nil {

pkg/controllers/nodeclaim/garbagecollection/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ func (c *Controller) Reconcile(ctx context.Context) (reconcile.Result, error) {
100100
return
101101
}
102102
log.FromContext(ctx).WithValues(
103-
"NodeClaim", klog.KRef("", nodeClaims[i].Name),
103+
"NodeClaim", klog.KObj(nodeClaims[i]),
104104
"provider-id", nodeClaims[i].Status.ProviderID,
105105
"nodepool", nodeClaims[i].Labels[v1.NodePoolLabelKey],
106106
).V(1).Info("garbage collecting nodeclaim with no cloudprovider representation")

pkg/controllers/nodeclaim/hydration/controller.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func NewController(kubeClient client.Client, cloudProvider cloudprovider.CloudPr
5454

5555
func (c *Controller) Reconcile(ctx context.Context, nc *v1.NodeClaim) (reconcile.Result, error) {
5656
ctx = injection.WithControllerName(ctx, c.Name())
57-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("NodeClaim", klog.KRef(nc.Namespace, nc.Name)))
57+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("NodeClaim", klog.KObj(nc)))
5858
if !nodeclaimutils.IsManaged(nc, c.cloudProvider) {
5959
return reconcile.Result{}, nil
6060
}

pkg/controllers/nodeclaim/lifecycle/initialization.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func (i *Initialization) Reconcile(ctx context.Context, nodeClaim *v1.NodeClaim)
5959
nodeClaim.StatusConditions().SetUnknownWithReason(v1.ConditionTypeInitialized, "NodeNotFound", "Node not registered with cluster")
6060
return reconcile.Result{}, nil //nolint:nilerr
6161
}
62-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KRef("", node.Name)))
62+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KObj(node)))
6363
if nodeutils.GetCondition(node, corev1.NodeReady).Status != corev1.ConditionTrue {
6464
nodeClaim.StatusConditions().SetUnknownWithReason(v1.ConditionTypeInitialized, "NodeNotReady", "Node status is NotReady")
6565
return reconcile.Result{}, nil

pkg/controllers/nodeclaim/lifecycle/registration.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func (r *Registration) Reconcile(ctx context.Context, nodeClaim *v1.NodeClaim) (
6868
nodeClaim.StatusConditions().SetFalse(v1.ConditionTypeRegistered, "UnregisteredTaintNotFound", fmt.Sprintf("Invariant violated, %s taint must be present on Karpenter-managed nodes", v1.UnregisteredTaintKey))
6969
return reconcile.Result{}, fmt.Errorf("missing required startup taint, %s", v1.UnregisteredTaintKey)
7070
}
71-
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KRef("", node.Name)))
71+
ctx = log.IntoContext(ctx, log.FromContext(ctx).WithValues("Node", klog.KObj(node)))
7272
if err = r.syncNode(ctx, nodeClaim, node); err != nil {
7373
if errors.IsConflict(err) {
7474
return reconcile.Result{Requeue: true}, nil

0 commit comments

Comments
 (0)