Skip to content

Add operator controller and runner integration for Redis storage - #3823

Merged
tgrunnagle merged 5 commits into
mainfrom
issue_3630_as-controller
Feb 19, 2026
Merged

tgrunnagle merged 5 commits into
mainfrom
issue_3630_as-controller

Conversation

@tgrunnagle

@tgrunnagle tgrunnagle commented Feb 13, 2026 •

Copy link
Copy Markdown
Collaborator

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)

  • Added buildStorageRunConfig to convert CRD AuthServerStorageConfig into a serializable storage.RunConfig for the runner
  • Added resolveSentinelAddrs and resolveSentinelServiceAddrs for Sentinel address resolution, supporting both static addresses and Kubernetes EndpointSlice-based service discovery
  • Extended GenerateAuthServerEnvVars to inject Redis ACL credential environment variables (TOOLHIVE_AUTH_SERVER_REDIS_USERNAME, TOOLHIVE_AUTH_SERVER_REDIS_PASSWORD) from Secret references
  • Extended buildEmbeddedAuthServerRunnerConfig to include storage configuration and pass mcpServerName for namespace-scoped key prefixes (thv:auth:{namespace}:{name}:)

Auth Server Runner (pkg/authserver/runner/embeddedauthserver.go)

  • Added createStorage factory function that switches on storage type (memory default, Redis)
  • Added convertRedisRunConfig to transform serializable RedisRunConfig into runtime RedisConfig, resolving credentials from environment variables and parsing duration strings
  • Added resolveEnvVar helper for reading credentials from environment variables at runtime
  • Defined RedisUsernameEnvVar and RedisPasswordEnvVar constants for env var names

Controller Callers

  • Updated AddExternalAuthConfigOptions signature to accept mcpServerName for key prefix generation
  • Updated MCPServerReconciler and MCPRemoteProxyReconciler to pass MCP server name through to the auth server config builder

Config (pkg/authserver/config.go)

  • Added Storage *storage.RunConfig field to RunConfig for serializable storage configuration

Implementation Details

  • Sentinel service discovery uses EndpointSlices (not legacy Endpoints) with the standard kubernetes.io/service-name label, filtering to ready endpoints only
  • Redis key prefixes are scoped by namespace and MCP server name for multi-tenancy (thv:auth:{namespace}:{name}:)
  • Credential injection follows the Kubernetes pattern: Secrets are mounted as environment variables via SecretKeyRef, then resolved at runtime in the runner

Testing

  • Added TestResolveSentinelAddrs — covers static addresses, EndpointSlice discovery, default port, custom namespace, no-ready-endpoints error, and missing service error
  • Added TestBuildStorageRunConfig — covers nil/memory/Redis storage types, service discovery, and validation errors
  • Added TestBuildEmbeddedAuthServerRunnerConfig_WithRedisStorage — end-to-end config build with Redis storage
  • Added TestGenerateAuthServerEnvVars_RedisCredentials — verifies Redis credential env vars are generated correctly
  • Added TestCreateStorage — covers memory default, explicit memory, unsupported type, and Redis validation errors
  • Added TestConvertRedisRunConfig and TestConvertRedisRunConfig_WithEnvVars — covers config conversion, env var resolution, timeout parsing, and error cases
  • All tests use table-driven patterns with parallel execution

Large PR Justification

  • Implements both controller and runner portions of Redis configuration for verifiability.
  • Half of lines are tests and docs.

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
@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Feb 13, 2026

@github-actions github-actions Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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 transformation

Alternative:

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.

@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 13, 2026
@codecov

codecov Bot commented Feb 13, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.75740% with 19 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.03%. Comparing base (9305d9e) to head (3666de8).
⚠️ Report is 50 commits behind head on main.

Files with missing lines Patch % Lines
pkg/authserver/runner/embeddedauthserver.go 80.70% 6 Missing and 5 partials ⚠️
cmd/thv-operator/pkg/controllerutil/authserver.go 92.66% 4 Missing and 4 partials ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@jhrozek jhrozek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I only read the code, haven't tried it. Great work overall!

@github-actions
github-actions Bot dismissed their stale review February 18, 2026 16:50

Large PR justification has been provided. Thank you!

@github-actions github-actions Bot removed the size/XL Extra large PR: 1000+ lines changed label Feb 18, 2026
@github-actions

Copy link
Copy Markdown
Contributor

✅ Large PR justification has been provided. The size review has been dismissed and this PR can now proceed with normal review.

@github-actions github-actions Bot added the size/XL Extra large PR: 1000+ lines changed label Feb 18, 2026
@tgrunnagle
tgrunnagle requested a review from jhrozek February 18, 2026 16:50
jhrozek
jhrozek previously approved these changes Feb 19, 2026
@github-actions github-actions Bot added size/XL Extra large PR: 1000+ lines changed and removed size/XL Extra large PR: 1000+ lines changed labels Feb 19, 2026
@tgrunnagle
tgrunnagle merged commit 96de177 into main Feb 19, 2026
36 checks passed
@tgrunnagle
tgrunnagle deleted the issue_3630_as-controller branch February 19, 2026 19:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/XL Extra large PR: 1000+ lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Auth Server: Operator Controller & Runner Integration for Redis Storage

2 participants