apiVersion: v1
kind: ServiceAccount
metadata:
  name: rdma-shared-dp-sa
  namespace: kube-system
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
  name: rdma-shared-dp-cm-role
  namespace: kube-system
rules:
  - apiGroups: [""]
    resources: ["configmaps"]
    verbs: ["get", "create", "update", "delete", "list", "watch"]
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: rdma-shared-dp-cm-rb
  namespace: kube-system
roleRef:
  apiGroup: rbac.authorization.k8s.io
  kind: Role
  name: rdma-shared-dp-cm-role
subjects:
  - kind: ServiceAccount
    name: rdma-shared-dp-sa
    namespace: kube-system
---
apiVersion: v1
kind: ConfigMap
metadata:
  name: rdma-devices
  namespace: kube-system
data:
  config.json: |
    {
      "periodicUpdateInterval": 300,
      "faultDetectPeriod": 5,
      "configList": [
        {
          "resourcePrefix": "huawei.com",
          "resourceName": "ub_rdma",
          "rdmaHcaMax": 8,
          "selectors": {
            "buses": ["ub"],
            "vendors": ["0xcc08"],
            "deviceIDs": ["0x8200"]
          }
        }
      ]
    }
---
apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: rdma-shared-dp-ds
  namespace: kube-system
spec:
  selector:
    matchLabels:
      name: rdma-shared-dp-ds
  template:
    metadata:
      labels:
        name: rdma-shared-dp-ds
    spec:
      hostNetwork: true
      priorityClassName: system-node-critical
      serviceAccountName: rdma-shared-dp-sa
      nodeSelector:
        workerselector: dls-worker-node # for node with atlas 950/850 use ,the node must have ub rdma
      initContainers:
        - name: init-log-setup
          image: k8s-rdma-shared-dp:v26.0.0
          command: ['sh', '-c', 'mkdir -p /var/log/mindx-dl && chmod 755 /var/log/mindx-dl && chown root:root /var/log/mindx-dl && mkdir -p /var/log/mindx-dl/k8s-rdma-shared-dp && chmod 750 /var/log/mindx-dl/k8s-rdma-shared-dp && chown root:root /var/log/mindx-dl/k8s-rdma-shared-dp']
          securityContext:
            runAsUser: 0
            runAsNonRoot: false
          volumeMounts:
            - name: log-k8s-rdma-shared-dp
              mountPath: /var/log
      containers:
        - image: k8s-rdma-shared-dp:v26.0.0
          name: k8s-rdma-shared-dp-ds
          imagePullPolicy: IfNotPresent
          securityContext:
            privileged: true
            readOnlyRootFilesystem: true
          volumeMounts:
            - name: device-plugin
              mountPath: /var/lib/kubelet/device-plugins
            - name: config
              mountPath: /k8s-rdma-shared-dev-plugin
            - name: devs
              mountPath: /dev/
            - name: sys
              mountPath: /sys
            - name: infiniband
              mountPath: /dev/infiniband
            - name: log-k8s-rdma-shared-dp
              mountPath: /var/log/mindx-dl/k8s-rdma-shared-dp
              subPath: mindx-dl/k8s-rdma-shared-dp
            - name: hinicadmdfx5
              mountPath: /usr/bin/hinicadmdfx5
              readOnly: true
            - name: hinic-log
              mountPath: /var/log/hinic5
          env:
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
      volumes:
        - name: device-plugin
          hostPath:
            path: /var/lib/kubelet/device-plugins
        - name: config
          configMap:
            name: rdma-devices
            items:
              - key: config.json
                path: config.json
        - name: devs
          hostPath:
            path: /dev/
            type: Directory
        - name: sys
          hostPath:
            path: /sys/
        - name: infiniband
          hostPath:
            path: /dev/infiniband/
        - name: log-k8s-rdma-shared-dp
          hostPath:
            path: /var/log
            type: Directory
        - name: hinicadmdfx5
          hostPath:
            path: /usr/bin/hinicadmdfx5
            type: File
        - name: hinic-log
          hostPath:
            path: /var/log/hinic5
            type: DirectoryOrCreate