{{ if .Values.server_api.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: server-api
spec:
  replicas: {{ .Values.server_api.replicas }}
  selector:
    matchLabels:
      app: server-api
  template:
    metadata:
      name: server-api
      labels:
        app: server-api
    spec:
      terminationGracePeriodSeconds: 1
      containers:
      - name: server-api
        image: docker.io/goalprofit/server-api:{{.Values.server_api.version}}
        imagePullPolicy: Always
        env:
          - name: SERVICE_LOGIN
            valueFrom:
              secretKeyRef:
                name: secret-admin
                key: username
                optional: false
          - name: SERVICE_PASSWORD
            valueFrom:
              secretKeyRef:
                name: secret-admin
                key: password
                optional: false
          - name: REDIS_URL
            value: server-api-redis-master:6379
          - name: REDIS_USER
            value: default
          - name: REDIS_PASSWORD
            valueFrom:
              secretKeyRef:
                name: server-api-redis
                key: redis-password
                optional: true
          - name: QUERY_CORES
            value: "{{.Values.server_api.query_cores}}"
          - name: QUERY_TIME_LOGGING
            value: "{{.Values.server_api.query_time_logging}}"
          - name: QUERY_LOGGING
            value: "{{.Values.server_api.query_logging}}"
          - name: CODES_IN_CHUNK
            value: "{{.Values.server_api.codes_in_chunk}}"
      imagePullSecrets:
      - name: regcred
        
      {{ include "app.affinity" . | nindent 6}}
---
apiVersion: v1
kind: Service
metadata:
  name: server-api
spec:
  type: ClusterIP
  selector:
    app: server-api
  ports:
    - name: http
      protocol: TCP
      port: 8080
      targetPort: 8080
    {{ if .Values.server_api.debug }}
    - name: debug
      protocol: TCP
      port: 9229
      targetPort: 9229
    {{ end }}
{{ end }}