pkg/rbd: Updated for new versions of CSI/Kubernetes dependencies

This commit is contained in:
Mike Cronce 2018-11-24 14:18:24 -05:00
parent 41b30eb6c2
commit 93cb8a04d7
5 changed files with 52 additions and 47 deletions

View File

@ -24,8 +24,9 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/container-storage-interface/spec/lib/go/csi/v0" "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/golang/glog" "github.com/golang/glog"
"github.com/golang/protobuf/ptypes/timestamp"
"github.com/kubernetes-csi/drivers/pkg/csi-common" "github.com/kubernetes-csi/drivers/pkg/csi-common"
"github.com/pborman/uuid" "github.com/pborman/uuid"
"github.com/pkg/errors" "github.com/pkg/errors"
@ -69,9 +70,9 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
// TODO (sbezverk) Do I need to make sure that RBD volume still exists? // TODO (sbezverk) Do I need to make sure that RBD volume still exists?
return &csi.CreateVolumeResponse{ return &csi.CreateVolumeResponse{
Volume: &csi.Volume{ Volume: &csi.Volume{
Id: exVol.VolID, VolumeId: exVol.VolID,
CapacityBytes: int64(exVol.VolSize), CapacityBytes: int64(exVol.VolSize),
Attributes: req.GetParameters(), VolumeContext: req.GetParameters(),
}, },
}, nil }, nil
} }
@ -103,7 +104,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
volSizeGB := int(volSizeBytes / 1024 / 1024 / 1024) volSizeGB := int(volSizeBytes / 1024 / 1024 / 1024)
// Check if there is already RBD image with requested name // Check if there is already RBD image with requested name
found, _, _ := rbdStatus(rbdVol, rbdVol.UserId, req.GetControllerCreateSecrets()) found, _, _ := rbdStatus(rbdVol, rbdVol.UserId, req.GetSecrets())
if !found { if !found {
// if VolumeContentSource is not nil, this request is for snapshot // if VolumeContentSource is not nil, this request is for snapshot
if req.VolumeContentSource != nil { if req.VolumeContentSource != nil {
@ -112,7 +113,7 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return nil, status.Error(codes.InvalidArgument, "Volume Snapshot cannot be empty") return nil, status.Error(codes.InvalidArgument, "Volume Snapshot cannot be empty")
} }
snapshotID := snapshot.GetId() snapshotID := snapshot.GetSnapshotId()
if len(snapshotID) == 0 { if len(snapshotID) == 0 {
return nil, status.Error(codes.InvalidArgument, "Volume Snapshot ID cannot be empty") return nil, status.Error(codes.InvalidArgument, "Volume Snapshot ID cannot be empty")
} }
@ -122,13 +123,13 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
return nil, err return nil, err
} }
err = restoreSnapshot(rbdVol, rbdSnap, rbdVol.AdminId, req.GetControllerCreateSecrets()) err = restoreSnapshot(rbdVol, rbdSnap, rbdVol.AdminId, req.GetSecrets())
if err != nil { if err != nil {
return nil, err return nil, err
} }
glog.V(4).Infof("create volume %s from snapshot %s", volName, rbdSnap.SnapName) glog.V(4).Infof("create volume %s from snapshot %s", volName, rbdSnap.SnapName)
} else { } else {
if err := createRBDImage(rbdVol, volSizeGB, rbdVol.AdminId, req.GetControllerCreateSecrets()); err != nil { if err := createRBDImage(rbdVol, volSizeGB, rbdVol.AdminId, req.GetSecrets()); err != nil {
if err != nil { if err != nil {
glog.Warningf("failed to create volume: %v", err) glog.Warningf("failed to create volume: %v", err)
return nil, err return nil, err
@ -145,9 +146,9 @@ func (cs *controllerServer) CreateVolume(ctx context.Context, req *csi.CreateVol
rbdVolumes[volumeID] = rbdVol rbdVolumes[volumeID] = rbdVol
return &csi.CreateVolumeResponse{ return &csi.CreateVolumeResponse{
Volume: &csi.Volume{ Volume: &csi.Volume{
Id: volumeID, VolumeId: volumeID,
CapacityBytes: int64(volSizeBytes), CapacityBytes: int64(volSizeBytes),
Attributes: req.GetParameters(), VolumeContext: req.GetParameters(),
}, },
}, nil }, nil
} }
@ -172,7 +173,7 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
volName := rbdVol.VolName volName := rbdVol.VolName
// Deleting rbd image // Deleting rbd image
glog.V(4).Infof("deleting volume %s", volName) glog.V(4).Infof("deleting volume %s", volName)
if err := deleteRBDImage(rbdVol, rbdVol.AdminId, req.GetControllerDeleteSecrets()); err != nil { if err := deleteRBDImage(rbdVol, rbdVol.AdminId, req.GetSecrets()); err != nil {
// TODO: can we detect "already deleted" situations here and proceed? // TODO: can we detect "already deleted" situations here and proceed?
glog.V(3).Infof("failed to delete rbd image: %s/%s with error: %v", rbdVol.Pool, volName, err) glog.V(3).Infof("failed to delete rbd image: %s/%s with error: %v", rbdVol.Pool, volName, err)
return nil, err return nil, err
@ -189,10 +190,14 @@ func (cs *controllerServer) DeleteVolume(ctx context.Context, req *csi.DeleteVol
func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) { func (cs *controllerServer) ValidateVolumeCapabilities(ctx context.Context, req *csi.ValidateVolumeCapabilitiesRequest) (*csi.ValidateVolumeCapabilitiesResponse, error) {
for _, cap := range req.VolumeCapabilities { for _, cap := range req.VolumeCapabilities {
if cap.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER { if cap.GetAccessMode().GetMode() != csi.VolumeCapability_AccessMode_SINGLE_NODE_WRITER {
return &csi.ValidateVolumeCapabilitiesResponse{Supported: false, Message: ""}, nil return &csi.ValidateVolumeCapabilitiesResponse{Message: ""}, nil
} }
} }
return &csi.ValidateVolumeCapabilitiesResponse{Supported: true, Message: ""}, nil return &csi.ValidateVolumeCapabilitiesResponse{
Confirmed: &csi.ValidateVolumeCapabilitiesResponse_Confirmed{
VolumeCapabilities: req.VolumeCapabilities,
},
}, nil
} }
func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) { func (cs *controllerServer) ControllerUnpublishVolume(ctx context.Context, req *csi.ControllerUnpublishVolumeRequest) (*csi.ControllerUnpublishVolumeResponse, error) {
@ -227,12 +232,12 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
return &csi.CreateSnapshotResponse{ return &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{ Snapshot: &csi.Snapshot{
SizeBytes: exSnap.SizeBytes, SizeBytes: exSnap.SizeBytes,
Id: exSnap.SnapID, SnapshotId: exSnap.SnapID,
SourceVolumeId: exSnap.SourceVolumeID, SourceVolumeId: exSnap.SourceVolumeID,
CreatedAt: exSnap.CreatedAt, CreationTime: &timestamp.Timestamp{
Status: &csi.SnapshotStatus{ Seconds: exSnap.CreatedAt,
Type: csi.SnapshotStatus_READY,
}, },
ReadyToUse: true,
}, },
}, nil }, nil
} }
@ -262,7 +267,7 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
rbdSnap.SourceVolumeID = req.GetSourceVolumeId() rbdSnap.SourceVolumeID = req.GetSourceVolumeId()
rbdSnap.SizeBytes = rbdVolume.VolSize rbdSnap.SizeBytes = rbdVolume.VolSize
err = createSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets()) err = createSnapshot(rbdSnap, rbdSnap.AdminId, req.GetSecrets())
// if we already have the snapshot, return the snapshot // if we already have the snapshot, return the snapshot
if err != nil { if err != nil {
if exitErr, ok := err.(*exec.ExitError); ok { if exitErr, ok := err.(*exec.ExitError); ok {
@ -283,10 +288,10 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
} }
} else { } else {
glog.V(4).Infof("create snapshot %s", snapName) glog.V(4).Infof("create snapshot %s", snapName)
err = protectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets()) err = protectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetSecrets())
if err != nil { if err != nil {
err = deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets()) err = deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetSecrets())
if err != nil { if err != nil {
return nil, fmt.Errorf("snapshot is created but failed to protect and delete snapshot: %v", err) return nil, fmt.Errorf("snapshot is created but failed to protect and delete snapshot: %v", err)
} }
@ -301,14 +306,14 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
glog.Warningf("rbd: failed to store snapInfo with error: %v", err) glog.Warningf("rbd: failed to store snapInfo with error: %v", err)
// Unprotect snapshot // Unprotect snapshot
err := unprotectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets()) err := unprotectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetSecrets())
if err != nil { if err != nil {
return nil, status.Error(codes.Unknown, fmt.Sprintf("This Snapshot should be removed but failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)) return nil, status.Error(codes.Unknown, fmt.Sprintf("This Snapshot should be removed but failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err))
} }
// Deleting snapshot // Deleting snapshot
glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName) glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName)
if err := deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetCreateSnapshotSecrets()); err != nil { if err := deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetSecrets()); err != nil {
return nil, status.Error(codes.Unknown, fmt.Sprintf("This Snapshot should be removed but failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)) return nil, status.Error(codes.Unknown, fmt.Sprintf("This Snapshot should be removed but failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err))
} }
@ -318,12 +323,12 @@ func (cs *controllerServer) CreateSnapshot(ctx context.Context, req *csi.CreateS
return &csi.CreateSnapshotResponse{ return &csi.CreateSnapshotResponse{
Snapshot: &csi.Snapshot{ Snapshot: &csi.Snapshot{
SizeBytes: rbdSnap.SizeBytes, SizeBytes: rbdSnap.SizeBytes,
Id: snapshotID, SnapshotId: snapshotID,
SourceVolumeId: req.GetSourceVolumeId(), SourceVolumeId: req.GetSourceVolumeId(),
CreatedAt: rbdSnap.CreatedAt, CreationTime: &timestamp.Timestamp{
Status: &csi.SnapshotStatus{ Seconds: rbdSnap.CreatedAt,
Type: csi.SnapshotStatus_READY,
}, },
ReadyToUse: true,
}, },
}, nil }, nil
} }
@ -347,14 +352,14 @@ func (cs *controllerServer) DeleteSnapshot(ctx context.Context, req *csi.DeleteS
} }
// Unprotect snapshot // Unprotect snapshot
err := unprotectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetDeleteSnapshotSecrets()) err := unprotectSnapshot(rbdSnap, rbdSnap.AdminId, req.GetSecrets())
if err != nil { if err != nil {
return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)) return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("failed to unprotect snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err))
} }
// Deleting snapshot // Deleting snapshot
glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName) glog.V(4).Infof("deleting Snaphot %s", rbdSnap.SnapName)
if err := deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetDeleteSnapshotSecrets()); err != nil { if err := deleteSnapshot(rbdSnap, rbdSnap.AdminId, req.GetSecrets()); err != nil {
return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err)) return nil, status.Error(codes.FailedPrecondition, fmt.Sprintf("failed to delete snapshot: %s/%s with error: %v", rbdSnap.Pool, rbdSnap.SnapName, err))
} }
@ -391,12 +396,12 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
{ {
Snapshot: &csi.Snapshot{ Snapshot: &csi.Snapshot{
SizeBytes: rbdSnap.SizeBytes, SizeBytes: rbdSnap.SizeBytes,
Id: rbdSnap.SnapID, SnapshotId: rbdSnap.SnapID,
SourceVolumeId: rbdSnap.SourceVolumeID, SourceVolumeId: rbdSnap.SourceVolumeID,
CreatedAt: rbdSnap.CreatedAt, CreationTime: &timestamp.Timestamp{
Status: &csi.SnapshotStatus{ Seconds: rbdSnap.CreatedAt,
Type: csi.SnapshotStatus_READY,
}, },
ReadyToUse: true,
}, },
}, },
}, },
@ -415,12 +420,12 @@ func (cs *controllerServer) ListSnapshots(ctx context.Context, req *csi.ListSnap
entries = append(entries, &csi.ListSnapshotsResponse_Entry{ entries = append(entries, &csi.ListSnapshotsResponse_Entry{
Snapshot: &csi.Snapshot{ Snapshot: &csi.Snapshot{
SizeBytes: rbdSnap.SizeBytes, SizeBytes: rbdSnap.SizeBytes,
Id: rbdSnap.SnapID, SnapshotId: rbdSnap.SnapID,
SourceVolumeId: rbdSnap.SourceVolumeID, SourceVolumeId: rbdSnap.SourceVolumeID,
CreatedAt: rbdSnap.CreatedAt, CreationTime: &timestamp.Timestamp{
Status: &csi.SnapshotStatus{ Seconds: rbdSnap.CreatedAt,
Type: csi.SnapshotStatus_READY,
}, },
ReadyToUse: true,
}, },
}) })
} }

View File

@ -19,7 +19,7 @@ package rbd
import ( import (
"context" "context"
"github.com/container-storage-interface/spec/lib/go/csi/v0" "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/drivers/pkg/csi-common" "github.com/kubernetes-csi/drivers/pkg/csi-common"
) )

View File

@ -24,7 +24,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"golang.org/x/net/context" "golang.org/x/net/context"
"github.com/container-storage-interface/spec/lib/go/csi/v0" "github.com/container-storage-interface/spec/lib/go/csi"
"google.golang.org/grpc/codes" "google.golang.org/grpc/codes"
"google.golang.org/grpc/status" "google.golang.org/grpc/status"
@ -65,13 +65,13 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
if !notMnt { if !notMnt {
return &csi.NodePublishVolumeResponse{}, nil return &csi.NodePublishVolumeResponse{}, nil
} }
volOptions, err := getRBDVolumeOptions(req.VolumeAttributes) volOptions, err := getRBDVolumeOptions(req.GetVolumeContext())
if err != nil { if err != nil {
return nil, err return nil, err
} }
volOptions.VolName = volName volOptions.VolName = volName
// Mapping RBD image // Mapping RBD image
devicePath, err := attachRBDImage(volOptions, volOptions.UserId, req.GetNodePublishSecrets()) devicePath, err := attachRBDImage(volOptions, volOptions.UserId, req.GetSecrets())
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -79,7 +79,7 @@ func (ns *nodeServer) NodePublishVolume(ctx context.Context, req *csi.NodePublis
fsType := req.GetVolumeCapability().GetMount().GetFsType() fsType := req.GetVolumeCapability().GetMount().GetFsType()
readOnly := req.GetReadonly() readOnly := req.GetReadonly()
attrib := req.GetVolumeAttributes() attrib := req.GetVolumeContext()
mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags() mountFlags := req.GetVolumeCapability().GetMount().GetMountFlags()
glog.V(4).Infof("target %v\nfstype %v\ndevice %v\nreadonly %v\nattributes %v\n mountflags %v\n", glog.V(4).Infof("target %v\nfstype %v\ndevice %v\nreadonly %v\nattributes %v\n mountflags %v\n",

View File

@ -25,7 +25,7 @@ import (
"github.com/golang/glog" "github.com/golang/glog"
"github.com/container-storage-interface/spec/lib/go/csi/v0" "github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-csi/drivers/pkg/csi-common" "github.com/kubernetes-csi/drivers/pkg/csi-common"
"k8s.io/kubernetes/pkg/util/mount" "k8s.io/kubernetes/pkg/util/mount"

View File

@ -76,17 +76,17 @@ type rbdSnapshot struct {
var ( var (
// serializes operations based on "<rbd pool>/<rbd image>" as key // serializes operations based on "<rbd pool>/<rbd image>" as key
attachdetachMutex = keymutex.NewKeyMutex() attachdetachMutex = keymutex.NewHashed(0)
// serializes operations based on "volume name" as key // serializes operations based on "volume name" as key
volumeNameMutex = keymutex.NewKeyMutex() volumeNameMutex = keymutex.NewHashed(0)
// serializes operations based on "volume id" as key // serializes operations based on "volume id" as key
volumeIDMutex = keymutex.NewKeyMutex() volumeIDMutex = keymutex.NewHashed(0)
// serializes operations based on "snapshot name" as key // serializes operations based on "snapshot name" as key
snapshotNameMutex = keymutex.NewKeyMutex() snapshotNameMutex = keymutex.NewHashed(0)
// serializes operations based on "snapshot id" as key // serializes operations based on "snapshot id" as key
snapshotIDMutex = keymutex.NewKeyMutex() snapshotIDMutex = keymutex.NewHashed(0)
// serializes operations based on "mount target path" as key // serializes operations based on "mount target path" as key
targetPathMutex = keymutex.NewKeyMutex() targetPathMutex = keymutex.NewHashed(0)
supportedFeatures = sets.NewString("layering") supportedFeatures = sets.NewString("layering")
) )