{{ if semverCompare ">=1.17-0" .Capabilities.KubeVersion.GitVersion }}
apiVersion: rbac.authorization.k8s.io/v1
{{ else }}
apiVersion: rbac.authorization.k8s.io/v1beta1
{{ end }}
kind: ClusterRoleBinding
metadata:
  name: topology-agent
  namespace: imxc
  labels:
    k8s-app: topology-agent
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: ClusterRole
  name: cluster-admin
subjects:
  - kind: ServiceAccount
    name: topology-agent
    namespace: imxc
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: topology-agent
  namespace: imxc
  labels:
    app: topology-agent
spec:
  selector:
    matchLabels:
      app: topology-agent
  template:
    metadata:
      labels:
        app: topology-agent
    spec:
      hostNetwork: true
      hostPID: true
      dnsPolicy: ClusterFirstWithHostNet
      # below appended
      hostPID: true
      tolerations:
      - effect: NoSchedule
        operator: Exists
      - effect: NoExecute
        operator: Exists
      containers:
        - image: {{ .Values.global.IMXC_IN_REGISTRY }}/node-exporter
          name: node-agent
          resources:
            limits:
              cpu: 250m
              memory: 180Mi
            requests:
              cpu: 125m
              memory: 90Mi
          ports:
          - containerPort: 9100
            hostPort: 9100
            name: scrape
          args:
          - --path.procfs=/host/proc
          - --path.sysfs=/host/sys
          - --path.rootfs=/host/root
          - --collector.filesystem.ignored-mount-points=^/(dev|proc|sys|run|var/lib/docker/.+|var/lib/kubelet/pods/.+)($|/)
          - --collector.tcpstat
          # --log.level=debug
          env:
          - name: GOMAXPROCS
            value: "1"
          volumeMounts:
          - mountPath: /host/proc
            name: proc-volume
            readOnly: false
          - mountPath: /host/sys
            name: sys-volume
            readOnly: false
          - mountPath: /host/root
            mountPropagation: HostToContainer
            name: root-volume
            readOnly: true
        - name: topology-agent
          image: {{ .Values.global.IMXC_IN_REGISTRY }}/topology-agent:{{ .Values.global.TOPOLOGY_AGENT_VERSION }}
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
          volumeMounts:
            - mountPath: /host/usr/bin
              name: bin-volume
            - mountPath: /var/run/docker.sock
              name: docker-volume
            - mountPath: /host/proc
              name: proc-volume
            - mountPath: /root
              name: root-volume
          env:
            - name: CLUSTER_ID
              value: cloudmoa
            - name: ROOT_DIRECTORY
              value: /root
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  apiVersion: v1
                  fieldPath: spec.nodeName
            - name: POD_ID
              valueFrom:
                fieldRef:
                  fieldPath: metadata.name
            - name: NAMESPACE
              valueFrom:
                 fieldRef:
                   fieldPath: metadata.namespace
            - name: DATAGATE
              value: datagate:50051
            - name: LOG_RNAME_USE
              value: "false"
            - name: LOG_LEVEL
              value: "DEBUG"
            - name: CLOUDMOA_SETTING_PATH
              value: /home/cloudmoa/setting/
          resources:
            requests:
              memory: "125Mi"
              cpu: "100m"
            limits:
              memory: "600Mi"
              cpu: "500m"
      volumes:
        - name: bin-volume
          hostPath:
            path: /usr/bin
            type: Directory
        - name: docker-volume
          hostPath:
            path: /var/run/docker.sock
        - name: proc-volume
          hostPath:
            path: /proc
        - name: root-volume
          hostPath:
            path: /
        - hostPath:
            path: /sys
          name: sys-volume