@@ -19,11 +19,12 @@ package sidecar_controller
1919import  (
2020	"context" 
2121	"fmt" 
22+ 	"strings" 
23+ 	"time" 
24+ 
2225	"github.com/container-storage-interface/spec/lib/go/csi" 
2326	crdv1alpha1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumegroupsnapshot/v1alpha1" 
2427	"github.com/kubernetes-csi/external-snapshotter/v6/pkg/group_snapshotter" 
25- 	"strings" 
26- 	"time" 
2728
2829	crdv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1" 
2930	"github.com/kubernetes-csi/external-snapshotter/v6/pkg/snapshotter" 
@@ -36,6 +37,7 @@ type Handler interface {
3637	GetSnapshotStatus (content  * crdv1.VolumeSnapshotContent , snapshotterListCredentials  map [string ]string ) (bool , time.Time , int64 , error )
3738	CreateGroupSnapshot (content  * crdv1alpha1.VolumeGroupSnapshotContent , volumeIDs  []string , parameters  map [string ]string , snapshotterCredentials  map [string ]string ) (string , string , []* csi.Snapshot , time.Time , bool , error )
3839	GetGroupSnapshotStatus (content  * crdv1alpha1.VolumeGroupSnapshotContent , snapshotterListCredentials  map [string ]string ) (bool , time.Time , error )
40+ 	DeleteGroupSnapshot (content  * crdv1alpha1.VolumeGroupSnapshotContent , SanpshotID  []string , snapshotterCredentials  map [string ]string ) error 
3941}
4042
4143// csiHandler is a handler that calls CSI to create/delete volume snapshot. 
@@ -165,6 +167,30 @@ func (handler *csiHandler) CreateGroupSnapshot(content *crdv1alpha1.VolumeGroupS
165167	return  handler .groupSnapshotter .CreateGroupSnapshot (ctx , groupSnapshotName , volumeIDs , parameters , snapshotterCredentials )
166168}
167169
170+ func  (handler  * csiHandler ) DeleteGroupSnapshot (content  * crdv1alpha1.VolumeGroupSnapshotContent , snapshotIDs  []string , snapshotterCredentials  map [string ]string ) error  {
171+ 	ctx , cancel  :=  context .WithTimeout (context .Background (), handler .timeout )
172+ 	defer  cancel ()
173+ 
174+ 	if  content .Spec .VolumeGroupSnapshotRef .UID  ==  ""  {
175+ 		return  fmt .Errorf ("cannot delete group snapshot. Group snapshot content %s not bound to a group snapshot" , content .Name )
176+ 	}
177+ 
178+ 	if  len (snapshotIDs ) !=  0  {
179+ 		return  fmt .Errorf ("cannot delete group snapshot. Snapshots found in the group snapshot%s" , content .Name )
180+ 	}
181+ 	var  groupSnapshotHandle  string 
182+ 
183+ 	if  content .Status  !=  nil  &&  content .Status .VolumeGroupSnapshotHandle  !=  nil  {
184+ 		groupSnapshotHandle  =  * content .Status .VolumeGroupSnapshotHandle 
185+ 	} else  if  content .Spec .Source .VolumeGroupSnapshotHandle  !=  nil  {
186+ 		groupSnapshotHandle  =  * content .Spec .Source .VolumeGroupSnapshotHandle 
187+ 	} else  {
188+ 		return  fmt .Errorf ("failed to delete group snapshot content %s: groupsnapshotHandle is missing" , content .Name )
189+ 	}
190+ 
191+ 	return  handler .groupSnapshotter .DeleteGroupSnapshot (ctx , groupSnapshotHandle , snapshotIDs , snapshotterCredentials )
192+ }
193+ 
168194func  (handler  * csiHandler ) GetGroupSnapshotStatus (groupSnapshotContent  * crdv1alpha1.VolumeGroupSnapshotContent , snapshotterListCredentials  map [string ]string ) (bool , time.Time , error ) {
169195	ctx , cancel  :=  context .WithTimeout (context .Background (), handler .timeout )
170196	defer  cancel ()
0 commit comments