#jinja2: trim_blocks: "true", lstrip_blocks: "false"
---
{% set gid_range = kaas_openshift_gid_ranges[kaas_project].split("/") %}
apiVersion: v1
kind: Template
metadata:
  name: kaas-manager
  annotations:
    descriptions: KaaS Data Management Service
objects:
  - apiVersion: v1
    kind: DeploymentConfig
    metadata:
      name: kaas-manager
    spec:
      replicas: 0
      revisionHistoryLimit: {{ kaas_pod_history_limit }}
      strategy:
        type: Rolling
      triggers:
      - type: ConfigChange
      selector:
        name: kaas-manager
      triggers:
        - type: ConfigChange
        - type: ImageChange
          imageChangeParams:
            automatic: true
            from:
              kind: "ImageStreamTag"
              name: "kaas-manager:latest"
              namespace: "kaas"
            containerNames:
              - kaas-manager
      template:
        metadata:
          name: kaas-manager
          labels:
            name: kaas-manager
        spec:
          securityContext:
            supplementalGroups:
{% for ofs in range(gid_range[1] | default(1) | int) %}
              - {{ (gid_range[0] | int) + ofs }}
{% endfor %}
{% if (ands_openshift_gid_mode | default('')) == "RunAsAny" %}
            fsGroup: {{ gid_range[0] }}
{% endif %}
{% if (kaas_project_config.run_pods_as is defined) %}
{%   if ((kaas_project_config.uids | default(kaas_openshift_uids))[kaas_project_config.run_pods_as] is defined) %}
            runAsUser: {{ (kaas_project_config.uids | default(kaas_openshift_uids))[kaas_project_config.run_pods_as].id }}
{%   else %}
            runAsUser: {{ kaas_project_config.run_pods_as }}
{%   endif %}
{% endif %}
          volumes:
            - name: lsdf-katrin-kdb
              persistentVolumeClaim:
                claimName: lsdf-katrin-kdb
{% for name, vol in kaas_project_volumes.items() %}
{%   set oc_name = name | regex_replace('_','-') %}
{%   if (vol.write | default(false)) %}
            - name: vol-{{ name }}
              persistentVolumeClaim:
                claimName: {{ oc_name }}
{%   endif %}
{% endfor %}
{% if ('data' not in kaas_project_volumes) %}
            - name: home
              emptyDir: {}
{% endif %}
          containers:
            - name: kaas-manager
              image: kaas-manager
              command: [ "/docker-entrypoint.sh", "/bin/sx" ]
              volumeMounts: 
                - name: lsdf-katrin-kdb
                  mountPath: /mnt/lsdf-kdb
{% for name, vol in kaas_project_volumes.items() %}
{%   if (vol.write | default(false)) %}
                - name: vol-{{ name }}
                  mountPath: /mnt/{{ name }}
{%   endif %}
{% endfor %}
{% if ('data' not in kaas_project_volumes) %}
                - name: home
                  mountPath: /home
{% endif %}
              env:
                - name: HOME
{% if ('data' in kaas_project_volumes) %}
                  value: /mnt/data/home
{% else %}
                  value: /tmp
{% endif %}
#              lifecycle:
#                postStart:
#                  exec: 
#                    command: [ "/bin/bash", "[ -d $HOME ] || mkdir -p $HOME" ]
