apiVersion: v1
kind: Service
metadata:
  name: {{ include "fluent-bit.fullname" . }}
  namespace: {{ .Release.Namespace }}
  labels:
    {{- include "fluent-bit.labels" . | nindent 4 }}
    {{- with .Values.service.labels }}
    {{- toYaml . | nindent 4 }}
    {{- end }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if and (eq .Values.service.type "ClusterIP") (.Values.service.clusterIP) }}
  clusterIP: {{ .Values.service.clusterIP }}
  {{- end }}
  {{- if (eq .Values.service.type "LoadBalancer")}}
  {{- with .Values.service.loadBalancerClass}}
  loadBalancerClass: {{ . }}
  {{- end }}
  {{- with .Values.service.loadBalancerSourceRanges}}
  loadBalancerSourceRanges:
    {{- toYaml . | nindent 4 }}
  {{- end }}
  {{- end }}
  ports:
    - port: {{ .Values.service.port }}
      targetPort: http
      protocol: TCP
      name: http
      {{- if and (eq .Values.service.type "NodePort") (.Values.service.nodePort) }}
      nodePort: {{ .Values.service.nodePort }}
      {{- end }}
  {{- if .Values.extraPorts }}
    {{- range .Values.extraPorts }}
    - name: {{ .name }}
      targetPort: {{ .name }}
      protocol: {{ .protocol }}
      port: {{ .port }}
      {{- if and (eq $.Values.service.type "NodePort") (.nodePort) }}
      nodePort: {{ .nodePort }}
      {{- end }}
    {{- end }}
  {{- end }}
  selector:
    {{- include "fluent-bit.selectorLabels" . | nindent 4 }}
