apiVersion: apps/v1beta2
kind: Deployment
metadata:
  name: {{ template "dask.fullname" . }}-worker
  labels:
    app: {{ template "dask.name" . }}
    heritage: {{ .Release.Service | quote }}
    release: {{ .Release.Name | quote }}
    chart: {{ template "dask.chart" . }}
    component: worker
spec:
  replicas: {{ .Values.worker.replicas }}
  selector:
    matchLabels:
      app: {{ template "dask.name" . }}
      release: {{ .Release.Name | quote }}
      component: worker
  strategy:
    type: RollingUpdate
  template:
    metadata:
      labels:
        app: {{ template "dask.name" . }}
        release: {{ .Release.Name | quote }}
        component: worker
    spec:
      containers:
        - name: {{ template "dask.fullname" . }}-worker
          image: "{{ .Values.worker.image.repository }}:{{ .Values.worker.image.tag }}"
          imagePullPolicy: {{ .Values.worker.image.pullPolicy }}
          args:
            - dask-worker
            - {{ template "dask.fullname" . }}-scheduler:{{ .Values.scheduler.servicePort }}
          {{- if .Values.worker.resources.limits }}
            - --nthreads
            - {{ .Values.worker.resources.limits.cpu | default .Values.worker.default_resources.cpu | quote }}
            - --memory-limit
            - {{ .Values.worker.resources.limits.memory | default .Values.worker.default_resources.memory | quote }}
          {{- end }}
            - --no-bokeh
          ports:
            - containerPort: 8789
          resources:
{{ toYaml .Values.worker.resources | indent 12 }}
          env:
{{ toYaml .Values.worker.env | indent 12 }}
      tolerations:
        - key: "k8s.dask.org_dedicated"
          operator: "Equal"
          value: "worker"
          effect: "NoSchedule"
        - key: "k8s.dask.org/dedicated"
          operator: "Equal"
          value: "worker"
          effect: "NoSchedule"
