mirror of
https://github.com/vmware-tanzu/velero.git
synced 2026-04-22 16:50:34 +00:00
Add controller name to periodical_enqueue_source
The code changes are related to the `NewPeriodicalEnqueueSource` function in the `kube/periodical_enqueue_source.go` file. This function is used to create a new instance of the `PeriodicalEnqueueSource` struct, which is responsible for periodically enqueueing objects into a work queue. The changes involve adding two new parameters to this function: `controllerName string` and modifying the existing `logger` parameter to include additional fields. Here's what changed: 1. A new `controllerName` parameter was added to the `NewPeriodicalEnqueueSource` function. These changes are to adding more context or metadata to the logging output, possibly for debugging or monitoring purposes. The other files (`restore_operations_controller.go`, `schedule_controller.go`, and their respective test files) were modified to use this updated `NewPeriodicalEnqueueSource` function with the new `controllerName` parameter. Signed-off-by: Tiger Kaovilai <tkaovila@redhat.com>
This commit is contained in:
1
changelogs/unreleased/8198-kaovilai
Normal file
1
changelogs/unreleased/8198-kaovilai
Normal file
@@ -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.
|
||||
@@ -102,7 +102,7 @@ func NewBackupDeletionReconciler(
|
||||
|
||||
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{})
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.DeleteBackupRequest{}).
|
||||
WatchesRawSource(s, nil).
|
||||
|
||||
@@ -84,7 +84,7 @@ func NewBackupOperationsReconciler(
|
||||
}
|
||||
|
||||
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{})
|
||||
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
|
||||
backup := object.(*velerov1api.Backup)
|
||||
return (backup.Status.Phase == velerov1api.BackupPhaseWaitingForPluginOperations ||
|
||||
|
||||
@@ -75,7 +75,7 @@ func NewBackupRepoReconciler(namespace string, logger logrus.FieldLogger, client
|
||||
}
|
||||
|
||||
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{})
|
||||
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.BackupRepository{}, builder.WithPredicates(kube.SpecChangePredicate{})).
|
||||
|
||||
@@ -191,6 +191,7 @@ func (r *backupStorageLocationReconciler) logReconciledPhase(defaultFound bool,
|
||||
|
||||
func (r *backupStorageLocationReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
g := kube.NewPeriodicalEnqueueSource(
|
||||
"backupStorageLocation",
|
||||
r.log,
|
||||
mgr.GetClient(),
|
||||
&velerov1api.BackupStorageLocationList{},
|
||||
|
||||
@@ -348,6 +348,7 @@ func (b *backupSyncReconciler) filterBackupOwnerReferences(ctx context.Context,
|
||||
// SetupWithManager is used to setup controller and its watching sources.
|
||||
func (b *backupSyncReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
backupSyncSource := kube.NewPeriodicalEnqueueSource(
|
||||
"backupSync",
|
||||
b.logger,
|
||||
mgr.GetClient(),
|
||||
&velerov1api.BackupStorageLocationList{},
|
||||
|
||||
@@ -497,7 +497,7 @@ func (r *DataDownloadReconciler) OnDataDownloadProgress(ctx context.Context, nam
|
||||
// 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{})
|
||||
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
|
||||
dd := object.(*velerov2alpha1api.DataDownload)
|
||||
return (dd.Status.Phase == velerov2alpha1api.DataDownloadPhaseAccepted)
|
||||
|
||||
@@ -534,7 +534,7 @@ func (r *DataUploadReconciler) OnDataUploadProgress(ctx context.Context, namespa
|
||||
// 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{})
|
||||
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
|
||||
du := object.(*velerov2alpha1api.DataUpload)
|
||||
return (du.Status.Phase == velerov2alpha1api.DataUploadPhaseAccepted)
|
||||
|
||||
@@ -218,7 +218,7 @@ func (r *downloadRequestReconciler) Reconcile(ctx context.Context, req ctrl.Requ
|
||||
}
|
||||
|
||||
func (r *downloadRequestReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
||||
downloadRequestSource := kube.NewPeriodicalEnqueueSource(r.log, mgr.GetClient(),
|
||||
downloadRequestSource := kube.NewPeriodicalEnqueueSource("downloadRequest", r.log, mgr.GetClient(),
|
||||
&velerov1api.DownloadRequestList{}, defaultDownloadRequestSyncPeriod, kube.PeriodicalEnqueueSourceOption{})
|
||||
downloadRequestPredicates := kube.NewGenericEventPredicate(func(object kbclient.Object) bool {
|
||||
downloadRequest := object.(*velerov1api.DownloadRequest)
|
||||
|
||||
@@ -75,7 +75,7 @@ func NewGCReconciler(
|
||||
// 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{})
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
For(&velerov1api.Backup{}, builder.WithPredicates(predicate.Funcs{
|
||||
UpdateFunc: func(ue event.UpdateEvent) bool {
|
||||
|
||||
@@ -82,7 +82,7 @@ func NewRestoreOperationsReconciler(
|
||||
}
|
||||
|
||||
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{})
|
||||
gp := kube.NewGenericEventPredicate(func(object client.Object) bool {
|
||||
restore := object.(*velerov1api.Restore)
|
||||
return (restore.Status.Phase == velerov1api.RestorePhaseWaitingForPluginOperations ||
|
||||
|
||||
@@ -69,7 +69,7 @@ func NewScheduleReconciler(
|
||||
}
|
||||
|
||||
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{})
|
||||
return ctrl.NewControllerManagedBy(mgr).
|
||||
// global predicate, works for both For and Watch
|
||||
WithEventFilter(kube.NewAllEventPredicate(func(obj client.Object) bool {
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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{},
|
||||
@@ -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{},
|
||||
|
||||
Reference in New Issue
Block a user