apiVersion: rds.valkey.buf.red/v1alpha1
kind: Valkey
metadata:
  name: production-cluster
spec:
  # Valkey version, supports 7.2, 8.0, 8.1, 8.2, 9.0
  version: "8.0"
  
  # Valkey architecture, supports cluster, failover, replica
  arch: cluster

  # Production cluster sizing
  replicas:
    shards: 6                    # 6 shards for better distribution
    replicasOfShard: 2          # A primary and a replica per shard for HA
  
  # Production resource allocation
  resources:
    requests:
      memory: "4Gi"
      cpu: "2000m"
    limits:
      memory: "8Gi"
      cpu: "4000m"
  
  # Persistent storage with retention
  storage:
    storageClassName: fast-ssd
    capacity: 50Gi
    accessMode: ReadWriteOnce
    retainAfterDeleted: true
  
  # LoadBalancer for external access
  access:
    serviceType: LoadBalancer
  
  # Production Valkey configuration
  customConfigs:
    # Memory management
    maxmemory-policy: "allkeys-lru"
    maxmemory-samples: "10"
    
    # Persistence configuration
    save: "900 1 300 10 60 10000"  # RDB snapshots
    stop-writes-on-bgsave-error: "yes"
    rdbcompression: "yes"
    rdbchecksum: "yes"
    
    # Network configuration
    tcp-keepalive: "300"
    tcp-backlog: "511"
    timeout: "300"
    
    # Security
    protected-mode: "yes"
    
    # Performance tuning
    hz: "10"
    dynamic-hz: "yes"
    
    # Logging
    loglevel: "notice"
    syslog-enabled: "yes"
    syslog-ident: "valkey-cluster"
  
  # Monitoring with Prometheus exporter
  exporter:
    resources:
      requests:
        memory: "64Mi"
        cpu: "50m"
      limits:
        memory: "128Mi"
        cpu: "100m"
  
  # Anti-affinity for high availability
  affinityPolicy: AntiAffinity
  
  # Tolerations for dedicated nodes
  tolerations:
    - key: "valkey"
      operator: "Equal"
      value: "production"
      effect: "NoSchedule"
    - key: "high-memory"
      operator: "Equal"
      value: "true"
      effect: "NoSchedule"
  
  # Node selection for performance
  nodeSelector:
    node-type: "memory-optimized"
    storage-type: "ssd"
