apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "dragon-graphql-gateway.fullname" . }}
  labels:
    app: {{ template "dragon-graphql-gateway.name" . }}
    chart: {{ template "dragon-graphql-gateway.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.graphql_gateway.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "dragon-graphql-gateway.name" . }}
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "dragon-graphql-gateway.name" . }}
        release: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ required "Service account is required" .Values.serviceAccountName }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.graphql_gateway.image.repository }}:{{ .Values.graphql_gateway.image.tag }}"
          imagePullPolicy: {{ .Values.graphql_gateway.image.pullPolicy }}
          env:
            - name: FOO
              value: bar
            - name: DOMAIN_NAME
              value: "{{ required "A valid siteDomainName is required" .Values.siteDomainName }}"
            - name: NODE_ENV
              value: "{{ default "production" .Values.env }}"
            - name: ONLINE_USERS_COUNTER_ENABLED
              value: "true"
            - name: HEALTHCHECK_TIMEOUT
              value: "20000"
            - name: USER_ONLINE_TTL
              value: "30000"
            - name: REDIS_URL
              value: "{{ required "A valid redis url is required" .Values.redis.url }}"
            - name: PORT
              value: "5000"
            - name: ADAPTER_ENDPOINT
              value: "http://{{ template "graphql-adapter-url" . }}"
            - name: GRAPHQL_ENDPOINT_1
              value: "http://{{ template "graphql-adapter-url" . }}/users-graphql|ws://{{ template "graphql-adapter-url" . }}/graphql"
            - name: GRAPHQL_ENDPOINT_2
              value: "http://{{ template "graphql-adapter-url" . }}/cases-graphql|ws://{{ template "graphql-adapter-url" . }}/graphql"
            - name: GRAPHQL_ENDPOINT_3
              value: "http://{{ template "graphql-adapter-url" . }}/banking-graphql|ws://{{ template "graphql-adapter-url" . }}/graphql"
            - name: GRAPHQL_ENDPOINT_4
              value: "http://{{ template "graphql-adapter-url" . }}/admin-graphql|ws://{{ template "graphql-adapter-url" . }}/graphql"
            - name: GRAPHQL_ENDPOINT_5
              value: "http://{{ template "dragon-graphql-i18n.fullname" . }}-i18n:5000/graphql"
            - name: GRAPHQL_ENDPOINT_6
              value: "http://{{ template "graphql-adapter-url" . }}/app-graphql"
          ports:
            - name: graphql-http
              containerPort: 5000
              protocol: TCP
          livenessProbe:
            httpGet:
              path: /health
              port: graphql-http
            initialDelaySeconds: 5
            failureThreshold: 3
            successThreshold: 1
            timeoutSeconds: 10
          readinessProbe:
            httpGet:
              path: /health
              port: graphql-http
            initialDelaySeconds: 10
            failureThreshold: 3
            periodSeconds: 20
            timeoutSeconds: 10
          resources:
{{ toYaml .Values.graphql_gateway.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 }}
