---
apiVersion: v1
kind: Service
metadata:
  name: {{ .NAME }}
  namespace: {{ .NAMESPACE }}
  annotations:
    external-dns.alpha.kubernetes.io/hostname: {{ .HOSTNAME }}
  labels:
    app: {{ .NAME }}
spec:
  type: LoadBalancer
  selector:
    app: {{ .NAME }}
  ports:
    - port: 80
      targetPort: {{ .PORT }}
      name: {{ .NAME }}
      protocol: TCP
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .NAME }}
  namespace: {{ .NAMESPACE }}
spec:
  replicas: {{ .REPLICAS }}
  selector:
    matchLabels:
      app: {{ .NAME }}
  template:
    metadata:
      labels:
        app: {{ .NAME }}
    spec:
      containers:
        - name: {{ .NAME }}
          env:
            - name: REDIS_URI
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: redis-uri
            - name: REDIS_PREFIX
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: redis-prefix
            - name: REDIS_VAA_CHANNEL
              value: "{{ .REDIS_VAA_CHANNEL }}"
            - name: GRPC_ADDRESS
              value: {{ .GRPC_ADDRESS }}
            - name: PORT
              value: "8000"
            - name: PPROF_ENABLED
              value: "{{ .PPROF_ENABLED }}"
          image: {{ .IMAGE_NAME }}
          livenessProbe:
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 2
            failureThreshold: 4
            httpGet:
              path: /api/health
              port: 8000
          readinessProbe:
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 1
            failureThreshold: 2
            httpGet:
              path: /api/ready
              port: 8000
          resources:
            limits:
              cpu: {{ .RESOURCES_LIMITS_CPU }}
              memory: {{ .RESOURCES_LIMITS_MEMORY }}
            requests:
              cpu: {{ .RESOURCES_REQUESTS_CPU }}
              memory: {{ .RESOURCES_REQUESTS_MEMORY }}
      restartPolicy: Always
      terminationGracePeriodSeconds: 45