-
Notifications
You must be signed in to change notification settings - Fork 218
Wire SessionStorage into MCPRemoteProxy for HA support #5237
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -173,9 +173,37 @@ func (r *MCPRemoteProxyReconciler) createRunConfigFromMCPRemoteProxy( | |||||||||||||||||||||||||||||||||
| return nil, fmt.Errorf("failed to populate middleware configs: %w", err) | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Populate ScalingConfig.SessionRedis from spec.sessionStorage so the | ||||||||||||||||||||||||||||||||||
| // proxy runner has the address/db/keyPrefix needed to construct a | ||||||||||||||||||||||||||||||||||
| // shared Redis-backed session store. The Redis password is intentionally | ||||||||||||||||||||||||||||||||||
| // excluded here — it is injected as the THV_SESSION_REDIS_PASSWORD env | ||||||||||||||||||||||||||||||||||
| // var by buildRedisPasswordEnvVar in mcpremoteproxy_deployment.go. | ||||||||||||||||||||||||||||||||||
| populateScalingConfigForRemoteProxy(runConfig, proxy) | ||||||||||||||||||||||||||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ordering bug (latent):
// Must run before PopulateMiddlewareConfigs because rate limiting reads SessionRedis.
populateScalingConfig(runConfig, m)
if err := runner.PopulateMiddlewareConfigs(runConfig); err != nil { ... }
Suggested change
|
||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| return runConfig, nil | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // populateScalingConfigForRemoteProxy mirrors populateScalingConfig from | ||||||||||||||||||||||||||||||||||
| // mcpserver_runconfig.go but for MCPRemoteProxy (which has no | ||||||||||||||||||||||||||||||||||
| // BackendReplicas concept). When MCPRemoteProxy.spec.sessionStorage uses | ||||||||||||||||||||||||||||||||||
| // the redis provider, this populates runner.ScalingConfig.SessionRedis with | ||||||||||||||||||||||||||||||||||
| // the non-sensitive connection parameters. | ||||||||||||||||||||||||||||||||||
| func populateScalingConfigForRemoteProxy(runConfig *runner.RunConfig, proxy *mcpv1beta1.MCPRemoteProxy) { | ||||||||||||||||||||||||||||||||||
| if proxy.Spec.SessionStorage == nil || | ||||||||||||||||||||||||||||||||||
| proxy.Spec.SessionStorage.Provider != mcpv1beta1.SessionStorageProviderRedis { | ||||||||||||||||||||||||||||||||||
| return | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if runConfig.ScalingConfig == nil { | ||||||||||||||||||||||||||||||||||
| runConfig.ScalingConfig = &runner.ScalingConfig{} | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| runConfig.ScalingConfig.SessionRedis = &runner.SessionRedisConfig{ | ||||||||||||||||||||||||||||||||||
| Address: proxy.Spec.SessionStorage.Address, | ||||||||||||||||||||||||||||||||||
| DB: proxy.Spec.SessionStorage.DB, | ||||||||||||||||||||||||||||||||||
| KeyPrefix: proxy.Spec.SessionStorage.KeyPrefix, | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // resolveAndAddOIDCConfig resolves OIDC configuration from the shared MCPOIDCConfigRef, | ||||||||||||||||||||||||||||||||||
| // adds the appropriate runner options, and returns the resolved config. | ||||||||||||||||||||||||||||||||||
| func (r *MCPRemoteProxyReconciler) resolveAndAddOIDCConfig( | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider documenting the
sessionAffinity+sessionStorageinteraction.These two fields now coexist without any cross-reference, which creates a footgun. When
sessionStorage.provider == redisthe correct HA setup also requiressessionAffinity: None— otherwise the k8s Service's ClientIP stickiness makes the Redis store redundant. Conversely,sessionAffinity: Nonewithout Redis is the broken configuration this PR was written to fix.At minimum, the
SessionStoragefield comment should say: "When using the Redis provider, also setsessionAffinity: Noneso the Service routes requests round-robin and all replicas rely on the shared session store rather than pod-local state."A stronger option is a kubebuilder
XValidationthat requiressessionAffinity == "None"whensessionStorage.provider == "redis", catching the misconfiguration at admission time.