cephfs/controllerserver: write ceph.conf

This commit is contained in:
gman 2018-03-20 16:15:19 +01:00
parent aa4130865c
commit 9fefc270d8

View File

@ -24,7 +24,7 @@ import (
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
"github.com/container-storage-interface/spec/lib/go/csi" "github.com/container-storage-interface/spec/lib/go/csi/v0"
"github.com/kubernetes-csi/drivers/pkg/csi-common" "github.com/kubernetes-csi/drivers/pkg/csi-common"
) )
@ -36,56 +36,64 @@ const (
oneGB = 1073741824 oneGB = 1073741824
) )
func GetVersionString(v *csi.Version) string { func (cs *controllerServer) validateCreateVolumeRequest(req *csi.CreateVolumeRequest) error {
return fmt.Sprintf("%d.%d.%d", v.GetMajor(), v.GetMinor(), v.GetPatch()) if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
} return fmt.Errorf("Invalid CreateVolumeRequest: %v", err)
func (cs *controllerServer) validateRequest(v *csi.Version) error {
if v == nil {
return status.Error(codes.InvalidArgument, "Version missing in request")
} }
return cs.Driver.ValidateControllerServiceRequest(v, csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME) if req.GetName() == "" {
return status.Error(codes.InvalidArgument, "Volume Name cannot be empty")
}
if req.GetVolumeCapabilities() == nil {
return status.Error(codes.InvalidArgument, "Volume Capabilities cannot be empty")
}
return nil
}
func (cs *controllerServer) validateDeleteVolumeRequest(req *csi.DeleteVolumeRequest) error {
if err := cs.Driver.ValidateControllerServiceRequest(csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME); err != nil {
return fmt.Errorf("Invalid DeleteVolumeRequest: %v", err)
}
return nil
} }
func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) { func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVolumeRequest) (*csi.CreateVolumeResponse, error) {
if err := cs.validateRequest(req.Version); err != nil { if err := cs.validateCreateVolumeRequest(req); err != nil {
glog.Warningf("invalid create volume request: %v", req) glog.Errorf("CreateVolumeRequest validation failed: %v", err)
return nil, err return nil, err
} }
volOptions, err := newVolumeOptions(req.GetParameters()) volOptions, err := newVolumeOptions(req.GetParameters())
if err != nil { if err != nil {
return nil, err glog.Errorf("error reading volume options: %v", err)
return nil, status.Error(codes.InvalidArgument, err.Error())
} }
volId := newVolumeIdentifier(volOptions, req) volId := newVolumeIdentifier(volOptions, req)
volSz := int64(oneGB)
if req.GetCapacityRange() != nil { conf := cephConfigData{Monitors: volOptions.Monitors}
volSz = int64(req.GetCapacityRange().GetRequiredBytes()) if err = conf.writeToFile(); err != nil {
} glog.Errorf("couldn't generate ceph.conf: %v", err)
vol, err := newVolume(volId, volOptions)
if err != nil {
glog.Errorf("failed to create a volume: %v", err)
return nil, status.Error(codes.Internal, err.Error()) return nil, status.Error(codes.Internal, err.Error())
} }
glog.V(4).Infof("cephfs: volume created at %s", vol.Root) glog.V(4).Infof("cephfs: volume %s successfuly created", volId.id)
return &csi.CreateVolumeResponse{ return &csi.CreateVolumeResponse{
Volume: &csi.Volume{ Volume: &csi.Volume{
Id: volId.id, Id: volId.id,
CapacityBytes: volSz, CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
Attributes: vol.makeMap(), Attributes: req.GetParameters(),
}, },
}, nil }, nil
} }
func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) { func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVolumeRequest) (*csi.DeleteVolumeResponse, error) {
if err := cs.validateRequest(req.Version); err != nil { if err := cs.validateDeleteVolumeRequest(req); err != nil {
glog.Warningf("invalid delete volume request: %v", req) glog.Errorf("DeleteVolumeRequest validation failed: %v", err)
return nil, err return nil, err
} }