# Copyright 2021 Nutanix Inc
# 
# example usage: kubectl create -f <this_file>

kind: StatefulSet
apiVersion: apps/v1
metadata:
  name: csi-provisioner-ntnx-plugin
  namespace: kube-system
spec:
  serviceName: csi-provisioner-ntnx-plugin
  replicas: 1
  selector:
    matchLabels:
      app: csi-provisioner-ntnx-plugin
  template:
    metadata:
      labels:
        app: csi-provisioner-ntnx-plugin
    spec:
      serviceAccount: csi-provisioner
      containers:
      - name: csi-provisioner
        image: k8s.gcr.io/sig-storage/csi-provisioner:v2.2.0
        args:
        - --csi-address=$(ADDRESS)
        - --timeout=60s
        - --worker-threads=16
        # This adds PV/PVC metadata to create volume requests
        - --extra-create-metadata=true
        - --default-fstype=ext4
        # This is used to collect CSI operation metrics
        - --http-endpoint=:9809
        - --v=5
        env:
        - name: ADDRESS
          value: /var/lib/csi/sockets/pluginproxy/csi.sock
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: socket-dir
          mountPath: /var/lib/csi/sockets/pluginproxy/
      - name: csi-resizer
        image: k8s.gcr.io/sig-storage/csi-resizer:v1.2.0
        args:
        - --v=5
        - --csi-address=$(ADDRESS)
        - --timeout=60s
        - --leader-election=false
        # NTNX CSI dirver supports online volume expansion.
        - --handle-volume-inuse-error=false
        - --http-endpoint=:9810
        env:
        - name: ADDRESS
          value: /var/lib/csi/sockets/pluginproxy/csi.sock
        imagePullPolicy: IfNotPresent
        volumeMounts:
        - name: socket-dir
          mountPath: /var/lib/csi/sockets/pluginproxy/
      - name: csi-snapshotter
        image: quay.io/k8scsi/csi-snapshotter:v2.1.0
        args:
        - --csi-address=$(ADDRESS)
        - --leader-election=false
        - --logtostderr=true
        env:
        - name: ADDRESS
          value: /csi/csi.sock
        volumeMounts:
        - name: socket-dir
          mountPath: /csi
      - name: ntnx-csi-plugin
        image: quay.io/karbon/ntnx-csi:v2.4.1
        securityContext:
          allowPrivilegeEscalation: true
          privileged: true
        args:
        - --endpoint=$(CSI_ENDPOINT)
        - --nodeid=$(NODE_ID)
        env:
        - name: CSI_ENDPOINT
          value: unix:///var/lib/csi/sockets/pluginproxy/csi.sock
        - name: NODE_ID
          valueFrom:
            fieldRef:
              fieldPath: spec.nodeName
        volumeMounts:
        - mountPath: /var/lib/csi/sockets/pluginproxy/
          name: socket-dir
        # This is needed for static NFS volume feature.
        - mountPath: /host
          name: root-dir
        ports:
        - containerPort: 9808
          name: http-endpoint
          protocol: TCP
        livenessProbe:
          httpGet:
            path: /healthz
            port: http-endpoint
          initialDelaySeconds: 10
          timeoutSeconds: 3
          periodSeconds: 2
          failureThreshold: 3
      - name: liveness-probe
        volumeMounts:
          - mountPath: /csi
            name: socket-dir
        image: k8s.gcr.io/sig-storage/livenessprobe:v2.3.0
        args:
        - --csi-address=/csi/csi.sock
        - --http-endpoint=:9808
      volumes:
      - emptyDir: {}
        name: socket-dir
      - hostPath:
          path: /
          type: Directory
        name: root-dir
