Repository navigation
Add operator controller and runner integration for Redis storage - #3823
Conversation
Integrate Redis Sentinel storage backend into the operator controller and auth server runner to enable horizontally scalable auth state persistence across replicas. Controller changes: - Convert CRD AuthServerStorageConfig to storage.RunConfig - Generate env vars for Redis ACL credentials from Secret refs - Discover Sentinel addresses via EndpointSlice API or static config - Restructure GenerateAuthServerEnvVars to support Redis alongside upstream provider env vars Runner changes: - Add createStorage factory (memory default, Redis when configured) - Add convertRedisRunConfig to resolve env vars and parse durations - Add Storage field to authserver.RunConfig Includes comprehensive unit tests for all new functionality. Closes #3630
There was a problem hiding this comment.
Large PR Detected
This PR exceeds 1000 lines of changes and requires justification before it can be reviewed.
How to unblock this PR:
Add a section to your PR description with the following format:
## Large PR Justification
[Explain why this PR must be large, such as:]
- Generated code that cannot be split
- Large refactoring that must be atomic
- Multiple related changes that would break if separated
- Migration or data transformationAlternative:
Consider splitting this PR into smaller, focused changes (< 1000 lines each) for easier review and reduced risk.
See our Contributing Guidelines for more details.
This review will be automatically dismissed once you add the justification section.
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #3823 +/- ##
==========================================
+ Coverage 66.88% 67.03% +0.15%
==========================================
Files 439 444 +5
Lines 43561 44771 +1210
==========================================
+ Hits 29135 30012 +877
- Misses 12173 12423 +250
- Partials 2253 2336 +83 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
jhrozek
left a comment
There was a problem hiding this comment.
I only read the code, haven't tried it. Great work overall!
Large PR justification has been provided. Thank you!
|
✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review. |
Closes #3630
Summary
Wires the Redis storage backend through the operator controller and auth server runner, enabling the embedded auth server to use Redis Sentinel for persistent, horizontally-scalable token storage in Kubernetes. This builds on the CRD types (#3793) and core Redis storage implementation (#3628) to complete the end-to-end integration.
Changes Made
Operator Controller (
cmd/thv-operator/pkg/controllerutil/authserver.go)buildStorageRunConfigto convert CRDAuthServerStorageConfiginto a serializablestorage.RunConfigfor the runnerresolveSentinelAddrsandresolveSentinelServiceAddrsfor Sentinel address resolution, supporting both static addresses and Kubernetes EndpointSlice-based service discoveryGenerateAuthServerEnvVarsto inject Redis ACL credential environment variables (TOOLHIVE_AUTH_SERVER_REDIS_USERNAME,TOOLHIVE_AUTH_SERVER_REDIS_PASSWORD) from Secret referencesbuildEmbeddedAuthServerRunnerConfigto include storage configuration and passmcpServerNamefor namespace-scoped key prefixes (thv:auth:{namespace}:{name}:)Auth Server Runner (
pkg/authserver/runner/embeddedauthserver.go)createStoragefactory function that switches on storage type (memory default, Redis)convertRedisRunConfigto transform serializableRedisRunConfiginto runtimeRedisConfig, resolving credentials from environment variables and parsing duration stringsresolveEnvVarhelper for reading credentials from environment variables at runtimeRedisUsernameEnvVarandRedisPasswordEnvVarconstants for env var namesController Callers
AddExternalAuthConfigOptionssignature to acceptmcpServerNamefor key prefix generationMCPServerReconcilerandMCPRemoteProxyReconcilerto pass MCP server name through to the auth server config builderConfig (
pkg/authserver/config.go)Storage *storage.RunConfigfield toRunConfigfor serializable storage configurationImplementation Details
kubernetes.io/service-namelabel, filtering to ready endpoints onlythv:auth:{namespace}:{name}:)SecretKeyRef, then resolved at runtime in the runnerTesting
TestResolveSentinelAddrs— covers static addresses, EndpointSlice discovery, default port, custom namespace, no-ready-endpoints error, and missing service errorTestBuildStorageRunConfig— covers nil/memory/Redis storage types, service discovery, and validation errorsTestBuildEmbeddedAuthServerRunnerConfig_WithRedisStorage— end-to-end config build with Redis storageTestGenerateAuthServerEnvVars_RedisCredentials— verifies Redis credential env vars are generated correctlyTestCreateStorage— covers memory default, explicit memory, unsupported type, and Redis validation errorsTestConvertRedisRunConfigandTestConvertRedisRunConfig_WithEnvVars— covers config conversion, env var resolution, timeout parsing, and error casesLarge PR Justification