Fix ServiceAccount secret accumulation on OpenShift#3627
Open
ChrisJBurns wants to merge 3 commits intomainfrom
Open
Fix ServiceAccount secret accumulation on OpenShift#3627ChrisJBurns wants to merge 3 commits intomainfrom
ChrisJBurns wants to merge 3 commits intomainfrom
Conversation
On OpenShift/OKD, the openshift-controller-manager automatically manages the Secrets and ImagePullSecrets fields on ServiceAccounts by creating kubernetes.io/service-account-token and kubernetes.io/dockercfg secrets. Previously, the operator's upsertServiceAccount function unconditionally overwrote these fields with nil during reconciliation. This caused OpenShift to detect the SA as "missing dockercfg" and create new secrets, while the old ones became orphaned. Over time, this led to unbounded secret accumulation (~90 orphaned secret pairs/day). This fix preserves existing Secrets and ImagePullSecrets fields when the desired values are nil, following the pattern recommended in: operator-framework/operator-sdk#6494 The fix is safe for standard Kubernetes clusters where these fields are typically empty anyway. Fixes #3622 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #3627 +/- ##
==========================================
- Coverage 65.78% 65.77% -0.02%
==========================================
Files 411 411
Lines 40727 40729 +2
==========================================
- Hits 26794 26791 -3
- Misses 11850 11857 +7
+ Partials 2083 2081 -2 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jhrozek
approved these changes
Feb 5, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
SecretsandImagePullSecretsfields when the operator doesn't explicitly set themProblem
On OpenShift/OKD 4.15, the operator's reconciliation loop caused unbounded creation of
kubernetes.io/service-account-tokenandkubernetes.io/dockercfgsecrets for ServiceAccounts. Over ~1 week, hundreds to thousands of orphaned secrets accumulated per MCPServer instance (~90 orphaned secret pairs/day).Root cause: The
upsertServiceAccountfunction unconditionally overwroteSecretsandImagePullSecretsfields with nil values. On OpenShift, theopenshift-controller-managerautomatically manages these fields, so when cleared, OpenShift created new secrets while old ones became orphaned.Solution
Modified
upsertServiceAccountto only overwriteSecretsandImagePullSecretswhen explicitly specified (non-nil). When nil, existing values are preserved.This follows the pattern recommended in: operator-framework/operator-sdk#6494
Impact
[]) will apply the desired stateTest plan
preserves_existing_Secrets_and_ImagePullSecrets_when_not_specified_(OpenShift_compatibility)overwrites_Secrets_and_ImagePullSecrets_when_explicitly_specifiedFixes #3622
🤖 Generated with Claude Code