{{- if .Values.service.enabled -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ include "fluentd.fullname" . }}
  labels:
    {{- include "fluentd.labels" . | nindent 4 }}
  {{- with .Values.service.annotations }}
  annotations:
    {{- toYaml . | nindent 4 }}
  {{- end }}
spec:
  type: {{ .Values.service.type }}
  {{- if .Values.service.loadBalancerIP }}
  loadBalancerIP: {{ .Values.service.loadBalancerIP }}
  {{- end }}
  {{- if .Values.service.externalTrafficPolicy }}
  externalTrafficPolicy: {{ .Values.service.externalTrafficPolicy }}
  {{- end }}
  ports:
  - port: 24231
    targetPort: metrics
    protocol: TCP
    name: metrics
  {{- if .Values.service.ports }}
  {{- range $port := .Values.service.ports }}
  - name: {{ $port.name }}
    port: {{ $port.containerPort }}
    targetPort: {{ $port.containerPort }}
    protocol: {{ $port.protocol }}
  {{- end }}
  {{- end }}
  selector:
    {{- include "fluentd.selectorLabels" . | nindent 4 }}
{{- end -}}
