Skip to content

fix: improve error handling for retryable operations#2342

Merged
eddycharly merged 4 commits into
kyverno:mainfrom
karthikmanam:fix/improve-retryable-errors
Dec 15, 2025
Merged

fix: improve error handling for retryable operations#2342
eddycharly merged 4 commits into
kyverno:mainfrom
karthikmanam:fix/improve-retryable-errors

Conversation

@karthikmanam

Copy link
Copy Markdown
Contributor

Explanation

This PR improves error handling in the create, update, and patch operations by implementing proper retry logic for transient errors. Previously, the code had TODO comments indicating the need to determine which errors could be retried. This PR addresses these TODOs by implementing specific logic to identify and handle retryable errors like conflicts, server timeouts, too many requests, and service unavailability.

Additionally, the create operation has been simplified to directly check for the AlreadyExists error from the API server instead of making a separate Get request followed by a Create request.

Related issue

This PR addresses TODO comments found in the code that were highlighting the need for better error handling in the Kubernetes resource operations. It improves the reliability of the application when interacting with Kubernetes API server under load or unstable network conditions.

Proposed Changes

  • Added specific error type checking to determine which errors are retryable in all three operations (create, update, patch)
  • Improved the create operation to directly use the AlreadyExists error from the Kubernetes API instead of making a separate Get call first
  • Added proper handling for various error types with appropriate retry behavior
  • Ensured permanent errors (like NotFound or AlreadyExists) are immediately returned without unnecessary retries

Checklist

  • I have read the contributing guidelines.
  • I have read the PR documentation guide and followed the process including adding proof manifests to this PR.
  • This is a bug fix and I have added unit tests that prove my fix is effective.

Signed-off-by: Karthik babu Manam [email protected]

@karthikmanam
karthikmanam requested a review from a team as a code owner April 1, 2025 07:08
This change adds retry logic for handling transient errors in Kubernetes operations (update, create, and patch). It properly retries operations when encountering conflict errors, server timeouts, too many requests, and service unavailability errors. Non-retryable errors are properly propagated. Tests are added to verify the retry behavior.

Signed-off-by: Karthik babu Manam <[email protected]>
@karthikmanam
karthikmanam force-pushed the fix/improve-retryable-errors branch from 2152fb7 to f45c235 Compare April 1, 2025 10:16
@eddycharly
eddycharly merged commit 515e407 into kyverno:main Dec 15, 2025
13 of 16 checks passed
@codecov

codecov Bot commented Dec 15, 2025

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (ad0ee39) to head (3255a01).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@     Coverage Diff      @@
##   main   #2342   +/-   ##
============================
============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants