# helm_charts_worker-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "locust.worker" . }}
  labels:
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    app: {{ template "locust.fullname" . }}
    component: worker
spec:
  replicas: {{ default 2 .Values.worker.replicaCount }}
  selector:
    matchLabels:
      {{- include "locust.selectorLabels" . | nindent 6 }}
      component: worker
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: {{ default 1 .Values.worker.maxSurge }}
      maxUnavailable: {{ default 1 .Values.worker.maxUnavailable }}
  template:
    metadata:
      labels:
        {{- include "locust.selectorLabels" . | nindent 8 }}
        component: worker
    spec:
    {{- if .Values.image.pullSecrets }}
      imagePullSecrets:
{{ toYaml .Values.image.pullSecrets | indent 8 }}
    {{- end }}
      containers:
      - name: locust
        image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
        imagePullPolicy: {{ .Values.image.pullPolicy }}
        volumeMounts:
          - name: locust-tasks
            mountPath: /locust-tasks/
{{- if .Values.extraVolumeMounts }}
{{ toYaml .Values.extraVolumeMounts | indent 10 }}
{{- end }}
        env:
        {{- range $key, $value :=  .Values.worker.config }}
        - name: {{ $key | upper | replace "-" "_" }}
          value: {{ $value | quote }}
        {{- end }}
        - name: LOCUST_MODE
          value: "worker"
        - name: LOCUST_MASTER
          value: {{ template "locust.master-svc" . }}
        - name: LOCUST_MASTER_WEB
          value: "{{ .Values.service.internalPort }}"
        - name: TARGET_HOST
          value: {{ index .Values.master.config "target-host" | quote }}
{{- if .Values.extraEnvs }}
{{ toYaml .Values.extraEnvs | indent 8 }}
{{- end }}
        resources:
{{ toYaml .Values.worker.resources | indent 10 }}
      restartPolicy: Always
      volumes:
        - name: "locust-tasks"
          configMap:
            name: {{ template "locust.worker-configmap" . }}
{{- if .Values.extraVolumes }}
{{ toYaml .Values.extraVolumes | indent 8 }}
{{- end }}
{{- with .Values.worker.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.worker.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.worker.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
{{- end }}