kind: DaemonSet
apiVersion: apps/v1
metadata:
  name: openstack-manila-csi-nodeplugin
  labels:
    app: openstack-manila-csi
    component: nodeplugin
spec:
  selector:
    matchLabels:
      app: openstack-manila-csi
      component: nodeplugin
  template:
    metadata:
      labels:
        app: openstack-manila-csi
        component: nodeplugin
    spec:
      serviceAccountName: openstack-manila-csi-nodeplugin
      hostNetwork: true
      dnsPolicy: ClusterFirstWithHostNet
      containers:
        - name: registrar
          image: "quay.io/k8scsi/csi-node-driver-registrar:v1.1.0"
          args:
            - "--v=5"
            - "--csi-address=/csi/csi.sock"
            - "--kubelet-registration-path=/var/lib/kubelet/plugins/manila.csi.openstack.org/csi.sock"
          lifecycle:
            preStop:
              exec:
                  command: [
                    "/bin/sh", "-c",
                    'rm -rf /registration/manila.csi.openstack.org
                  /registration/manila.csi.openstack.org-reg.sock'
                  ]
          env:
            - name: KUBE_NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: plugin-dir
              mountPath: /csi
            - name: registration-dir
              mountPath: /registration
        - name: nodeplugin
          securityContext:
            privileged: true
            capabilities:
              add: ["SYS_ADMIN"]
            allowPrivilegeEscalation: true
          image: "k8scloudprovider/manila-csi-plugin:latest"
          command: ["/bin/sh", "-c",
            '/bin/manila-csi-plugin
            --v=5
            --nodeid=$(NODE_ID)
            --endpoint=$(CSI_ENDPOINT)
            --drivername=$(DRIVER_NAME)
            --share-protocol-selector=$(MANILA_SHARE_PROTO)
            --fwdendpoint=$(FWD_CSI_ENDPOINT)'
            # To enable topology awareness and retrieve compute node AZs from the OpenStack Metadata Service, add the following flags:
            # --with-topology
            # --nodeaz=$(curl http://169.254.169.254/openstack/latest/meta_data.json | jq -r .availability_zone)
            # Those flags need to be added to csi-controllerplugin.yaml as well.
          ]
          env:
            - name: DRIVER_NAME
              value: manila.csi.openstack.org
            - name: NODE_ID
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
            - name: CSI_ENDPOINT
              value: "unix:///var/lib/kubelet/plugins/manila.csi.openstack.org/csi.sock"
            - name: FWD_CSI_ENDPOINT
              value: "unix:///var/lib/kubelet/plugins/FWD-NODEPLUGIN/csi.sock"
            - name: MANILA_SHARE_PROTO
              value: "SHARE-PROTOCOL"
          imagePullPolicy: IfNotPresent
          volumeMounts:
            - name: plugin-dir
              mountPath: /var/lib/kubelet/plugins/manila.csi.openstack.org
            - name: fwd-plugin-dir
              mountPath: /var/lib/kubelet/plugins/FWD-NODEPLUGIN
      volumes:
        - name: registration-dir
          hostPath:
            path: /var/lib/kubelet/plugins_registry
            type: Directory
        - name: plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins/manila.csi.openstack.org
            type: DirectoryOrCreate
        - name: fwd-plugin-dir
          hostPath:
            path: /var/lib/kubelet/plugins/FWD-NODEPLUGIN
            type: DirectoryOrCreate

