apiVersion: apps/v1
kind: StatefulSet
metadata:
  labels:
    app.kubernetes.io/component: controller
    app.kubernetes.io/name: p5x-controller
  name: p5x-controller
  namespace: p5x-system
spec:
  replicas: 1
  selector:
    matchLabels:
      app: p5x-csi-controller
  serviceName: p5x-csi-controller
  template:
    metadata:
      labels:
        app: p5x-csi-controller
    spec:
      priorityClassName: system-cluster-critical
      serviceAccountName: p5x-csi-controller
      tolerations:
        - key: CriticalAddonsOnly
          operator: Exists
      volumes:
        - emptyDir: {}
          name: socket-dir
      containers:
        - name: csi-plugin
          args:
            - --endpoint=$(CSI_ENDPOINT)
#            - --logtostderr
            - --nodeid=$(NODE_NAME)
            - --p5x-endpoint=http://172.20.0.22
            - --p5x-token=1
          env:
            - name: CSI_ENDPOINT
              value: unix:///var/lib/csi/sockets/pluginproxy/csi.sock
            - name: NODE_NAME
              valueFrom:
                fieldRef:
                  fieldPath: spec.nodeName
          image: registry.millslan.net/p5x-csi:latest
          livenessProbe:
            failureThreshold: 5
            httpGet:
              path: /healthz
              port: healthz
            initialDelaySeconds: 10
            periodSeconds: 10
            timeoutSeconds: 3
          ports:
            - containerPort: 9909
              name: healthz
              protocol: TCP
          securityContext:
            capabilities:
              add:
                - SYS_ADMIN
            privileged: true
          volumeMounts:
            - mountPath: /var/lib/csi/sockets/pluginproxy/
              name: socket-dir


        - name: csi-provisioner
          args:
            - --csi-address=$(ADDRESS)
            - --timeout=60s
            - --v=5
          env:
            - name: ADDRESS
              value: /var/lib/csi/sockets/pluginproxy/csi.sock
          image: registry.k8s.io/sig-storage/csi-provisioner:v3.6.0
          volumeMounts:
            - mountPath: /var/lib/csi/sockets/pluginproxy/
              name: socket-dir


        - name: csi-attacher
          args:
            - --csi-address=$(ADDRESS)
            - --timeout=60s
            - --v=5
          env:
            - name: ADDRESS
              value: /var/lib/csi/sockets/pluginproxy/csi.sock
          image: registry.k8s.io/sig-storage/csi-attacher:v4.4.0
          volumeMounts:
            - mountPath: /var/lib/csi/sockets/pluginproxy/
              name: socket-dir


        - name: liveness-probe
          args:
            - --csi-address=$(ADDRESS)
            - --health-port=$(HEALTH_PORT)
          env:
            - name: ADDRESS
              value: /csi/csi.sock
            - name: HEALTH_PORT
              value: "9909"
          image: quay.io/k8scsi/livenessprobe:v1.1.0
          volumeMounts:
            - mountPath: /csi
              name: socket-dir