apiVersion: apps/v1
kind: DaemonSet
metadata:
  name: client
  namespace: quobyte
spec:
  # operator requires 'OnDelete' strategy
  updateStrategy:
    type: 'OnDelete'
  selector:
    matchLabels:
     # operator currently supports only single label
      role: client
  template:
    metadata:
      annotations:
        prometheus.io/scrape: 'true'
        prometheus.io/path: '/prometheus'
        prometheus.io/port: '55000'
        # operator requires this flag.
        quobyteClient: 'true'
      labels:
        role: client
        version: "2"
    spec:
      # operator uses tain while upgrading the client image
      tolerations:
        - key: "quobyte-upgrade"
          operator: "Equal"
          value: "true"
          effect: "NoSchedule"
      containers:
      - name: quobyte-client
        image: quay.io/quobyte/quobyte-client:2
        imagePullPolicy: Always
        env:
          - name: QUOBYTE_CLIENT_LOG_LEVEL
            value: INFO
          - name: QUOBYTE_REGISTRY
            value: registry.quobyte
          - name: QUOBYTE_MOUNT_POINT
            # Note that the mount point has to be a subdir of the volume(Mount)
            value: /mnt/kubernetes.io~quobyte
          - name: NODENAME
            valueFrom:
              fieldRef:
                fieldPath: spec.nodeName
        ports:
          - name: http-port
            containerPort: 55000
            hostPort: 55000
            protocol: TCP
        readinessProbe:
          timeoutSeconds: 5
          httpGet:
            port: 55000
            path: /
        livenessProbe:
          initialDelaySeconds: 30
          timeoutSeconds: 5
          httpGet:
            port: 55000
            path: /
        command:
          - /bin/bash
          - -xec
          - |
            if cut -d" " -f2 /proc/self/mounts | grep -q ${QUOBYTE_MOUNT_POINT}; then
              umount -l ${QUOBYTE_MOUNT_POINT}
            fi

            mkdir -p /root/.quobyte ${QUOBYTE_MOUNT_POINT}

            # set the mount point immutable. As long as mount.quobyte does not run,
            # other processes cannot write data to this dir.
            chattr +i ${QUOBYTE_MOUNT_POINT} || \
              echo "WARNING: The local filesystem does not support IMMUTABLE flag"

            /usr/bin/mount.quobyte --hostname ${NODENAME} \
              --allow-usermapping-in-volumename --http-port 55000 -f \
              -d ${QUOBYTE_CLIENT_LOG_LEVEL} -l /dev/stdout ${OPTS} \
              ${QUOBYTE_REGISTRY}/ ${QUOBYTE_MOUNT_POINT}
        securityContext:
          privileged: true
        volumeMounts:
          - name: k8s-plugin-dir
            mountPath: /mnt
            mountPropagation: Bidirectional
        lifecycle:
          preStop:
            exec:
              command: ["/bin/bash", "-xc", "umount -l ${QUOBYTE_MOUNT_POINT}"]
      nodeSelector:
        # operator currently supports only single selector
        quobyte_client: "true"
      volumes:
      - name: k8s-plugin-dir
        hostPath:
          path: /var/lib/kubelet/plugins/
