{{- if .Values.runners.enabled }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "n8n.fullname" . }}-runners
  labels:
    {{- include "n8n.labels" . | nindent 4 }}
    app.kubernetes.io/component: runners
spec:
  replicas: {{ .Values.runners.replicaCount | default 1 }}
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "n8n.name" . }}-runners
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "n8n.name" . }}-runners
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/component: runners
    spec:
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      containers:
      - name: runners
        image: "{{ .Values.runners.image.repository }}:{{ .Values.runners.image.tag }}"
        imagePullPolicy: {{ .Values.runners.image.pullPolicy }}
        env:
        - name: N8N_RUNNERS_TASK_BROKER_URI
          value: http://{{ include "n8n.fullname" . }}:{{ .Values.service.brokerPort | default 5679 }}
        - name: N8N_RUNNERS_AUTH_TOKEN
          valueFrom:
            secretKeyRef:
              name: {{ .Values.runners.authSecretName }}
              key: {{ .Values.runners.authSecretKey }}
        - name: N8N_BLOCK_ENV_ACCESS_IN_NODE
          value: "false"
        - name: TELEGRAM_BOT_TOKEN
          valueFrom:
            secretKeyRef:
              name: {{ .Values.runners.envSecretName }}
              key: TELEGRAM_BOT_TOKEN
        {{- if .Values.runners.launcherConfig.enabled }}
        volumeMounts:
        - name: runners-config
          mountPath: /etc/n8n-task-runners.json
          subPath: n8n-task-runners.json
        {{- end }}
        resources:
          {{- toYaml .Values.runners.resources | nindent 10 }}
      {{- if .Values.runners.launcherConfig.enabled }}
      volumes:
      - name: runners-config
        configMap:
          name: {{ include "n8n.fullname" . }}-runners-config
      {{- end }}
{{- end }}
