{{- /*
Copyright Broadcom, Inc. All Rights Reserved.
SPDX-License-Identifier: APACHE-2.0
*/}}

{{- if .Values.worker.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ printf "%s-headless" (include "deepspeed.v0.worker.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: deepspeed
    app.kubernetes.io/component: worker
  {{- if or .Values.commonAnnotations .Values.worker.headlessServiceAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.worker.headlessServiceAnnotations .Values.commonAnnotations ) "context" . ) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
  {{- end }}
spec:
  type: ClusterIP
  clusterIP: None
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.worker.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: deepspeed
    app.kubernetes.io/component: worker
{{- end }}
