Skip to content

Retry PackageRepository updates on conflict - #1879

Open
NopeCharon wants to merge 1 commit into
carvel-dev:developfrom
NopeCharon:retry-pkgr-update-on-conflict
Open

NopeCharon wants to merge 1 commit into
carvel-dev:developfrom
NopeCharon:retry-pkgr-update-on-conflict

Conversation

@NopeCharon

Copy link
Copy Markdown

What this PR does / why we need it:

The PackageRepository reconciler adds and removes its deletion finalizer by fetching the latest PackageRepository and updating it straight away. If something else changes the resource between those two calls, the update is rejected with the object has been modified; please apply your changes to the latest version and try again. When this happens while removing the finalizer, deletion fails with Unblocking for deploy: Updating PackageRepository: ....

App CRs already retry these updates (pkg/app/crd_app.go, #1766). This PR wraps the PackageRepository get-and-update in retry.RetryOnConflict from client-go, which is already used in pkg/apiserver. On a conflict, the PackageRepository is fetched again and the change is reapplied. Other errors are still returned immediately. The error message returned to callers stays the same (Updating PackageRepository: ...).

Which issue(s) this PR fixes:

Fixes #417

Does this PR introduce a user-facing change?

PackageRepository finalizer updates are now retried on conflicts, so deletion no longer fails with "the object has been modified" errors.

Additional Notes for your reviewer:

Added pkg/pkgrepository/crd_app_test.go with two tests:

  • TestUnblockDeletionRetriesOnConflict: the first two updates return a conflict. The test checks that the finalizers are removed after the third attempt. It fails without the fix.
  • TestUnblockDeletionDoesNotRetryOnNonConflictError: a non-conflict error is returned after one attempt.
Review Checklist:
  • Follows the developer guidelines
  • Relevant tests are added or updated
  • Relevant docs in this repo added or updated
  • Relevant carvel.dev docs added or updated in a separate PR and there's
    a link to that PR
  • Code is at least as readable and maintainable as it was before this
    change

Additional documentation e.g., Proposal, usage docs, etc.:


Adding and removing the PackageRepository deletion finalizer is done by
fetching the latest PackageRepository and immediately updating it. If the
resource is modified by someone else between those two calls (e.g. a
status update or another controller touching it), the API server rejects
the update with "the object has been modified; please apply your changes
to the latest version and try again". When that happened while removing
the finalizer, deletion failed with "Unblocking for deploy: Updating
PackageRepository: ..." and the PackageRepository stayed stuck until the
next reconcile.

App CRs already retry such updates (see pkg/app/crd_app.go). Wrap the
PackageRepository get-and-update in retry.RetryOnConflict so that it is
refetched and the change is reapplied on conflicts, while other errors
are still returned immediately.

Add unit tests verifying that the finalizer is removed after transient
conflicts and that non-conflict errors are not retried.

Signed-off-by: NopeCharon <115794254+NopeCharon@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

retry removing finalizer from app cr

2 participants