Add retry logic for App CR updates to handle optimistic concurrency conflicts#1766
Merged
praveenrewar merged 3 commits intocarvel-dev:developfrom Oct 14, 2025
Merged
Conversation
673129c to
444d1fe
Compare
…onflicts - Implement updateAppWithRetry() function in PackageInstall reconciler - Add retry logic with up to 5 attempts for App CR updates - Re-fetch App CR after each failed update to get latest resourceVersion - Handle NotFound errors immediately without retries - Add comprehensive unit tests for retry logic covering: - Conflict error handling with retries - NotFound error immediate return - Update function error propagation - Use NewApp function for App transformations in retry logic Fixes optimistic concurrency control conflicts that occur when multiple operations attempt to update the same App CR simultaneously. Signed-off-by: Marin Dzhigarov <m.dzhigarov@gmail.com>
- Rename unused 'action' parameters to '_' in test reactors - Rename unused 'app' parameter to '_' in failing update function test - Addresses revive linter warnings for unused parameters Signed-off-by: Marin Dzhigarov <m.dzhigarov@gmail.com>
9105dba to
b75623d
Compare
de33b80 to
b1eef69
Compare
- Update updateAppWithRetry to only retry on conflict errors, not on NotFound errors - Change retry condition from !errors.IsNotFound(err) to !errors.IsConflict(err) - Update unit tests to reflect new retry behavior: - Fix Test_UpdateAppWithRetry_HandlesNotFoundError to expect no retries for NotFound - Add Test_UpdateAppWithRetry_HandlesNonConflictError for non-conflict error handling - Update Test_UpdateAppWithRetry_HandlesConflictErrors to use proper errors.NewConflict() - Add k8s.io/apimachinery/pkg/api/errors import for proper error types This ensures that only conflict errors trigger retries, while all other errors (including NotFound) are returned immediately without retries. Signed-off-by: Marin Dzhigarov <m.dzhigarov@gmail.com>
b1eef69 to
f4033d5
Compare
praveenrewar
approved these changes
Oct 14, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR implements retry logic for App CR updates in the PackageInstall reconciler to handle optimistic concurrency control conflicts that can occur when multiple operations attempt to update the same App CR simultaneously.
Changes
Core Implementation
updateAppWithRetry()function inpkg/packageinstall/packageinstall.goupdateFuncsignature that returns an App, allowing direct integration withNewApp()Integration Points
NewApp()for transformation)Testing
pkg/packageinstall/packageinstall_test.go:Test_UpdateAppWithRetry_HandlesConflictErrors: Tests retry logic with simulated conflict errorsTest_UpdateAppWithRetry_HandlesNotFoundError: Verifies immediate return for NotFound errorsTest_UpdateAppWithRetry_HandlesUpdateFunctionError: Tests error propagation from update functionProblem Solved
Fixes the "object has been modified; please apply your changes to the latest version and try again" error that occurs when:
Testing
All existing tests pass, and new tests specifically validate:
Backward Compatibility
This change is fully backward compatible: