Skip to content

Commit 7504df8

Browse files
feat(go): update module sigs.k8s.io/controller-runtime to v0.23.1 (#80)
* feat(go): update module sigs.k8s.io/controller-runtime to v0.23.1 * feat(tests): add event recorder and converter registry to fakeManager * refactor(events): replace EventRecorder with updated events.EventRecorder in controllers --------- Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: Magnus Ullberg <magnus@ullberg.us>
1 parent 98ac64a commit 7504df8

7 files changed

Lines changed: 74 additions & 75 deletions

File tree

cmd/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ func newLeaseWatcher(mgr ctrl.Manager, gvk schema.GroupVersionKind, leaderElecti
331331
return &controllers.LeaseWatcher{
332332
Client: mgr.GetClient(),
333333
GVK: gvk,
334-
Recorder: mgr.GetEventRecorderFor(leaderElectionID),
334+
Recorder: mgr.GetEventRecorder(leaderElectionID),
335335
Annotations: controllers.Annotations{
336336
TTL: AnnTTL,
337337
LeaseStart: AnnLeaseStart,
@@ -360,7 +360,7 @@ func configureNamespaceReconciler(mgr ctrl.Manager, optInLabelKey, optInLabelVal
360360
tracker := util.NewNamespaceTracker()
361361
nw := &controllers.NamespaceReconciler{
362362
Client: mgr.GetClient(),
363-
Recorder: mgr.GetEventRecorderFor(leaderElectionID),
363+
Recorder: mgr.GetEventRecorder(leaderElectionID),
364364
LabelKey: optInLabelKey,
365365
LabelValue: optInLabelValue,
366366
Tracker: tracker,

cmd/main_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
logr "github.com/go-logr/logr"
2121
"k8s.io/client-go/rest"
22+
"k8s.io/client-go/tools/events"
2223
"k8s.io/client-go/tools/record"
2324
config "sigs.k8s.io/controller-runtime/pkg/config"
2425

@@ -29,6 +30,7 @@ import (
2930
"sigs.k8s.io/controller-runtime/pkg/healthz"
3031
"sigs.k8s.io/controller-runtime/pkg/manager"
3132
"sigs.k8s.io/controller-runtime/pkg/webhook"
33+
"sigs.k8s.io/controller-runtime/pkg/webhook/conversion"
3234
// ctrl alias not required; we use manager.Runnable from pkg/manager
3335
)
3436

@@ -73,6 +75,16 @@ func (f *fakeManager) AddReadyzCheck(name string, check healthz.Checker) error
7375
func (f *fakeManager) GetWebhookServer() webhook.Server { return nil }
7476
func (f *fakeManager) GetLogger() logr.Logger { return logr.Discard() }
7577
func (f *fakeManager) GetControllerOptions() config.Controller { return config.Controller{} }
78+
func (f *fakeManager) GetConverterRegistry() conversion.Registry { return nil }
79+
func (f *fakeManager) GetEventRecorder(name string) events.EventRecorder {
80+
return &fakeEventsRecorder{}
81+
}
82+
83+
// fakeEventsRecorder implements events.EventRecorder for tests.
84+
type fakeEventsRecorder struct{}
85+
86+
func (r *fakeEventsRecorder) Eventf(regarding runtime.Object, related runtime.Object, eventtype, reason, action, note string, args ...interface{}) {
87+
}
7688

7789
// The rest of the manager methods are not used by healthCheck; add stubs to satisfy interface
7890
func (t *testMgr) GetScheme() *runtime.Scheme { return runtime.NewScheme() }
@@ -90,6 +102,8 @@ func (t *testMgr) AddReadyzCheck(name string, check healthz.Checker) error
90102
func (t *testMgr) GetWebhookServer() webhook.Server { return nil }
91103
func (t *testMgr) GetLogger() logr.Logger { return logr.Discard() }
92104
func (t *testMgr) GetControllerOptions() config.Controller { return config.Controller{} }
105+
func (t *testMgr) GetConverterRegistry() conversion.Registry { return nil }
106+
func (t *testMgr) GetEventRecorder(name string) events.EventRecorder { return &fakeEventsRecorder{} }
93107

94108
// GetRESTMapper already defined above
95109

go.mod

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ require (
99
k8s.io/api v0.35.1
1010
k8s.io/apimachinery v0.35.1
1111
k8s.io/client-go v0.35.1
12-
sigs.k8s.io/controller-runtime v0.22.4
12+
sigs.k8s.io/controller-runtime v0.23.1
1313
)
1414

1515
require (
@@ -24,7 +24,6 @@ require (
2424
github.com/go-openapi/jsonpointer v0.21.0 // indirect
2525
github.com/go-openapi/jsonreference v0.20.2 // indirect
2626
github.com/go-openapi/swag v0.23.0 // indirect
27-
github.com/gogo/protobuf v1.3.2 // indirect
2827
github.com/google/btree v1.1.3 // indirect
2928
github.com/google/gnostic-models v0.7.0 // indirect
3029
github.com/google/go-cmp v0.7.0 // indirect
@@ -56,12 +55,12 @@ require (
5655
gopkg.in/evanphx/json-patch.v4 v4.13.0 // indirect
5756
gopkg.in/inf.v0 v0.9.1 // indirect
5857
gopkg.in/yaml.v3 v3.0.1 // indirect
59-
k8s.io/apiextensions-apiserver v0.34.1 // indirect
58+
k8s.io/apiextensions-apiserver v0.35.0 // indirect
6059
k8s.io/klog/v2 v2.130.1 // indirect
6160
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 // indirect
6261
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 // indirect
6362
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
6463
sigs.k8s.io/randfill v1.0.0 // indirect
65-
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
64+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 // indirect
6665
sigs.k8s.io/yaml v1.6.0 // indirect
6766
)

go.sum

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@ github.com/go-openapi/swag v0.23.0 h1:vsEVJDUo2hPJ2tu0/Xc+4noaxyEffXNIs3cOULZ+Gr
3232
github.com/go-openapi/swag v0.23.0/go.mod h1:esZ8ITTYEsH1V2trKHjAN8Ai7xHb8RV+YSZ577vPjgQ=
3333
github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI=
3434
github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8=
35-
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
36-
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
3735
github.com/google/btree v1.1.3 h1:CVpQJjYgC4VbzxeGVHfvZrv1ctoYCAI8vbl07Fcxlyg=
3836
github.com/google/btree v1.1.3/go.mod h1:qOPhT0dTNdNzV6Z/lhRX0YXUafgPLFUh+gZMl761Gm4=
3937
github.com/google/gnostic-models v0.7.0 h1:qwTtogB15McXDaNqTZdzPJRHvaVJlAl+HVQnLmJEJxo=
@@ -51,8 +49,6 @@ github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8Hm
5149
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
5250
github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM=
5351
github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo=
54-
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
55-
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
5652
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
5753
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
5854
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
@@ -107,8 +103,6 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
107103
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
108104
github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM=
109105
github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg=
110-
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
111-
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
112106
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
113107
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
114108
go.uber.org/multierr v1.11.0 h1:blXXJkSxSSfBVBlC76pxqeO+LN3aDfLQo+309xJstO0=
@@ -119,49 +113,24 @@ go.yaml.in/yaml/v2 v2.4.3 h1:6gvOSjQoTB3vt1l+CU+tSyi/HOjfOjRLJ4YwYZGwRO0=
119113
go.yaml.in/yaml/v2 v2.4.3/go.mod h1:zSxWcmIDjOzPXpjlTTbAsKokqkDNAVtZO0WOMiT90s8=
120114
go.yaml.in/yaml/v3 v3.0.4 h1:tfq32ie2Jv2UxXFdLJdh3jXuOzWiL1fo0bu/FbuKpbc=
121115
go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg=
122-
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
123-
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
124-
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
125-
golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
126-
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
127116
golang.org/x/mod v0.29.0 h1:HV8lRxZC4l2cr3Zq1LvtOsi/ThTgWnUk/y64QSs8GwA=
128117
golang.org/x/mod v0.29.0/go.mod h1:NyhrlYXJ2H4eJiRy/WDBO6HMqZQ6q9nk4JzS3NuCK+w=
129-
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
130-
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
131-
golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
132-
golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
133118
golang.org/x/net v0.47.0 h1:Mx+4dIFzqraBXUugkia1OOvlD6LemFo1ALMHjrXDOhY=
134119
golang.org/x/net v0.47.0/go.mod h1:/jNxtkgq5yWUGYkaZGqo27cfGZ1c5Nen03aYrrKpVRU=
135120
golang.org/x/oauth2 v0.30.0 h1:dnDm7JmhM45NNpd8FDDeLhK6FwqbOf4MLCM9zb1BOHI=
136121
golang.org/x/oauth2 v0.30.0/go.mod h1:B++QgG3ZKulg6sRPGD/mqlHQs5rB3Ml9erfeDY7xKlU=
137-
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
138-
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
139-
golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
140122
golang.org/x/sync v0.18.0 h1:kr88TuHDroi+UVf+0hZnirlk8o8T+4MrK6mr60WkH/I=
141123
golang.org/x/sync v0.18.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
142-
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
143-
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
144-
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
145124
golang.org/x/sys v0.38.0 h1:3yZWxaJjBmCWXqhN1qh02AkOnCQ1poK6oF+a7xWL6Gc=
146125
golang.org/x/sys v0.38.0/go.mod h1:OgkHotnGiDImocRcuBABYBEXf8A9a87e/uXjp9XT3ks=
147126
golang.org/x/term v0.37.0 h1:8EGAD0qCmHYZg6J17DvsMy9/wJ7/D/4pV/wfnld5lTU=
148127
golang.org/x/term v0.37.0/go.mod h1:5pB4lxRNYYVZuTLmy8oR2BH8dflOR+IbTYFD8fi3254=
149-
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
150-
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
151128
golang.org/x/text v0.31.0 h1:aC8ghyu4JhP8VojJ2lEHBnochRno1sgL6nEi9WGFGMM=
152129
golang.org/x/text v0.31.0/go.mod h1:tKRAlv61yKIjGGHX/4tP1LTbc13YSec1pxVEWXzfoeM=
153130
golang.org/x/time v0.9.0 h1:EsRrnYcQiGH+5FfbgvV4AP7qEZstoyrHB0DzarOQ4ZY=
154131
golang.org/x/time v0.9.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
155-
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
156-
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
157-
golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE=
158-
golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA=
159132
golang.org/x/tools v0.38.0 h1:Hx2Xv8hISq8Lm16jvBZ2VQf+RLmbd7wVUsALibYI/IQ=
160133
golang.org/x/tools v0.38.0/go.mod h1:yEsQ/d/YK8cjh0L6rZlY8tgtlKiBNTL14pGDJPJpYQs=
161-
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
162-
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
163-
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
164-
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
165134
gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw=
166135
gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY=
167136
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
@@ -178,8 +147,8 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
178147
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
179148
k8s.io/api v0.35.1 h1:0PO/1FhlK/EQNVK5+txc4FuhQibV25VLSdLMmGpDE/Q=
180149
k8s.io/api v0.35.1/go.mod h1:28uR9xlXWml9eT0uaGo6y71xK86JBELShLy4wR1XtxM=
181-
k8s.io/apiextensions-apiserver v0.34.1 h1:NNPBva8FNAPt1iSVwIE0FsdrVriRXMsaWFMqJbII2CI=
182-
k8s.io/apiextensions-apiserver v0.34.1/go.mod h1:hP9Rld3zF5Ay2Of3BeEpLAToP+l4s5UlxiHfqRaRcMc=
150+
k8s.io/apiextensions-apiserver v0.35.0 h1:3xHk2rTOdWXXJM+RDQZJvdx0yEOgC0FgQ1PlJatA5T4=
151+
k8s.io/apiextensions-apiserver v0.35.0/go.mod h1:E1Ahk9SADaLQ4qtzYFkwUqusXTcaV2uw3l14aqpL2LU=
183152
k8s.io/apimachinery v0.35.1 h1:yxO6gV555P1YV0SANtnTjXYfiivaTPvCTKX6w6qdDsU=
184153
k8s.io/apimachinery v0.35.1/go.mod h1:jQCgFZFR1F4Ik7hvr2g84RTJSZegBc8yHgFWKn//hns=
185154
k8s.io/client-go v0.35.1 h1:+eSfZHwuo/I19PaSxqumjqZ9l5XiTEKbIaJ+j1wLcLM=
@@ -190,13 +159,13 @@ k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912 h1:Y3gxNAuB0OBLImH611+UDZ
190159
k8s.io/kube-openapi v0.0.0-20250910181357-589584f1c912/go.mod h1:kdmbQkyfwUagLfXIad1y2TdrjPFWp2Q89B3qkRwf/pQ=
191160
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4 h1:SjGebBtkBqHFOli+05xYbK8YF1Dzkbzn+gDM4X9T4Ck=
192161
k8s.io/utils v0.0.0-20251002143259-bc988d571ff4/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
193-
sigs.k8s.io/controller-runtime v0.22.4 h1:GEjV7KV3TY8e+tJ2LCTxUTanW4z/FmNB7l327UfMq9A=
194-
sigs.k8s.io/controller-runtime v0.22.4/go.mod h1:+QX1XUpTXN4mLoblf4tqr5CQcyHPAki2HLXqQMY6vh8=
162+
sigs.k8s.io/controller-runtime v0.23.1 h1:TjJSM80Nf43Mg21+RCy3J70aj/W6KyvDtOlpKf+PupE=
163+
sigs.k8s.io/controller-runtime v0.23.1/go.mod h1:B6COOxKptp+YaUT5q4l6LqUJTRpizbgf9KSRNdQGns0=
195164
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 h1:IpInykpT6ceI+QxKBbEflcR5EXP7sU1kvOlxwZh5txg=
196165
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730/go.mod h1:mdzfpAEoE6DHQEN0uh9ZbOCuHbLK5wOm7dK4ctXE9Tg=
197166
sigs.k8s.io/randfill v1.0.0 h1:JfjMILfT8A6RbawdsK2JXGBR5AQVfd+9TbzrlneTyrU=
198167
sigs.k8s.io/randfill v1.0.0/go.mod h1:XeLlZ/jmk4i1HRopwe7/aU3H5n1zNUcX6TM94b3QxOY=
199-
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 h1:jTijUJbW353oVOd9oTlifJqOGEkUw2jB/fXCbTiQEco=
200-
sigs.k8s.io/structured-merge-diff/v6 v6.3.0/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
168+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482 h1:2WOzJpHUBVrrkDjU4KBT8n5LDcj824eX0I5UKcgeRUs=
169+
sigs.k8s.io/structured-merge-diff/v6 v6.3.2-0.20260122202528-d9cc6641c482/go.mod h1:M3W8sfWvn2HhQDIbGWj3S099YozAsymCo/wrT5ohRUE=
201170
sigs.k8s.io/yaml v1.6.0 h1:G8fkbMSAFqgEFgh4b1wmtzDnioxFCUgTZhlbj5P9QYs=
202171
sigs.k8s.io/yaml v1.6.0/go.mod h1:796bPqUfzR/0jLAl6XjHl3Ck7MiyVv8dbTdyT3/pMf4=

pkg/controllers/lease_controller.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88

99
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1010
"k8s.io/apimachinery/pkg/runtime/schema"
11-
"k8s.io/client-go/tools/record"
11+
"k8s.io/client-go/tools/events"
1212
controller_runtime "sigs.k8s.io/controller-runtime"
1313
"sigs.k8s.io/controller-runtime/pkg/builder"
1414
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -29,7 +29,7 @@ type LeaseWatcher struct {
2929
client.Client
3030
GVK schema.GroupVersionKind
3131
Tracker *util.NamespaceTracker
32-
Recorder record.EventRecorder
32+
Recorder events.EventRecorder
3333
eventChan chan util.NamespaceChangeEvent
3434
Annotations Annotations
3535
Metrics *ometrics.LeaseMetrics
@@ -188,7 +188,7 @@ func (r *LeaseWatcher) cleanupLeaseAnnotations(ctx context.Context, obj *unstruc
188188
obj.SetAnnotations(anns)
189189
_ = r.Patch(ctx, obj, client.MergeFrom(base))
190190
if r.Recorder != nil {
191-
r.Recorder.Event(obj, "Normal", "LeaseAnnotationsCleaned", "Removed lease annotations because TTL is missing")
191+
r.Recorder.Eventf(obj, nil, "Normal", "LeaseAnnotationsCleaned", "LeaseAnnotationsCleaned", "Removed lease annotations because TTL is missing")
192192
}
193193
}
194194

@@ -202,15 +202,15 @@ func (r *LeaseWatcher) ensureLeaseStart(ctx context.Context, obj *unstructured.U
202202
anns[r.Annotations.LeaseStart] = now.Format(time.RFC3339)
203203
r.updateAnnotations(ctx, obj, map[string]string{r.Annotations.LeaseStart: anns[r.Annotations.LeaseStart]})
204204
if r.Recorder != nil {
205-
r.Recorder.Event(obj, "Warning", "LeaseStartReset", "Invalid lease-start, reset to now")
205+
r.Recorder.Eventf(obj, nil, "Warning", "LeaseStartReset", "LeaseStartReset", "Invalid lease-start, reset to now")
206206
}
207207
return now
208208
}
209209
// missing, set
210210
anns[r.Annotations.LeaseStart] = now.Format(time.RFC3339)
211211
r.updateAnnotations(ctx, obj, map[string]string{r.Annotations.LeaseStart: anns[r.Annotations.LeaseStart]})
212212
if r.Recorder != nil {
213-
r.Recorder.Event(obj, "Normal", "LeaseStarted", "Lease started")
213+
r.Recorder.Eventf(obj, nil, "Normal", "LeaseStarted", "LeaseStarted", "Lease started")
214214
}
215215
if r.Metrics != nil {
216216
r.Metrics.LeasesStarted.Inc()
@@ -222,7 +222,7 @@ func (r *LeaseWatcher) markInvalidTTL(ctx context.Context, obj *unstructured.Uns
222222
msg := fmt.Sprintf("Invalid TTL: %v", parseErr)
223223
r.updateAnnotations(ctx, obj, map[string]string{r.Annotations.Status: msg})
224224
if r.Recorder != nil {
225-
r.Recorder.Event(obj, "Warning", "InvalidTTL", msg)
225+
r.Recorder.Eventf(obj, nil, "Warning", "InvalidTTL", "InvalidTTL", "%s", msg)
226226
}
227227
if r.Metrics != nil {
228228
r.Metrics.InvalidTTL.Inc()
@@ -238,7 +238,7 @@ func (r *LeaseWatcher) handleExpired(ctx context.Context, obj *unstructured.Unst
238238
r.Annotations.Status: leaseStatus,
239239
})
240240
if r.Recorder != nil {
241-
r.Recorder.Event(obj, "Normal", "LeaseExpired", leaseStatus)
241+
r.Recorder.Eventf(obj, nil, "Normal", "LeaseExpired", "LeaseExpired", "%s", leaseStatus)
242242
}
243243
if r.Metrics != nil {
244244
r.Metrics.LeasesExpired.Inc()
@@ -262,14 +262,14 @@ func (r *LeaseWatcher) handleExpired(ctx context.Context, obj *unstructured.Unst
262262
// Invalid configuration - log error, emit event, proceed with deletion
263263
log.Error(err, "Invalid cleanup job configuration")
264264
if r.Recorder != nil {
265-
r.Recorder.Event(obj, "Warning", "CleanupJobConfigInvalid", fmt.Sprintf("Invalid cleanup job config: %v", err))
265+
r.Recorder.Eventf(obj, nil, "Warning", "CleanupJobConfigInvalid", "CleanupJobConfigInvalid", "Invalid cleanup job config: %v", err)
266266
}
267267
} else if config != nil {
268268
// Cleanup job is configured - attempt to create and optionally wait
269269
if err := r.executeCleanupJob(ctx, obj, config, expireAt); err != nil {
270270
log.Error(err, "Cleanup job execution failed")
271271
if r.Recorder != nil {
272-
r.Recorder.Event(obj, "Warning", "CleanupJobFailed", fmt.Sprintf("Cleanup job failed: %v", err))
272+
r.Recorder.Eventf(obj, nil, "Warning", "CleanupJobFailed", "CleanupJobFailed", "Cleanup job failed: %v", err)
273273
}
274274
if r.Metrics != nil {
275275
r.Metrics.CleanupJobsFailed.Inc()
@@ -305,7 +305,7 @@ func (r *LeaseWatcher) executeCleanupJob(ctx context.Context, obj *unstructured.
305305

306306
log.Info("Cleanup job created", "job", job.Name, "namespace", job.Namespace)
307307
if r.Recorder != nil {
308-
r.Recorder.Event(obj, "Normal", "CleanupJobCreated", fmt.Sprintf("Created cleanup job: %s", job.Name))
308+
r.Recorder.Eventf(obj, nil, "Normal", "CleanupJobCreated", "CleanupJobCreated", "Created cleanup job: %s", job.Name)
309309
}
310310
if r.Metrics != nil {
311311
r.Metrics.CleanupJobsCreated.Inc()
@@ -317,15 +317,15 @@ func (r *LeaseWatcher) executeCleanupJob(ctx context.Context, obj *unstructured.
317317
if err := util.WaitForJobCompletion(ctx, r.Client, job, config.Timeout); err != nil {
318318
// Job failed or timed out
319319
if r.Recorder != nil {
320-
r.Recorder.Event(obj, "Warning", "CleanupJobTimeout", fmt.Sprintf("Cleanup job did not complete: %v", err))
320+
r.Recorder.Eventf(obj, nil, "Warning", "CleanupJobTimeout", "CleanupJobTimeout", "Cleanup job did not complete: %v", err)
321321
}
322322
return fmt.Errorf("cleanup job did not complete: %w", err)
323323
}
324324

325325
// Job completed successfully
326326
log.Info("Cleanup job completed successfully", "job", job.Name)
327327
if r.Recorder != nil {
328-
r.Recorder.Event(obj, "Normal", "CleanupJobCompleted", fmt.Sprintf("Cleanup job completed: %s", job.Name))
328+
r.Recorder.Eventf(obj, nil, "Normal", "CleanupJobCompleted", "CleanupJobCompleted", "Cleanup job completed: %s", job.Name)
329329
}
330330
if r.Metrics != nil {
331331
r.Metrics.CleanupJobsCompleted.Inc()

0 commit comments

Comments
 (0)