Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

disk: remove expand auto snapshot #1213

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pkg/disk/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,6 @@ const (
annAppendPrefix = "csi.alibabacloud.com/annotation-prefix/"

VolumeDeleteAutoSnapshotKey = "csi.alibabacloud.com/volume-delete-autosnapshot-retentiondays"
VOLUME_EXPAND_AUTO_SNAPSHOT_OP_KEY = "volumeExpandAutoSnapshot"
VOLUME_DELETE_AUTO_SNAPSHOT_OP_RETENT_DAYS_KEY = "volumeDeleteSnapshotRetentionDays"

PROVISIONED_IOPS_KEY = "provisionedIops"
Expand Down
134 changes: 0 additions & 134 deletions pkg/disk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"github.com/aliyun/alibaba-cloud-sdk-go/services/ecs"
"github.com/container-storage-interface/spec/lib/go/csi"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/common"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/features"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
Expand Down Expand Up @@ -775,12 +774,6 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
return &csi.ControllerExpandVolumeResponse{CapacityBytes: volSizeBytes, NodeExpansionRequired: true}, nil
}

// Check if autoSnapshot is enabled
ok, snapshot, err := cs.autoSnapshot(ctx, disk)
if !ok {
return nil, status.Errorf(codes.Internal, "ControllerExpandVolume:: autoSnapshot failed with error: %+v", err)
}
snapshotEnable := snapshot != nil
// do resize
resizeDiskRequest := ecs.CreateResizeDiskRequest()
resizeDiskRequest.RegionId = GlobalConfigVar.Region
Expand All @@ -793,24 +786,15 @@ func (cs *controllerServer) ControllerExpandVolume(ctx context.Context, req *csi
response, err := resizeDisk(ctx, ecsClient, resizeDiskRequest)
if err != nil {
klog.Errorf("ControllerExpandVolume:: resize got error: %s", err.Error())
if snapshotEnable {
cs.deleteUntagAutoSnapshot(snapshot.SnapshotId, diskID)
}
return nil, status.Errorf(codes.Internal, "resize disk %s get error: %s", diskID, err.Error())
}
checkDisk, err := findDiskByID(disk.DiskId, ecsClient)
if err != nil {
klog.Infof("ControllerExpandVolume:: find disk failed with error: %+v", err)
if snapshotEnable {
cs.deleteUntagAutoSnapshot(snapshot.SnapshotId, diskID)
}
return nil, status.Errorf(codes.Internal, "ControllerExpandVolume:: find disk failed with error: %+v", err)
}
if requestGB != checkDisk.Size {
klog.Infof("ControllerExpandVolume:: resize disk err with excepted size: %vGB, actual size: %vGB", requestGB, checkDisk.Size)
if snapshotEnable {
klog.Warningf("ControllerExpandVolume:: Please use the snapshot %s for data recovery. The retentionDays is %d", snapshot.SnapshotId, veasp.RetentionDays)
}
return nil, status.Errorf(codes.Internal, "resize disk err with excepted size: %vGB, actual size: %vGB", requestGB, checkDisk.Size)
}

Expand Down Expand Up @@ -874,107 +858,6 @@ func updateVolumeExpandAutoSnapshotID(pvc *v1.PersistentVolumeClaim, snapshotID,
return nil
}

// autoSnapshot is used in volume expanding of ESSD,
// returns if the volume expanding should be continued
func (cs *controllerServer) autoSnapshot(ctx context.Context, disk *ecs.Disk) (bool, *csi.Snapshot, error) {
if features.FunctionalMutableFeatureGate.Enabled(features.DisableExpandAutoSnapshots) {
return true, nil, nil
}
if !AllCategories[Category(disk.Category)].InstantAccessSnapshot {
return true, nil, nil
}
pv, pvc, err := getPvPvcFromDiskId(disk.DiskId)
if err != nil {
klog.Errorf("ControllerExpandVolume:: failed to get pvc from apiserver: %s", err.Error())
return true, nil, nil
}

if pv.Spec.CSI == nil || pv.Spec.CSI.VolumeAttributes == nil {
klog.Errorf("ControllerExpandVolume: pv.Spec.CSI/Spec.CSI.VolumeAttributes is nil, volumeId=%s", disk.DiskId)
return true, nil, nil
}

if value, ok := pv.Spec.CSI.VolumeAttributes["volumeExpandAutoSnapshot"]; !ok || value == "closed" {
return true, nil, nil
}

snapshotEnable := false
snapshot, err := cs.createVolumeExpandAutoSnapshot(ctx, pv, disk)
if err != nil {
klog.Errorf("ControllerExpandVolume:: failed to create volumeExpandAutoSnapshot: %s", err.Error())
if strings.Contains(err.Error(), NeverAttached) {
return true, nil, err
}
} else {
snapshotEnable = true
err = updateVolumeExpandAutoSnapshotID(pvc, snapshot.SnapshotId, "add")
if err != nil {
klog.Errorf("ControllerExpandVolume:: failed to tag volumeExpandAutoSnapshot: %s", err.Error())
err = cs.deleteVolumeExpandAutoSnapshot(ctx, pvc, snapshot.SnapshotId)
if err != nil {
klog.Errorf("ControllerExpandVolume:: failed to delete volumeExpandAutoSnapshot: %s", err.Error())
}
snapshotEnable = false
}
}
if pv.Spec.CSI.VolumeAttributes["volumeExpandAutoSnapshot"] == "forced" {
return snapshotEnable, snapshot, err
} else {
return true, snapshot, err
}
}

func (cs *controllerServer) createVolumeExpandAutoSnapshot(ctx context.Context, pv *v1.PersistentVolume, disk *ecs.Disk) (*csi.Snapshot, error) {
// create the instance snapshot
cur := time.Now()
timeStr := cur.Format("-2006-01-02-15:04:05")
volumeExpandAutoSnapshotName := veasp.Prefix + pv.Name + timeStr
sourceVolumeID := disk.DiskId

klog.Infof("ControllerExpandVolume:: Starting to create volumeExpandAutoSnapshot with name: %s", volumeExpandAutoSnapshotName)

GlobalConfigVar.EcsClient = updateEcsClient(GlobalConfigVar.EcsClient)

pvcName, pvcNamespace := pv.Spec.ClaimRef.Name, pv.Spec.ClaimRef.Namespace
pvc, err := GlobalConfigVar.ClientSet.CoreV1().PersistentVolumeClaims(pvcNamespace).Get(ctx, pvcName, metav1.GetOptions{})
if err != nil {
klog.Errorf("ControllerExpandVolume:: failed to get pvc from apiserver: %v", err)
return nil, err
}

ecsClient, err := getEcsClientByID(sourceVolumeID, "")
if err != nil {
return nil, status.Error(codes.Internal, err.Error())
}

// init createSnapshotRequest and parameters
createAt := timestamppb.New(cur)
snapshotResponse, err := requestAndCreateSnapshot(ecsClient, &createSnapshotParams{
SourceVolumeID: sourceVolumeID,
SnapshotName: volumeExpandAutoSnapshotName,
RetentionDays: veasp.RetentionDays,
})
if err != nil {
klog.Errorf("ControllerExpandVolume:: volumeExpandAutoSnapshot create Failed: snapshotName[%s], sourceId[%s], error[%s]", volumeExpandAutoSnapshotName, sourceVolumeID, err.Error())
cs.recorder.Event(pvc, v1.EventTypeWarning, snapshotCreateError, err.Error())
return nil, status.Errorf(codes.Internal, "volumeExpandAutoSnapshot create Failed: %v", err)
}

str := fmt.Sprintf("ControllerExpandVolume:: Snapshot create successful: snapshotName[%s], sourceId[%s], snapshotId[%s]", volumeExpandAutoSnapshotName, sourceVolumeID, snapshotResponse.SnapshotId)
klog.Infof(str)
csiSnapshot := &csi.Snapshot{
SnapshotId: snapshotResponse.SnapshotId,
SourceVolumeId: sourceVolumeID,
CreationTime: createAt,
ReadyToUse: false, // even if instant access is available, the snapshot is not ready to use immediately
SizeBytes: utils.Gi2Bytes(int64(disk.Size)),
}
cs.recorder.Event(pvc, v1.EventTypeNormal, snapshotCreatedSuccessfully, str)

return csiSnapshot, nil

}

func (cs *controllerServer) deleteVolumeExpandAutoSnapshot(ctx context.Context, pvc *v1.PersistentVolumeClaim, snapshotID string) error {
klog.Infof("ControllerExpandVolume:: Starting to delete volumeExpandAutoSnapshot with id: %s", snapshotID)

Expand All @@ -995,20 +878,3 @@ func (cs *controllerServer) deleteVolumeExpandAutoSnapshot(ctx context.Context,
cs.recorder.Event(pvc, v1.EventTypeNormal, snapshotDeletedSuccessfully, str)
return nil
}

// deleteUntagAutoSnapshot deletes and untags volumeExpandAutoSnapshot facing expand error
func (cs *controllerServer) deleteUntagAutoSnapshot(snapshotID, diskID string) {
klog.Infof("Deleted volumeExpandAutoSnapshot with id: %s", snapshotID)
_, pvc, err := getPvPvcFromDiskId(diskID)
if err != nil {
klog.Errorf("ControllerExpandVolume:: failed to get pvc from apiserver: %s", err.Error())
}
err = cs.deleteVolumeExpandAutoSnapshot(context.Background(), pvc, snapshotID)
if err != nil {
klog.Errorf("ControllerExpandVolume:: failed to delete volumeExpandAutoSnapshot: %s", err.Error())
}
err = updateVolumeExpandAutoSnapshotID(pvc, snapshotID, "delete")
if err != nil {
klog.Errorf("ControllerExpandVolume:: failed to untag volumeExpandAutoSnapshot: %s", err.Error())
}
}
12 changes: 2 additions & 10 deletions pkg/disk/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ import (
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/cloud/metadata"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/common"
proto "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/disk/proto"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/features"
"github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils"
utilshttp "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils/http"
utilsio "github.com/kubernetes-sigs/alibaba-cloud-csi-driver/pkg/utils/io"
Expand Down Expand Up @@ -684,15 +683,8 @@ func getDiskVolumeOptions(req *csi.CreateVolumeRequest) (*diskVolumeArgs, error)
}
}

// volumeExpandAutoSnapshot, default closed
if !features.FunctionalMutableFeatureGate.Enabled(features.DisableExpandAutoSnapshots) {
if value, ok = volOptions[VOLUME_EXPAND_AUTO_SNAPSHOT_OP_KEY]; ok {
value = strings.ToLower(value)
if value != "forced" && value != "besteffort" && value != "closed" {
return nil, fmt.Errorf("illegal optional parameter volumeExpandAutoSnapshot, only support forced, besteffort and closed, the input is: %s", value)
}
}
}
// volumeExpandAutoSnapshot parameter is obsolete and has no effect now

if value, ok = volOptions[VOLUME_DELETE_AUTO_SNAPSHOT_OP_RETENT_DAYS_KEY]; ok {
iValue, err := strconv.Atoi(value)
if err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/features/features.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ var (
DiskADController: {Default: false, PreRelease: featuregate.Alpha},
DiskParallelAttach: {Default: false, PreRelease: featuregate.Alpha},
DiskParallelDetach: {Default: false, PreRelease: featuregate.Alpha},
DisableExpandAutoSnapshots: {Default: true, PreRelease: featuregate.Beta},
DisableExpandAutoSnapshots: {Default: true, PreRelease: featuregate.GA, LockToDefault: true},
}

defaultOSSFeatureGate = map[featuregate.Feature]featuregate.FeatureSpec{
Expand Down