apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ template "appmesh-jaeger.fullname" . }}
  labels:
{{ include "appmesh-jaeger.labels" . | indent 4 }}
spec:
  replicas: {{ .Values.replicaCount }}
  strategy:
    type: Recreate
  selector:
    matchLabels:
      app.kubernetes.io/name: {{ include "appmesh-jaeger.name" . }}
      app.kubernetes.io/instance: {{ .Release.Name }}
  template:
    metadata:
      labels:
        app.kubernetes.io/name: {{ include "appmesh-jaeger.name" . }}
        app.kubernetes.io/instance: {{ .Release.Name }}
        app.kubernetes.io/part-of: appmesh
      annotations:
        prometheus.io/scrape: "true"
        prometheus.io/port: "14269"
    spec:
      serviceAccountName: {{ include "appmesh-jaeger.serviceAccountName" . }}
      volumes:
      - name: data
        {{- if .Values.persistentVolumeClaim.claimName }}
        persistentVolumeClaim:
          claimName: {{ .Values.persistentVolumeClaim.claimName }}
        {{- else }}
        emptyDir: {}
        {{- end }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
          imagePullPolicy: {{ .Values.image.pullPolicy }}
          ports:
            # agent: accept zipkin.thrift over compact thrift protocol (deprecated, used by legacy clients only)
            - containerPort: 5775
              protocol: UDP
            # agent: accept jaeger.thrift over compact thrift protocol
            - containerPort: 6831
              protocol: UDP
            # agent: accept jaeger.thrift over binary thrift protocol
            - containerPort: 6832
              protocol: UDP
            # collector: Zipkin compatible endpoint
            - containerPort: 9411
              protocol: TCP
            # query: serve frontend
            - containerPort: 16686
              protocol: TCP
            # agent: serve configs
            - containerPort: 5778
              protocol: TCP
            # collector: accept jaeger.thrift directly from clients
            - containerPort: 14268
              protocol: TCP
            # collector: Health Check server
            - containerPort: 14269
              protocol: TCP
          env:
            - name: MEMORY_MAX_TRACES
              value: "{{ .Values.memory.maxTraces }}"
            - name: COLLECTOR_ZIPKIN_HOST_PORT
              value: "9411"
            - name: BADGER_EPHEMERAL
              value: "false"
            - name: SPAN_STORAGE_TYPE
              value: "badger"
            - name: BADGER_DIRECTORY_VALUE
              value: "/badger/data"
            - name: BADGER_DIRECTORY_KEY
              value: "/badger/key"
            - name: QUERY_BASE_PATH
              value:  /jaeger
          livenessProbe:
            httpGet:
              path: /
              port: 14269
            initialDelaySeconds: {{ .Values.probes.liveness.initialDelaySeconds }}
            periodSeconds: {{ .Values.probes.liveness.periodSeconds }}
            timeoutSeconds: {{ .Values.probes.liveness.timeoutSeconds }}
            successThreshold: {{ .Values.probes.liveness.successThreshold }}
            failureThreshold: {{ .Values.probes.liveness.failureThreshold }}
          readinessProbe:
            httpGet:
              path: /
              port: 14269
            initialDelaySeconds: {{ .Values.probes.readiness.initialDelaySeconds }}
            periodSeconds: {{ .Values.probes.readiness.periodSeconds }}
            timeoutSeconds: {{ .Values.probes.readiness.timeoutSeconds }}
            successThreshold: {{ .Values.probes.readiness.successThreshold }}
            failureThreshold: {{ .Values.probes.readiness.failureThreshold }}
          volumeMounts:
            - name: data
              mountPath: /badger
          resources:
{{ toYaml .Values.resources | indent 12 }}
    {{- with .Values.nodeSelector }}
      nodeSelector:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.affinity }}
      affinity:
{{ toYaml . | indent 8 }}
    {{- end }}
    {{- with .Values.tolerations }}
      tolerations:
{{ toYaml . | indent 8 }}
    {{- end }}
