---
apiVersion: v1
kind: Deployment
metadata:
  name: "{{ ansible_operator_meta.name }}-redis"
  namespace: "{{ ansible_operator_meta.namespace }}"
  annotations: # About kube-linter checks: https://docs.kubelinter.io/#/generated/checks
    email: pulp-dev@redhat.com
    ignore-check.kube-linter.io/unset-cpu-requirements: "Temporarily disabled"
    ignore-check.kube-linter.io/unset-memory-requirements: "Temporarily disabled"
  labels:
    app.kubernetes.io/name: 'redis'
    app.kubernetes.io/instance: 'redis-{{ ansible_operator_meta.name }}'
    app.kubernetes.io/component: cache
    app.kubernetes.io/part-of: '{{ deployment_type }}'
    app.kubernetes.io/managed-by: '{{ deployment_type }}-operator'
    owner: pulp-dev
spec:
  replicas: 1
  selector:
    matchLabels:
      app.kubernetes.io/name: 'redis'
      app.kubernetes.io/instance: 'redis-{{ ansible_operator_meta.name }}'
      app.kubernetes.io/component: cache
      app.kubernetes.io/part-of: '{{ deployment_type }}'
      app.kubernetes.io/managed-by: '{{ deployment_type }}-operator'
  template:
    metadata:
      labels:
        app.kubernetes.io/name: 'redis'
        app.kubernetes.io/instance: 'redis-{{ ansible_operator_meta.name }}'
        app.kubernetes.io/component: cache
        app.kubernetes.io/part-of: '{{ deployment_type }}'
        app.kubernetes.io/managed-by: '{{ deployment_type }}-operator'
    spec:
{% if image_pull_secret %}
      imagePullSecrets:
        - name: {{ image_pull_secret }}
{% endif %}
{% if affinity is defined and affinity.node_affinity is defined %}
      affinity:
        nodeAffinity: {{ affinity.node_affinity }}
{% endif %}
      serviceAccountName: '{{ ansible_operator_meta.name }}'
      containers:
        - name: redis
          image: "{{ _redis_image }}"
          imagePullPolicy: "IfNotPresent"
          volumeMounts:
            - readOnly: false
              mountPath: /data
              name: '{{ ansible_operator_meta.name }}-redis-data'
          ports:
            - protocol: TCP
              containerPort: 6379
          livenessProbe:
            enabled: true
            initialDelaySeconds: 5
            periodSeconds: 5
            timeoutSeconds: 5
            failureThreshold: 5
            successThreshold: 1
            exec:
              command:
                - /bin/sh
                - -i
                - -c
                - redis-cli -h 127.0.0.1 -p 6379
          readinessProbe:
            enabled: true
            initialDelaySeconds: 5
            periodSeconds: 5
            timeoutSeconds: 5
            failureThreshold: 5
            successThreshold: 1
            exec:
              command:
                - /bin/sh
                - -i
                - -c
                - redis-cli -h 127.0.0.1 -p 6379
{% if redis_resource_requirements is defined %}
          resources: {{ redis_resource_requirements }}
{% endif %}
      volumes:
        - name: '{{ ansible_operator_meta.name }}-redis-data'
          persistentVolumeClaim:
            claimName: '{{ ansible_operator_meta.name }}-redis-data'
