apiVersion: v1
kind: List
items:
  - kind: ServiceAccount
    apiVersion: v1
    metadata:
      name: tester
  - kind: ImageStream
    apiVersion: v1
    metadata:
      name: {{ __test_harness_imgstream_name | d("linux-system-roles") }}
    spec:
      tags:
        - name: latest
          from:
            kind: DockerImage
            name: {{ __test_harness_imgstream_name | d("linux-system-roles") }}:latest
        - name: staging
          from:
            kind: DockerImage
            name: {{ __test_harness_imgstream_name | d("linux-system-roles") }}:staging
  - kind: BuildConfig
    apiVersion: v1
    metadata:
      name: {{ __test_harness_bc | d("linux-system-roles") }}
    spec:
      output:
        to:
          kind: ImageStreamTag
          name: {{ __test_harness_imgstream_name | d("linux-system-roles") }}:{{
            "latest" if test_harness_git_branch | d("production") == "production"
            else "staging"
          }}
      resources: {}
      source:
        git:
          uri: https://github.com/linux-system-roles/test-harness
          ref: {{ test_harness_git_branch | d("production") }}
        type: Git
{% if __test_harness_build_config_files %}
        configMaps:
          - configMap:
              name: {{ __test_harness_bc | d("linux-system-roles") }}-buildcm
{% endif %}
        dockerfile: |
          {{
            lookup('file', __test_harness_dockerfile) |
            regex_replace('^FROM .*\n', 'FROM ' ~ __test_harness_dockerfile_from) |
            replace('#EXTRAPRETESTER', __test_harness_dockerfile_pre_tester | join('\n')) |
            replace('#EXTRAPOST', __test_harness_dockerfile_post | join('\n')) |
            indent(width=10,blank=True)
          }}
      strategy:
        dockerStrategy: {}
      triggers:
      - type: ConfigChange
      - type: ImageChange
  - kind: DeploymentConfig
    apiVersion: v1
    metadata:
      name: {{ __test_harness_dc | d("linux-system-roles") }}
    spec:
      replicas: {{ __test_harness_deploy_replicas | d("8") | int }}
      selector:
        name: {{ __test_harness_dc | d("linux-system-roles") }}
      triggers:
        - type: ConfigChange
        - type: ImageChange
          imageChangeParams:
            automatic: true
            containerNames:
              - {{ __test_harness_dc | d("linux-system-roles") }}
            from:
              kind: ImageStreamTag
              name: {{ __test_harness_imgstream_name | d("linux-system-roles") }}:{{
                "latest" if test_harness_git_branch | d("production") == "production"
                else "staging"
              }}
      strategy:
        type: Rolling
      template:
        metadata:
          labels:
            name: {{ __test_harness_dc | d("linux-system-roles") }}
        spec:
          serviceAccountName: tester
          restartPolicy: Always
{% if test_harness_need_node_selector | d(false) %}
          nodeSelector: {{ test_harness_node_selector | to_json }}
{% endif %}
          securityContext:
{% if __test_harness_run_as_root | d(false) %}
            runAsUser: 0
{% else %}
            runAsUser: 1000
            fsGroup: 1000
{% endif %}
          containers:
            - name: {{ __test_harness_dc | d("linux-system-roles") }}
              image: {{ __test_harness_imgstream_name | d("linux-system-roles") }}:{{
                "latest" if test_harness_git_branch | d("production") == "production"
                else "staging"
              }}
{% if __test_harness_deploy_env %}
              env:
{%   for key,value in __test_harness_deploy_env.items() %}
                - name: {{ key }}
                  value: "{{ value }}"
{%   endfor %}
{% endif %}
              volumeMounts:
                - name: secrets
                  mountPath: /secrets
                  readOnly: true
                - name: config
                  mountPath: /config
                  readOnly: true
                - name: cache
                  mountPath: /cache
{% if __test_harness_run_as_root | d(false) %}
              securityContext:
                privileged: true
{% endif %}
          volumes:
            - name: secrets
              secret:
                secretName: {{ __test_harness_secret_name }}
{% if __test_harness_run_as_root | d(false) %}
                defaultMode: 256
{% else %}
                defaultMode: 288
{% endif %}
            - name: config
              configMap:
                name: {{ __test_harness_cm_name }}
                defaultMode: 420
            - name: cache
              emptyDir:
