---
# Source: redis/templates/secret.yaml
apiVersion: v1
kind: Secret
metadata:
  name: redis
  namespace: default
  labels:
    app.kubernetes.io/instance: redis
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: redis
    app.kubernetes.io/version: 8.10.0
    helm.sh/chart: redis-0.34.11
type: Opaque
data:
  redis-password: "Y29uZmlnaHViLXJlZGlzLXBhc3N3b3Jk"
  host: "cmVkaXMuZGVmYXVsdC5zdmM="
  port: "NjM3OQ=="
  username: "ZGVmYXVsdA=="
  uri: "cmVkaXM6Ly9kZWZhdWx0OmNvbmZpZ2h1Yi1yZWRpcy1wYXNzd29yZEByZWRpcy5kZWZhdWx0LnN2Yzo2Mzc5"
---
# Source: redis/templates/configmap.yaml
apiVersion: v1
kind: ConfigMap
metadata:
  name: redis-config
  namespace: default
  labels:
    app.kubernetes.io/instance: redis
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: redis
    app.kubernetes.io/version: 8.10.0
    helm.sh/chart: redis-0.34.11
data:
  redis.conf: |
    # Redis configuration
    bind * -::*

    # Standard Port Configuration
    port 6379
---
# Source: redis/templates/headless-service.yaml
apiVersion: v1
kind: Service
metadata:
  name: redis-headless
  namespace: default
  labels:
    app.kubernetes.io/instance: redis
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: redis
    app.kubernetes.io/version: 8.10.0
    helm.sh/chart: redis-0.34.11
spec:
  type: ClusterIP
  clusterIP: None
  ports:
    - port: 6379
      targetPort: redis
      protocol: TCP
      name: tcp-redis
  selector:
    app.kubernetes.io/instance: redis
    app.kubernetes.io/name: redis
---
# Source: redis/templates/service.yaml
apiVersion: v1
kind: Service
metadata:
  name: redis
  namespace: default
  labels:
    app.kubernetes.io/instance: redis
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: redis
    app.kubernetes.io/version: 8.10.0
    helm.sh/chart: redis-0.34.11
spec:
  type: ClusterIP
  ports:
    - port: 6379
      targetPort: redis
      protocol: TCP
      name: tcp-redis
  selector:
    app.kubernetes.io/instance: redis
    app.kubernetes.io/name: redis
---
# Source: redis/templates/statefulset.yaml
apiVersion: apps/v1
kind: StatefulSet
metadata:
  name: redis
  namespace: default
  labels:
    app.kubernetes.io/instance: redis
    app.kubernetes.io/managed-by: Helm
    app.kubernetes.io/name: redis
    app.kubernetes.io/version: 8.10.0
    helm.sh/chart: redis-0.34.11
spec:
  serviceName: redis-headless
  updateStrategy:
    type: RollingUpdate
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app.kubernetes.io/instance: redis
      app.kubernetes.io/name: redis
  template:
    metadata:
      labels:
        app.kubernetes.io/instance: redis
        app.kubernetes.io/name: redis
      annotations:
        checksum/config: 294a093cafef93d0e0b2d399b0d11a262d7f8618f7bfb84afaec0e75430a3dee
    spec:
      securityContext:
        fsGroup: 999
      automountServiceAccountToken: false
      serviceAccountName: default
      initContainers:
        - name: redis-init
          image: "docker.io/redis:8.10.0@sha256:39353c6a2f310da333374e1290c91805d15a85def073b5090f58e4ac646d284c"
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
              - ALL
            privileged: false
            readOnlyRootFilesystem: true
            runAsGroup: 999
            runAsNonRoot: true
            runAsUser: 999
            seccompProfile:
              type: RuntimeDefault
          imagePullPolicy: Always
          command:
            - /bin/sh
            - -c
            - |
              set -e
              # Get pod ordinal from hostname
              POD_ORDINAL=$(hostname | sed 's/.*-//')
              MY_HOSTNAME=$(hostname)

              touch /tmp/redis.conf

              # Check if we are using ACL authentication


              echo "Pod ordinal: $POD_ORDINAL, hostname: $MY_HOSTNAME"

              # Add user provided settings at the end of file to ensure their precedence
              echo "" >> /tmp/redis.conf
              # If there is existing config map or .Values.config value provided - use it
              if [ -f "/usr/local/etc/redis/redis.conf" ]; then
                echo "# Content from provided config" >> /tmp/redis.conf
                cat /usr/local/etc/redis/redis.conf >> /tmp/redis.conf
              else
                # Create minimal config if no config exists
                echo "# Default minimal config" >> /tmp/redis.conf
                cat >> /tmp/redis.conf << EOF
              bind * -::*
              port 6379
              EOF
              fi
              printf '\nrequirepass %s\n' "$REDIS_PASSWORD" >> /tmp/redis.conf
          env:
            - name: REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: redis
                  key: redis-password
            - name: REDISCLI_AUTH
              valueFrom:
                secretKeyRef:
                  name: redis
                  key: redis-password
          resources:
            {}
          volumeMounts:
            - name: config
              mountPath: /usr/local/etc/redis
            - name: redis-config
              mountPath: /tmp
      containers:
        - name: redis
          securityContext:
            allowPrivilegeEscalation: false
            capabilities:
              drop:
              - ALL
            privileged: false
            readOnlyRootFilesystem: true
            runAsGroup: 999
            runAsNonRoot: true
            runAsUser: 999
            seccompProfile:
              type: RuntimeDefault
          image: "docker.io/redis:8.10.0@sha256:39353c6a2f310da333374e1290c91805d15a85def073b5090f58e4ac646d284c"
          imagePullPolicy: Always
          command:
            - /bin/sh
            - -c
            - |
              CONFIG_FILE="/tmp/redis.conf"

              exec redis-server "$CONFIG_FILE"
          ports:
            - name: redis
              containerPort: 6379
              protocol: TCP
          env:
            - name: REDIS_PASSWORD
              valueFrom:
                secretKeyRef:
                  name: redis
                  key: redis-password
            - name: REDISCLI_AUTH
              valueFrom:
                secretKeyRef:
                  name: redis
                  key: redis-password
          livenessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - |

                  redis-cli -h "127.0.0.1" -p 6379 ping
            initialDelaySeconds: 30
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 6
            successThreshold: 1
          readinessProbe:
            exec:
              command:
                - /bin/sh
                - -c
                - |

                  redis-cli -h "127.0.0.1" -p 6379 ping
            initialDelaySeconds: 5
            periodSeconds: 10
            timeoutSeconds: 5
            failureThreshold: 6
            successThreshold: 1
          resources:
            {}
          volumeMounts:
            - name: data
              mountPath: /data
            - name: redis-config
              mountPath: /tmp
            - name: config
              mountPath: /usr/local/etc/redis
      volumes:
        - name: redis-config
          emptyDir: {}
        - name: config
          configMap:
            name: redis-config
      terminationGracePeriodSeconds: 30
  volumeClaimTemplates:
    - apiVersion: v1
      kind: PersistentVolumeClaim
      metadata:
        name: data
        labels:
          app.kubernetes.io/instance: redis
          app.kubernetes.io/name: redis
      spec:
        accessModes:
          - "ReadWriteOnce"
        resources:
          requests:
            storage: "8Gi"
