apiVersion: v1
kind: Service
metadata:
  name: grafana
  namespace: {{ .Release.Namespace }}
  annotations:
    {{- range $key, $val := .Values.service.annotations }}
    {{ $key }}: {{ $val | quote }}
    {{- end }}
  labels:
    app: {{ template "grafana.name" . }}
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    release: {{ .Release.Name }}
    heritage: {{ .Release.Service }}
spec:
  type: {{ .Values.service.type }}
  ports:
    - port: {{ .Values.service.externalPort }}
      targetPort: {{ .Values.service.internalPort }}
      protocol: TCP
      name: {{ .Values.service.name }}
  selector:
    app: grafana
{{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: "{{ .Values.service.loadBalancerIP }}"
{{- end }}
  {{if .Values.service.loadBalancerSourceRanges}}
  loadBalancerSourceRanges:
    {{range $rangeList := .Values.service.loadBalancerSourceRanges}}
    - {{ $rangeList }}
    {{end}}
  {{end}}