apiVersion: "v1"
kind: "DeploymentConfig"
metadata:
  name: "{{deploy_name}}"
  labels:
    provider: openshift
    component: "{{component}}"
    deployment: "{{deploy_name}}"
    logging-infra: "{{logging_component}}"
spec:
  replicas: {{replicas|default(0)}}
  selector:
    provider: openshift
    component: "{{component}}"
    deployment: "{{deploy_name}}"
    logging-infra: "{{logging_component}}"
  strategy:
    type: Recreate
  template:
    metadata:
      name: "{{deploy_name}}"
      labels:
        logging-infra: "{{logging_component}}"
        provider: openshift
        component: "{{component}}"
        deployment: "{{deploy_name}}"
    spec:
      terminationGracePeriod: 600
      serviceAccountName: aggregated-logging-elasticsearch
      securityContext:
        supplementalGroups:
        - {{openshift_logging_es_storage_group}}
{% if es_node_selector is iterable and es_node_selector | length > 0 %}
      nodeSelector:
{% for key, value in es_node_selector.iteritems() %}
        {{key}}: {{value}}
{% endfor %}
{% endif %}
      containers:
        -
          name: "elasticsearch"
          image: {{image}}
          imagePullPolicy: Always
          resources:
            limits:
              memory: "{{es_memory_limit}}"
{% if es_cpu_limit is defined and es_cpu_limit is not none %}
              cpu: "{{es_cpu_limit}}"
{% endif %}
            requests:
              memory: "512Mi"
          ports:
            -
              containerPort: 9200
              name: "restapi"
            -
              containerPort: 9300
              name: "cluster"
          env:
            -
              name: "NAMESPACE"
              valueFrom:
                fieldRef:
                  fieldPath: metadata.namespace
            -
              name: "KUBERNETES_TRUST_CERT"
              value: "true"
            -
              name: "SERVICE_DNS"
              value: "logging-{{es_cluster_name}}-cluster"
            -
              name: "CLUSTER_NAME"
              value: "logging-{{es_cluster_name}}"
            -
              name: "INSTANCE_RAM"
              value: "{{openshift_logging_es_memory_limit}}"
            -
              name: "NODE_QUORUM"
              value: "{{es_node_quorum | int}}"
            -
              name: "RECOVER_AFTER_NODES"
              value: "{{es_recover_after_nodes}}"
            -
              name: "RECOVER_EXPECTED_NODES"
              value: "{{es_recover_expected_nodes}}"
            -
              name: "RECOVER_AFTER_TIME"
              value: "{{openshift_logging_es_recover_after_time}}"
          volumeMounts:
            - name: elasticsearch
              mountPath: /etc/elasticsearch/secret
              readOnly: true
            - name: elasticsearch-config
              mountPath: /usr/share/java/elasticsearch/config
              readOnly: true
            - name: elasticsearch-storage
              mountPath: /elasticsearch/persistent
      volumes:
        - name: elasticsearch
          secret:
            secretName: logging-elasticsearch
        - name: elasticsearch-config
          configMap:
            name: logging-elasticsearch
        - name: elasticsearch-storage
{% if pvc_claim is defined and pvc_claim | trim | length > 0 %}
          persistentVolumeClaim:
            claimName: {{pvc_claim}}
{% else %}
          emptyDir: {}
{% endif %}
