apiVersion: apps/v1
kind: Deployment
metadata:
  name: longhorn-driver-deployer
  namespace: longhorn-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: longhorn-driver-deployer
  template:
    metadata:
      labels:
        app: longhorn-driver-deployer
    spec:
      initContainers:
        - name: wait-longhorn-manager
          image: longhornio/longhorn-manager:master
          command: ['sh', '-c', 'while [ $(curl -m 1 -s -o /dev/null -w "%{http_code}" http://longhorn-backend:9500/v1) != "200" ]; do echo waiting; sleep 2; done']
      containers:
        - name: longhorn-driver-deployer
          image: longhornio/longhorn-manager:master
          imagePullPolicy: Always
          command:
          - longhorn-manager
          - -d
          - deploy-driver
          - --manager-image
          - longhornio/longhorn-manager:master
          - --manager-url
          - http://longhorn-backend:9500/v1
          # manually choose "flexvolume" or "csi"
          #- --driver
          #- flexvolume
          # manually set root directory for flexvolume
          #- --flexvolume-dir
          #- /usr/libexec/kubernetes/kubelet-plugins/volume/exec/
          # manually set root directory for csi
          #- --kubelet-root-dir
          #- /var/lib/rancher/k3s/agent/kubelet
          # manually specify number of CSI attacher replicas
          #- --csi-attacher-replica-count
          #- "3"
          # manually specify number of CSI provisioner replicas
          #- --csi-provisioner-replica-count
          #- "3"
          env:
          - name: POD_NAMESPACE
            valueFrom:
              fieldRef:
                fieldPath: metadata.namespace
          - name: NODE_NAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
          - name: SERVICE_ACCOUNT
            valueFrom:
              fieldRef:
                fieldPath: spec.serviceAccountName
          # For auto detection, leave this parameter unset
          #- name: FLEXVOLUME_DIR
            # FOR RKE
            #value: "/var/lib/kubelet/volumeplugins"
            # FOR GKE
            #value: "/home/kubernetes/flexvolume/"
      serviceAccountName: longhorn-service-account
