{{- if and .Values.worker.enabled}} {{- $usePvc := not (or .Values.externalS3.enabled .Values.externalAzureBlobStorage.enabled .Values.externalOSS.enabled .Values.externalGCS.enabled .Values.externalCOS.enabled .Values.externalOBS.enabled) -}} apiVersion: apps/v1 kind: Deployment metadata: annotations: {{ include "dify.ud.annotations" . | indent 4 }} descriptions: worker labels: {{- include "dify.labels" . | nindent 4 }} component: worker # app: {{ template "dify.worker.fullname" . }} {{ include "dify.ud.labels" . | indent 4 }} name: {{ template "dify.worker.fullname" . }} spec: replicas: {{ .Values.worker.replicas }} selector: matchLabels: {{- include "dify.selectorLabels" . | nindent 6 }} component: worker {{/* # Required labels for istio # app: {{ template "dify.worker.fullname" . }} # version: {{ .Values.istioServiceMesh.version | quote }} */}} {{- if .Values.worker.updateStrategy }} strategy: {{- toYaml .Values.worker.updateStrategy | nindent 4 }} {{- end }} template: metadata: annotations: checksum/worker-config: {{ include (print $.Template.BasePath "/worker-config.yaml") . | sha256sum }} checksum/worker-secret: {{ include (print $.Template.BasePath "/worker-secret.yaml") . | sha256sum }} {{ include "dify.ud.annotations" . | indent 8 }} labels: {{- include "dify.selectorLabels" . | nindent 8 }} component: worker {{/* # Required labels for istio # app: {{ template "dify.worker.fullname" . }} # version: {{ .Values.istioServiceMesh.version | quote }} */}} {{ include "dify.ud.labels" . | indent 8 }} spec: serviceAccountName: {{ include "dify.worker.serviceAccountName" . }} {{- if .Values.worker.priorityClassName }} priorityClassName: {{ .Values.worker.priorityClassName | quote }} {{- end }} {{- if .Values.image.api.pullSecrets }} imagePullSecrets: {{- range .Values.image.api.pullSecrets }} - name: {{ . }} {{- end }} {{- end }} {{- if .Values.worker.podSecurityContext }} securityContext: {{ toYaml .Values.worker.podSecurityContext | indent 8 }} {{- end }} initContainers: - name: init image: "{{.Values.image.python.repository }}:{{ default "3.12-slim" .Values.image.python.tag }}" imagePullPolicy: "{{.Values.image.python.pullPolicy }}" command: ["/bin/sh"] args: ["-c", "pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple && pip config set install.trusted-host pypi.tuna.tsinghua.edu.cn"] volumeMounts: - name: python-config mountPath: /root/.config/pip {{- if .Values.api.migration }} - name: check-api image: "{{ .Values.image.api.repository }}:{{ default .Chart.AppVersion .Values.image.api.tag }}" command: - sh - -c - | until curl http://{{ template "dify.api.fullname" . }}:{{ .Values.api.service.port }}/health; do echo "Waiting for API service to be available..." sleep 1 done envFrom: - configMapRef: name: {{ template "dify.worker.fullname" . }} - secretRef: name: {{ template "dify.worker.fullname" . }} {{- end }} containers: - image: "{{ .Values.image.api.repository }}:{{ default .Chart.AppVersion .Values.image.api.tag }}" imagePullPolicy: "{{ .Values.image.api.pullPolicy }}" name: worker {{- if .Values.worker.customLivenessProbe }} livenessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.worker.customLivenessProbe "context" $) | nindent 10 }} {{- end }} {{- if .Values.worker.customReadinessProbe }} readinessProbe: {{- include "common.tplvalues.render" (dict "value" .Values.worker.customReadinessProbe "context" $) | nindent 10 }} {{- end }} {{- if .Values.worker.customStartupProbe }} startupProbe: {{- include "common.tplvalues.render" (dict "value" .Values.worker.customStartupProbe "context" $) | nindent 10 }} {{- end }} {{- if .Values.worker.containerSecurityContext }} securityContext: {{ toYaml .Values.worker.containerSecurityContext | indent 10 }} {{- end }} env: {{- if .Values.worker.extraEnv }} {{- toYaml .Values.worker.extraEnv | nindent 8 }} {{- end }} envFrom: - configMapRef: name: {{ template "dify.worker.fullname" . }} - secretRef: name: {{ template "dify.worker.fullname" . }} resources: {{- toYaml .Values.worker.resources | nindent 12 }} volumeMounts: - name: python-config mountPath: /root/.config/pip {{- if $usePvc }} - name: app-data mountPath: {{ .Values.api.persistence.mountPath | quote }} subPath: {{ .Values.api.persistence.persistentVolumeClaim.subPath | default "" }} {{- end }} {{- if and (.Values.nodeSelector) (not .Values.worker.nodeSelector) }} nodeSelector: {{ toYaml .Values.nodeSelector | indent 8 }} {{- end }} {{- if .Values.worker.nodeSelector }} nodeSelector: {{ toYaml .Values.worker.nodeSelector | indent 8 }} {{- end }} {{- if and (.Values.affinity) (not .Values.worker.affinity) }} affinity: {{ toYaml .Values.affinity | indent 8 }} {{- end }} {{- if .Values.worker.affinity }} affinity: {{ toYaml .Values.worker.affinity | indent 8 }} {{- end }} {{- if and (.Values.tolerations) (not .Values.worker.tolerations) }} tolerations: {{ toYaml .Values.tolerations | indent 8 }} {{- end }} {{- if .Values.worker.tolerations }} tolerations: {{ toYaml .Values.worker.tolerations | indent 8 }} {{- end }} volumes: - name: python-config emptyDir: {} {{- if $usePvc }} - name: app-data persistentVolumeClaim: claimName: {{ .Values.api.persistence.persistentVolumeClaim.existingClaim | default (printf "%s" (include "dify.fullname" . | trunc 58)) }} {{- end }} {{- end }}