From 74b515785ed584cf0cc7578dd2f0b3ef72a78baa Mon Sep 17 00:00:00 2001 From: lmq1999 Date: Mon, 30 Aug 2021 16:31:28 +0700 Subject: [PATCH 1/5] Add PVC name and PVC namespace when CreateVolume --- cmd/csi-bizflycloud/main.go | 4 ++-- driver/client.go | 2 +- driver/controller.go | 8 ++++++-- examples/pv-pod.yaml | 19 +++++++++++++++++++ examples/pvc.yml | 4 ++-- go.mod | 2 +- go.sum | 12 ++---------- 7 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 examples/pv-pod.yaml diff --git a/cmd/csi-bizflycloud/main.go b/cmd/csi-bizflycloud/main.go index 5c135c5..82942bb 100644 --- a/cmd/csi-bizflycloud/main.go +++ b/cmd/csi-bizflycloud/main.go @@ -158,8 +158,8 @@ func handle() { klog.Errorf("Failed to get bizfly client token: %v", err) return } - - client.SetKeystoneToken(tok.KeystoneToken) + + client.SetKeystoneToken(tok) d.SetupControlDriver(client, iMount, metadatda) d.Run() } else { diff --git a/driver/client.go b/driver/client.go index a4eccc6..597a380 100644 --- a/driver/client.go +++ b/driver/client.go @@ -130,7 +130,7 @@ func diskIsAttached(ctx context.Context, client *gobizfly.Client, serverId strin } func GetSnapshotByNameAndVolumeID(ctx context.Context, client *gobizfly.Client, volumeId string, name string) ([]*gobizfly.Snapshot, error) { - snapshots, err := client.Snapshot.List(ctx, &gobizfly.ListOptions{}) + snapshots, err := client.Snapshot.List(ctx, &gobizfly.ListSnasphotsOptions{}) if err != nil { return nil, err } diff --git a/driver/controller.go b/driver/controller.go index 9053fd3..d36db23 100644 --- a/driver/controller.go +++ b/driver/controller.go @@ -72,7 +72,10 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol // Volume Availability - Default is nova volAvailability = req.GetParameters()["availability"] } - + volPVCName := req.GetParameters()["csi.storage.k8s.io/pvc/name"] + volPVCNamespace := req.GetParameters()["csi.storage.k8s.io/pvc/namespace"] + Description := "bke_pvc_name: " + volPVCName + " ; bke_namespaces: " + volPVCNamespace + fmt.Println(Description) client := cs.Client // Verify a volume with the provided name doesn't already exist for this tenant @@ -106,6 +109,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol AvailabilityZone: volAvailability, SnapshotID: snapshotID, VolumeCategory: volCategory, + Description: Description, } vol, err := cs.Client.Volume.Create(ctx, &vcr) if err != nil { @@ -405,7 +409,7 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap return nil, status.Error(codes.Internal, fmt.Sprintf("ListSnapshots get snapshot failed with error %v", err)) } } else { - vlist, err = cs.Client.Snapshot.List(ctx, &gobizfly.ListOptions{}) + vlist, err = cs.Client.Snapshot.List(ctx, &gobizfly.ListSnasphotsOptions{}) if err != nil { klog.V(3).Infof("Failed to ListSnapshots: %v", err) return nil, status.Error(codes.Internal, fmt.Sprintf("ListSnapshots get snapshot failed with error %v", err)) diff --git a/examples/pv-pod.yaml b/examples/pv-pod.yaml new file mode 100644 index 0000000..1638e27 --- /dev/null +++ b/examples/pv-pod.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Pod +metadata: + name: task-pv-pod +spec: + volumes: + - name: task-pv-storage + persistentVolumeClaim: + claimName: task-pv-claim + containers: + - name: task-pv-container + image: nginx + ports: + - containerPort: 80 + name: "http-server" + volumeMounts: + - mountPath: "/usr/share/nginx/html" + name: task-pv-storage + diff --git a/examples/pvc.yml b/examples/pvc.yml index 8c7abbf..67fafad 100644 --- a/examples/pvc.yml +++ b/examples/pvc.yml @@ -1,12 +1,12 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: demo-pvc + name: task-pv-claim spec: accessModes: - ReadWriteOnce volumeMode: Filesystem resources: requests: - storage: 50Gi + storage: 5Gi storageClassName: premium-hdd diff --git a/go.mod b/go.mod index 450742f..f18255d 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/bizflycloud/csi-bizflycloud go 1.14 require ( - github.com/bizflycloud/gobizfly v0.0.0-20200925081217-c929a1f56559 + github.com/bizflycloud/gobizfly v0.0.0-20210826035312-56219bf93eb1 github.com/container-storage-interface/spec v1.2.0 github.com/golang/protobuf v1.4.1 github.com/spf13/cobra v1.0.0 diff --git a/go.sum b/go.sum index 8bebd94..d18c389 100644 --- a/go.sum +++ b/go.sum @@ -57,16 +57,8 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs= github.com/bifurcation/mint v0.0.0-20180715133206-93c51c6ce115/go.mod h1:zVt7zX3K/aDCk9Tj+VM7YymsX66ERvzCJzw8rFCX2JU= -github.com/bizflycloud/gobizfly v0.0.0-20200509022858-1dd705ff35b3 h1:3195YbHKzPFwKiRPXD75xUu0S3MWiCeSTr7liXqNoc0= -github.com/bizflycloud/gobizfly v0.0.0-20200509022858-1dd705ff35b3/go.mod h1:2otUgZd6PrKezjMrdAw9gy7byEXMrigX9Sm4ujCaFuk= -github.com/bizflycloud/gobizfly v0.0.0-20200514081735-03c430a0585b h1:9DaY0hAkK/PGs12481LXTyFmuGKfkW6u7VPsyRXuPHk= -github.com/bizflycloud/gobizfly v0.0.0-20200514081735-03c430a0585b/go.mod h1:2otUgZd6PrKezjMrdAw9gy7byEXMrigX9Sm4ujCaFuk= -github.com/bizflycloud/gobizfly v0.0.0-20200610135315-1b3e23893213 h1:Ihr811tiEnUKB0QaDJglGI+fCwFrcXy8Q17vpFTEvEc= -github.com/bizflycloud/gobizfly v0.0.0-20200610135315-1b3e23893213/go.mod h1:2otUgZd6PrKezjMrdAw9gy7byEXMrigX9Sm4ujCaFuk= -github.com/bizflycloud/gobizfly v0.0.0-20200824165811-4aad89a434b1 h1:MVd1DoK4jZD1vCSc8h0/ztu9BvLauoMJLo/XyV3AMl8= -github.com/bizflycloud/gobizfly v0.0.0-20200824165811-4aad89a434b1/go.mod h1:2otUgZd6PrKezjMrdAw9gy7byEXMrigX9Sm4ujCaFuk= -github.com/bizflycloud/gobizfly v0.0.0-20200925081217-c929a1f56559 h1:U/5x1+bfz+5IMTf6mAW6IeyZdwr2vumjnegerwS9VAg= -github.com/bizflycloud/gobizfly v0.0.0-20200925081217-c929a1f56559/go.mod h1:2otUgZd6PrKezjMrdAw9gy7byEXMrigX9Sm4ujCaFuk= +github.com/bizflycloud/gobizfly v0.0.0-20210826035312-56219bf93eb1 h1:q6w8IOT74Jy2XU+urDQKIlnF6miAHQT51f1RR02DdNY= +github.com/bizflycloud/gobizfly v0.0.0-20210826035312-56219bf93eb1/go.mod h1:dESSbBmjQ5OJBgRPCTgmxAeqxNnRzXIZuRK3CTW2DUs= github.com/blang/semver v3.5.0+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/boltdb/bolt v1.3.1/go.mod h1:clJnj/oiGkjum5o1McbSZDSLxVThjynRyGBgiAx27Ps= github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g= From 0b40cebd112d387dded50f5c683613be159f4b14 Mon Sep 17 00:00:00 2001 From: lmq1999 Date: Mon, 30 Aug 2021 16:33:33 +0700 Subject: [PATCH 2/5] Remove examples when coding --- examples/pv-pod.yaml | 19 ------------------- examples/pvc.yml | 4 ++-- 2 files changed, 2 insertions(+), 21 deletions(-) delete mode 100644 examples/pv-pod.yaml diff --git a/examples/pv-pod.yaml b/examples/pv-pod.yaml deleted file mode 100644 index 1638e27..0000000 --- a/examples/pv-pod.yaml +++ /dev/null @@ -1,19 +0,0 @@ -apiVersion: v1 -kind: Pod -metadata: - name: task-pv-pod -spec: - volumes: - - name: task-pv-storage - persistentVolumeClaim: - claimName: task-pv-claim - containers: - - name: task-pv-container - image: nginx - ports: - - containerPort: 80 - name: "http-server" - volumeMounts: - - mountPath: "/usr/share/nginx/html" - name: task-pv-storage - diff --git a/examples/pvc.yml b/examples/pvc.yml index 67fafad..8c7abbf 100644 --- a/examples/pvc.yml +++ b/examples/pvc.yml @@ -1,12 +1,12 @@ apiVersion: v1 kind: PersistentVolumeClaim metadata: - name: task-pv-claim + name: demo-pvc spec: accessModes: - ReadWriteOnce volumeMode: Filesystem resources: requests: - storage: 5Gi + storage: 50Gi storageClassName: premium-hdd From e7b29dd2ccac887e87899d25e9cfffcb9ca6f7ae Mon Sep 17 00:00:00 2001 From: lmq1999 Date: Mon, 30 Aug 2021 16:38:54 +0700 Subject: [PATCH 3/5] Remove print Description --- driver/controller.go | 1 - 1 file changed, 1 deletion(-) diff --git a/driver/controller.go b/driver/controller.go index d36db23..f04f17e 100644 --- a/driver/controller.go +++ b/driver/controller.go @@ -75,7 +75,6 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol volPVCName := req.GetParameters()["csi.storage.k8s.io/pvc/name"] volPVCNamespace := req.GetParameters()["csi.storage.k8s.io/pvc/namespace"] Description := "bke_pvc_name: " + volPVCName + " ; bke_namespaces: " + volPVCNamespace - fmt.Println(Description) client := cs.Client // Verify a volume with the provided name doesn't already exist for this tenant From d625edfd6e882be712366c1c8ec0557f18d9d710 Mon Sep 17 00:00:00 2001 From: lmq1999 Date: Mon, 30 Aug 2021 16:52:27 +0700 Subject: [PATCH 4/5] Add flag to collect pvc name and pvc namespace --- examples/pvc.yml | 2 +- manifest/plugin/csi-bizflycloud-controllerplugin.yaml | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/pvc.yml b/examples/pvc.yml index 8c7abbf..250a0e6 100644 --- a/examples/pvc.yml +++ b/examples/pvc.yml @@ -9,4 +9,4 @@ spec: resources: requests: storage: 50Gi - storageClassName: premium-hdd + storageClassName: premium-hdd \ No newline at end of file diff --git a/manifest/plugin/csi-bizflycloud-controllerplugin.yaml b/manifest/plugin/csi-bizflycloud-controllerplugin.yaml index f628928..99e0735 100644 --- a/manifest/plugin/csi-bizflycloud-controllerplugin.yaml +++ b/manifest/plugin/csi-bizflycloud-controllerplugin.yaml @@ -41,6 +41,7 @@ spec: - "--csi-address=/var/lib/csi/sockets/pluginproxy/csi.sock" - "--timeout=3m" - "--feature-gates=Topology=true" + - "--extra-create-metadata=True" volumeMounts: - name: socket-dir mountPath: /var/lib/csi/sockets/pluginproxy/ From b31d2ef0b72cb5c25f84095ed7a7a8e10b23fa66 Mon Sep 17 00:00:00 2001 From: lmq1999 Date: Mon, 30 Aug 2021 17:15:18 +0700 Subject: [PATCH 5/5] Change description output format --- driver/controller.go | 2 +- examples/pvc.yml | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/driver/controller.go b/driver/controller.go index f04f17e..1c29bb2 100644 --- a/driver/controller.go +++ b/driver/controller.go @@ -74,7 +74,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } volPVCName := req.GetParameters()["csi.storage.k8s.io/pvc/name"] volPVCNamespace := req.GetParameters()["csi.storage.k8s.io/pvc/namespace"] - Description := "bke_pvc_name: " + volPVCName + " ; bke_namespaces: " + volPVCNamespace + Description := volPVCNamespace + "/" + volPVCName + " by csi-bizflycloud" client := cs.Client // Verify a volume with the provided name doesn't already exist for this tenant diff --git a/examples/pvc.yml b/examples/pvc.yml index 250a0e6..840754a 100644 --- a/examples/pvc.yml +++ b/examples/pvc.yml @@ -9,4 +9,5 @@ spec: resources: requests: storage: 50Gi - storageClassName: premium-hdd \ No newline at end of file + storageClassName: premium-hdd + \ No newline at end of file