Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add controller name to periodical_enqueue_source #8198

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelogs/unreleased/8198-kaovilai
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add controller name to periodical_enqueue_source. The logger parameter now includes an additional field with the value of reflect.TypeOf(objList).String() and another field with the value of controllerName.
2 changes: 1 addition & 1 deletion pkg/controller/backup_deletion_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@

func (r *backupDeletionReconciler) SetupWithManager(mgr ctrl.Manager) error {
// Make sure the expired requests can be deleted eventually
s := kube.NewPeriodicalEnqueueSource(r.logger, mgr.GetClient(), &velerov1api.DeleteBackupRequestList{}, time.Hour, kube.PeriodicalEnqueueSourceOption{})
s := kube.NewPeriodicalEnqueueSource("backupDeletion", r.logger, mgr.GetClient(), &velerov1api.DeleteBackupRequestList{}, time.Hour, kube.PeriodicalEnqueueSourceOption{})

Check warning on line 105 in pkg/controller/backup_deletion_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_deletion_controller.go#L105

Added line #L105 was not covered by tests
kaovilai marked this conversation as resolved.
Show resolved Hide resolved
return ctrl.NewControllerManagedBy(mgr).
For(&velerov1api.DeleteBackupRequest{}).
WatchesRawSource(s, nil).
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/backup_operations_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
}

func (c *backupOperationsReconciler) SetupWithManager(mgr ctrl.Manager) error {
s := kube.NewPeriodicalEnqueueSource(c.logger, mgr.GetClient(), &velerov1api.BackupList{}, c.frequency, kube.PeriodicalEnqueueSourceOption{})
s := kube.NewPeriodicalEnqueueSource("backupOperations", c.logger, mgr.GetClient(), &velerov1api.BackupList{}, c.frequency, kube.PeriodicalEnqueueSourceOption{})

Check warning on line 87 in pkg/controller/backup_operations_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_operations_controller.go#L87

Added line #L87 was not covered by tests
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
backup := object.(*velerov1api.Backup)
return (backup.Status.Phase == velerov1api.BackupPhaseWaitingForPluginOperations ||
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/backup_repository_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
}

func (r *BackupRepoReconciler) SetupWithManager(mgr ctrl.Manager) error {
s := kube.NewPeriodicalEnqueueSource(r.logger, mgr.GetClient(), &velerov1api.BackupRepositoryList{}, repoSyncPeriod, kube.PeriodicalEnqueueSourceOption{})
s := kube.NewPeriodicalEnqueueSource("backupRepo", r.logger, mgr.GetClient(), &velerov1api.BackupRepositoryList{}, repoSyncPeriod, kube.PeriodicalEnqueueSourceOption{})

Check warning on line 78 in pkg/controller/backup_repository_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_repository_controller.go#L78

Added line #L78 was not covered by tests

return ctrl.NewControllerManagedBy(mgr).
For(&velerov1api.BackupRepository{}, builder.WithPredicates(kube.SpecChangePredicate{})).
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/backup_storage_location_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@

func (r *backupStorageLocationReconciler) SetupWithManager(mgr ctrl.Manager) error {
g := kube.NewPeriodicalEnqueueSource(
"backupStorageLocation",

Check warning on line 194 in pkg/controller/backup_storage_location_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_storage_location_controller.go#L194

Added line #L194 was not covered by tests
r.log,
mgr.GetClient(),
&velerov1api.BackupStorageLocationList{},
Expand Down
1 change: 1 addition & 0 deletions pkg/controller/backup_sync_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@
// SetupWithManager is used to setup controller and its watching sources.
func (b *backupSyncReconciler) SetupWithManager(mgr ctrl.Manager) error {
backupSyncSource := kube.NewPeriodicalEnqueueSource(
"backupSync",

Check warning on line 351 in pkg/controller/backup_sync_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/backup_sync_controller.go#L351

Added line #L351 was not covered by tests
b.logger,
mgr.GetClient(),
&velerov1api.BackupStorageLocationList{},
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/data_download_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,7 @@
// re-enqueue the previous related request once the related pod is in running status to keep going on the rest logic. and below logic will avoid handling the unwanted
// pod status and also avoid block others CR handling
func (r *DataDownloadReconciler) SetupWithManager(mgr ctrl.Manager) error {
s := kube.NewPeriodicalEnqueueSource(r.logger, r.client, &velerov2alpha1api.DataDownloadList{}, preparingMonitorFrequency, kube.PeriodicalEnqueueSourceOption{})
s := kube.NewPeriodicalEnqueueSource("dataDownload", r.logger, r.client, &velerov2alpha1api.DataDownloadList{}, preparingMonitorFrequency, kube.PeriodicalEnqueueSourceOption{})

Check warning on line 500 in pkg/controller/data_download_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/data_download_controller.go#L500

Added line #L500 was not covered by tests
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
dd := object.(*velerov2alpha1api.DataDownload)
return (dd.Status.Phase == velerov2alpha1api.DataDownloadPhaseAccepted)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/data_upload_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -534,7 +534,7 @@
// re-enqueue the previous related request once the related pod is in running status to keep going on the rest logic. and below logic will avoid handling the unwanted
// pod status and also avoid block others CR handling
func (r *DataUploadReconciler) SetupWithManager(mgr ctrl.Manager) error {
s := kube.NewPeriodicalEnqueueSource(r.logger, r.client, &velerov2alpha1api.DataUploadList{}, preparingMonitorFrequency, kube.PeriodicalEnqueueSourceOption{})
s := kube.NewPeriodicalEnqueueSource("dataUpload", r.logger, r.client, &velerov2alpha1api.DataUploadList{}, preparingMonitorFrequency, kube.PeriodicalEnqueueSourceOption{})

Check warning on line 537 in pkg/controller/data_upload_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/data_upload_controller.go#L537

Added line #L537 was not covered by tests
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
du := object.(*velerov2alpha1api.DataUpload)
return (du.Status.Phase == velerov2alpha1api.DataUploadPhaseAccepted)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/download_request_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,7 @@
}

func (r *downloadRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
downloadRequestSource := kube.NewPeriodicalEnqueueSource(r.log, mgr.GetClient(),
downloadRequestSource := kube.NewPeriodicalEnqueueSource("downloadRequest", r.log, mgr.GetClient(),

Check warning on line 221 in pkg/controller/download_request_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/download_request_controller.go#L221

Added line #L221 was not covered by tests
&velerov1api.DownloadRequestList{}, defaultDownloadRequestSyncPeriod, kube.PeriodicalEnqueueSourceOption{})
downloadRequestPredicates := kube.NewGenericEventPredicate(func(object kbclient.Object) bool {
downloadRequest := object.(*velerov1api.DownloadRequest)
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/gc_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
// Other Events will be filtered to decrease the number of reconcile call. Especially UpdateEvent must be filtered since we removed
// the backup status as the sub-resource of backup in v1.9, every change on it will be treated as UpdateEvent and trigger reconcile call.
func (c *gcReconciler) SetupWithManager(mgr ctrl.Manager) error {
s := kube.NewPeriodicalEnqueueSource(c.logger, mgr.GetClient(), &velerov1api.BackupList{}, c.frequency, kube.PeriodicalEnqueueSourceOption{})
s := kube.NewPeriodicalEnqueueSource("gc", c.logger, mgr.GetClient(), &velerov1api.BackupList{}, c.frequency, kube.PeriodicalEnqueueSourceOption{})

Check warning on line 78 in pkg/controller/gc_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/gc_controller.go#L78

Added line #L78 was not covered by tests
return ctrl.NewControllerManagedBy(mgr).
For(&velerov1api.Backup{}, builder.WithPredicates(predicate.Funcs{
UpdateFunc: func(ue event.UpdateEvent) bool {
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/restore_operations_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
}

func (r *restoreOperationsReconciler) SetupWithManager(mgr ctrl.Manager) error {
s := kube.NewPeriodicalEnqueueSource(r.logger, mgr.GetClient(), &velerov1api.RestoreList{}, r.frequency, kube.PeriodicalEnqueueSourceOption{})
s := kube.NewPeriodicalEnqueueSource("restoreOperations", r.logger, mgr.GetClient(), &velerov1api.RestoreList{}, r.frequency, kube.PeriodicalEnqueueSourceOption{})

Check warning on line 85 in pkg/controller/restore_operations_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/restore_operations_controller.go#L85

Added line #L85 was not covered by tests
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
restore := object.(*velerov1api.Restore)
return (restore.Status.Phase == velerov1api.RestorePhaseWaitingForPluginOperations ||
Expand Down
2 changes: 1 addition & 1 deletion pkg/controller/schedule_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
}

func (c *scheduleReconciler) SetupWithManager(mgr ctrl.Manager) error {
s := kube.NewPeriodicalEnqueueSource(c.logger, mgr.GetClient(), &velerov1.ScheduleList{}, scheduleSyncPeriod, kube.PeriodicalEnqueueSourceOption{})
s := kube.NewPeriodicalEnqueueSource("schedule", c.logger, mgr.GetClient(), &velerov1.ScheduleList{}, scheduleSyncPeriod, kube.PeriodicalEnqueueSourceOption{})

Check warning on line 72 in pkg/controller/schedule_controller.go

View check run for this annotation

Codecov / codecov/patch

pkg/controller/schedule_controller.go#L72

Added line #L72 was not covered by tests
return ctrl.NewControllerManagedBy(mgr).
// global predicate, works for both For and Watch
WithEventFilter(kube.NewAllEventPredicate(func(obj client.Object) bool {
Expand Down
5 changes: 4 additions & 1 deletion pkg/util/kube/periodical_enqueue_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,16 @@ import (
)

func NewPeriodicalEnqueueSource(
controllerName string,
logger logrus.FieldLogger,
client client.Client,
objList client.ObjectList,
period time.Duration,
option PeriodicalEnqueueSourceOption) *PeriodicalEnqueueSource {
return &PeriodicalEnqueueSource{
logger: logger.WithField("resource", reflect.TypeOf(objList).String()),
logger: logger.
WithField("resource", reflect.TypeOf(objList).String()).
WithField("controller", controllerName),
Client: client,
objList: objList,
period: period,
Expand Down
4 changes: 3 additions & 1 deletion pkg/util/kube/periodical_enqueue_source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func TestStart(t *testing.T) {
ctx, cancelFunc := context.WithCancel(context.TODO())
client := (&fake.ClientBuilder{}).Build()
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter())
source := NewPeriodicalEnqueueSource(logrus.WithContext(ctx), client, &velerov1.ScheduleList{}, 1*time.Second, PeriodicalEnqueueSourceOption{})
source := NewPeriodicalEnqueueSource("PES_TEST", logrus.WithContext(ctx), client, &velerov1.ScheduleList{}, 1*time.Second, PeriodicalEnqueueSourceOption{})

require.NoError(t, source.Start(ctx, nil, queue))

Expand Down Expand Up @@ -75,6 +75,7 @@ func TestPredicate(t *testing.T) {
client := (&fake.ClientBuilder{}).Build()
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter())
source := NewPeriodicalEnqueueSource(
"PES_TEST",
logrus.WithContext(ctx),
client,
&velerov1.BackupStorageLocationList{},
Expand Down Expand Up @@ -115,6 +116,7 @@ func TestOrder(t *testing.T) {
client := (&fake.ClientBuilder{}).Build()
queue := workqueue.NewRateLimitingQueue(workqueue.DefaultItemBasedRateLimiter())
source := NewPeriodicalEnqueueSource(
"PES_TEST",
logrus.WithContext(ctx),
client,
&velerov1.BackupStorageLocationList{},
Expand Down
Loading