Skip to content

Commit 8fea4da

Browse files
committed
Migrate to new Kubernetes events API
Replace deprecated record.EventRecorder with events.EventRecorder from k8s.io/client-go/tools/events. Update all controllers, event server, and tests to use the new API signature. Signed-off-by: Adrian Fernandez de la Torre <adri1197@gmail.com>
1 parent b4f379e commit 8fea4da

84 files changed

Lines changed: 152 additions & 156 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@ require (
1515
github.com/cdevents/sdk-go v0.4.1
1616
github.com/chainguard-dev/git-urls v1.0.2
1717
github.com/elazarl/goproxy v1.8.1
18-
github.com/fluxcd/cli-utils v0.37.2-flux.1
18+
github.com/fluxcd/cli-utils v1.2.0
1919
github.com/fluxcd/notification-controller/api v1.8.0
20-
github.com/fluxcd/pkg/apis/event v0.25.0
21-
github.com/fluxcd/pkg/apis/meta v1.26.0
20+
github.com/fluxcd/pkg/apis/event v0.26.0
21+
github.com/fluxcd/pkg/apis/meta v1.27.0
2222
github.com/fluxcd/pkg/auth v0.40.0
2323
github.com/fluxcd/pkg/cache v0.13.0
2424
github.com/fluxcd/pkg/git v0.46.0
2525
github.com/fluxcd/pkg/masktoken v0.8.0
2626
github.com/fluxcd/pkg/runtime v0.103.0
27-
github.com/fluxcd/pkg/ssa v0.70.0
27+
github.com/fluxcd/pkg/ssa v0.74.0
2828
github.com/fluxcd/pkg/ssh v0.24.0
2929
github.com/getsentry/sentry-go v0.42.0
3030
github.com/go-logr/logr v1.4.3

go.sum

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -133,16 +133,14 @@ github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
133133
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
134134
github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg=
135135
github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U=
136-
github.com/fluxcd/cli-utils v0.37.2-flux.1 h1:tQ588ghtRN+E+kHq415FddfqA9v4brn/1WWgrP6rQR0=
137-
github.com/fluxcd/cli-utils v0.37.2-flux.1/go.mod h1:LcWSu1NYET8d8U7O326RhEm5JkQXCMK6ITu4G1CT02c=
138-
github.com/fluxcd/pkg/apis/acl v0.9.0 h1:wBpgsKT+jcyZEcM//OmZr9RiF8klL3ebrDp2u2ThsnA=
139-
github.com/fluxcd/pkg/apis/acl v0.9.0/go.mod h1:TttNS+gocsGLwnvmgVi3/Yscwqrjc17+vhgYfqkfrV4=
140-
github.com/fluxcd/pkg/apis/event v0.25.0 h1:zdwytvDhG+fk+Ywl5DOtv7TklkrVgM21WHm1f+YhleE=
141-
github.com/fluxcd/pkg/apis/event v0.25.0/go.mod h1:TlK8HWYrTwl0raqBRC+ROoNpYW5fdVnwcwOBOx5Kzw8=
142-
github.com/fluxcd/pkg/apis/kustomize v1.16.0 h1:PhWXEhqQqsisIpwp1/wHvTvo+MO+GGzsBPoN0ZnRE3Y=
143-
github.com/fluxcd/pkg/apis/kustomize v1.16.0/go.mod h1:IZOy4CCtR/hxMGb7erK1RfbGnczVv4/dRBoVD37AywI=
144-
github.com/fluxcd/pkg/apis/meta v1.26.0 h1:dxP1FfBpTCYso6odzRcltVnnRuBb2VyhhgV0VX9YbUE=
145-
github.com/fluxcd/pkg/apis/meta v1.26.0/go.mod h1:c7o6mJGLCMvNrfdinGZehkrdZuFT9vZdZNrn66DtVD0=
136+
github.com/fluxcd/cli-utils v1.2.0 h1:1o07pXTMxJ/XJ1GpAbLtjdXwfCUMq4Ku1OcnvJHLohI=
137+
github.com/fluxcd/cli-utils v1.2.0/go.mod h1:d5HdTDdR5sCbsIbgtOQ7x7srKYwYeZORU6CD2yn4j/M=
138+
github.com/fluxcd/pkg/apis/acl v0.10.0 h1:KPfAmELNvtvaz8wixnm/MYXqa+MJf7ntVVMUU93Aenk=
139+
github.com/fluxcd/pkg/apis/acl v0.10.0/go.mod h1:a87i2A7AlFO5N2J8CxtzaUCCDmuLLWOHwkKu3eJF5fY=
140+
github.com/fluxcd/pkg/apis/kustomize v1.18.0 h1:FCNjViCLyKYj6lddpnjXybKBTC2eK6eXK9YOaNwLVTM=
141+
github.com/fluxcd/pkg/apis/kustomize v1.18.0/go.mod h1:mvtMtM4NNLipdCna6DYPC6Bd42xeaF15N+tNO+F6kxY=
142+
github.com/fluxcd/pkg/apis/meta v1.27.0 h1:EspByEk5j8w3rs1cGbEh9AjSmpDwQIz7DFG/zzqf6uI=
143+
github.com/fluxcd/pkg/apis/meta v1.27.0/go.mod h1:2t6JyrRfvIBhx6EBnXfFh/6sCCJ1db9WGaqko0JmNOE=
146144
github.com/fluxcd/pkg/auth v0.40.0 h1:p6Kw6KH+z8oRqngKhmTt8ILKD/rC+8tP87a//kLZhi8=
147145
github.com/fluxcd/pkg/auth v0.40.0/go.mod h1:Oq/hIEKUMTbL2bv5blf+EhC/jXXJLsOjIMtJj/AtG3Y=
148146
github.com/fluxcd/pkg/cache v0.13.0 h1:MqtlgOwIVcGKKgV422e39O+KFSVMWuExKeRaMDBjJlk=
@@ -151,10 +149,8 @@ github.com/fluxcd/pkg/git v0.46.0 h1:QMh0+ZzQ2jO6rIGj4ffR5trZ8g/cxvt8cVajReJ8Iyw
151149
github.com/fluxcd/pkg/git v0.46.0/go.mod h1:iHcIjx9c8zye3PQiajTJYxgOMRiy7WCs+hfLKDswpfI=
152150
github.com/fluxcd/pkg/masktoken v0.8.0 h1:Dm5xIVNbg0s6zNttjDvimaG38bKsXwxBVo5b+D7ThVU=
153151
github.com/fluxcd/pkg/masktoken v0.8.0/go.mod h1:Gc73ALOqIe+5Gj2V3JggMNiYcBiZ9bNNDYBE9R5XTTg=
154-
github.com/fluxcd/pkg/runtime v0.103.0 h1:J5y5GPhWdkyqIUBlaI1FP2N02TtZmsjbWhhZubuTSFk=
155-
github.com/fluxcd/pkg/runtime v0.103.0/go.mod h1:mbo2f3azo3yVQgm7XZGxQB6/2zvzQ5Wgtd8TjRRwwAw=
156-
github.com/fluxcd/pkg/ssa v0.70.0 h1:IBylYPiTK1IEdCC2DvjKXIhwQcbd5VufXA9WS3zO+tE=
157-
github.com/fluxcd/pkg/ssa v0.70.0/go.mod h1:6igtlt7/zF+nNFQpa5ZAkkvtpL6o36NRU39/PqqC+Bg=
152+
github.com/fluxcd/pkg/ssa v0.74.0 h1:a5VqQXBQ5TQlzucwZ9l37bshzR3IPK5awzfMEBF3pdM=
153+
github.com/fluxcd/pkg/ssa v0.74.0/go.mod h1:6mdhG+O1db8oXsP7Ex3buJTexM5r9F7+LzSybBgT1f0=
158154
github.com/fluxcd/pkg/ssh v0.24.0 h1:hrPlxs0hhXf32DRqs68VbsXs0XfQMphyRVIk0rYYJa4=
159155
github.com/fluxcd/pkg/ssh v0.24.0/go.mod h1:xWammEqalrpurpcMiixJRXtynRQtBEoqheyU5F/vWrg=
160156
github.com/fortytw2/leaktest v1.3.0 h1:u8491cBMTQ8ft8aeV+adlcytMZylmA5nnwwkRZjI8vw=

internal/controller/alert_controller.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"context"
2121

2222
corev1 "k8s.io/api/core/v1"
23-
kuberecorder "k8s.io/client-go/tools/record"
23+
"k8s.io/client-go/tools/events"
2424
ctrl "sigs.k8s.io/controller-runtime"
2525
"sigs.k8s.io/controller-runtime/pkg/builder"
2626
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -37,7 +37,7 @@ import (
3737
// AlertReconciler reconciles an Alert object to migrate it to static Alert.
3838
type AlertReconciler struct {
3939
client.Client
40-
kuberecorder.EventRecorder
40+
events.AnnotatedEventRecorder
4141

4242
ControllerName string
4343
}
@@ -88,7 +88,7 @@ func (r *AlertReconciler) Reconcile(ctx context.Context, req ctrl.Request) (resu
8888
controllerutil.RemoveFinalizer(obj, apiv1.NotificationFinalizer)
8989

9090
log.Info("removed finalizer from Alert to migrate to static Alert")
91-
r.Event(obj, corev1.EventTypeNormal, "Migration", "removed finalizer from Alert to migrate to static Alert")
91+
r.AnnotatedEventf(obj, nil, nil, corev1.EventTypeNormal, "Migration", "", "removed finalizer from Alert to migrate to static Alert")
9292

9393
return
9494
}

internal/controller/provider_controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ package controller
1919
import (
2020
"context"
2121

22-
kuberecorder "k8s.io/client-go/tools/record"
22+
"k8s.io/client-go/tools/events"
2323
ctrl "sigs.k8s.io/controller-runtime"
2424
"sigs.k8s.io/controller-runtime/pkg/builder"
2525
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -42,7 +42,7 @@ import (
4242
// Provider.
4343
type ProviderReconciler struct {
4444
client.Client
45-
kuberecorder.EventRecorder
45+
events.AnnotatedEventRecorder
4646

4747
TokenCache *cache.TokenCache
4848
}

internal/controller/receiver_controller.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
apierrors "k8s.io/apimachinery/pkg/api/errors"
2626
"k8s.io/apimachinery/pkg/types"
2727
kerrors "k8s.io/apimachinery/pkg/util/errors"
28-
kuberecorder "k8s.io/client-go/tools/record"
28+
"k8s.io/client-go/tools/events"
2929
"k8s.io/client-go/util/workqueue"
3030
ctrl "sigs.k8s.io/controller-runtime"
3131
"sigs.k8s.io/controller-runtime/pkg/builder"
@@ -50,7 +50,7 @@ import (
5050
type ReceiverReconciler struct {
5151
client.Client
5252
helper.Metrics
53-
kuberecorder.EventRecorder
53+
events.AnnotatedEventRecorder
5454

5555
ControllerName string
5656
}
@@ -166,14 +166,14 @@ func (r *ReceiverReconciler) Reconcile(ctx context.Context, req ctrl.Request) (r
166166

167167
// Emit warning event if the reconciliation failed.
168168
if retErr != nil {
169-
r.Event(obj, corev1.EventTypeWarning, meta.FailedReason, retErr.Error())
169+
r.AnnotatedEventf(obj, nil, nil, corev1.EventTypeWarning, meta.FailedReason, "", retErr.Error())
170170
}
171171

172172
// Log and emit success event.
173173
if retErr == nil && conditions.IsReady(obj) {
174174
msg := fmt.Sprintf("Reconciliation finished, next run in %s", obj.GetInterval().String())
175175
log.Info(msg)
176-
r.Event(obj, corev1.EventTypeNormal, meta.SucceededReason, msg)
176+
r.AnnotatedEventf(obj, nil, nil, corev1.EventTypeNormal, meta.SucceededReason, "", msg)
177177
}
178178
}()
179179

@@ -215,7 +215,7 @@ func (r *ReceiverReconciler) reconcile(ctx context.Context, obj *apiv1.Receiver)
215215
conditions.MarkStalled(obj, meta.InvalidCELExpressionReason, "%s", errMsg)
216216
obj.Status.ObservedGeneration = obj.Generation
217217
log.Error(err, msg)
218-
r.Event(obj, corev1.EventTypeWarning, meta.InvalidCELExpressionReason, errMsg)
218+
r.AnnotatedEventf(obj, nil, nil, corev1.EventTypeWarning, meta.InvalidCELExpressionReason, "", errMsg)
219219
return ctrl.Result{}, nil
220220
}
221221
}

internal/controller/receiver_controller_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
3333
"k8s.io/apimachinery/pkg/types"
34-
"k8s.io/client-go/tools/record"
34+
"k8s.io/client-go/tools/events"
3535
ctrl "sigs.k8s.io/controller-runtime"
3636
"sigs.k8s.io/controller-runtime/pkg/client"
3737
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
@@ -74,8 +74,8 @@ func TestReceiverReconciler_deleteBeforeFinalizer(t *testing.T) {
7474
g.Expect(k8sClient.Delete(ctx, receiver)).NotTo(HaveOccurred())
7575

7676
r := &ReceiverReconciler{
77-
Client: k8sClient,
78-
EventRecorder: record.NewFakeRecorder(32),
77+
Client: k8sClient,
78+
AnnotatedEventRecorder: events.NewFakeRecorder(32),
7979
}
8080
// NOTE: Only a real API server responds with an error in this scenario.
8181
_, err := r.Reconcile(ctx, ctrl.Request{NamespacedName: client.ObjectKeyFromObject(receiver)})

internal/controller/suite_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,25 +75,25 @@ func TestMain(m *testing.M) {
7575
testMetricsH := controller.NewMetrics(testEnv, metrics.MustMakeRecorder(), apiv1.NotificationFinalizer)
7676

7777
if err := (&AlertReconciler{
78-
Client: testEnv,
79-
ControllerName: controllerName,
80-
EventRecorder: testEnv.GetEventRecorderFor(controllerName),
78+
Client: testEnv,
79+
ControllerName: controllerName,
80+
AnnotatedEventRecorder: testEnv.GetAnnotatedEventRecorder(controllerName),
8181
}).SetupWithManager(testEnv); err != nil {
8282
panic(fmt.Sprintf("Failed to start AlertReconciler: %v", err))
8383
}
8484

8585
if err := (&ProviderReconciler{
86-
Client: testEnv,
87-
EventRecorder: testEnv.GetEventRecorderFor(controllerName),
86+
Client: testEnv,
87+
AnnotatedEventRecorder: testEnv.GetAnnotatedEventRecorder(controllerName),
8888
}).SetupWithManager(testEnv); err != nil {
8989
panic(fmt.Sprintf("Failed to start ProviderReconciler: %v", err))
9090
}
9191

9292
if err := (&ReceiverReconciler{
93-
Client: testEnv,
94-
Metrics: testMetricsH,
95-
ControllerName: controllerName,
96-
EventRecorder: testEnv.GetEventRecorderFor(controllerName),
93+
Client: testEnv,
94+
Metrics: testMetricsH,
95+
ControllerName: controllerName,
96+
AnnotatedEventRecorder: testEnv.GetAnnotatedEventRecorder(controllerName),
9797
}).SetupWithManager(testEnv, ReceiverReconcilerOptions{
9898
RateLimiter: controller.GetDefaultRateLimiter(),
9999
WatchConfigsPredicate: predicate.Not(predicate.Funcs{}),

internal/notifier/alertmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import (
2828
"golang.org/x/text/cases"
2929
"golang.org/x/text/language"
3030

31-
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
31+
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
3232
)
3333

3434
type Alertmanager struct {

internal/notifier/alertmanager_fuzz_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
"testing"
2727

2828
fuzz "github.com/AdaLogics/go-fuzz-headers"
29-
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
29+
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
3030
)
3131

3232
func Fuzz_AlertManager(f *testing.F) {

internal/notifier/azure_devops.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727
"github.com/microsoft/azure-devops-go-api/azuredevops/v6/git"
2828
"sigs.k8s.io/controller-runtime/pkg/client"
2929

30-
eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1"
30+
eventv1 "github.com/fluxcd/pkg/apis/event/v1"
3131
"github.com/fluxcd/pkg/apis/meta"
3232
"github.com/fluxcd/pkg/auth/azure"
3333
"github.com/fluxcd/pkg/cache"

0 commit comments

Comments
 (0)