{{- if .Values.applicationSet.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "argocd.applicationSet" . }}
  namespace: {{ .Release.Namespace | quote }}
  labels: {{- include "common.labels.standard" . | nindent 4 }}
    app.kubernetes.io/component: applicationSet
    {{- if .Values.commonLabels }}
    {{- include "common.tplvalues.render" ( dict "value" .Values.commonLabels "context" $ ) | nindent 4 }}
    {{- end }}
  {{- if or .Values.commonAnnotations .Values.applicationSet.service.annotations }}
  annotations:
  {{- if .Values.commonAnnotations }}
  {{- include "common.tplvalues.render" ( dict "value" .Values.commonAnnotations "context" $ ) | nindent 4 }}
  {{- end }}
  {{- if .Values.applicationSet.service.annotations }}
  {{- include "common.tplvalues.render" ( dict "value" .Values.applicationSet.service.annotations "context" $ ) | nindent 4 }}
  {{- end }}
  {{- end }}
spec:
  type: {{ .Values.applicationSet.service.type }}
  {{- if and .Values.applicationSet.service.clusterIP (eq .Values.applicationSet.service.type "ClusterIP") }}
  clusterIP: {{ .Values.applicationSet.service.clusterIP }}
  {{- end }}
  {{- if (or (eq .Values.applicationSet.service.type "LoadBalancer") (eq .Values.applicationSet.service.type "NodePort")) }}
  externalTrafficPolicy: {{ .Values.applicationSet.service.externalTrafficPolicy | quote }}
  {{- end }}
  {{- if eq .Values.applicationSet.service.type "LoadBalancer" }}
  loadBalancerSourceRanges: {{ .Values.applicationSet.service.loadBalancerSourceRanges }}
  {{- end }}
  {{- if (and (eq .Values.applicationSet.service.type "LoadBalancer") (not (empty .Values.applicationSet.service.loadBalancerIP))) }}
  loadBalancerIP: {{ .Values.applicationSet.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.applicationSet.service.sessionAffinity }}
  sessionAffinity: {{ .Values.applicationSet.service.sessionAffinity }}
  {{- end }}
  {{- if .Values.applicationSet.service.sessionAffinityConfig }}
  sessionAffinityConfig: {{- include "common.tplvalues.render" (dict "value" .Values.applicationSet.service.sessionAffinityConfig "context" $) | nindent 4 }}
  {{- end }}
  ports:
    - name: webhook
      port: {{ .Values.applicationSet.service.port }}
      targetPort: webhook
      {{- if (and (or (eq .Values.applicationSet.service.type "NodePort") (eq .Values.applicationSet.service.type "LoadBalancer")) (not (empty .Values.applicationSet.service.nodePort))) }}
      nodePort: {{ .Values.applicationSet.service.nodePort }}
      {{- else if eq .Values.applicationSet.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.applicationSet.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.applicationSet.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  selector: {{- include "common.labels.matchLabels" . | nindent 4 }}
    app.kubernetes.io/component: applicationSet
{{- end }}
