@@ -27,6 +27,7 @@ import (
2727 "github.com/ceph/ceph-csi/internal/rbd/types"
2828 "github.com/ceph/ceph-csi/internal/util/log"
2929
30+ "github.com/csi-addons/spec/lib/go/replication"
3031 "github.com/csi-addons/spec/lib/go/volumegroup"
3132 "google.golang.org/grpc"
3233 "google.golang.org/grpc/codes"
@@ -206,27 +207,41 @@ func (vs *VolumeGroupServer) DeleteVolumeGroup(
206207
207208 log .DebugLog (ctx , "VolumeGroup %q has been found" , req .GetVolumeGroupId ())
208209
209- // verify that the volume group is empty
210- volumes , err := vg .ListVolumes (ctx )
210+ volumes , mirror , err := mgr .GetMirrorSource (ctx , req .GetVolumeGroupId (), & replication.ReplicationSource {
211+ Type : & replication.ReplicationSource_Volumegroup {
212+ Volumegroup : & replication.ReplicationSource_VolumeGroupSource {
213+ VolumeGroupId : req .GetVolumeGroupId (),
214+ },
215+ },
216+ })
211217 if err != nil {
212- return nil , status .Errorf (
213- codes .NotFound ,
214- "could not list volumes for voluem group %q: %s" ,
215- req .GetVolumeGroupId (),
216- err .Error ())
218+ return nil , getGRPCError (err )
217219 }
220+ defer destoryVolumes (ctx , volumes )
218221
219- log . DebugLog ( ctx , "VolumeGroup %q contains %d volumes" , req . GetVolumeGroupId (), len ( volumes ) )
222+ vgrMirrorInfo , err := mirror . GetMirroringInfo ( ctx )
220223
221- if len (volumes ) != 0 {
222- return nil , status .Errorf (
223- codes .FailedPrecondition ,
224- "rejecting to delete non-empty volume group %q" ,
225- req .GetVolumeGroupId ())
224+ // verify that the volume group is empty, if the group is primary
225+ if vgrMirrorInfo .IsPrimary () {
226+ volumes , err := vg .ListVolumes (ctx )
227+ if err != nil {
228+ return nil , status .Errorf (
229+ codes .NotFound ,
230+ "could not list volumes for volume group %q: %s" ,
231+ req .GetVolumeGroupId (),
232+ err .Error ())
233+ }
234+ log .DebugLog (ctx , "VolumeGroup %q contains %d volumes" , req .GetVolumeGroupId (), len (volumes ))
235+ if len (volumes ) != 0 {
236+ return nil , status .Errorf (
237+ codes .FailedPrecondition ,
238+ "rejecting to delete non-empty volume group %q" ,
239+ req .GetVolumeGroupId ())
240+ }
226241 }
227242
228243 // delete the volume group
229- err = vg .Delete (ctx )
244+ err = vg .Delete (ctx , vgrMirrorInfo , mirror )
230245 if err != nil {
231246 return nil , status .Errorf (codes .Internal ,
232247 "failed to delete volume group %q: %s" ,
0 commit comments