Add Redis Cluster mode support to auth server storage#5153
Open
Add Redis Cluster mode support to auth server storage#5153
Conversation
Managed Redis services like GCP Memorystore Cluster and AWS ElastiCache Serverless use the Redis Cluster protocol rather than standalone or Sentinel connections, making it impossible to use them without this third mode. - Add ClusterConfig/ClusterRunConfig types to storage and runner layers - Wire cluster client creation via redis.NewClusterClient in NewRedisStorage - Update validateConfig, convertRedisRunConfig, and buildStorageRunConfig to enforce three-way mutual exclusion (addr / sentinel / cluster) - Add RedisClusterConfig CRD type with MinItems=1 validation; update CEL rule to require exactly one of the three modes - Regenerate deepcopy, CRD YAML, and Helm chart templates - Add unit tests for all new validation and happy-path code paths Closes #5010 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #5153 +/- ##
==========================================
+ Coverage 67.53% 67.55% +0.01%
==========================================
Files 601 601
Lines 61093 61114 +21
==========================================
+ Hits 41262 41283 +21
Misses 16714 16714
Partials 3117 3117 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
ClusterConfig{Addrs []string} was a misleading abstraction: GCP Memorystore
Cluster and AWS ElastiCache cluster mode both expose a single discovery endpoint,
so the slice always held exactly one address and was redundant with the existing
Addr field.
Replace ClusterConfig with a ClusterMode bool flag that is set alongside the
existing Addr field. go-redis NewClusterClient still receives the single endpoint
as []string{addr} and auto-discovers the full cluster topology from there.
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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
Managed Redis services like GCP Memorystore Cluster and AWS ElastiCache cluster mode enabled expose a single discovery endpoint — not a list of shard nodes. The operator needs a way to tell go-redis to use the Cluster protocol for that endpoint, rather than treating it as a standalone server.
This PR adds
clusterMode: trueas a flag on the existingaddrfield instead of introducing a separateclusterConfigstruct with anaddrsslice. WhenclusterModeis set, the runner callsredis.NewClusterClient({Addrs: []string{addr}}), which auto-discovers the full cluster topology from the single discovery endpoint.Changes:
pkg/authserver/storage): replaceClusterConfig *ClusterConfigwithClusterMode boolonRedisConfig/RedisRunConfig;NewRedisStoragebranches oncfg.ClusterModeand wrapscfg.Addrin the slice thatClusterOptionsexpectspkg/authserver/runner):convertRedisRunConfigmapsClusterModestraight through; validation updated to: addr XOR sentinel, plusclusterModerequiresaddrcmd/thv-operator/api/v1beta1):RedisStorageConfiggainsclusterMode bool; CEL rules revert to a simple XOR (addr vs sentinelConfig) plus a second rule forclusterModerequiringaddr;RedisClusterConfigstruct removedCloses #5010
Type of change
Test plan
task test)task lint-fix)New unit tests cover: cluster mode + sentinel conflict, cluster mode without addr, cluster mode happy-path at all three layers (storage, runner, operator).
API Compatibility
v1beta1API, OR theapi-break-allowedlabel is applied and the migration guidance is described above.clusterModeis a new optional bool field (defaults to false). Adding it is a backward-compatible change. The CEL XOR rule for addr vs sentinelConfig is equivalent to the previous rule for the existing combinations.Changes
pkg/authserver/storage/redis.goClusterConfigstruct withClusterMode bool; updatevalidateConfigandNewRedisStoragepkg/authserver/storage/config.goClusterRunConfig/ClusterConfigfield withClusterMode boolonRedisRunConfigpkg/authserver/runner/embeddedauthserver.goClusterModeinconvertRedisRunConfig; simplified validationcmd/thv-operator/api/v1beta1/mcpexternalauthconfig_types.goClusterMode bool; removeRedisClusterConfigstruct; update CEL rulescmd/thv-operator/pkg/controllerutil/authserver.goClusterMode; removevalidateRedisConnectionModehelperzz_generated.deepcopy.go, CRD YAML × 4Does this introduce a user-facing change?
Yes. Kubernetes operators can now enable Redis Cluster protocol by setting
spec.authServer.storage.redis.clusterMode: truealongside the existingaddrfield. Setaddrto the single discovery endpoint of the managed Redis Cluster service (e.g., GCP Memorystore Cluster discovery IP, AWS ElastiCache configuration endpoint).Generated with Claude Code