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

{{- if .Values.webhooks.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ printf "%s-webhook" (include "common.names.fullname" .) | trunc 63 | trimSuffix "-" }}
  namespace: {{ include "common.names.namespace" . | quote }}
  {{- $labels := include "common.tplvalues.merge" ( dict "values" ( list .Values.commonLabels .Values.webhooks.service.labels) "context" . ) }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" $labels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: kube-arangodb
    app.kubernetes.io/component: operator
  {{- if or .Values.webhooks.service.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" ( dict "values" ( list .Values.webhooks.service.annotations .Values.commonAnnotations ) "context" . ) }}
  annotations:
    {{- if or .Values.webhooks.service.annotations .Values.commonAnnotations }}
    {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $) | nindent 4 }}
    {{- end }}
  {{- end }}
spec:
  type: ClusterIP
  {{- if .Values.webhooks.service.clusterIP }}
  clusterIP: {{ .Values.webhooks.service.clusterIP }}
  {{- end }}
  ports:
    - name: http-webhook
      port: {{ .Values.webhooks.service.ports.webhook }}
      protocol: TCP
      targetPort: http-webhook
  {{- $podLabels := include "common.tplvalues.merge" ( dict "values" ( list .Values.podLabels .Values.commonLabels ) "context" . ) }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/part-of: kube-arangodb
    app.kubernetes.io/component: operator
{{- end }}