apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "dragon-graphql-gateway.fullname" . }}-adapter
  labels:
    app: {{ template "dragon-graphql-gateway.name" . }}-adapter
    chart: {{ template "dragon-graphql-gateway.chart" . }}-adapter
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  replicas: {{ .Values.graphql_adapter.replicaCount }}
  selector:
    matchLabels:
      app: {{ template "dragon-graphql-gateway.name" . }}-adapter
      release: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app: {{ template "dragon-graphql-gateway.name" . }}-adapter
        release: {{ .Release.Name }}
    spec:
      serviceAccountName: {{ required "Service account is required" .Values.serviceAccountName }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.graphql_adapter.image.repository }}:{{ .Values.graphql_adapter.image.tag }}"
          imagePullPolicy: {{ .Values.graphql_adapter.image.pullPolicy }}
          env:
            - name: NODE_ENV
              value: "{{ default "production" .Values.env }}"
            - name: HEALTH_CHECK_ENABLED
              value: "false"
            - name: REDIS_PUB_SUB_ENABLED
              value: "{{ .Values.redis.enabled }}"
            - name: REDIS_URL
              value: "{{ required "A valid redis url is required" .Values.redis.url }}"
            - name: SERVICE_PORT
              value: "5000"
            - name: API_URL
              value: "{{ .Values.drakemall.apiAddr }}"
            - name: API_HOST
              value: "{{ .Values.drakemall.domainName }}"
            - name: AMAZON_BUCKET_LOCATION
              value: "drakemall-files.s3.amazonaws.com"
            - name: ADAPTER_ENDPOINT
              value: "http://{{ template "graphql-adapter-url" . }}"
          ports:
            - name: adapter-http
              containerPort: 5000
              protocol: TCP
          # livenessProbe:
          #   httpGet:
          #     path: /
          #     port: graphql-http
          # readinessProbe:
          #   httpGet:
          #     path: /
          #     port: graphql-http
          resources:
{{ toYaml .Values.graphql_adapter.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 }}
