Skip to content

fix: invalidate cluster cache after sync operations #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

pjiang-dev
Copy link
Contributor

@pjiang-dev pjiang-dev commented Jul 10, 2025

There have been several times after a sync that the diff shows the live resource before the sync, causing incorrect diffs. This change will ensure if there is a sync with a valid task (non no-op) then we invalidate the cache. We only invalidate cache for resources that were modified to save on operational cost
This is guaranteeing fresh data for subsequent diff calculations

This could also help/fix this issue with CRDs argoproj/argo-cd#20458
as previously after a CRD schema changes and is synced, we run into a diff error because diff is using stale schema

Signed-off-by: Peter Jiang <peterjiang823@gmail.com>
Copy link

codecov bot commented Jul 10, 2025

Codecov Report

Attention: Patch coverage is 73.77049% with 16 lines in your changes missing coverage. Please review.

Project coverage is 47.75%. Comparing base (8849c3f) to head (f303abe).
Report is 52 commits behind head on master.

Files with missing lines Patch % Lines
pkg/engine/engine.go 0.00% 13 Missing ⚠️
pkg/sync/sync_context.go 90.62% 2 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #745      +/-   ##
==========================================
- Coverage   54.26%   47.75%   -6.51%     
==========================================
  Files          64       64              
  Lines        6164     6627     +463     
==========================================
- Hits         3345     3165     -180     
- Misses       2549     3203     +654     
+ Partials      270      259      -11     

☔ 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.

Signed-off-by: Peter Jiang <peterjiang823@gmail.com>
Copy link
Contributor

@leoluz leoluz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check my comments.

Comment on lines 97 to 98
// Invalidate the entire cache to ensure consistency
e.cache.Invalidate()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Invalidating the entire cache during a sync operation seems heavy... iirc this forces a re-list of everything on the destination cluster, which is slow and expensive. Is there something more narrow we could do?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, i was thinking that we can only invalidate cache for resources which were modified. Need to check if this is possible and what the possible side-effects are

Signed-off-by: Peter Jiang <peterjiang823@gmail.com>
Signed-off-by: Peter Jiang <peterjiang823@gmail.com>
Signed-off-by: Peter Jiang <peterjiang823@gmail.com>
Signed-off-by: Peter Jiang <peterjiang823@gmail.com>
Copy link

@pjiang-dev pjiang-dev marked this pull request as ready for review July 11, 2025 16:28
@pjiang-dev pjiang-dev requested a review from a team as a code owner July 11, 2025 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants