apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ .NAME }}
  namespace: {{ .NAMESPACE }}
spec:
  replicas: {{ .REPLICAS }}
  selector:
    matchLabels:
      app: {{ .NAME }}
  template:
    metadata:
      labels:
        app: {{ .NAME }}
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "8000"
    spec:
      restartPolicy: Always
      terminationGracePeriodSeconds: 40
      serviceAccountName: analytic
      containers:
        - name: {{ .NAME }}
          image: {{ .IMAGE_NAME }}
          imagePullPolicy: Always
          readinessProbe:
            initialDelaySeconds: 30
            periodSeconds: 20
            timeoutSeconds: 3
            failureThreshold: 3
            httpGet:
              path: /api/ready
              port: 8000
          livenessProbe:
            initialDelaySeconds: 30
            periodSeconds: 30
            timeoutSeconds: 3
            failureThreshold: 3
            httpGet:
              path: /api/health
              port: 8000
          env:
            - name: ENVIRONMENT
              value: {{ .ENVIRONMENT }}
            - name: PORT
              value: "8000"
            - name: LOG_LEVEL
              value: "INFO"
            - name: PIPELINE_SQS_URL
              valueFrom:
                configMapKeyRef:
                  name: analytics
                  key: pipeline-sqs-url
            - name: NOTIFICATIONS_SQS_URL
              valueFrom:
                configMapKeyRef:
                  name: analytics
                  key: notifications-sqs-url
            - name: AWS_REGION
              valueFrom:
                configMapKeyRef:
                  name: analytics
                  key: aws-region
            - name: PPROF_ENABLED
              value: "{{ .PPROF_ENABLED }}"
            - name: P2P_NETWORK
              value: {{ .P2P_NETWORK }}
            - name: MONGODB_URI
              valueFrom:
                secretKeyRef:
                  name: mongodb
                  key: mongo-uri
            - name: MONGODB_DATABASE
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: mongo-database
            - name: INFLUX_URL
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-url
            - name: INFLUX_TOKEN
              valueFrom:
                secretKeyRef:
                  name: influxdb
                  key: token
            - name: INFLUX_ORGANIZATION
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-organization
            - name: INFLUX_BUCKET_INFINITE
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-bucket-infinite
            - name: INFLUX_BUCKET_30_DAYS
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-bucket-30-days
            - name: INFLUX_BUCKET_24_HOURS
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: influxdb-bucket-24-hours
            - name: CACHE_CHANNEL
              value: {{ .CACHE_CHANNEL }}
            - name: CACHE_URL
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: redis-uri
            - name: CACHE_PREFIX
              valueFrom:
                configMapKeyRef:
                  name: config
                  key: redis-prefix
            - name: VAA_PAYLOAD_PARSER_URL
              value: {{ .VAA_PAYLOAD_PARSER_URL }}
            - name: VAA_PAYLOAD_PARSER_TIMEOUT
              value: "{{ .VAA_PAYLOAD_PARSER_TIMEOUT }}"
          resources:
            limits:
              memory: {{ .RESOURCES_LIMITS_MEMORY }}
              cpu: {{ .RESOURCES_LIMITS_CPU }}
            requests:
              memory: {{ .RESOURCES_REQUESTS_MEMORY }}
              cpu: {{ .RESOURCES_REQUESTS_CPU }}