mirror of
https://github.com/ceph/ceph-csi.git
synced 2025-01-31 00:59:30 +00:00
csiaddons: use rbd.Manager
within ReclaimSpaceControllerServer
Signed-off-by: Niels de Vos <ndevos@ibm.com>
This commit is contained in:
parent
6560eee3d8
commit
af0a223edb
@ -37,13 +37,18 @@ import (
|
|||||||
// of CSI-addons reclaimspace controller service spec.
|
// of CSI-addons reclaimspace controller service spec.
|
||||||
type ReclaimSpaceControllerServer struct {
|
type ReclaimSpaceControllerServer struct {
|
||||||
*rs.UnimplementedReclaimSpaceControllerServer
|
*rs.UnimplementedReclaimSpaceControllerServer
|
||||||
|
|
||||||
|
driver string
|
||||||
volumeLocks *util.VolumeLocks
|
volumeLocks *util.VolumeLocks
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewReclaimSpaceControllerServer creates a new ReclaimSpaceControllerServer which handles
|
// NewReclaimSpaceControllerServer creates a new ReclaimSpaceControllerServer which handles
|
||||||
// the ReclaimSpace Service requests from the CSI-Addons specification.
|
// the ReclaimSpace Service requests from the CSI-Addons specification.
|
||||||
func NewReclaimSpaceControllerServer(volumeLocks *util.VolumeLocks) *ReclaimSpaceControllerServer {
|
func NewReclaimSpaceControllerServer(driver string, volumeLocks *util.VolumeLocks) *ReclaimSpaceControllerServer {
|
||||||
return &ReclaimSpaceControllerServer{volumeLocks: volumeLocks}
|
return &ReclaimSpaceControllerServer{
|
||||||
|
driver: driver,
|
||||||
|
volumeLocks: volumeLocks,
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (rscs *ReclaimSpaceControllerServer) RegisterService(server grpc.ServiceRegistrar) {
|
func (rscs *ReclaimSpaceControllerServer) RegisterService(server grpc.ServiceRegistrar) {
|
||||||
@ -59,12 +64,6 @@ func (rscs *ReclaimSpaceControllerServer) ControllerReclaimSpace(
|
|||||||
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
|
return nil, status.Error(codes.InvalidArgument, "empty volume ID in request")
|
||||||
}
|
}
|
||||||
|
|
||||||
cr, err := util.NewUserCredentials(req.GetSecrets())
|
|
||||||
if err != nil {
|
|
||||||
return nil, status.Error(codes.Internal, err.Error())
|
|
||||||
}
|
|
||||||
defer cr.DeleteCredentials()
|
|
||||||
|
|
||||||
if acquired := rscs.volumeLocks.TryAcquire(volumeID); !acquired {
|
if acquired := rscs.volumeLocks.TryAcquire(volumeID); !acquired {
|
||||||
log.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volumeID)
|
log.ErrorLog(ctx, util.VolumeOperationAlreadyExistsFmt, volumeID)
|
||||||
|
|
||||||
@ -72,13 +71,16 @@ func (rscs *ReclaimSpaceControllerServer) ControllerReclaimSpace(
|
|||||||
}
|
}
|
||||||
defer rscs.volumeLocks.Release(volumeID)
|
defer rscs.volumeLocks.Release(volumeID)
|
||||||
|
|
||||||
rbdVol, err := rbdutil.GenVolFromVolID(ctx, volumeID, cr, req.GetSecrets())
|
mgr := rbdutil.NewManager(rscs.driver, nil, req.GetSecrets())
|
||||||
|
defer mgr.Destroy(ctx)
|
||||||
|
|
||||||
|
rbdVol, err := mgr.GetVolumeByID(ctx, volumeID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, status.Errorf(codes.Aborted, "failed to find volume with ID %q: %s", volumeID, err.Error())
|
return nil, status.Errorf(codes.Aborted, "failed to find volume with ID %q: %s", volumeID, err.Error())
|
||||||
}
|
}
|
||||||
defer rbdVol.Destroy(ctx)
|
defer rbdVol.Destroy(ctx)
|
||||||
|
|
||||||
err = rbdVol.Sparsify()
|
err = rbdVol.Sparsify(ctx)
|
||||||
if errors.Is(err, rbdutil.ErrImageInUse) {
|
if errors.Is(err, rbdutil.ErrImageInUse) {
|
||||||
// FIXME: https://github.com/csi-addons/kubernetes-csi-addons/issues/406.
|
// FIXME: https://github.com/csi-addons/kubernetes-csi-addons/issues/406.
|
||||||
// treat sparsify call as no-op if volume is in use.
|
// treat sparsify call as no-op if volume is in use.
|
||||||
|
@ -32,7 +32,7 @@ import (
|
|||||||
func TestControllerReclaimSpace(t *testing.T) {
|
func TestControllerReclaimSpace(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
|
|
||||||
controller := NewReclaimSpaceControllerServer(util.NewVolumeLocks())
|
controller := NewReclaimSpaceControllerServer("test.driver", util.NewVolumeLocks())
|
||||||
|
|
||||||
req := &rs.ControllerReclaimSpaceRequest{
|
req := &rs.ControllerReclaimSpaceRequest{
|
||||||
VolumeId: "",
|
VolumeId: "",
|
||||||
|
@ -17,6 +17,7 @@ limitations under the License.
|
|||||||
package rbd
|
package rbd
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -25,7 +26,7 @@ import (
|
|||||||
// of the image.
|
// of the image.
|
||||||
// This function will return ErrImageInUse if the image is in use, since
|
// This function will return ErrImageInUse if the image is in use, since
|
||||||
// sparsifying an image on which i/o is in progress is not optimal.
|
// sparsifying an image on which i/o is in progress is not optimal.
|
||||||
func (ri *rbdImage) Sparsify() error {
|
func (ri *rbdImage) Sparsify(_ context.Context) error {
|
||||||
inUse, err := ri.isInUse()
|
inUse, err := ri.isInUse()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to check if image is in use: %w", err)
|
return fmt.Errorf("failed to check if image is in use: %w", err)
|
||||||
|
@ -229,7 +229,7 @@ func (r *Driver) setupCSIAddonsServer(conf *util.Config) error {
|
|||||||
r.cas.RegisterService(is)
|
r.cas.RegisterService(is)
|
||||||
|
|
||||||
if conf.IsControllerServer {
|
if conf.IsControllerServer {
|
||||||
rs := casrbd.NewReclaimSpaceControllerServer(r.cs.VolumeLocks)
|
rs := casrbd.NewReclaimSpaceControllerServer(conf.InstanceID, r.cs.VolumeLocks)
|
||||||
r.cas.RegisterService(rs)
|
r.cas.RegisterService(rs)
|
||||||
|
|
||||||
fcs := casrbd.NewFenceControllerServer()
|
fcs := casrbd.NewFenceControllerServer()
|
||||||
|
@ -45,6 +45,9 @@ type csiAddonsVolume interface {
|
|||||||
// RotateEncryptionKey processes the key rotation for the RBD Volume.
|
// RotateEncryptionKey processes the key rotation for the RBD Volume.
|
||||||
RotateEncryptionKey(ctx context.Context) error
|
RotateEncryptionKey(ctx context.Context) error
|
||||||
|
|
||||||
|
// Sparsify tries to free unused blocks of the volume from the CSI-Addons Controller.
|
||||||
|
Sparsify(ctx context.Context) error
|
||||||
|
|
||||||
// HandleParentImageExistence checks the image's parent.
|
// HandleParentImageExistence checks the image's parent.
|
||||||
// if the parent image does not exist and is not in trash, it returns nil.
|
// if the parent image does not exist and is not in trash, it returns nil.
|
||||||
// if the flattenMode is FlattenModeForce, it flattens the image itself.
|
// if the flattenMode is FlattenModeForce, it flattens the image itself.
|
||||||
|
Loading…
Reference in New Issue
Block a user