Skip to content

Commit

Permalink
fix
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 Feb 19, 2024
1 parent 59351ad commit 7c45a4d
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions images/sds-lvm-csi/pkg/utils/func.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"math"
"sds-lvm-csi/api/v1alpha1"
"sds-lvm-csi/pkg/logger"
"time"
Expand All @@ -31,6 +32,7 @@ import (

const (
LLVStatusCreated = "Created"
LLVStatusFailed = "Failed"
LLVTypeThin = "Thin"
KubernetesApiRequestLimit = 3
KubernetesApiRequestTimeout = 1
Expand Down Expand Up @@ -118,8 +120,11 @@ func WaitForStatusUpdate(ctx context.Context, kc client.Client, log logger.Logge

sizeEquals := AreSizesEqualWithinDelta(llvSize, llv.Status.ActualSize, delta)

if attemptCounter%20 == 0 {
if attemptCounter%10 == 0 {
log.Info(fmt.Sprintf("[WaitForStatusUpdate] Attempt: %d,LVM Logical Volume status: %+v; delta=%s; sizeEquals=%t", attemptCounter, llv.Status, delta.String(), sizeEquals))
if llv.Status != nil && llv.Status.Phase == LLVStatusFailed {
return attemptCounter, fmt.Errorf("LVM Logical Volume %s in namespace %s failed", LvmLogicalVolumeName, namespace)
}
}
if llv.Status != nil && llv.Status.Phase == LLVStatusCreated && sizeEquals {
return attemptCounter, nil
Expand All @@ -146,12 +151,10 @@ func GetLVMLogicalVolume(ctx context.Context, kc client.Client, LvmLogicalVolume
}

func AreSizesEqualWithinDelta(leftSize, rightSize, allowedDelta resource.Quantity) bool {
delta := leftSize.DeepCopy()
delta.Sub(rightSize)
if delta.Sign() < 0 {
delta.Neg()
}
return delta.Cmp(allowedDelta) <= 0
leftSizeFloat := float64(leftSize.Value())
rightSizeFloat := float64(rightSize.Value())

return math.Abs(leftSizeFloat-rightSizeFloat) < float64(delta.Value())
}

func GetNodeMaxFreeVGSize(ctx context.Context, kc client.Client) (nodeName string, freeSpace resource.Quantity, err error) {
Expand Down

0 comments on commit 7c45a4d

Please sign in to comment.