{{- if .Values.valkey.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: axon-valkey
  labels:
    {{- include "axon.labels" . | nindent 4 }}
    app.kubernetes.io/component: valkey
spec:
  replicas: 1
  selector:
    matchLabels:
      {{- include "axon.valkey.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      labels:
        {{- include "axon.valkey.selectorLabels" . | nindent 8 }}
    spec:
      containers:
        - name: valkey
          image: {{ .Values.valkey.image }}
          args:
            - valkey-server
            - --maxmemory
            - {{ .Values.valkey.maxmemory | default "768mb" | quote }}
            - --maxmemory-policy
            - {{ .Values.valkey.maxmemoryPolicy | default "allkeys-lru" | quote }}
          ports:
            - containerPort: 6379
              protocol: TCP
          volumeMounts:
            - name: data
              mountPath: /data
          resources:
            {{- toYaml .Values.resources.valkey | nindent 12 }}
          livenessProbe:
            tcpSocket:
              port: 6379
            initialDelaySeconds: 15
            periodSeconds: 10
            failureThreshold: 3
          readinessProbe:
            tcpSocket:
              port: 6379
            initialDelaySeconds: 10
            periodSeconds: 5
            failureThreshold: 3
          securityContext:
            allowPrivilegeEscalation: false
            readOnlyRootFilesystem: false
            runAsNonRoot: true
            runAsUser: 999
      volumes:
        - name: data
          persistentVolumeClaim:
            claimName: axon-valkey-data
{{- end }}
