apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "drakemall-admin.fullname" . }}-graphql-es-gateway
  labels:
    app: {{ template "drakemall-admin.name" . }}-graphql-es-gateway
    chart: {{ template "drakemall-admin.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    rollingUpdate:
      maxSurge: 50%
      maxUnavailable: 50%
    type: RollingUpdate
  selector:
    matchLabels:
      app: {{ template "drakemall-admin.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "drakemall-admin.name" . }}
        release: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ required "Service account is required" .Values.serviceAccountName }}
      containers:
        - name: {{ .Chart.Name }}-graphql-adapter
          image: "{{ .Values.graphql_adapter.image.repository }}:{{ .Values.graphql_adapter.image.tag }}"
          imagePullPolicy: {{ .Values.graphql_adapter.image.pullPolicy }}
          env:
            - name: SERVICE_PORT
              value: "5001"
            - name: API_URL
              value: "{{ .Values.drakemall.api_addr }}"
            - name: AMAZON_BUCKET_LOCATION
              value: "drakemall-files.s3.amazonaws.com"
          ports:
            - name: http
              containerPort: 5001
              protocol: TCP
          # livenessProbe:
          #   httpGet:
          #     path: /
          #     port: http
          # readinessProbe:
          #   httpGet:
          #     path: /
          #     port: http
        - name: {{ .Chart.Name }}-graphql-es-gateway
          image: "{{ .Values.graphql_es_gateway.image.repository }}:{{ .Values.graphql_es_gateway.image.tag }}"
          imagePullPolicy: {{ .Values.graphql_es_gateway.image.pullPolicy }}
          env:
            - name: NODE_ENV
              value: production
            - name: SERVICE_PORT
              value: "5000"
            - name: GRAPHQL_ENDPOINT_1
              value: "UserManagement|http://localhost:5001/users-graphql"
            - name: GRAPHQL_ENDPOINT_2
              value: "AdminManagement|http://localhost:5001/admin-graphql"
          ports:
            - name: graphql-http
              containerPort: 5000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /
              port: graphql-http
            initialDelaySeconds: 10
            failureThreshold: 2
            periodSeconds: 10
            timeoutSeconds: 10
          readinessProbe:
            httpGet:
              path: /
              port: graphql-http
            initialDelaySeconds: 10
            failureThreshold: 2
            periodSeconds: 10
            timeoutSeconds: 10
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
