# SPDX-License-Identifier: Apache-2.0
# Copyright 2022 The HuggingFace Authors.

{{- define "deploymentWorker" -}}
---
apiVersion: apps/v1
kind: Deployment
metadata:
  labels: {{ include "labels.worker" (merge (dict "workerValues" .workerValues) $ ) | nindent 4 }}
  name: "{{ include "name" . }}-worker-{{ .workerValues.deployName }}"
  namespace: {{ .Release.Namespace }}
  {{- if .Values.secrets.infisical.enabled }}
  annotations:
    secrets.infisical.com/auto-reload: "true"
  {{- end }}
spec:
  progressDeadlineSeconds: 600
  {{- if not .workerValues.autoscaling.enabled }}
  replicas: {{ .workerValues.replicas }}
  {{- end }}
  revisionHistoryLimit: 10
  selector:
    matchLabels: {{ include "labels.worker" (merge (dict "workerValues" .workerValues) $ ) | nindent 6 }}
  strategy:
    type: Recreate
  template:
    metadata:
      labels: {{ include "labels.worker" (merge (dict "workerValues" .workerValues) $ ) | nindent 8 }}
    spec:
      {{- include "dnsConfig" . | nindent 6 }}
      {{- include "image.imagePullSecrets" . | nindent 6 }}
      initContainers:
        {{ include "initContainerParquetMetadata" . | nindent 8 }}
      containers: {{ include "containerWorker" . | nindent 8 }}
      nodeSelector: {{ toYaml .workerValues.nodeSelector | nindent 8 }}
      tolerations: {{ toYaml .workerValues.tolerations | nindent 8 }}
      volumes:
        {{ include "volumeParquetMetadata" . | nindent 8 }}
      securityContext: {{ include "securityContext" . | nindent 8 }}
{{- end -}}
