diff --git a/src/csi/driver/identity.go b/src/csi/driver/identity.go index b6868e09..7746d128 100644 --- a/src/csi/driver/identity.go +++ b/src/csi/driver/identity.go @@ -2,9 +2,12 @@ package driver import ( "context" + "fmt" + "utils" "utils/log" "github.com/container-storage-interface/spec/lib/go/csi" + "github.com/golang/protobuf/ptypes/wrappers" ) func (d *Driver) GetPluginInfo(ctx context.Context, req *csi.GetPluginInfoRequest) (*csi.GetPluginInfoResponse, error) { @@ -32,6 +35,17 @@ func (d *Driver) GetPluginCapabilities(ctx context.Context, req *csi.GetPluginCa } func (d *Driver) Probe(ctx context.Context, req *csi.ProbeRequest) (*csi.ProbeResponse, error) { - log.Infof("Probe plugin %v", *d) - return &csi.ProbeResponse{}, nil + + log.Infof("Probe the csi-driver plugin %v", *d) + bootstrap := utils.GetBootStrap() + + if !bootstrap { + return &csi.ProbeResponse{}, fmt.Errorf("Bootstarp is false") + } + resp := &csi.ProbeResponse{ + Ready: &wrappers.BoolValue{Value: bootstrap}, + } + + return resp, nil + } diff --git a/src/csi/main.go b/src/csi/main.go index 4cd9a617..16ad557d 100644 --- a/src/csi/main.go +++ b/src/csi/main.go @@ -64,7 +64,7 @@ type CSIConfig struct { } type CSISecret struct { - Secrets map[string]interface{} `json:"secrets"` + Secrets map[string]interface{} `json:"secrets"` } func init() { @@ -208,6 +208,10 @@ func main() { csi.RegisterNodeServer(server, d) log.Infof("Starting Huawei CSI driver, listening on %s", *endpoint) + + // set the bootstarp value as true bcz here csi driver would be ready + utils.SetBootStrap(true) + if err := server.Serve(listener); err != nil { log.Fatalf("Start Huawei CSI driver error: %v", err) } diff --git a/src/utils/utils.go b/src/utils/utils.go index 265fe361..e03680b3 100644 --- a/src/utils/utils.go +++ b/src/utils/utils.go @@ -38,15 +38,24 @@ const ( V5Version = "V500" ) +var bootstrap bool var maskObject = []string{"user", "password", "iqn", "tgt", "tgtname", "initiatorname"} type VolumeMetrics struct { - Available *resource.Quantity - Capacity *resource.Quantity + Available *resource.Quantity + Capacity *resource.Quantity InodesUsed *resource.Quantity - Inodes *resource.Quantity + Inodes *resource.Quantity InodesFree *resource.Quantity - Used *resource.Quantity + Used *resource.Quantity +} + +func GetBootStrap() bool { + return bootstrap +} + +func SetBootStrap(value bool) { + bootstrap = value } func PathExist(path string) (bool, error) { diff --git a/yamls/deploy/huawei-csi-controller-probe.yaml b/yamls/deploy/huawei-csi-controller-probe.yaml new file mode 100644 index 00000000..3e1ab0a7 --- /dev/null +++ b/yamls/deploy/huawei-csi-controller-probe.yaml @@ -0,0 +1,99 @@ +--- +kind: Deployment +apiVersion: apps/v1 +metadata: + name: huawei-csi-controller + namespace: kube-system +spec: + replicas: 1 + selector: + matchLabels: + app: huawei-csi-controller + template: + metadata: + labels: + app: huawei-csi-controller + spec: + serviceAccount: huawei-csi-controller + hostNetwork: true + containers: + - name: liveness-probe + image: k8s.gcr.io/sig-storage/livenessprobe:v2.4.0 + args: + - --csi-address=/var/lib/csi/sockets/pluginproxy/csi.sock + imagePullPolicy: "IfNotPresent" + volumeMounts: + - mountPath: /var/lib/csi/sockets/pluginproxy/ + name: socket-dir + + - name: csi-provisioner + image: quay.io/k8scsi/csi-provisioner:v1.6.0 + args: + - "--csi-address=$(ADDRESS)" + - "--timeout=6h" + 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-attacher + image: quay.io/k8scsi/csi-attacher:v1.2.1 + args: + - "--csi-address=$(ADDRESS)" + env: + - name: ADDRESS + value: /var/lib/csi/sockets/pluginproxy/csi.sock + imagePullPolicy: "IfNotPresent" + volumeMounts: + - name: socket-dir + mountPath: /var/lib/csi/sockets/pluginproxy/ + + - name: huawei-csi-driver + image: huawei-csi:*.*.* + args: + - "--endpoint=$(CSI_ENDPOINT)" + - "--controller" + - "--containerized" + - "--driver-name=csi.huawei.com" + env: + - name: CSI_ENDPOINT + value: /var/lib/csi/sockets/pluginproxy/csi.sock + imagePullPolicy: "IfNotPresent" + ports: + - containerPort: 9808 + name: healthz + protocol: TCP + # The probe + livenessProbe: + failureThreshold: 5 + httpGet: + path: /healthz + port: healthz + initialDelaySeconds: 10 + timeoutSeconds: 3 + periodSeconds: 10 + volumeMounts: + - name: socket-dir + mountPath: /var/lib/csi/sockets/pluginproxy/ + - name: log + mountPath: /var/log + - name: config-map + mountPath: /etc/huawei + - name: secret + mountPath: /etc/huawei/secret + volumes: + - name: socket-dir + emptyDir: + - name: log + hostPath: + path: /var/log/ + type: Directory + - name: config-map + configMap: + name: huawei-csi-configmap + - name: secret + secret: + secretName: huawei-csi-secret