{{- if .Values.agent.enabled -}}
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: {{ template "jaeger.agent.name" . }}
  labels:
    app.kubernetes.io/name: {{ include "jaeger.name" . }}
    helm.sh/chart: {{ include "jaeger.chart" . }}
    app.kubernetes.io/instance: {{ .Release.Name }}
    app.kubernetes.io/managed-by: {{ .Release.Service }}
    app.kubernetes.io/component: agent
{{- if .Values.agent.annotations }}
  annotations:
{{ toYaml .Values.agent.annotations | indent 4 }}
{{- end }}
spec:
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "jaeger.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
      app.kubernetes.io/component: agent
  template:
    metadata:
{{- if .Values.agent.podAnnotations }}
      annotations:
{{ toYaml .Values.agent.podAnnotations | indent 8 }}
{{- end }}
      labels:
        app.kubernetes.io/name: {{ include "jaeger.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/component: agent
{{- if .Values.agent.podLabels }}
{{ toYaml .Values.agent.podLabels | indent 8 }}
{{- end }}
    spec:
      {{- if .Values.agent.useHostNetwork }}
      hostNetwork: true
      {{- end }}
      dnsPolicy: {{ .Values.agent.dnsPolicy }}
      nodeSelector:
{{ toYaml .Values.agent.nodeSelector | indent 8 }}
{{- if .Values.agent.tolerations }}
      tolerations:
{{ toYaml .Values.agent.tolerations | indent 8 }}
{{- end }}
      serviceAccountName: {{ template "jaeger.agent.serviceAccountName" . }}
      containers:
      - name: {{ template "jaeger.agent.name" . }}
        image: {{ .Values.agent.image }}:{{ .Values.tag }}
        imagePullPolicy: {{ .Values.agent.pullPolicy }}
        env:
        - name: REPORTER_GRPC_HOST_PORT
          value: {{ include "jaeger.collector.name" . }}:{{ .Values.collector.service.grpcPort }}
        {{- range $key, $value := .Values.agent.cmdlineParams }}
        - name: {{ $key | replace "." "_" | replace "-" "_" | upper | quote }}
          value: {{ $value }}
        {{- end }}
        ports:
        - name: zipkin-compact
          containerPort: {{ .Values.agent.service.zipkinThriftPort }}
          protocol: UDP
          {{- if .Values.agent.daemonset.useHostPort }}
          hostPort: {{ .Values.agent.service.zipkinThriftPort }}
          {{- end }}
        - name: jaeger-compact
          containerPort: {{ .Values.agent.service.compactPort }}
          protocol: UDP
          {{- if .Values.agent.daemonset.useHostPort }}
          hostPort: {{ .Values.agent.service.compactPort }}
          {{- end }}
        - name: jaeger-binary
          containerPort: {{ .Values.agent.service.binaryPort }}
          protocol: UDP
          {{- if .Values.agent.daemonset.useHostPort }}
          hostPort: {{ .Values.agent.service.binaryPort }}
          {{- end }}
        - name: http
          containerPort: {{ .Values.agent.service.samplingPort }}
          protocol: TCP
          {{- if .Values.agent.daemonset.useHostPort }}
          hostPort: {{ .Values.agent.service.samplingPort }}
          {{- end }}
        - name: admin
          containerPort: 14271
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /
            port: admin
        readinessProbe:
          httpGet:
            path: /
            port: admin
        resources:
{{ toYaml .Values.agent.resources | indent 10 }}
{{- end -}}
