Delete individual volume snapshots as part of the group snapshot delete API and prevent users from deleting individual volume snapshots if it is part of an existing group snapshot
Also revert commit bb29899ca3
.
This commit is contained in:
@@ -22,13 +22,14 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
crdv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
|
||||
"github.com/kubernetes-csi/external-snapshotter/v6/pkg/utils"
|
||||
codes "google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
klog "k8s.io/klog/v2"
|
||||
|
||||
crdv1 "github.com/kubernetes-csi/external-snapshotter/client/v6/apis/volumesnapshot/v1"
|
||||
"github.com/kubernetes-csi/external-snapshotter/v6/pkg/utils"
|
||||
)
|
||||
|
||||
// Design:
|
||||
@@ -251,7 +252,7 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateContentStatusOperation(c
|
||||
var size int64
|
||||
readyToUse := false
|
||||
var driverName string
|
||||
var snapshotID string
|
||||
var snapshotID, groupSnapshotID string
|
||||
var snapshotterListCredentials map[string]string
|
||||
|
||||
if content.Spec.Source.SnapshotHandle != nil {
|
||||
@@ -278,7 +279,7 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateContentStatusOperation(c
|
||||
}
|
||||
}
|
||||
|
||||
readyToUse, creationTime, size, err = ctrl.handler.GetSnapshotStatus(content, snapshotterListCredentials)
|
||||
readyToUse, creationTime, size, groupSnapshotID, err = ctrl.handler.GetSnapshotStatus(content, snapshotterListCredentials)
|
||||
if err != nil {
|
||||
klog.Errorf("checkandUpdateContentStatusOperation: failed to call get snapshot status to check whether snapshot is ready to use %q", err)
|
||||
return content, err
|
||||
@@ -286,13 +287,13 @@ func (ctrl *csiSnapshotSideCarController) checkandUpdateContentStatusOperation(c
|
||||
driverName = content.Spec.Driver
|
||||
snapshotID = *content.Spec.Source.SnapshotHandle
|
||||
|
||||
klog.V(5).Infof("checkandUpdateContentStatusOperation: driver %s, snapshotId %s, creationTime %v, size %d, readyToUse %t", driverName, snapshotID, creationTime, size, readyToUse)
|
||||
klog.V(5).Infof("checkandUpdateContentStatusOperation: driver %s, snapshotId %s, creationTime %v, size %d, readyToUse %t, groupSnapshotID %s", driverName, snapshotID, creationTime, size, readyToUse, groupSnapshotID)
|
||||
|
||||
if creationTime.IsZero() {
|
||||
creationTime = time.Now()
|
||||
}
|
||||
|
||||
updatedContent, err := ctrl.updateSnapshotContentStatus(content, snapshotID, readyToUse, creationTime.UnixNano(), size)
|
||||
updatedContent, err := ctrl.updateSnapshotContentStatus(content, snapshotID, readyToUse, creationTime.UnixNano(), size, groupSnapshotID)
|
||||
if err != nil {
|
||||
return content, err
|
||||
}
|
||||
@@ -354,7 +355,7 @@ func (ctrl *csiSnapshotSideCarController) createSnapshotWrapper(content *crdv1.V
|
||||
creationTime = time.Now()
|
||||
}
|
||||
|
||||
newContent, err := ctrl.updateSnapshotContentStatus(content, snapshotID, readyToUse, creationTime.UnixNano(), size)
|
||||
newContent, err := ctrl.updateSnapshotContentStatus(content, snapshotID, readyToUse, creationTime.UnixNano(), size, "")
|
||||
if err != nil {
|
||||
klog.Errorf("error updating status for volume snapshot content %s: %v.", content.Name, err)
|
||||
return content, fmt.Errorf("error updating status for volume snapshot content %s: %v", content.Name, err)
|
||||
@@ -429,8 +430,9 @@ func (ctrl *csiSnapshotSideCarController) updateSnapshotContentStatus(
|
||||
snapshotHandle string,
|
||||
readyToUse bool,
|
||||
createdAt int64,
|
||||
size int64) (*crdv1.VolumeSnapshotContent, error) {
|
||||
klog.V(5).Infof("updateSnapshotContentStatus: updating VolumeSnapshotContent [%s], snapshotHandle %s, readyToUse %v, createdAt %v, size %d", content.Name, snapshotHandle, readyToUse, createdAt, size)
|
||||
size int64,
|
||||
groupSnapshotID string) (*crdv1.VolumeSnapshotContent, error) {
|
||||
klog.V(5).Infof("updateSnapshotContentStatus: updating VolumeSnapshotContent [%s], snapshotHandle %s, readyToUse %v, createdAt %v, size %d, groupSnapshotID %s", content.Name, snapshotHandle, readyToUse, createdAt, size, groupSnapshotID)
|
||||
|
||||
contentObj, err := ctrl.clientset.SnapshotV1().VolumeSnapshotContents().Get(context.TODO(), content.Name, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
@@ -446,6 +448,9 @@ func (ctrl *csiSnapshotSideCarController) updateSnapshotContentStatus(
|
||||
CreationTime: &createdAt,
|
||||
RestoreSize: &size,
|
||||
}
|
||||
if groupSnapshotID != "" {
|
||||
newStatus.VolumeGroupSnapshotHandle = &groupSnapshotID
|
||||
}
|
||||
updated = true
|
||||
} else {
|
||||
newStatus = contentObj.Status.DeepCopy()
|
||||
@@ -468,6 +473,10 @@ func (ctrl *csiSnapshotSideCarController) updateSnapshotContentStatus(
|
||||
newStatus.RestoreSize = &size
|
||||
updated = true
|
||||
}
|
||||
if newStatus.VolumeGroupSnapshotHandle == nil && groupSnapshotID != "" {
|
||||
newStatus.VolumeGroupSnapshotHandle = &groupSnapshotID
|
||||
updated = true
|
||||
}
|
||||
}
|
||||
|
||||
if updated {
|
||||
|
Reference in New Issue
Block a user