Repository navigation
Description
Description
Update the operator controller and auth server runner to support Redis storage configuration end-to-end. This covers converting CRD types into runtime config, Sentinel service discovery, credential env var generation, and the storage factory in the runner.
Note: CRD type definitions have been split into #3792. Documentation is in #3790.
Context
The Redis storage backend implemented in #3628 and integration tested in #3629 provides horizontal scaling capabilities for the embedded auth server. The CRD types defined in #3792 provide the declarative schema. This task wires everything together in the controller and runner.
Parent Issue: https://github.com/stacklok/stacklok-epics/issues/197
Dependencies: #3628 (Core Implementation), #3629 (Integration Testing), #3792 (CRD Types)
Related: #3790 (Documentation)
Acceptance Criteria
- Controller in
cmd/thv-operator/pkg/controllerutil/authserver.goupdated to:- Convert CRD Redis config to
storage.RedisRunConfig - Generate environment variables for ACL credentials from Secret references
- Implement Sentinel service discovery from Kubernetes Service endpoints
- Convert CRD Redis config to
- Runner in
pkg/authserver/runner/embeddedauthserver.goupdated to:- Create storage based on
RunConfig.Storageconfiguration - Support both memory (default) and Redis storage types
- Create storage based on
-
task lint,task test, andtask operator-manifestspass - Code reviewed and approved
Technical Approach
Controller Updates
Follow the pattern in cmd/thv-operator/pkg/controllerutil/authserver.go:
- Extend
GenerateAuthServerConfigto include Redis credential environment variables - Extend
buildEmbeddedAuthServerRunnerConfigto include storage configuration - Add Sentinel service discovery using Kubernetes Endpoints API
Runner Updates
Follow the factory pattern for creating storage:
- Add a
createStoragefunction that switches on storage type - Default to
MemoryStoragewhen no storage config is provided - Create
RedisStoragewhen Redis config is specified
Patterns & Frameworks
- Controller-runtime client: Use for Kubernetes Service/Endpoints discovery
- Factory pattern: For storage creation in the runner (memory vs Redis)
- Environment variables: For passing Redis credentials from Secrets to containers
Code Pointers
cmd/thv-operator/pkg/controllerutil/authserver.go— Extend to handle Redis config (lines 52-85 forGenerateAuthServerConfig, lines 285-334 forbuildEmbeddedAuthServerRunnerConfig)pkg/authserver/runner/embeddedauthserver.go— Add storage factory (line 84 wherestorage.NewMemoryStorage()is called)pkg/authserver/storage/config.go— Reference for storage configuration typesdocs/proposals/THV-0035-auth-server-redis-storage.md— RFC with complete design
Component Interfaces
Storage Factory (add to embeddedauthserver.go):
// createStorage creates the appropriate storage backend based on configuration.
func createStorage(ctx context.Context, cfg *storage.RunConfig) (storage.Storage, error) {
if cfg == nil || cfg.Type == "" || cfg.Type == string(storage.TypeMemory) {
return storage.NewMemoryStorage(), nil
}
if cfg.Type == string(storage.TypeRedis) {
redisCfg, err := convertRedisRunConfig(cfg.Redis)
if err != nil {
return nil, fmt.Errorf("invalid Redis config: %w", err)
}
return storage.NewRedisStorage(ctx, *redisCfg)
}
return nil, fmt.Errorf("unsupported storage type: %s", cfg.Type)
}Sentinel Service Discovery (add to authserver.go):
// resolveSentinelAddrs discovers Sentinel addresses from a Kubernetes Service.
func resolveSentinelAddrs(
ctx context.Context,
c client.Client,
sentinelService *mcpv1alpha1.SentinelServiceRef,
defaultNamespace string,
) ([]string, error) {
namespace := sentinelService.Namespace
if namespace == "" {
namespace = defaultNamespace
}
port := sentinelService.Port
if port == 0 {
port = 26379
}
endpoints := &corev1.Endpoints{}
if err := c.Get(ctx, client.ObjectKey{
Name: sentinelService.Name,
Namespace: namespace,
}, endpoints); err != nil {
return nil, fmt.Errorf("failed to get Endpoints %s/%s: %w", namespace, sentinelService.Name, err)
}
var addrs []string
for _, subset := range endpoints.Subsets {
for _, addr := range subset.Addresses {
addrs = append(addrs, fmt.Sprintf("%s:%d", addr.IP, port))
}
}
if len(addrs) == 0 {
return nil, fmt.Errorf("no ready addresses found for Sentinel service %s/%s", namespace, sentinelService.Name)
}
return addrs, nil
}Testing Strategy
Unit Tests
- Test
resolveSentinelAddrswith mock Kubernetes client - Test
createStoragefactory function with various configurations - Test
buildEmbeddedAuthServerRunnerConfigincludes storage config correctly - Test
GenerateAuthServerEnvVarsincludes Redis credential env vars
Integration Tests
- Test controller generates correct RunConfig with Redis storage
- Test environment variables are correctly mounted from Secrets
- Test Sentinel service discovery resolves correct addresses
Out of Scope
- CRD type definitions (covered in Auth Server: Add Operator CRD Types for Redis Storage #3792)
- Documentation (covered in Auth Server: Add Redis Storage Documentation #3790)
- Operator integration tests with real Redis (Phase 5, tracked separately)
- TLS/mTLS configuration for Redis connections (future enhancement)
- Custom connection pool configuration (use go-redis defaults)
References
- Epic: https://github.com/stacklok/stacklok-epics/issues/197
- RFC Design Document:
docs/proposals/THV-0035-auth-server-redis-storage.md - CRD Types: Auth Server: Add Operator CRD Types for Redis Storage #3792
- Documentation: Auth Server: Add Redis Storage Documentation #3790
- Upstream Dependency (Core): Auth Server: Implement Redis Storage: Core Implementation (Phase 1) #3628
- Upstream Dependency (Integration Tests): Auth Server: Add Redis Storage Integration Tests with Testcontainers (Phase 2) #3629
- Controller Utilities:
cmd/thv-operator/pkg/controllerutil/authserver.go - Runner Implementation:
pkg/authserver/runner/embeddedauthserver.go
Activity
[-]Add Redis Storage Documentation and Operator CRD Types (Phases 3+4)[/-][+]Auth Server: Add Redis Storage Documentation and Operator CRD Types (Phases 3+4)[/+][-]Auth Server: Add Redis Storage Documentation and Operator CRD Types (Phases 3+4)[/-][+]Auth Server: Add Operator CRD Types for Redis Storage (Phase 4)[/+][-]Auth Server: Add Operator CRD Types for Redis Storage (Phase 4)[/-][+]Auth Server: Operator Controller & Runner Integration for Redis Storage[/+]Add operator controller and runner integration for Redis storage
Add operator controller and runner integration for Redis storage