---
# Standalone Valkey (Redis-compatible) for Gitea's session store, cache and
# queue. The Gitea chart bundles a redis-cluster subchart, but we run our own
# standalone Valkey here: it keeps image control in-estate (valkey/valkey,
# already allowlisted through the artifactapi dockerhub mirror) and matches the
# standalone-cache pattern used by litellm/netbox. One instance serves three
# logical DBs: DB 0 = session, DB 1 = cache, DB 2 = queue. AOF persistence is
# enabled so queued actions/webhook deliveries survive a restart.
apiVersion: apps/v1
kind: Deployment
metadata:
  name: gitea-valkey
  namespace: gitea
  labels:
    app.kubernetes.io/name: gitea
    app.kubernetes.io/component: valkey
spec:
  replicas: 1
  selector:
    matchLabels:
      app: gitea-valkey
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: gitea-valkey
        app.kubernetes.io/name: gitea
        app.kubernetes.io/component: valkey
    spec:
      securityContext:
        fsGroup: 999
      containers:
        - name: valkey
          image: valkey/valkey:8-alpine
          imagePullPolicy: IfNotPresent
          command:
            - valkey-server
            - --appendonly
            - "yes"
            - --save
            - "60"
            - "1"
          ports:
            - containerPort: 6379
              name: valkey
              protocol: TCP
          securityContext:
            allowPrivilegeEscalation: false
            runAsNonRoot: true
            runAsUser: 999
            capabilities:
              drop:
                - ALL
          livenessProbe:
            exec:
              command:
                - valkey-cli
                - ping
            failureThreshold: 3
            initialDelaySeconds: 30
            periodSeconds: 30
            successThreshold: 1
            timeoutSeconds: 5
          readinessProbe:
            exec:
              command:
                - valkey-cli
                - ping
            failureThreshold: 3
            initialDelaySeconds: 5
            periodSeconds: 10
            successThreshold: 1
            timeoutSeconds: 5
          resources:
            limits:
              cpu: 500m
              memory: 512Mi
            requests:
              cpu: 50m
              memory: 128Mi
          volumeMounts:
            - mountPath: /data
              name: data
        - name: metrics-exporter
          image: artifactapi.k8s.syd1.au.unkin.net/dockerhub/oliver006/redis_exporter:v1.89.0
          imagePullPolicy: IfNotPresent
          ports:
            - containerPort: 9121
              name: metrics
              protocol: TCP
          securityContext:
            allowPrivilegeEscalation: false
            runAsNonRoot: true
            capabilities:
              drop:
                - ALL
          resources:
            limits:
              cpu: 100m
              memory: 64Mi
            requests:
              cpu: 25m
              memory: 32Mi
      restartPolicy: Always
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: gitea-valkey-data
