apiVersion: apps/v1
kind: Deployment
metadata:
  name: '{{ meta.name }}-smartgateway'
  namespace: '{{ meta.namespace }}'
spec:
  replicas: {{ size }}
  progressDeadlineSeconds: 600
  revisionHistoryLimit: 10
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  selector:
    matchLabels:
      app: smart-gateway
      smart-gateway: '{{ meta.name }}'
  template:
    metadata:
      labels:
        app: smart-gateway
        smart-gateway: '{{ meta.name }}'
{% if smartgateway_resource_configmap is defined %}
        sg-config-resource-name: {{ smartgateway_resource_configmap.env | k8s_config_resource_name }}
{% endif %}
    spec:
      containers:
{% if (applications | selectattr('name','equalto','prometheus') | list | count > 0) %}
      - name: oauth-proxy
        image: {{ oauth_proxy_image }}
        args:
        - -https-address=:8083
        - -tls-cert=/etc/tls/private/tls.crt
        - -tls-key=/etc/tls/private/tls.key
        - -cookie-secret-file=/etc/proxy/secrets/session_secret
        - -openshift-service-account=NA
        - -upstream=http://localhost:8081/
        - '-openshift-delegate-urls={"/": {"resource": "namespaces", "verb": "get"}}'
        ports:
        - containerPort: 8083
          name: https
        volumeMounts:
          - mountPath: /etc/tls/private
            name: {{ meta.name }}-proxy-tls
          - mountPath: /etc/proxy/secrets
            name: session-secret
{% endif -%}
{% if sg_vars.bridge.enabled is defined and sg_vars.bridge.enabled %}
      - name: bridge
        image: {{ bridge_container_image_path }}
        args:
{%   if sg_vars.bridge.amqp_url is defined and sg_vars.bridge.amqp_url != "" %}
        - --amqp_url
        - {{ sg_vars.bridge.amqp_url }}
{%   endif -%}
{%   if sg_vars.bridge.verbose is defined and sg_vars.bridge.verbose %}
        - --verbose
{%   endif -%}
{%   if sg_vars.bridge.socket_block is defined and sg_vars.bridge.socket_block %}
        - --block
{%   endif -%}
{%   if sg_vars.bridge.stats_period is defined and sg_vars.bridge.stats_period != "" %}
        - --stat_period
        - "{{ sg_vars.bridge.stats_period }}"
{%   endif -%}
{%   if sg_vars.bridge.ring_buffer_count is defined and sg_vars.bridge.ring_buffer_count != "" %}
        - --rbc
        - "{{ sg_vars.bridge.ring_buffer_count }}"
{%   endif -%}
{%   if sg_vars.bridge.stop_count is defined and sg_vars.bridge.stop_count != "" %}
        - --count
        - "{{ sg_vars.bridge.stop_count }}"
{%   endif -%}
{%   if sg_vars.bridge.inet_target is defined and sg_vars.bridge.inet_target != "" %}
        - --gw_inet
        - "{{ sg_vars.bridge.inet_target }}"
{%   endif -%}
{%   if sg_vars.bridge.unix_socket_path is defined and sg_vars.bridge.unix_socket_path != "" %}
        - --gw_unix
        - "{{ sg_vars.bridge.unix_socket_path }}/smartgateway"
{%   endif -%}
{%   if sg_vars.bridge.ring_buffer_size is defined and sg_vars.bridge.ring_buffer_size != "" %}
        - --rbs
        - "{{ sg_vars.bridge.ring_buffer_size }}"
{%   endif -%}
{%   if sg_vars.bridge.container_id_pattern is defined and sg_vars.bridge.container_id_pattern != "" %}
        - --cid
        - "{{ sg_vars.bridge.container_id_pattern }}"
{%   endif -%}
{%   if sg_vars.bridge.amqp_block is defined and sg_vars.bridge.amqp_block %}
        - --amqp_block
{%   endif -%}
{%   if sg_vars.bridge.unix_socket_path is defined and sg_vars.bridge.unix_socket_path != "" %}
        volumeMounts:
        - mountPath: {{ sg_vars.bridge.unix_socket_path }}
          name: socket-dir
{%   endif %}
{% endif %}
{% if transports is defined and transports != "" %}
      - name: sg-core
        image: {{ core_container_image_path }}
        args:
          - -config
          - /etc/sg-core/sg-core.conf.yaml
{%   if sg_vars.bridge.unix_socket_path is defined and sg_vars.bridge.unix_socket_path != "" %}
        volumeMounts:
        - mountPath: {{ sg_vars.bridge.unix_socket_path }}
          name: socket-dir
{%   endif %}
{%   if smartgateway_resource_configmap is defined %}
        - mountPath: /etc/sg-core/
          name: sg-core-config
          readOnly: true
{%   endif %}
{%   if (applications | selectattr('name','equalto','elasticsearch') | list | count > 0) %}
        - name: elastic-certs
          mountPath: /config/certs
{%   endif %}
        env:
          - name: MY_POD_NAME
            valueFrom:
              fieldRef:
                apiVersion: v1
                fieldPath: metadata.name
{%   if services is defined and services != "" %}
        ports:
{%     for service in services %}
{%       if service.ports is defined and service.ports != "" %}
{%         for port in service.ports %}
          - name: {{ port.name }}
            containerPort: {{ port.target_port }}
            protocol: {{ port.protocol }}
{%         endfor %}
{%       endif %}
{%     endfor %}
{%   endif %}
{% endif %}
      volumes:
{% if (applications | selectattr('name','equalto','prometheus') | list | count > 0) %}
      - name: {{ meta.name }}-proxy-tls
        secret:
          defaultMode: 420
          secretName: {{ meta.name }}-proxy-tls
{% endif %}
      - name: socket-dir
        emptyDir: {}
{% if smartgateway_resource_configmap is defined %}
      - name: sg-core-config
        configMap:
          name: {{ meta.name }}-sg-core-configmap
{% endif %}
{% if (applications | selectattr('name','equalto','elasticsearch') | list | count > 0) %}
      - name: elastic-certs
        secret:
          secretName: {{ tls_secret_name }}
{% endif %}
      - name: session-secret
        secret:
          secretName: smart-gateway-session-secret
# vim: set ft=yaml shiftwidth=2 tabstop=2 expandtab:
