Skip to content

Commit

Permalink
some fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Aleksandr Zimin <alexandr.zimin@flant.com>
  • Loading branch information
AleksZimin committed Aug 17, 2024
1 parent 275c7a6 commit 45f489b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 23 deletions.
3 changes: 1 addition & 2 deletions images/sds-local-volume-csi/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,7 @@ func (d *Driver) ControllerExpandVolume(ctx context.Context, request *csi.Contro

d.log.Info(fmt.Sprintf("[ControllerExpandVolume][traceID:%s][volumeID:%s] start resize LVMLogicalVolume", traceID, volumeID))
d.log.Info(fmt.Sprintf("[ControllerExpandVolume][traceID:%s][volumeID:%s] requested size: %s, actual size: %s", traceID, volumeID, requestCapacity.String(), llv.Status.ActualSize.String()))
llv.Spec.Size = requestCapacity.String()
err = utils.UpdateLVMLogicalVolume(ctx, d.cl, llv)
err = utils.ExpandLVMLogicalVolume(ctx, d.cl, llv, requestCapacity.String())
if err != nil {
d.log.Error(err, fmt.Sprintf("[ControllerExpandVolume][traceID:%s][volumeID:%s] error updating LVMLogicalVolume", traceID, volumeID))
return nil, status.Errorf(codes.Internal, "error updating LVMLogicalVolume: %v", err)
Expand Down
75 changes: 54 additions & 21 deletions images/sds-local-volume-csi/pkg/utils/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -290,20 +290,33 @@ func GetLVMThinPoolFreeSpace(lvg snc.LvmVolumeGroup, thinPoolName string) (thinP
return storagePoolThinPool.AvailableSpace, nil
}

func UpdateLVMLogicalVolume(ctx context.Context, kc client.Client, llv *snc.LVMLogicalVolume) error {
var err error
func ExpandLVMLogicalVolume(ctx context.Context, kc client.Client, llv *snc.LVMLogicalVolume, newSize string) error {
for attempt := 0; attempt < KubernetesAPIRequestLimit; attempt++ {
err = kc.Update(ctx, llv)
llv.Spec.Size = newSize
err := kc.Update(ctx, llv)
if err == nil {
return nil
}
time.Sleep(KubernetesAPIRequestTimeout)
}

if err != nil {
return fmt.Errorf("after %d attempts of updating LVMLogicalVolume %s, last error: %w", KubernetesAPIRequestLimit, llv.Name, err)
if attempt < KubernetesAPIRequestLimit-1 {
select {
case <-ctx.Done():
return ctx.Err()
default:
time.Sleep(KubernetesAPIRequestTimeout)
}

if kerrors.IsConflict(err) {
freshLLV, getErr := GetLVMLogicalVolume(ctx, kc, llv.Name, "")
if getErr != nil {
return fmt.Errorf("[ExpandLVMLogicalVolume] error getting LVMLogicalVolume %s after update conflict: %w", llv.Name, getErr)
}
llv = freshLLV
}
}
}
return nil

return fmt.Errorf("after %d attempts of expanding LVMLogicalVolume %s, last error: %w", KubernetesAPIRequestLimit, llv.Name, nil)
}

func GetStorageClassLVGsAndParameters(ctx context.Context, kc client.Client, log *logger.Logger, storageClassLVGParametersString string) (storageClassLVGs []snc.LvmVolumeGroup, storageClassLVGParametersMap map[string]string, err error) {
Expand Down Expand Up @@ -393,24 +406,44 @@ func SelectLVG(storageClassLVGs []snc.LvmVolumeGroup, nodeName string) (snc.LvmV
}

func removeLLVFinalizerIfExist(ctx context.Context, kc client.Client, llv *snc.LVMLogicalVolume, finalizer string) (bool, error) {
removed := false
for attempt := 0; attempt < KubernetesAPIRequestLimit; attempt++ {
removed := false
for i, val := range llv.Finalizers {
if val == finalizer {
llv.Finalizers = slices.Delete(llv.Finalizers, i, i+1)
removed = true
break
}
}

for i, val := range llv.Finalizers {
if val == finalizer {
llv.Finalizers = slices.Delete(llv.Finalizers, i, i+1)
removed = true
break
if !removed {
return false, nil
}
}

if removed {
err := UpdateLVMLogicalVolume(ctx, kc, llv)
if err != nil {
return false, err
err := kc.Update(ctx, llv)
if err == nil {
return true, nil
}

if attempt < KubernetesAPIRequestLimit-1 {
select {
case <-ctx.Done():
return false, ctx.Err()
default:
time.Sleep(KubernetesAPIRequestTimeout)
}

if kerrors.IsConflict(err) {
freshLLV, getErr := GetLVMLogicalVolume(ctx, kc, llv.Name, "")
if getErr != nil {
return false, fmt.Errorf("[removeLLVFinalizerIfExist] error getting LVMLogicalVolume %s after update conflict: %w", llv.Name, getErr)
}
llv = freshLLV
}
}
return true, nil
}
return false, nil

return false, fmt.Errorf("after %d attempts of removing finalizer %s from LVMLogicalVolume %s, last error: %w", KubernetesAPIRequestLimit, finalizer, llv.Name, nil)
}

func IsContiguous(request *csi.CreateVolumeRequest, lvmType string) bool {
Expand Down

0 comments on commit 45f489b

Please sign in to comment.