# helm_charts_master-deploy.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "locust.master" . }}
  labels:
    app: {{ template "locust.fullname" . }}
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    component: master
spec:
  replicas: 1
  selector:
    matchLabels:
      {{- include "locust.selectorLabels" . | nindent 6 }}
      component: "master"
  strategy:
    type: RollingUpdate
    rollingUpdate:
      maxSurge: {{ default 1 .Values.master.maxSurge }}
      maxUnavailable: {{ default 1 .Values.master.maxUnavailable }}
  template:
    metadata:
      labels:
        {{- include "locust.selectorLabels" . | nindent 8 }}
        component: "master"
    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 }}
        resources:
{{ toYaml .Values.master.resources | indent 10 }}
        env:
        {{- range $key, $value :=  .Values.master.config }}
        - name: {{ $key | upper | replace "-" "_" }}
          value: {{ $value | quote }}
        {{- end }}
        - name: LOCUST_MODE
          value: "master"
        - name: LOCUST_SCRIPT
          value: {{ index .Values.worker.config "locust-script" | quote }}
{{- if .Values.extraEnvs }}
{{ toYaml .Values.extraEnvs | indent 8 }}
{{- end }}
        ports:
        - containerPort: {{ .Values.service.internalPort }}
          name: loc-master-web
          protocol: TCP
        - containerPort: 5557
          name: loc-master-p1
          protocol: TCP
        - containerPort: 5558
          name: loc-master-p2
          protocol: TCP
        volumeMounts:
          - name: locust-tasks
            mountPath: /locust-tasks/
{{- if .Values.extraVolumeMounts }}
{{ toYaml .Values.extraVolumeMounts | indent 10 }}
{{- end }}
        livenessProbe:
          periodSeconds: 30
          httpGet:
            path: /
            port: {{ .Values.service.internalPort }}
        readinessProbe:
          periodSeconds: 30
          httpGet:
            path: /
            port: {{ .Values.service.internalPort }}
      volumes:
      - name: "locust-tasks"
        configMap:
          name: {{ template "locust.worker-configmap" . }}
{{- if .Values.extraVolumes }}
{{ toYaml .Values.extraVolumes | indent 6 }}
{{- end }}
      restartPolicy: Always
{{- with .Values.master.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
{{- end }}
{{- with .Values.master.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
{{- end }}