Context is not propagated in backup repository BSL invalidation handler
What steps did you take and what happened:
In pkg/controller/backup_repository_controller.go, invalidateBackupReposForBSL(ctx context.Context, bslObj client.Object) receives a ctx context.Context parameter from the controller-runtime event handler:
func (r *BackupRepoReconciler) invalidateBackupReposForBSL(ctx context.Context, bslObj client.Object) []reconcile.RequestHowever, inside the function, ctx is ignored in two places and replaced with context.TODO() and context.Background():
- Line 149:
if err := r.List(context.TODO(), list, options); err != nil {- Line 157:
if err := r.patchBackupRepository(context.Background(), &list.Items[i], repoNotReady("re-establish on BSL change, create or delete")); err != nil {Because context.TODO() and context.Background() are passed instead of the caller's ctx, cancellation signals and deadlines (for example, when the controller manager is shutting down or the reconcile event context is canceled) are bypassed during the BackupRepository listing and patching operations.
What did you expect to happen:
The caller-provided ctx should be passed to r.List(ctx, list, options) and r.patchBackupRepository(ctx, &list.Items[i], ...) so context cancellation and deadlines are properly honored.
The following information will help us better understand what's going on: N/A (Code health / context propagation issue in backup repository controller)
Anything else you would like to add:
I have identified the fix and would like to submit a PR along with unit test coverage for invalidateBackupReposForBSL.
Environment:
- Velero version (use
velero version): main branch (v1.17 / v1.18 development) - Velero features (use
velero client config get features): N/A - Kubernetes version (use
kubectl version): N/A - Kubernetes installer & version: N/A
- Cloud provider or hardware configuration: N/A
- OS (e.g. from
/etc/os-release): Linux / all platforms
Source: velero-io/velero