Fix reconcile loop caused by non-deterministic env var ordering in di…#4783
Merged
Fix reconcile loop caused by non-deterministic env var ordering in di…#4783
Conversation
…scovered auth mode Signed-off-by: lujunsan <luisjuncaldev@gmail.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #4783 +/- ##
==========================================
+ Coverage 69.11% 69.21% +0.09%
==========================================
Files 533 533
Lines 55251 55257 +6
==========================================
+ Hits 38186 38244 +58
+ Misses 14134 14069 -65
- Partials 2931 2944 +13 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jerm-dro
reviewed
Apr 13, 2026
|
Any possibility to check progress on this? |
jerm-dro
approved these changes
Apr 16, 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
Deployments for VirtualMCPServer with
outgoingAuth.source: discoveredand 4+MCPExternalAuthConfigs entered a continuous update loop (~10 updates/sec), causing
constant pod rolling restarts and dropped MCP client sessions.
order (Go map iteration over
Spec.OutgoingAuth.Backends; K8s informer cache orderingfor
typedWorkloads) causeddiscoverExternalAuthConfigSecretsanddiscoverInlineExternalAuthConfigSecretsto returnTOOLHIVE_TOKEN_EXCHANGE_CLIENT_SECRET_*env vars in a different sequence on every reconcile.
containerNeedsUpdatecompares env vars withreflect.DeepEqual, which isorder-sensitive on slices, so every reconcile saw a spurious diff and triggered a
deployment update, which triggered the next reconcile, ad infinitum.
[]corev1.EnvVarby.Namebefore returning from bothfunctions. Env var ordering has no semantic meaning in Kubernetes; the vMCP runtime
looks up secrets by name via
os.Getenv, not by slice position.Type of change
Test plan
task test)Two new tests added:
TestDiscoverExternalAuthConfigSecrets_DeterministicOrdering— table-driven, exercisesboth reverse-alphabetical and mixed workload orderings, asserts output is always sorted
TestDiscoverInlineExternalAuthConfigSecrets_DeterministicOrdering— exercises Go mapnon-determinism in
Spec.OutgoingAuth.Backends, asserts output is always sortedBoth tests were written first (failing), then the sort was added (passing) — confirmed
the tests catch the bug before the fix.
Does this introduce a user-facing change?
Yes. VirtualMCPServer deployments using
outgoingAuth.source: discoveredwith 4+MCPExternalAuthConfigs will no longer enter a continuous update/restart loop.
Special notes for reviewers
buildCABundleVolumesForEntriesalso iteratestypedWorkloadsto produce ordered slices,but volumes are not compared in any
*NeedsUpdatecheck — so it does not contribute tothis loop and is out of scope for this fix.
The ConfigMap side (
discoverExternalAuthConfigs) was also reviewed: it populates amap[string]*BackendAuthStrategywhichyaml.v3serialises with sorted keys, so theConfigMap content and its checksum are already deterministic.
Generated with Claude Code