You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add retry logic for App CR updates to handle optimistic concurrency conflicts (#1766)
* Add retry logic for App CR updates to handle optimistic concurrency conflicts
- 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>
* Fix golangci-lint unused parameter warnings in tests
- 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>
* Fix app update retry logic to only retry on conflict errors
- 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>
---------
Signed-off-by: Marin Dzhigarov <m.dzhigarov@gmail.com>
conflictCount:=3// Fail first 3 attempts with conflict, succeed on 4th
1027
+
1028
+
// Add reactor to simulate conflict errors on update
1029
+
fakekctrl.PrependReactor("update", "apps", func(action k8stesting.Action) (handledbool, ret runtime.Object, errerror) {
1030
+
updateAttempts++
1031
+
updateAction:=action.(k8stesting.UpdateAction)
1032
+
app:=updateAction.GetObject().(*v1alpha1.App)
1033
+
1034
+
ifupdateAttempts<=conflictCount {
1035
+
// Simulate conflict error for first few attempts
1036
+
returntrue, nil, errors.NewConflict(schema.GroupResource{Group: "kappctrl.carvel.dev", Resource: "apps"}, "instl-pkg", fmt.Errorf("the object has been modified; please apply your changes to the latest version and try again"))
0 commit comments