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

{{- if .Values.flower.enabled }}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "superset.flower.fullname" . }}
  namespace: {{ include "common.names.namespace" . | quote }}
  labels: {{- include "common.labels.standard" ( dict "customLabels" .Values.commonLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: celery-flower
    app.kubernetes.io/part-of: superset
  {{- if or .Values.flower.service.annotations .Values.commonAnnotations }}
  {{- $annotations := include "common.tplvalues.merge" (dict "values" (list .Values.flower.service.annotations .Values.commonAnnotations) "context" .) }}
  annotations: {{- include "common.tplvalues.render" ( dict "value" $annotations "context" $ ) | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.flower.service.type }}
  {{- if and .Values.flower.service.clusterIP (eq .Values.flower.service.type "ClusterIP") }}
  clusterIP: {{ .Values.flower.service.clusterIP }}
  {{- end }}
  {{- if .Values.flower.service.sessionAffinity }}
  sessionAffinity: {{ .Values.flower.service.sessionAffinity }}
  {{- end }}
  {{- if .Values.flower.service.sessionAffinityConfig }}
  sessionAffinityConfig: {{- include "common.tplvalues.render" (dict "value" .Values.flower.service.sessionAffinityConfig "context" $) | nindent 4 }}
  {{- end }}
  {{- if or (eq .Values.flower.service.type "LoadBalancer") (eq .Values.flower.service.type "NodePort") }}
  externalTrafficPolicy: {{ .Values.flower.service.externalTrafficPolicy | quote }}
  {{- end }}
  {{- if and (eq .Values.flower.service.type "LoadBalancer") (not (empty .Values.flower.service.loadBalancerSourceRanges)) }}
  loadBalancerSourceRanges: {{ .Values.flower.service.loadBalancerSourceRanges }}
  {{- end }}
  {{- if and (eq .Values.flower.service.type "LoadBalancer") (not (empty .Values.flower.service.loadBalancerIP)) }}
  loadBalancerIP: {{ .Values.flower.service.loadBalancerIP }}
  {{- end }}
  ports:
    - name: flower
      port: {{ .Values.flower.service.ports.flower }}
      targetPort: flower
      protocol: TCP
      {{- if and (or (eq .Values.flower.service.type "NodePort") (eq .Values.flower.service.type "LoadBalancer")) (not (empty .Values.flower.service.nodePorts.flower)) }}
      nodePort: {{ .Values.flower.service.nodePorts.flower }}
      {{- else if eq .Values.flower.service.type "ClusterIP" }}
      nodePort: null
      {{- end }}
    {{- if .Values.flower.service.extraPorts }}
    {{- include "common.tplvalues.render" (dict "value" .Values.flower.service.extraPorts "context" $) | nindent 4 }}
    {{- end }}
  {{- $podLabels := include "common.tplvalues.merge" (dict "values" (list .Values.flower.podLabels .Values.commonLabels) "context" .) | fromYaml }}
  selector: {{- include "common.labels.matchLabels" ( dict "customLabels" $podLabels "context" $ ) | nindent 4 }}
    app.kubernetes.io/component: celery-flower
    app.kubernetes.io/part-of: superset
{{- end }}
