{{- range $it := .Values.consoleVersions }}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels:
    app: {{ include "controlPlaneConsole.name" $ }}
    version: {{ $it.registryVersion }}
  name: {{ include "controlPlaneConsole.name" $ }}-{{ $it.registryVersion }}
spec:
  replicas: 1
  revisionHistoryLimit: 10
  selector:
    matchLabels:
      app: {{ include "controlPlaneConsole.name" $ }}
      version: {{ $it.registryVersion }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels:
        app: {{ include "controlPlaneConsole.name" $ }}
        version: {{ $it.registryVersion }}
      annotations:
        sidecar.istio.io/inject: 'true'
    spec:
      containers:
        - env:
            - name: NAMESPACE
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: metadata.namespace
            - name: HOST
              value: "{{ template "control-plane-console.url" $ }}"
            - name: BASE_PATH
              value: "{{if $.Values.basePath}}/{{ $.Values.basePath }}{{else}}{{end}}"
            - name: EDP_ADMIN_CONSOLE_VERSION
              value: "{{ $.Values.version }}"
            - name: GERRIT_GLOBAL_LINK
              value: "https://gerrit-{{ template "edp.hostnameSuffix" $ }}"
            - name: CLUSTER_REPO
              value: "cluster-mgmt"
            - name: GROUP_GIT_REPO
              value: "registry-group"
            - name: REGISTRY_REPO_HOST
              value: "https://gerrit-{{ template "edp.hostnameSuffix" $ }}"
            - name: REGISTRY_REPO_PREFIX
              value: "registry-tenant-template-"
            - name: REGISTRY_TEMPLATE_NAME
              value: "templates/registry-tenant-template"
            - name: JENKINS_GLOBAL_LINK
              value: "https://jenkins-{{ template "edp.hostnameSuffix" $ }}"
            - name: AUTH_ENABLED
              value: "true"
            - name: INTEGRATION_STRATEGIES
              value: "Create,Import"
            - name: BUILD_TOOLS
              value: "maven"
            - name: DEPLOYMENT_SCRIPT
              value: "helm-chart,openshift-template"
            - name: PLATFORM_TYPE
              value: "openshift"
            - name: VERSIONING_TYPES
              value: "default,edp"
            - name: CI_TOOLS
              value: "Jenkins,GitLab CI"
            - name: PERF_DATA_SOURCES
              value: "Sonar,Jenkins,GitLab"
            - name: EDP_NAME
              value: {{ $.Release.Namespace }}
            - name: OC_CLIENT_SECRET
              valueFrom:
                secretKeyRef:
                  name: oauth-admin-console-client
                  key: secret
            - name: OC_CLIENT_ID
              valueFrom:
                secretKeyRef:
                  name: oauth-admin-console-client
                  key: clientId
            - name: PROJECT_MASK_URL
              value: "{{$.Values.projectUrlMask}}"
            - name: IMAGE_STREAM_MASK_URL
              value: "{{ $.Values.imageStreamUrlMask }}"
            - name: ENABLE_BRANCH_PROVISIONERS
              value: "{{ $.Values.enable_branch_provisioners }}"
            - name: SESSION_SECRET
              valueFrom:
                secretKeyRef:
                  name: {{ include "сontrolPlaneConsole.secret.sessionSecret.name" $ }}
                  key: "token"
            - name: REGISTRY_DNS_MANUAL_PATH
              value: "ua/platform/1.9.5/admin/registry-management/custom-dns/cp-custom-dns-keycloak.html#external-configuration"
            - name: CLOUD_PROVIDER
              value: {{ $.Values.cloudProvider }}
            {{- if eq $it.registryVersion "1.9.6" }}
            - name: REGISTRY_VERSION_FILTER
              value: "<1.9.7"
            {{- else }}
            - name: REGISTRY_VERSION_FILTER
              value: =={{ $it.registryVersion }}
            {{- end }}
          image: {{ template "controlPlaneConsole.image" (dict "root" $ "stream" $it.stream "version" $it.consoleVersion) }}
          imagePullPolicy: IfNotPresent
          livenessProbe:
            failureThreshold: 5
            initialDelaySeconds: 180
            periodSeconds: 20
            successThreshold: 1
            tcpSocket:
              port: 8080
            timeoutSeconds: 1
          name: {{ $.Values.name }}
          ports:
            - containerPort: 8080
              protocol: TCP
          readinessProbe:
            failureThreshold: 5
            initialDelaySeconds: 60
            periodSeconds: 20
            successThreshold: 1
            tcpSocket:
              port: 8080
            timeoutSeconds: 1
          resources:
            requests:
              memory: 500Mi
          terminationMessagePath: /dev/termination-log
          terminationMessagePolicy: File
      dnsPolicy: ClusterFirst
      restartPolicy: Always
      schedulerName: default-scheduler
      securityContext: {}
      serviceAccountName: {{ $.Values.operator.serviceAccountName }}
      terminationGracePeriodSeconds: 30
{{- end }}
