Skip to content

fix(appset): fall back to create when patch returns NotFound (#17312)#28645

Open
rickbrouwer wants to merge 4 commits into
argoproj:masterfrom
rickbrouwer:issue-17312
Open

fix(appset): fall back to create when patch returns NotFound (#17312)#28645
rickbrouwer wants to merge 4 commits into
argoproj:masterfrom
rickbrouwer:issue-17312

Conversation

@rickbrouwer

@rickbrouwer rickbrouwer commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

When an Application managed by an ApplicationSet is manually deleted, the applicationset-controller's informer cache can remain stale. CreateOrUpdate then reads the deleted Application from the cache, takes the update path, and Patch fails against the API server with applications.argoproj.io "XXX" not found.
The ApplicationSet keeps reporting UpdateApplicationError until the controller is restarted.

The fix is in cacheSyncingClient.Patch. When Patch returns NotFound, evict the stale object from the informer store. The requeued reconcile sees a fresh cache and takes the Create path, so the ApplicationSet self-heals without a controller restart.

Because this is a bug fix, please cherry-pick to release-3.5, release-3.4 and release-3.3.

Fixes #17312

Checklist:

  • Either (a) I've created an enhancement proposal and discussed it with the community, (b) this is a bug fix, or (c) this does not need to be in the release notes.
  • The title of the PR states what changed and the related issues number (used for the release note).
  • The title of the PR conforms to the Title of the PR
  • I've included "Closes [ISSUE #]" or "Fixes [ISSUE #]" in the description to automatically close the associated issue.
  • I've updated both the CLI and UI to expose my feature, or I plan to submit a second PR with them.
  • Does this PR require documentation updates?
  • I've updated documentation as required by this PR.
  • I have signed off all my commits as required by DCO
  • I have written unit and/or e2e tests for my change. PRs without these are unlikely to be merged.
  • My build is green (troubleshooting builds).
  • My new feature complies with the feature status guidelines.
  • I have added a brief description of why this PR is necessary and/or what this PR solves.
  • Optional. My organization is added to USERS.md.
  • Optional. For bug fixes, I've indicated what older releases this fix should be cherry-picked into (this may or may not happen depending on risk/complexity).

@bunnyshell

bunnyshell Bot commented Jul 9, 2026

Copy link
Copy Markdown

❗ Preview Environment stop on Bunnyshell failed

See: Environment Details | Pipeline Logs

Available commands (reply to this comment):

  • 🔴 /bns:stop to stop again the environment
  • 🔵 /bns:start to start the environment
  • 🚀 /bns:deploy to redeploy the environment
  • /bns:delete to remove the environment

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Bundle Report

Bundle size has no change ✅

@rickbrouwer rickbrouwer marked this pull request as ready for review July 9, 2026 09:02
@rickbrouwer rickbrouwer requested a review from a team as a code owner July 9, 2026 09:02
@blakepettersson blakepettersson added cherry-pick/3.3 Candidate for cherry picking into the 3.3 release cherry-pick/3.4 cherry-pick/3.5 labels Jul 9, 2026
@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.23%. Comparing base (aeda334) to head (fafdba0).
⚠️ Report is 4 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master   #28645      +/-   ##
==========================================
+ Coverage   65.22%   65.23%   +0.01%     
==========================================
  Files         426      426              
  Lines       59741    59748       +7     
==========================================
+ Hits        38964    38977      +13     
- Misses      17191    17192       +1     
+ Partials     3586     3579       -7     
Flag Coverage Δ
e2e 26.73% <100.00%> (-0.03%) ⬇️
unit-tests 60.68% <85.71%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

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

@rickbrouwer

Copy link
Copy Markdown
Contributor Author

I don't know if that can still be done that quickly, but given that you (@reggie-k) just indicated at the Contributors Office Hours closing the patch release for 3.4 today, it would be super super super nice if this could still be included.

@rumstead rumstead left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Let's fix the issue at the source. We can update the cacheSyncingClient's patch command to evict the application from the cache on a not found error and return the not found error. That should (almost) immediately requeue the applicationset.

@rickbrouwer

Copy link
Copy Markdown
Contributor Author

Thanks @rumstead !

@rickbrouwer rickbrouwer requested a review from rumstead July 9, 2026 18:31
Comment thread applicationset/utils/client.go Outdated
Comment on lines +130 to +132
err := c.Client.Patch(ctx, obj, patch, opts...)
if err != nil && apierrors.IsNotFound(err) {
c.evictFromCache(ctx, obj)

@rumstead rumstead Jul 9, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i think there is still a case where the phantom application would live in the cache. eg, if DeepEqual returns true. I think we just add a comment somewhere and acknowledge that is PR is getting us in a better spot but doesn't cover every case.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Seems good to me indeed, added

Comment thread applicationset/utils/client.go Outdated
Comment on lines +138 to +141
func (c *cacheSyncingClient) evictFromCache(ctx context.Context, obj client.Object) {
if _, ok := obj.(*application.Application); !ok {
return
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

r.Update in removeOwnerReferencesOnDeleteAppSet and r.Delete in deleteInCluster hit the same stale cache NotFound and won't evict. moving this into execAndSyncCache's error branch covers all the verbs and avoids duplicating the guard/getStore/log here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Comment thread applicationset/utils/client_test.go Outdated
Comment on lines +144 to +154
func TestEvictFromCacheHandlesGetStoreError(t *testing.T) {
t.Parallel()
scheme := runtime.NewScheme()
require.NoError(t, application.AddToScheme(scheme))
c := &cacheSyncingClient{
Client: fake.NewClientBuilder().WithScheme(scheme).Build(),
storesByNs: map[string]k8scache.Store{},
getNSCache: func(_ context.Context, _ client.Object) (ctrlcache.Cache, error) {
return nil, errors.New("no cache")
},
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NIT: these literals duplicate what newClient does. should we parameterize and reuse?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Fixes a reconciliation failure mode in the ApplicationSet controller when an Application is manually deleted but the controller’s informer cache remains stale, causing Patch to hit the API server and return NotFound repeatedly.

Changes:

  • On Patch returning NotFound, evicts the stale Application object from the informer store to force a fresh cache read on the next reconcile.
  • Adds unit tests covering the eviction behavior and error/skip paths.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
applicationset/utils/client.go Evicts stale cached Application objects when Patch fails with NotFound, enabling self-healing reconcile behavior.
applicationset/utils/client_test.go Adds tests verifying eviction on NotFound and validating safe behavior for non-Application objects and store/cache error paths.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
Signed-off-by: Rick Brouwer <rickbrouwer@gmail.com>
@blakepettersson

Copy link
Copy Markdown
Member

@rickbrouwer now there's a conflict

@rickbrouwer

Copy link
Copy Markdown
Contributor Author

I see. I need to take a look at it for a moment to process this correctly.

@rickbrouwer

Copy link
Copy Markdown
Contributor Author

@rickbrouwer now there's a conflict

Done. Just a little heads-up: I touched the same block you modified in #28663. Just for information.

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

Labels

cherry-pick/3.3 Candidate for cherry picking into the 3.3 release cherry-pick/3.4 cherry-pick/3.5

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: manually deleting an app from an appset does not trigger a recreate

4 participants