{{- if eq ( tpl $.Values.deployMode . ) "process" }}
apiVersion: apps/v1
kind: Deployment
metadata:
  name: {{ include "deepflow-agent.fullname" . }}-watcher
  labels:
    {{- include "deepflow-agent.labels" . | nindent 4 }}
spec:
  replicas: 1
  selector:
    matchLabels:
      {{- include "deepflow-agent.selectorLabels" . | nindent 6 }}
  template:
    metadata:
      annotations:
        checksum/config: {{ include (print $.Template.BasePath "/configmap.yaml") . | sha256sum }}
        checksum/customConfig: {{ sha256sum (print .Values.deepflowAgentConfig) }}
        container.apparmor.security.beta.kubernetes.io/deepflow-agent: unconfined
      {{- with .Values.podAnnotations }}
        {{- toYaml . | nindent 8 }}
      {{- end }}
      labels:
        {{- include "deepflow-agent.selectorLabels" . | nindent 8 }}
        {{- with .Values.podLabels }}
        {{- toYaml . | nindent 8 }}
        {{- end }}
    spec:
      dnsPolicy: ClusterFirst
      imagePullSecrets:
      {{- with .Values.global.imagePullSecrets }}
        {{- toYaml . | nindent 8 }}
      {{- end }}
      {{- with .Values.imagePullSecrets }}
        {{- toYaml . | nindent 8 }}
      {{- end }}
      serviceAccountName: {{ include "deepflow-agent.fullname" . }}
      containers:
        - name: {{ .Chart.Name }}
          image: "{{ tpl .Values.image.repository . }}:{{ tpl (toString .Values.image.tag) . }}"
          imagePullPolicy: {{ tpl .Values.image.pullPolicy . }}
          ports:
            - name: receive
              containerPort: {{ tpl (toString .Values.externalAgentHttpProxyPort) . }}
              protocol: TCP
          # livenessProbe:
          #   tcpSocket:
          #     port: otel
          #   initialDelaySeconds: 5
          #   periodSeconds: 10
          # readinessProbe:
          #   tcpSocket:
          #     port: otel
          #   initialDelaySeconds: 5
          #   periodSeconds: 10
          env:
          - name: ONLY_WATCH_K8S_RESOURCE
            value: "true"
          resources:
            {{- toYaml .Values.resources | nindent 12 }}
          volumeMounts:
            - name: deepflow-agent-conf
              mountPath: /etc/deepflow-agent
      volumes:
        - name: deepflow-agent-conf
          configMap:
            name: {{ include "deepflow-agent.fullname" . }}
      {{- with .Values.nodeSelector }}
      nodeSelector:
        {{- toYaml . | nindent 8 }}
      {{- end }}
      affinity:
      {{- include "nodeaffinity" . | indent 6 }}
      {{- include "podAffinity" . | indent 6 }}
      {{- include "podAntiAffinity" . | indent 6 }}
      {{- if or .Values.global.tolerations .Values.tolerations }}
      tolerations:
      {{- if .Values.global.tolerations }}
      {{- toYaml .Values.global.tolerations | nindent 8 }}
      {{- end }}
      {{- if .Values.tolerations }}
      {{- toYaml .Values.tolerations | nindent 8 }}
      {{- end }}
      {{- end }}
{{- end }}
