Skip to content

fix: prevent panic on nil APIResource in permission validator#26610

Merged
rumstead merged 1 commit intoargoproj:masterfrom
loafoe:fix/nil-apiresource-panic-26608
Mar 18, 2026
Merged

fix: prevent panic on nil APIResource in permission validator#26610
rumstead merged 1 commit intoargoproj:masterfrom
loafoe:fix/nil-apiresource-panic-26608

Conversation

@loafoe
Copy link
Contributor

@loafoe loafoe commented Feb 25, 2026

Summary

  • Add nil check for APIResource parameter in permission validator callback to prevent panic during API server connectivity issues
  • Return informative error message instead of crashing when API resource info cannot be retrieved

Details

When syncing an application with CreateNamespace=true and the control-plane becomes temporarily unreachable (e.g., during k3s control plane refresh), the API resource discovery can fail in a way that results in a nil *metav1.APIResource being passed to the permission validator callback. This causes a nil pointer dereference panic at controller/sync.go:311.

The fix adds a defensive nil check that returns a meaningful error instead of panicking, allowing the sync to fail gracefully and be retried.

Test plan

  • Existing controller tests pass
  • Manual testing: interrupt control-plane connectivity during sync with CreateNamespace=true - should show error instead of panic

Fixes #26608

@loafoe loafoe requested a review from a team as a code owner February 25, 2026 09:34
@bunnyshell
Copy link

bunnyshell bot commented Feb 25, 2026

❌ Preview Environment deleted from Bunnyshell

Available commands (reply to this comment):

  • 🚀 /bns:deploy to deploy the environment

@loafoe loafoe force-pushed the fix/nil-apiresource-panic-26608 branch 2 times, most recently from 4810e24 to 5159d37 Compare February 25, 2026 12:58
@loafoe loafoe force-pushed the fix/nil-apiresource-panic-26608 branch from 5159d37 to 5a8c1eb Compare February 25, 2026 17:27
@loafoe loafoe requested a review from ppapapetrou76 February 25, 2026 17:35
@codecov
Copy link

codecov bot commented Feb 25, 2026

Codecov Report

❌ Patch coverage is 66.66667% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 63.17%. Comparing base (a87aab1) to head (c5fa609).
⚠️ Report is 4 commits behind head on master.

Files with missing lines Patch % Lines
controller/sync.go 66.66% 3 Missing and 2 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master   #26610      +/-   ##
==========================================
+ Coverage   63.15%   63.17%   +0.02%     
==========================================
  Files         414      414              
  Lines       56444    56448       +4     
==========================================
+ Hits        35645    35659      +14     
+ Misses      17428    17422       -6     
+ Partials     3371     3367       -4     

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

@loafoe loafoe force-pushed the fix/nil-apiresource-panic-26608 branch from 5a8c1eb to 5343207 Compare February 26, 2026 06:15
Copy link
Contributor

@ppapapetrou76 ppapapetrou76 left a comment

Choose a reason for hiding this comment

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

#LGTM 🏅 - thanks for addressing my comments

@loafoe loafoe force-pushed the fix/nil-apiresource-panic-26608 branch 5 times, most recently from 5f5c615 to c660449 Compare March 3, 2026 18:38
Add a nil check for the APIResource parameter in the permission
validator callback to prevent panic when API server connectivity
is interrupted during sync operations. Extracted the function
for testability. Added Unit Tests.

Fixes argoproj#26608

Signed-off-by: Andy Lo-A-Foe <andy.loafoe@gmail.com>
@loafoe loafoe force-pushed the fix/nil-apiresource-panic-26608 branch from c660449 to c5fa609 Compare March 18, 2026 17:39
@rumstead rumstead merged commit 442aed4 into argoproj:master Mar 18, 2026
27 checks passed
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.

Panic in application-controller on connectivity issues with control-plane

3 participants