apiVersion: v1
kind: Service
metadata:
  name: {{ include "superset.fullname" . }}
  labels:
    app: {{ include "superset.name" . }}
    chart: {{ include "superset.chart" . }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
  {{- if .Values.service.annotations }}
  annotations:
    {{- .Values.service.annotations | toYaml | nindent 4 }}
  {{- end }}
spec:
  {{- if (or (eq .Values.service.type "ClusterIP") (empty .Values.service.type)) }}
  type: ClusterIP
  {{- if .Values.service.clusterIP }}
  clusterIP: {{ .Values.service.clusterIP }}
  {{- end }}
  {{- else if eq .Values.service.type "LoadBalancer" }}
  type: {{ .Values.service.type }}
  {{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.service.loadBalancerSourceRanges }}
  loadBalancerSourceRanges:
  {{- .Values.service.loadBalancerSourceRanges | toYaml | nindent 4 }}
  {{- end }}
  {{- else }}
  type: {{ .Values.service.type }}
  {{- end }}
  {{- if .Values.service.externalIPs }}
  externalIPs:
    {{- .Values.service.externalIPs | toYaml | nindent 4 }}
  {{- end }}
  ports:
    - name: http
      port: {{ .Values.service.port }}
      targetPort: 8088
      protocol: TCP
      {{- if (and (eq .Values.service.type "NodePort") (not (empty .Values.service.nodePort))) }}
      nodePort: {{.Values.service.nodePort}}
      {{- end }}
  selector:
    app: {{ include "superset.name" . }}
    release: {{ .Release.Name }}
