{{- if .Values.agent.enabled -}}
apiVersion: v1
kind: Service
metadata:
  name: {{ template "jaeger.agent.name" . }}
  labels:
    app: {{ template "jaeger.name" . }}
    jaeger-infra: agent-service
    chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}
    component: agent
    heritage: {{ .Release.Service }}
    release: {{ .Release.Name }}
{{- if .Values.agent.service.annotations }}
  annotations:
{{ toYaml .Values.agent.service.annotations | indent 4 }}
{{- end }}
spec:
  ports:
  - name: agent-zipkin-thrift
    port: {{ .Values.agent.service.zipkinThriftPort }}
    protocol: UDP
    targetPort: {{ .Values.agent.service.zipkinThriftPort }}
  - name: agent-compact
    port: {{ .Values.agent.service.compactPort }}
    protocol: UDP
    targetPort: {{ .Values.agent.service.compactPort }}
  - name: agent-binary
    port: {{ .Values.agent.service.binaryPort }}
    protocol: UDP
    targetPort: {{ .Values.agent.service.binaryPort }}
  - name: agent-sampling
    port: {{ .Values.agent.service.samplingPort }}
    protocol: TCP
    targetPort: {{ .Values.agent.service.samplingPort }}
  type: {{ .Values.agent.service.type }}
  selector:
    app: {{ template "jaeger.name" . }}
    component: agent
    release: {{ .Release.Name }}
    jaeger-infra: agent-instance
{{- template "loadBalancerSourceRanges" .Values.agent }}
{{- end -}}
