---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "mikrotik-portal.fullname" . }}-poller
  labels:
    {{- include "mikrotik-portal.labels" . | nindent 4 }}
    app.kubernetes.io/component: poller
spec:
  replicas: {{ .Values.poller.replicaCount }}
  selector:
    matchLabels:
      {{- include "mikrotik-portal.selectorLabels" . | nindent 6 }}
      app.kubernetes.io/component: poller
  template:
    metadata:
      labels:
        {{- include "mikrotik-portal.selectorLabels" . | nindent 8 }}
        app.kubernetes.io/component: poller
    spec:
      containers:
        - name: poller
          image: "{{ .Values.poller.image.repository }}:{{ .Values.poller.image.tag }}"
          imagePullPolicy: {{ .Values.poller.image.pullPolicy }}
          env:
            - name: DATABASE_URL
              valueFrom:
                secretKeyRef:
                  name: {{ include "mikrotik-portal.fullname" . }}-secrets
                  key: POLLER_DATABASE_URL
            - name: CREDENTIAL_ENCRYPTION_KEY
              valueFrom:
                secretKeyRef:
                  name: {{ include "mikrotik-portal.fullname" . }}-secrets
                  key: CREDENTIAL_ENCRYPTION_KEY
            - name: NATS_URL
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mikrotik-portal.fullname" . }}-config
                  key: NATS_URL
            - name: REDIS_URL
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mikrotik-portal.fullname" . }}-config
                  key: REDIS_URL
            - name: POLL_INTERVAL_SECONDS
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mikrotik-portal.fullname" . }}-config
                  key: POLL_INTERVAL_SECONDS
            - name: LOG_LEVEL
              valueFrom:
                configMapKeyRef:
                  name: {{ include "mikrotik-portal.fullname" . }}-config
                  key: POLLER_LOG_LEVEL
          resources:
            requests:
              cpu: {{ .Values.poller.resources.requests.cpu }}
              memory: {{ .Values.poller.resources.requests.memory }}
            limits:
              cpu: {{ .Values.poller.resources.limits.cpu }}
              memory: {{ .Values.poller.resources.limits.memory }}
