@@ -32,9 +32,7 @@ import (
3232 "golang.org/x/sync/errgroup"
3333 "golang.org/x/sync/semaphore"
3434 corev1 "k8s.io/api/core/v1"
35- "k8s.io/apimachinery/pkg/runtime"
3635 "k8s.io/apimachinery/pkg/types"
37- kuberecorder "k8s.io/client-go/tools/record"
3836 "k8s.io/client-go/util/workqueue"
3937 ctrl "sigs.k8s.io/controller-runtime"
4038 "sigs.k8s.io/controller-runtime/pkg/client"
@@ -43,14 +41,15 @@ import (
4341 "sigs.k8s.io/controller-runtime/pkg/predicate"
4442 "sigs.k8s.io/controller-runtime/pkg/reconcile"
4543
46- eventv1 "github.com/fluxcd/pkg/apis/event/v1beta1 "
44+ eventv1 "github.com/fluxcd/pkg/apis/event/v1 "
4745 "github.com/fluxcd/pkg/apis/meta"
4846 intdigest "github.com/fluxcd/pkg/artifact/digest"
4947 "github.com/fluxcd/pkg/artifact/storage"
5048 "github.com/fluxcd/pkg/auth"
5149 "github.com/fluxcd/pkg/cache"
5250 "github.com/fluxcd/pkg/runtime/conditions"
5351 helper "github.com/fluxcd/pkg/runtime/controller"
52+ "github.com/fluxcd/pkg/runtime/events"
5453 "github.com/fluxcd/pkg/runtime/jitter"
5554 "github.com/fluxcd/pkg/runtime/patch"
5655 "github.com/fluxcd/pkg/runtime/predicates"
@@ -126,7 +125,7 @@ var bucketFailConditions = []string{
126125// BucketReconciler reconciles a v1.Bucket object.
127126type BucketReconciler struct {
128127 client.Client
129- kuberecorder .EventRecorder
128+ events .EventRecorder
130129 helper.Metrics
131130
132131 Storage * storage.Storage
@@ -348,13 +347,13 @@ func (r *BucketReconciler) notify(ctx context.Context, oldObj, newObj *sourcev1.
348347
349348 // Notify on new artifact and failure recovery.
350349 if ! oldObj .GetArtifact ().HasDigest (newObj .GetArtifact ().Digest ) {
351- r .AnnotatedEventf (newObj , annotations , corev1 .EventTypeNormal ,
352- "NewArtifact" , "%s" , message )
350+ r .AnnotatedEventf (newObj , nil , annotations , corev1 .EventTypeNormal ,
351+ "NewArtifact" , eventv1 . ActionApplied , "%s" , message )
353352 ctrl .LoggerFrom (ctx ).Info (message )
354353 } else {
355354 if sreconcile .FailureRecovery (oldObj , newObj , bucketFailConditions ) {
356- r .AnnotatedEventf (newObj , annotations , corev1 .EventTypeNormal ,
357- meta .SucceededReason , "%s" , message )
355+ r .AnnotatedEventf (newObj , nil , annotations , corev1 .EventTypeNormal ,
356+ meta .SucceededReason , eventv1 . ActionReconciled , "%s" , message )
358357 ctrl .LoggerFrom (ctx ).Info (message )
359358 }
360359 }
@@ -388,7 +387,7 @@ func (r *BucketReconciler) reconcileStorage(ctx context.Context, sp *patch.Seria
388387 // matches the actual artifact
389388 if ! artifactMissing {
390389 if err := r .Storage .VerifyArtifact (* artifact ); err != nil {
391- r .Eventf (obj , corev1 .EventTypeWarning , "ArtifactVerificationFailed" , "failed to verify integrity of artifact: %s" , err .Error ())
390+ r .Eventf (obj , nil , corev1 .EventTypeWarning , "ArtifactVerificationFailed" , eventv1 . ActionFailed , "failed to verify integrity of artifact: %s" , err .Error ())
392391
393392 if err = r .Storage .Remove (* artifact ); err != nil {
394393 return sreconcile .ResultEmpty , fmt .Errorf ("failed to remove artifact after digest mismatch: %w" , err )
@@ -525,7 +524,7 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, sp *patch.Seri
525524 if curArtifact := obj .GetArtifact (); curArtifact != nil && curArtifact .Revision != "" {
526525 curRev := digest .Digest (curArtifact .Revision )
527526 if curRev .Validate () == nil && index .Digest (curRev .Algorithm ()) == curRev {
528- r . eventLogf (ctx , obj , eventv1 .EventTypeTrace , sourcev1 .ArtifactUpToDateReason , "artifact up-to-date with remote revision: '%s'" , artifact .Revision )
527+ sreconcile . EventLogf (ctx , r , obj , eventv1 .EventTypeTrace , sourcev1 .ArtifactUpToDateReason , "artifact up-to-date with remote revision: '%s'" , artifact .Revision )
529528 return sreconcile .ResultSuccess , nil
530529 }
531530 }
@@ -582,7 +581,7 @@ func (r *BucketReconciler) reconcileArtifact(ctx context.Context, sp *patch.Seri
582581 // Update symlink on a "best effort" basis
583582 url , err := r .Storage .Symlink (artifact , "latest.tar.gz" )
584583 if err != nil {
585- r . eventLogf (ctx , obj , eventv1 .EventTypeTrace , sourcev1 .SymlinkUpdateFailedReason ,
584+ sreconcile . EventLogf (ctx , r , obj , eventv1 .EventTypeTrace , sourcev1 .SymlinkUpdateFailedReason ,
586585 "failed to update status URL symlink: %s" , err )
587586 }
588587 if url != "" {
@@ -626,7 +625,7 @@ func (r *BucketReconciler) garbageCollect(ctx context.Context, obj *sourcev1.Buc
626625 "GarbageCollectionFailed" ,
627626 )
628627 } else if deleted != "" {
629- r . eventLogf (ctx , obj , eventv1 .EventTypeTrace , "GarbageCollectionSucceeded" ,
628+ sreconcile . EventLogf (ctx , r , obj , eventv1 .EventTypeTrace , "GarbageCollectionSucceeded" ,
630629 "garbage collected artifacts for deleted resource" )
631630 }
632631 obj .Status .Artifact = nil
@@ -641,40 +640,14 @@ func (r *BucketReconciler) garbageCollect(ctx context.Context, obj *sourcev1.Buc
641640 )
642641 }
643642 if len (delFiles ) > 0 {
644- r . eventLogf (ctx , obj , eventv1 .EventTypeTrace , "GarbageCollectionSucceeded" ,
643+ sreconcile . EventLogf (ctx , r , obj , eventv1 .EventTypeTrace , "GarbageCollectionSucceeded" ,
645644 "garbage collected %d artifacts" , len (delFiles ))
646645 return nil
647646 }
648647 }
649648 return nil
650649}
651650
652- // eventLogf records events, and logs at the same time.
653- //
654- // This log is different from the debug log in the EventRecorder, in the sense
655- // that this is a simple log. While the debug log contains complete details
656- // about the event.
657- func (r * BucketReconciler ) eventLogf (ctx context.Context , obj runtime.Object , eventType string , reason string , messageFmt string , args ... interface {}) {
658- r .annotatedEventLogf (ctx , obj , nil , eventType , reason , messageFmt , args ... )
659- }
660-
661- // annotatedEventLogf records annotated events, and logs at the same time.
662- //
663- // This log is different from the debug log in the EventRecorder, in the sense
664- // that this is a simple log. While the debug log contains complete details
665- // about the event.
666- func (r * BucketReconciler ) annotatedEventLogf (ctx context.Context ,
667- obj runtime.Object , annotations map [string ]string , eventType string , reason string , messageFmt string , args ... interface {}) {
668- msg := fmt .Sprintf (messageFmt , args ... )
669- // Log and emit event.
670- if eventType == corev1 .EventTypeWarning {
671- ctrl .LoggerFrom (ctx ).Error (errors .New (reason ), msg )
672- } else {
673- ctrl .LoggerFrom (ctx ).Info (msg )
674- }
675- r .AnnotatedEventf (obj , annotations , eventType , reason , "%s" , msg )
676- }
677-
678651// fetchEtagIndex fetches the current etagIndex for the in the obj specified
679652// bucket using the given provider, while filtering them using .sourceignore
680653// rules. After fetching an object, the etag value in the index is updated to
0 commit comments