diff --git a/pkg/driver/controllerserver.go b/pkg/driver/controllerserver.go index 6f57359..535759d 100644 --- a/pkg/driver/controllerserver.go +++ b/pkg/driver/controllerserver.go @@ -5,6 +5,10 @@ import ( "crypto/sha1" "encoding/hex" "fmt" + "io" + "strconv" + "strings" + "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" "github.com/chrislusf/seaweedfs/weed/pb/mount_pb" @@ -14,8 +18,6 @@ import ( "google.golang.org/grpc/credentials/insecure" _ "google.golang.org/grpc/resolver/passthrough" "google.golang.org/grpc/status" - "io" - "strings" ) type ControllerServer struct { @@ -42,11 +44,19 @@ func (cs *ControllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol } params := req.GetParameters() + if params == nil { + params = make(map[string]string) + } glog.V(4).Infof("params:%v", params) - capacity := req.GetCapacityRange().GetLimitBytes() + capacity := req.GetCapacityRange().GetRequiredBytes() cs.Driver.Capacity = capacity cs.Driver.DiskType = params["diskType"] + if capacity > 0 { + glog.V(4).Infof("volume capacity: %d", capacity) + params["volumeCapacity"] = strconv.FormatInt(capacity, 10) + } + if err := filer_pb.Mkdir(cs.Driver, "/buckets", volumeId, nil); err != nil { return nil, fmt.Errorf("Error setting bucket metadata: %v", err) } diff --git a/pkg/driver/nodeserver.go b/pkg/driver/nodeserver.go index 365fb4c..1f3ce20 100644 --- a/pkg/driver/nodeserver.go +++ b/pkg/driver/nodeserver.go @@ -3,6 +3,10 @@ package driver import ( "context" "fmt" + "os" + "strconv" + "strings" + "github.com/chrislusf/seaweedfs/weed/glog" "github.com/chrislusf/seaweedfs/weed/pb/mount_pb" "github.com/container-storage-interface/spec/lib/go/csi" @@ -12,8 +16,6 @@ import ( _ "google.golang.org/grpc/resolver/passthrough" "google.golang.org/grpc/status" "k8s.io/utils/mount" - "os" - "strings" ) type NodeServer struct { @@ -69,6 +71,15 @@ func (ns *NodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis ns.Driver.DiskType = diskType } + if volumeCapacity, ok := volContext["volumeCapacity"]; ok { + vCap, err := strconv.ParseInt(volumeCapacity, 10, 64) + if err != nil { + glog.Errorf("volumeCapacity %s can not be parsed to Int64, err is: %v", volumeCapacity, err) + } else { + ns.Driver.Capacity = vCap + } + } + mounter, err := newMounter(path, collection, req.GetReadonly(), ns.Driver, volContext) if err != nil { return nil, err