{{- if .Values.gateway.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "openstack-api-simulator.fullname" . }}-gateway
  labels:
    {{- include "openstack-api-simulator.labels" . | nindent 4 }}
    app.kubernetes.io/component: gateway
spec:
  replicas: {{ .Values.gateway.replicaCount }}
  selector:
    matchLabels:
      {{- include "openstack-api-simulator.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: gateway
  template:
    metadata:
      annotations:
        checksum/gateway-config: {{ include (print $.Template.BasePath "/gateway-configmap.yaml") . | sha256sum }}
      labels:
        {{- include "openstack-api-simulator.labels" . | nindent 8 }}
        app.kubernetes.io/component: gateway
    spec:
      {{- with .Values.imagePullSecrets }}
      imagePullSecrets:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "openstack-api-simulator.serviceAccountName" . }}
      containers:
        - name: gateway
          image: "{{ .Values.gateway.image.repository }}:{{ .Values.gateway.image.tag }}"
          imagePullPolicy: {{ .Values.gateway.image.pullPolicy }}
          ports:
            {{- range .Values.gateway.service.ports }}
            - name: {{ .name | trunc 15 | trimSuffix "-" }}
              containerPort: {{ .port }}
              protocol: TCP
            {{- end }}
          volumeMounts:
            - name: nginx-conf
              mountPath: /etc/nginx/conf.d
              readOnly: true
          readinessProbe:
            tcpSocket:
              port: 5000
            initialDelaySeconds: 3
            periodSeconds: 5
          livenessProbe:
            tcpSocket:
              port: 5000
            initialDelaySeconds: 10
            periodSeconds: 10
          resources:
            {{- toYaml .Values.gateway.resources | nindent 12 }}
      volumes:
        - name: nginx-conf
          configMap:
            name: {{ include "openstack-api-simulator.fullname" . }}-gateway
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.affinity }}
      affinity:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.tolerations }}
      tolerations:
        {{- toYaml . | nindent 8 }}
      {{- end }}
{{- end }}
