Skip to content

Auth Server: Operator Controller & Runner Integration for Redis Storage #3630

Closed

Description

@tgrunnagle

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.go updated 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
  • Runner in pkg/authserver/runner/embeddedauthserver.go updated to:
    • Create storage based on RunConfig.Storage configuration
    • Support both memory (default) and Redis storage types
  • task lint, task test, and task operator-manifests pass
  • Code reviewed and approved

Technical Approach

Controller Updates

Follow the pattern in cmd/thv-operator/pkg/controllerutil/authserver.go:

  1. Extend GenerateAuthServerConfig to include Redis credential environment variables
  2. Extend buildEmbeddedAuthServerRunnerConfig to include storage configuration
  3. Add Sentinel service discovery using Kubernetes Endpoints API

Runner Updates

Follow the factory pattern for creating storage:

  1. Add a createStorage function that switches on storage type
  2. Default to MemoryStorage when no storage config is provided
  3. Create RedisStorage when 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 for GenerateAuthServerConfig, lines 285-334 for buildEmbeddedAuthServerRunnerConfig)
  • pkg/authserver/runner/embeddedauthserver.go — Add storage factory (line 84 where storage.NewMemoryStorage() is called)
  • pkg/authserver/storage/config.go — Reference for storage configuration types
  • docs/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 resolveSentinelAddrs with mock Kubernetes client
  • Test createStorage factory function with various configurations
  • Test buildEmbeddedAuthServerRunnerConfig includes storage config correctly
  • Test GenerateAuthServerEnvVars includes 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

References

Activity

  1. added
    documentation
    enhancement
    kubernetes
    api
    and removed
    applied-ai
    on Feb 5, 2026
  2. self-assigned this
    on Feb 5, 2026
  3. changed the title [-]Add Redis Storage Documentation and Operator CRD Types (Phases 3+4)[/-] [+]Auth Server: Add Redis Storage Documentation and Operator CRD Types (Phases 3+4)[/+] on Feb 6, 2026
  4. removed
    documentation
    on Feb 11, 2026
  5. changed the title [-]Auth Server: Add Redis Storage Documentation and Operator CRD Types (Phases 3+4)[/-] [+]Auth Server: Add Operator CRD Types for Redis Storage (Phase 4)[/+] on Feb 11, 2026
  6. changed the title [-]Auth Server: Add Operator CRD Types for Redis Storage (Phase 4)[/-] [+]Auth Server: Operator Controller & Runner Integration for Redis Storage[/+] on Feb 11, 2026
  7. added 2 commits that reference this issue on Feb 13, 2026
    c5d064b
    0ab3793
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

apiauthenticationenhancementkubernetesoperator

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions