2024-06-24 12:18:50 +00:00
|
|
|
/*
|
|
|
|
Copyright 2024 The Ceph-CSI Authors.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
package rbd
|
|
|
|
|
|
|
|
import (
|
2024-07-09 15:52:54 +00:00
|
|
|
"context"
|
2024-12-04 06:37:44 +00:00
|
|
|
"errors"
|
2024-07-29 11:47:59 +00:00
|
|
|
"fmt"
|
2024-07-25 07:34:10 +00:00
|
|
|
"slices"
|
2024-07-09 15:52:54 +00:00
|
|
|
|
|
|
|
"github.com/ceph/ceph-csi/internal/rbd"
|
2024-12-04 06:37:44 +00:00
|
|
|
"github.com/ceph/ceph-csi/internal/rbd/group"
|
2024-07-09 15:52:54 +00:00
|
|
|
"github.com/ceph/ceph-csi/internal/rbd/types"
|
|
|
|
"github.com/ceph/ceph-csi/internal/util/log"
|
2024-06-24 12:18:50 +00:00
|
|
|
|
|
|
|
"github.com/csi-addons/spec/lib/go/volumegroup"
|
|
|
|
"google.golang.org/grpc"
|
2024-07-09 15:52:54 +00:00
|
|
|
"google.golang.org/grpc/codes"
|
|
|
|
"google.golang.org/grpc/status"
|
2024-06-24 12:18:50 +00:00
|
|
|
)
|
|
|
|
|
2024-07-09 15:52:54 +00:00
|
|
|
// VolumeGroupServer struct of rbd CSI driver with supported methods of
|
|
|
|
// VolumeGroup controller server spec.
|
2024-06-24 12:18:50 +00:00
|
|
|
type VolumeGroupServer struct {
|
2024-07-09 15:52:54 +00:00
|
|
|
// added UnimplementedControllerServer as a member of ControllerServer.
|
|
|
|
// if volumegroup spec add more RPC services in the proto file, then we
|
|
|
|
// don't need to add all RPC methods leading to forward compatibility.
|
2024-06-24 12:18:50 +00:00
|
|
|
*volumegroup.UnimplementedControllerServer
|
2024-07-17 08:08:27 +00:00
|
|
|
|
|
|
|
// csiID is the unique ID for this CSI-driver deployment.
|
|
|
|
csiID string
|
2024-06-24 12:18:50 +00:00
|
|
|
}
|
|
|
|
|
2024-07-09 15:52:54 +00:00
|
|
|
// NewVolumeGroupServer creates a new VolumeGroupServer which handles the
|
|
|
|
// VolumeGroup Service requests from the CSI-Addons specification.
|
2024-07-17 08:08:27 +00:00
|
|
|
func NewVolumeGroupServer(instanceID string) *VolumeGroupServer {
|
|
|
|
return &VolumeGroupServer{
|
|
|
|
csiID: instanceID,
|
|
|
|
}
|
2024-06-24 12:18:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
func (vs *VolumeGroupServer) RegisterService(server grpc.ServiceRegistrar) {
|
|
|
|
volumegroup.RegisterControllerServer(server, vs)
|
|
|
|
}
|
2024-07-09 15:52:54 +00:00
|
|
|
|
|
|
|
// CreateVolumeGroup RPC call to create a volume group.
|
|
|
|
//
|
|
|
|
// From the spec:
|
|
|
|
// This RPC will be called by the CO to create a new volume group on behalf of
|
|
|
|
// a user. This operation MUST be idempotent. If a volume group corresponding
|
|
|
|
// to the specified volume group name already exists, is compatible with the
|
|
|
|
// specified parameters in the CreateVolumeGroupRequest, the Plugin MUST reply
|
|
|
|
// 0 OK with the corresponding CreateVolumeGroupResponse. CSI Plugins MAY
|
|
|
|
// create the following types of volume groups:
|
|
|
|
//
|
|
|
|
// Create a new empty volume group or a group with specific volumes. Note that
|
|
|
|
// N volumes with some backend label Y could be considered to be in "group Y"
|
|
|
|
// which might not be a physical group on the storage backend. In this case, an
|
|
|
|
// empty group can still be created by the CO to hold volumes. After the empty
|
|
|
|
// group is created, create a new volume. CO may call
|
|
|
|
// ModifyVolumeGroupMembership to add new volumes to the group.
|
|
|
|
//
|
|
|
|
// Implementation steps:
|
|
|
|
// 1. resolve all volumes given in the volume_ids list (can be empty)
|
|
|
|
// 2. create the Volume Group
|
|
|
|
// 3. add all volumes to the Volume Group
|
|
|
|
//
|
|
|
|
// Idempotency should be handled by the rbd.Manager, keeping this function and
|
|
|
|
// the potential error handling as simple as possible.
|
|
|
|
func (vs *VolumeGroupServer) CreateVolumeGroup(
|
|
|
|
ctx context.Context,
|
|
|
|
req *volumegroup.CreateVolumeGroupRequest,
|
|
|
|
) (*volumegroup.CreateVolumeGroupResponse, error) {
|
2024-07-22 15:51:17 +00:00
|
|
|
mgr := rbd.NewManager(vs.csiID, req.GetParameters(), req.GetSecrets())
|
2024-07-09 15:52:54 +00:00
|
|
|
defer mgr.Destroy(ctx)
|
|
|
|
|
|
|
|
// resolve all volumes
|
|
|
|
volumes := make([]types.Volume, len(req.GetVolumeIds()))
|
2024-07-29 11:47:59 +00:00
|
|
|
defer func() {
|
|
|
|
for _, vol := range volumes {
|
|
|
|
vol.Destroy(ctx)
|
|
|
|
}
|
|
|
|
}()
|
2024-07-09 15:52:54 +00:00
|
|
|
for i, id := range req.GetVolumeIds() {
|
|
|
|
vol, err := mgr.GetVolumeByID(ctx, id)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.InvalidArgument,
|
|
|
|
"failed to find required volume %q for volume group %q: %s",
|
|
|
|
id,
|
|
|
|
req.GetName(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
volumes[i] = vol
|
|
|
|
}
|
|
|
|
|
2024-07-22 14:59:07 +00:00
|
|
|
log.DebugLog(ctx, "all %d Volumes for VolumeGroup %q have been found", len(volumes), req.GetName())
|
2024-07-09 15:52:54 +00:00
|
|
|
|
|
|
|
// create a RBDVolumeGroup
|
|
|
|
vg, err := mgr.CreateVolumeGroup(ctx, req.GetName())
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Internal,
|
|
|
|
"failed to create volume group %q: %s",
|
|
|
|
req.GetName(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
|
2024-07-22 14:59:07 +00:00
|
|
|
log.DebugLog(ctx, "VolumeGroup %q has been created: %+v", req.GetName(), vg)
|
2024-07-09 15:52:54 +00:00
|
|
|
|
2024-07-29 11:47:59 +00:00
|
|
|
// extract the flatten mode
|
|
|
|
flattenMode, err := getFlattenMode(ctx, req.GetParameters())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Flatten the image if the flatten mode is set to FlattenModeForce
|
|
|
|
// before adding it to the volume group.
|
|
|
|
for _, v := range volumes {
|
|
|
|
err = v.HandleParentImageExistence(ctx, flattenMode)
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("failed to handle parent image for volume group %q: %w", vg, err)
|
|
|
|
|
|
|
|
return nil, getGRPCError(err)
|
|
|
|
}
|
|
|
|
}
|
2024-07-09 15:52:54 +00:00
|
|
|
// add each rbd-image to the RBDVolumeGroup
|
|
|
|
for _, vol := range volumes {
|
|
|
|
err = vg.AddVolume(ctx, vol)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Internal,
|
|
|
|
"failed to add volume %q to volume group %q: %s",
|
|
|
|
vol,
|
|
|
|
req.GetName(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-22 14:59:07 +00:00
|
|
|
log.DebugLog(ctx, "all %d Volumes have been added to for VolumeGroup %q", len(volumes), req.GetName())
|
2024-07-09 15:52:54 +00:00
|
|
|
|
2024-07-22 15:51:17 +00:00
|
|
|
csiVG, err := vg.ToCSI(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Internal,
|
|
|
|
"failed to convert volume group %q to CSI type: %s",
|
|
|
|
req.GetName(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
|
2024-07-09 15:52:54 +00:00
|
|
|
return &volumegroup.CreateVolumeGroupResponse{
|
2024-07-22 15:51:17 +00:00
|
|
|
VolumeGroup: csiVG,
|
2024-07-09 15:52:54 +00:00
|
|
|
}, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteVolumeGroup RPC call to delete a volume group.
|
|
|
|
//
|
|
|
|
// From the spec:
|
|
|
|
// This RPC will be called by the CO to delete a volume group on behalf of a
|
|
|
|
// user. This operation MUST be idempotent.
|
|
|
|
//
|
|
|
|
// If a volume group corresponding to the specified volume_group_id does not
|
|
|
|
// exist or the artifacts associated with the volume group do not exist
|
|
|
|
// anymore, the Plugin MUST reply 0 OK.
|
|
|
|
//
|
|
|
|
// A volume cannot be deleted individually when it is part of the group. It has
|
|
|
|
// to be removed from the group first. Delete a volume group will delete all
|
|
|
|
// volumes in the group.
|
|
|
|
//
|
|
|
|
// Note:
|
|
|
|
// The undocumented DO_NOT_ALLOW_VG_TO_DELETE_VOLUMES capability is set. There
|
|
|
|
// is no need to delete each volume that may be part of the volume group. If
|
|
|
|
// the volume group is not empty, a FAILED_PRECONDITION error will be returned.
|
|
|
|
func (vs *VolumeGroupServer) DeleteVolumeGroup(
|
|
|
|
ctx context.Context,
|
|
|
|
req *volumegroup.DeleteVolumeGroupRequest,
|
|
|
|
) (*volumegroup.DeleteVolumeGroupResponse, error) {
|
2024-07-22 15:51:17 +00:00
|
|
|
mgr := rbd.NewManager(vs.csiID, nil, req.GetSecrets())
|
2024-07-09 15:52:54 +00:00
|
|
|
defer mgr.Destroy(ctx)
|
|
|
|
|
|
|
|
// resolve the volume group
|
|
|
|
vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId())
|
|
|
|
if err != nil {
|
2024-12-04 06:37:44 +00:00
|
|
|
if errors.Is(err, group.ErrRBDGroupNotFound) {
|
2024-12-16 05:21:18 +00:00
|
|
|
log.ErrorLog(ctx, "VolumeGroup %q doesn't exists", req.GetVolumeGroupId())
|
2024-12-04 06:37:44 +00:00
|
|
|
|
|
|
|
return &volumegroup.DeleteVolumeGroupResponse{}, nil
|
|
|
|
}
|
|
|
|
|
2024-07-09 15:52:54 +00:00
|
|
|
return nil, status.Errorf(
|
2024-12-04 06:37:44 +00:00
|
|
|
codes.Internal,
|
|
|
|
"could not fetch volume group %q: %s",
|
2024-07-09 15:52:54 +00:00
|
|
|
req.GetVolumeGroupId(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
defer vg.Destroy(ctx)
|
|
|
|
|
2024-07-22 14:59:07 +00:00
|
|
|
log.DebugLog(ctx, "VolumeGroup %q has been found", req.GetVolumeGroupId())
|
2024-07-09 15:52:54 +00:00
|
|
|
|
|
|
|
// verify that the volume group is empty
|
|
|
|
volumes, err := vg.ListVolumes(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.NotFound,
|
|
|
|
"could not list volumes for voluem group %q: %s",
|
|
|
|
req.GetVolumeGroupId(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
|
2024-07-22 14:59:07 +00:00
|
|
|
log.DebugLog(ctx, "VolumeGroup %q contains %d volumes", req.GetVolumeGroupId(), len(volumes))
|
2024-07-09 15:52:54 +00:00
|
|
|
|
|
|
|
if len(volumes) != 0 {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.FailedPrecondition,
|
|
|
|
"rejecting to delete non-empty volume group %q",
|
|
|
|
req.GetVolumeGroupId())
|
|
|
|
}
|
|
|
|
|
|
|
|
// delete the volume group
|
2024-09-17 12:07:19 +00:00
|
|
|
err = vg.Delete(ctx)
|
2024-07-09 15:52:54 +00:00
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(codes.Internal,
|
|
|
|
"failed to delete volume group %q: %s",
|
|
|
|
req.GetVolumeGroupId(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
|
2024-07-22 14:59:07 +00:00
|
|
|
log.DebugLog(ctx, "VolumeGroup %q has been deleted", req.GetVolumeGroupId())
|
2024-07-09 15:52:54 +00:00
|
|
|
|
|
|
|
return &volumegroup.DeleteVolumeGroupResponse{}, nil
|
|
|
|
}
|
2024-07-25 07:34:10 +00:00
|
|
|
|
|
|
|
// ModifyVolumeGroupMembership RPC call to modify a volume group.
|
|
|
|
//
|
|
|
|
// From the spec:
|
|
|
|
// This RPC will be called by the CO to modify an existing volume group on
|
|
|
|
// behalf of a user. volume_ids provided in the
|
|
|
|
// ModifyVolumeGroupMembershipRequest will be compared to the ones in the
|
|
|
|
// existing volume group. New volume_ids in the modified volume group will be
|
|
|
|
// added to the volume group. Existing volume_ids not in the modified volume
|
|
|
|
// group will be removed from the volume group. If volume_ids is empty, the
|
|
|
|
// volume group will be removed of all existing volumes. This operation MUST be
|
|
|
|
// idempotent.
|
|
|
|
//
|
|
|
|
// File-based storage systems usually do not support this PRC. Block-based
|
|
|
|
// storage systems usually support this PRC.
|
|
|
|
//
|
|
|
|
// By adding an existing volume to a group, however, there is no way to pass in
|
|
|
|
// parameters to influence placement when provisioning a volume.
|
|
|
|
//
|
|
|
|
// It is out of the scope of the CSI spec to determine whether a group is
|
|
|
|
// consistent or not. It is up to the storage provider to clarify that in the
|
|
|
|
// vendor specific documentation. This is true either when creating a new
|
|
|
|
// volume with a group id or adding an existing volume to a group.
|
|
|
|
//
|
|
|
|
// CSI drivers supporting MODIFY_VOLUME_GROUP_MEMBERSHIP MUST implement
|
|
|
|
// ModifyVolumeGroupMembership RPC.
|
|
|
|
//
|
|
|
|
// Note:
|
|
|
|
//
|
|
|
|
// The implementation works as the following:
|
|
|
|
// - resolve the existing volume group
|
|
|
|
// - get the CSI-IDs of all volumes
|
|
|
|
// - create a list of volumes that should be removed
|
|
|
|
// - create a list of volume IDs that should be added
|
|
|
|
// - remove the volumes from the group
|
|
|
|
// - add the volumes to the group
|
|
|
|
//
|
|
|
|
// Also, MODIFY_VOLUME_GROUP_MEMBERSHIP does not exist, it is called
|
|
|
|
// MODIFY_VOLUME_GROUP instead.
|
|
|
|
func (vs *VolumeGroupServer) ModifyVolumeGroupMembership(
|
|
|
|
ctx context.Context,
|
|
|
|
req *volumegroup.ModifyVolumeGroupMembershipRequest,
|
|
|
|
) (*volumegroup.ModifyVolumeGroupMembershipResponse, error) {
|
|
|
|
mgr := rbd.NewManager(vs.csiID, nil, req.GetSecrets())
|
|
|
|
defer mgr.Destroy(ctx)
|
|
|
|
|
|
|
|
// resolve the volume group
|
|
|
|
vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId())
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.NotFound,
|
|
|
|
"could not find volume group %q: %s",
|
|
|
|
req.GetVolumeGroupId(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
defer vg.Destroy(ctx)
|
|
|
|
|
|
|
|
beforeVolumes, err := vg.ListVolumes(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Internal,
|
|
|
|
"failed to list volumes of volume group %q: %v",
|
|
|
|
vg,
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// beforeIDs contains the csiID as key, volume as value
|
|
|
|
beforeIDs := make(map[string]types.Volume, len(beforeVolumes))
|
|
|
|
for _, vol := range beforeVolumes {
|
|
|
|
id, idErr := vol.GetID(ctx)
|
|
|
|
if idErr != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.InvalidArgument,
|
|
|
|
"failed to get the CSI ID of volume %q: %v",
|
|
|
|
vol,
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
|
|
|
|
beforeIDs[id] = vol
|
|
|
|
}
|
|
|
|
|
|
|
|
// check which volumes should not be part of the group
|
|
|
|
afterIDs := req.GetVolumeIds()
|
|
|
|
toRemove := make([]string, 0)
|
|
|
|
for id := range beforeIDs {
|
|
|
|
if !slices.Contains(afterIDs, id) {
|
|
|
|
toRemove = append(toRemove, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// check which volumes are new to the group
|
|
|
|
toAdd := make([]string, 0)
|
|
|
|
for _, id := range afterIDs {
|
|
|
|
if _, ok := beforeIDs[id]; !ok {
|
|
|
|
toAdd = append(toAdd, id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// remove the volume that should not be part of the group
|
|
|
|
for _, id := range toRemove {
|
|
|
|
vol := beforeIDs[id]
|
|
|
|
err = vg.RemoveVolume(ctx, vol)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Internal,
|
|
|
|
"failed to remove volume %q from volume group %q: %v",
|
|
|
|
vol,
|
|
|
|
vg,
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-29 11:55:25 +00:00
|
|
|
// resolve all volumes
|
|
|
|
volumes := make([]types.Volume, len(toAdd))
|
|
|
|
defer func() {
|
|
|
|
for _, vol := range volumes {
|
|
|
|
vol.Destroy(ctx)
|
|
|
|
}
|
|
|
|
}()
|
|
|
|
for i, id := range toAdd {
|
|
|
|
var vol types.Volume
|
|
|
|
vol, err = mgr.GetVolumeByID(ctx, id)
|
|
|
|
if err != nil {
|
2024-07-25 07:34:10 +00:00
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.NotFound,
|
|
|
|
"failed to find a volume with CSI ID %q: %v",
|
|
|
|
id,
|
|
|
|
err)
|
|
|
|
}
|
2024-07-29 11:55:25 +00:00
|
|
|
volumes[i] = vol
|
|
|
|
}
|
2024-07-25 07:34:10 +00:00
|
|
|
|
2024-07-29 11:55:25 +00:00
|
|
|
// extract the flatten mode
|
|
|
|
flattenMode, err := getFlattenMode(ctx, req.GetParameters())
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Flatten the image if the flatten mode is set to FlattenModeForce
|
|
|
|
// before adding it to the volume group.
|
|
|
|
for _, vol := range volumes {
|
|
|
|
err = vol.HandleParentImageExistence(ctx, flattenMode)
|
|
|
|
if err != nil {
|
|
|
|
err = fmt.Errorf("failed to handle parent image for volume group %q: %w", vg, err)
|
|
|
|
|
|
|
|
return nil, getGRPCError(err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// add the new volumes to the group
|
|
|
|
for _, vol := range volumes {
|
2024-07-25 07:34:10 +00:00
|
|
|
err = vg.AddVolume(ctx, vol)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Internal,
|
|
|
|
"failed to add volume %q to volume group %q: %v",
|
|
|
|
vol,
|
|
|
|
vg,
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
csiVG, err := vg.ToCSI(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Internal,
|
|
|
|
"failed to convert volume group %q to CSI format: %v",
|
|
|
|
vg,
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &volumegroup.ModifyVolumeGroupMembershipResponse{
|
|
|
|
VolumeGroup: csiVG,
|
|
|
|
}, nil
|
|
|
|
}
|
2024-07-25 13:26:51 +00:00
|
|
|
|
|
|
|
// ControllerGetVolumeGroup RPC call to get a volume group.
|
|
|
|
//
|
|
|
|
// From the spec:
|
|
|
|
// ControllerGetVolumeGroupResponse should contain current information of a
|
|
|
|
// volume group if it exists. If the volume group does not exist any more,
|
|
|
|
// ControllerGetVolumeGroup should return gRPC error code NOT_FOUND.
|
|
|
|
func (vs *VolumeGroupServer) ControllerGetVolumeGroup(
|
|
|
|
ctx context.Context,
|
|
|
|
req *volumegroup.ControllerGetVolumeGroupRequest,
|
|
|
|
) (*volumegroup.ControllerGetVolumeGroupResponse, error) {
|
|
|
|
mgr := rbd.NewManager(vs.csiID, nil, req.GetSecrets())
|
|
|
|
defer mgr.Destroy(ctx)
|
|
|
|
|
|
|
|
// resolve the volume group
|
|
|
|
vg, err := mgr.GetVolumeGroupByID(ctx, req.GetVolumeGroupId())
|
|
|
|
if err != nil {
|
2024-12-16 05:21:18 +00:00
|
|
|
if errors.Is(err, group.ErrRBDGroupNotFound) {
|
|
|
|
log.ErrorLog(ctx, "VolumeGroup %q doesn't exists", req.GetVolumeGroupId())
|
|
|
|
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.NotFound,
|
|
|
|
"could not find volume group %q: %s",
|
|
|
|
req.GetVolumeGroupId(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
|
2024-07-25 13:26:51 +00:00
|
|
|
return nil, status.Errorf(
|
2024-12-16 05:21:18 +00:00
|
|
|
codes.Internal,
|
|
|
|
"could not fetch volume group %q: %s",
|
2024-07-25 13:26:51 +00:00
|
|
|
req.GetVolumeGroupId(),
|
|
|
|
err.Error())
|
|
|
|
}
|
|
|
|
defer vg.Destroy(ctx)
|
|
|
|
|
|
|
|
csiVG, err := vg.ToCSI(ctx)
|
|
|
|
if err != nil {
|
|
|
|
return nil, status.Errorf(
|
|
|
|
codes.Internal,
|
|
|
|
"failed to convert volume group %q to CSI format: %v",
|
|
|
|
vg,
|
|
|
|
err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return &volumegroup.ControllerGetVolumeGroupResponse{
|
|
|
|
VolumeGroup: csiVG,
|
|
|
|
}, nil
|
|
|
|
}
|