Skip to content

Commit

Permalink
disk: do not delete expand auto snapshot
Browse files Browse the repository at this point in the history
Avoid OpenAPI authorization on node server
  • Loading branch information
huww98 committed Nov 13, 2024
1 parent 816087c commit 68a5ab5
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 104 deletions.
46 changes: 0 additions & 46 deletions pkg/disk/controllerserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,6 @@ type diskVolumeArgs struct {
RequestGB int64
}

var veasp = struct {
IDKey string
Prefix string
RetentionDays int
}{"volumeExpandAutoSnapshotID", "volume-expand-auto-snapshot-", 1}

var delVolumeSnap sync.Map

// NewControllerServer is to create controller server
Expand Down Expand Up @@ -865,43 +859,3 @@ func formatCSISnapshot(ecsSnapshot *ecs.Snapshot) (*csi.Snapshot, error) {
ReadyToUse: ecsSnapshot.Available,
}, nil
}

func updateVolumeExpandAutoSnapshotID(pvc *v1.PersistentVolumeClaim, snapshotID, option string) error {
var err error

volumeExpandAutoSnapshotMap := map[string]string{
veasp.IDKey: snapshotID,
}
for n := 1; n < RetryMaxTimes; n++ {
_, err = updatePvcWithAnnotations(context.Background(), pvc, volumeExpandAutoSnapshotMap, option)
if err != nil {
continue
}
break
}
if err != nil {
return status.Errorf(codes.Internal, "failed to %s snapshotID on pvc", option)
}
return 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)

GlobalConfigVar.EcsClient = updateEcsClient(GlobalConfigVar.EcsClient)

// Delete Snapshot
response, err := requestAndDeleteSnapshot(snapshotID)
if err != nil {
if response != nil {
klog.Errorf("ControllerExpandVolume:: fail to delete %s with error: %s", snapshotID, err.Error())
}

cs.recorder.Event(pvc, v1.EventTypeWarning, snapshotDeleteError, err.Error())
return status.Errorf(codes.Internal, "volumeExpandAutoSnapshot delete Failed: %v", err)
}

str := fmt.Sprintf("ControllerExpandVolume:: Successfully delete snapshot %s", snapshotID)
cs.recorder.Event(pvc, v1.EventTypeNormal, snapshotDeletedSuccessfully, str)
return nil
}
59 changes: 1 addition & 58 deletions pkg/disk/nodeserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -928,16 +928,6 @@ func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
return &csi.NodeExpandVolumeResponse{}, nil
}

_, pvc, err := getPvPvcFromDiskId(diskID)
if err != nil {
klog.Errorf("NodeExpandVolume:: failed to get pvc from apiserver: %s", err.Error())
}

volumeExpandAutoSnapshotID := ""
if pvc != nil && pvc.Annotations != nil {
volumeExpandAutoSnapshotID, _ = pvc.Annotations[veasp.IDKey]
}

// volume resize in rund type will transfer to guest os
isRund, err := checkRundVolumeExpand(req)
if isRund && err == nil {
Expand All @@ -948,18 +938,7 @@ func (ns *nodeServer) NodeExpandVolume(ctx context.Context, req *csi.NodeExpandV
return nil, status.Error(codes.InvalidArgument, err.Error())
}

snapshotEnable := volumeExpandAutoSnapshotID != ""
defer func() {
if snapshotEnable {
deleteUntagAutoSnapshot(volumeExpandAutoSnapshotID, diskID)
}
}()
resp, err := localExpandVolume(ctx, req)
if err != nil && snapshotEnable {
klog.Warningf("NodeExpandVolume:: Please use the snapshot %s for data recovery. The retentionDays is %d", volumeExpandAutoSnapshotID, veasp.RetentionDays)
snapshotEnable = false
}
return resp, err
return localExpandVolume(ctx, req)
}

func localExpandVolume(ctx context.Context, req *csi.NodeExpandVolumeRequest) (*csi.NodeExpandVolumeResponse, error) {
Expand Down Expand Up @@ -1168,42 +1147,6 @@ func collectMountOptions(fsType string, mntFlags []string) (options []string) {

}

// func handle error : event( autoSnapshot ID return) + error
func deleteVolumeExpandAutoSnapshot(ctx context.Context, volumeExpandAutoSnapshotID string) error {
klog.Infof("NodeExpandVolume:: Starting to delete volumeExpandAutoSnapshot with id: %s", volumeExpandAutoSnapshotID)

GlobalConfigVar.EcsClient = updateEcsClient(GlobalConfigVar.EcsClient)

response, err := requestAndDeleteSnapshot(volumeExpandAutoSnapshotID)
if err != nil {
if response != nil {
klog.Errorf("NodeExpandVolume:: fail to delete %s with error: %s", volumeExpandAutoSnapshotID, err.Error())
}
return err
}
str := fmt.Sprintf("NodeExpandVolume:: Successfully delete snapshot %s", volumeExpandAutoSnapshotID)
klog.Info(str)
//utils.CreateEvent(cs.recorder, ref, v1.EventTypeNormal, snapshotDeletedSuccessfully, str)
return nil
}

// deleteUntagAutoSnapshot deletes and untags volumeExpandAutoSnapshot facing expand error
func deleteUntagAutoSnapshot(snapshotID, diskID string) {
klog.Infof("Deleted volumeExpandAutoSnapshot with id: %s", snapshotID)
_, pvc, err := getPvPvcFromDiskId(diskID)
if err != nil {
klog.Errorf("NodeExpandVolume:: failed to get pvc from apiserver: %s", err.Error())
}
err = deleteVolumeExpandAutoSnapshot(context.Background(), snapshotID)
if err != nil {
klog.Errorf("NodeExpandVolume:: failed to delete volumeExpandAutoSnapshot: %s", err.Error())
}
err = updateVolumeExpandAutoSnapshotID(pvc, snapshotID, "delete")
if err != nil {
klog.Errorf("NodeExpandVolume:: failed to untag volumeExpandAutoSnapshot: %s", err.Error())
}
}

// umountRunDVolumes umount runD volumes
func (ns *nodeServer) umountRunDVolumes(volumePath string) (bool, error) {
// check runtime mode
Expand Down

0 comments on commit 68a5ab5

Please sign in to comment.