apiVersion: "v1"
kind: "DeploymentConfig"
metadata:
  name: "{{deploy_name}}"
  labels:
    provider: openshift
    component: "{{component}}"
    logging-infra: "{{logging_component}}"
spec:
  replicas: {{replicas|default(1)}}
  selector:
    provider: openshift
    component: "{{component}}"
    logging-infra: "{{logging_component}}"
  strategy:
    rollingParams:
      intervalSeconds: 1
      timeoutSeconds: 600
      updatePeriodSeconds: 1
    type: Rolling
  template:
    metadata:
      name: "{{deploy_name}}"
      labels:
        logging-infra: "{{logging_component}}"
        provider: openshift
        component: "{{component}}"
    spec:
      serviceAccountName: aggregated-logging-mux
{% if mux_node_selector is iterable and mux_node_selector | length > 0 %}
      nodeSelector:
{% for key, value in mux_node_selector.iteritems() %}
        {{key}}: "{{value}}"
{% endfor %}
{% endif %}
      containers:
      - name: "mux"
        image: {{image}}
        imagePullPolicy: Always
{% if (mux_memory_limit is defined and mux_memory_limit is not none) or (mux_cpu_limit is defined and mux_cpu_limit is not none) %}
        resources:
          limits:
{% if mux_cpu_limit is not none %}
            cpu: "{{mux_cpu_limit}}"
{% endif %}
{% if mux_memory_limit is not none %}
            memory: "{{mux_memory_limit}}"
{% endif %}
{% endif %}
        ports:
        - containerPort: "{{ openshift_logging_mux_port }}"
          name: mux-forward
        volumeMounts:
        - name: config
          mountPath: /etc/fluent/configs.d/user
          readOnly: true
        - name: certs
          mountPath: /etc/fluent/keys
          readOnly: true
        - name: dockerhostname
          mountPath: /etc/docker-hostname
          readOnly: true
        - name: localtime
          mountPath: /etc/localtime
          readOnly: true
        - name: muxcerts
          mountPath: /etc/fluent/muxkeys
          readOnly: true
        env:
        - name: "K8S_HOST_URL"
          value: "{{openshift_logging_mux_master_url}}"
        - name: "ES_HOST"
          value: "{{openshift_logging_mux_app_host}}"
        - name: "ES_PORT"
          value: "{{openshift_logging_mux_app_port}}"
        - name: "ES_CLIENT_CERT"
          value: "{{openshift_logging_mux_app_client_cert}}"
        - name: "ES_CLIENT_KEY"
          value: "{{openshift_logging_mux_app_client_key}}"
        - name: "ES_CA"
          value: "{{openshift_logging_mux_app_ca}}"
        - name: "OPS_HOST"
          value: "{{openshift_logging_mux_ops_host}}"
        - name: "OPS_PORT"
          value: "{{openshift_logging_mux_ops_port}}"
        - name: "OPS_CLIENT_CERT"
          value: "{{openshift_logging_mux_ops_client_cert}}"
        - name: "OPS_CLIENT_KEY"
          value: "{{openshift_logging_mux_ops_client_key}}"
        - name: "OPS_CA"
          value: "{{openshift_logging_mux_ops_ca}}"
        - name: "USE_JOURNAL"
          value: "false"
        - name: "JOURNAL_SOURCE"
          value: "{{openshift_logging_mux_journal_source | default('')}}"
        - name: "JOURNAL_READ_FROM_HEAD"
          value: "{{openshift_logging_mux_journal_read_from_head|lower}}"
        - name: FORWARD_LISTEN_HOST
          value: "{{ openshift_logging_mux_hostname }}"
        - name: FORWARD_LISTEN_PORT
          value: "{{ openshift_logging_mux_port }}"
        - name: USE_MUX
          value: "true"
        - name: MUX_ALLOW_EXTERNAL
          value: "{{ openshift_logging_mux_allow_external | default('false') }}"
      volumes:
      - name: config
        configMap:
          name: logging-mux
      - name: certs
        secret:
          secretName: logging-mux
      - name: dockerhostname
        hostPath:
          path: /etc/hostname
      - name: localtime
        hostPath:
          path: /etc/localtime
      - name: muxcerts
        secret:
          secretName: logging-mux
