apiVersion: v1
kind: Service
metadata:
  labels:
    app: {{ template "grafana.fullname" . }}
    chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
    heritage: "{{ .Release.Service }}"
    release: "{{ .Release.Name }}"
  name: {{ template "grafana.server.fullname" . }}
  {{- if .Values.service.annotations }}
  annotations:
{{ toYaml .Values.service.annotations | indent 4 }}
  {{- end }}
spec:
  ports:
    - name: "http"
      port: 80
      protocol: TCP
      targetPort: 3000
      {{- if .Values.service.nodePort }}
      nodePort:  {{ .Values.service.nodePort }}
      {{- end }}
  selector:
    app: {{ template "grafana.fullname" . }}
  type: "{{ .Values.service.type }}"
{{- if contains "LoadBalancer" .Values.service.type }}
  {{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end -}}
  {{- if .Values.service.loadBalancerSourceRanges}}
  loadBalancerSourceRanges:
  {{- range .Values.service.loadBalancerSourceRanges }}
  - {{ . }}
  {{- end }}
  {{- end -}}
{{- end -}}
