apiVersion: apps/v1
kind: Deployment
metadata:
  name: drycc-monitor-telegraf
  labels:
    heritage: drycc
  annotations:
    component.drycc.cc/version: {{ .Values.telegraf.imageTag }}
spec:
  replicas: 1
  selector:
    matchLabels:
      app: drycc-monitor-telegraf
  {{- if ge .Capabilities.KubeVersion.Minor "6" }}
  updateStrategy:
    type: RollingUpdate
  {{- end }}
  template:
    metadata:
      labels:
        app: drycc-monitor-telegraf
    spec:
      affinity:
        podAffinity: {{- include "common.affinities.pods" (dict "type" .Values.telegraf.podAffinityPreset.type "key" .Values.telegraf.podAffinityPreset.key "values" .Values.telegraf.podAffinityPreset.values ) | nindent 10 }}
        podAntiAffinity: {{- include "common.affinities.pods" (dict "type" .Values.telegraf.podAntiAffinityPreset.type "key" .Values.telegraf.podAntiAffinityPreset.key "values" .Values.telegraf.podAntiAffinityPreset.values ) | nindent 10 }}
        nodeAffinity: {{- include "common.affinities.nodes" (dict "type" .Values.telegraf.nodeAffinityPreset.type "key" .Values.telegraf.nodeAffinityPreset.key "values" .Values.telegraf.nodeAffinityPreset.values ) | nindent 10 }}
      securityContext:
        fsGroup: 1001
        runAsGroup: 1001
        runAsUser: 1001
      serviceAccount: drycc-monitor-telegraf
      initContainers:
      - name: drycc-monitor-telegraf-init
        image: {{.Values.telegraf.imageRegistry}}/{{.Values.telegraf.imageOrg}}/python-dev:latest
        imagePullPolicy: {{.Values.imagePullPolicy}}
        args:
          - netcat
          - -v
          - -u
          - $(INFLUXDB_URLS_V2)
          - -g
          - $(DRYCC_STORAGE_HEALTH)
          - -a
          - $(DRYCC_REDIS_ADDRS),$(DRYCC_STORAGE_PD_ADDRS),$(DRYCC_STORAGE_TIKV_ADDRS)
        {{- include "telegraf.deployment.envs" . | indent 8 }}
      containers:
      - name: drycc-monitor-telegraf
        image: {{.Values.telegraf.imageRegistry}}/{{.Values.telegraf.imageOrg}}/telegraf:{{.Values.telegraf.imageTag}}
        imagePullPolicy: {{.Values.telegraf.imagePullPolicy}}
{{- if or (.Values.telegraf.limitsCpu) (.Values.telegraf.limitsMemory)}}
        resources:
          limits:
{{- if (.Values.telegraf.limitsCpu) }}
            cpu: {{.Values.telegraf.limitsCpu}}
{{- end}}
{{- if (.Values.telegraf.limitsMemory) }}
            memory: {{.Values.telegraf.limitsMemory}}
{{- end}}
{{- end}}
        {{- include "telegraf.deployment.envs" . | indent 8 }}
