From e0765c42fc73e290bd6154edef6a4b85f03cc8bd Mon Sep 17 00:00:00 2001 From: Jonny Date: Tue, 13 Aug 2024 10:46:17 +0100 Subject: [PATCH] Instantiate drives and ignore pvs errors --- pkg/lvm/lvm.go | 21 +++++++++++++++++---- tests/bats/test.bats | 5 +++++ 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/pkg/lvm/lvm.go b/pkg/lvm/lvm.go index 7ffc4ce3..275af58e 100644 --- a/pkg/lvm/lvm.go +++ b/pkg/lvm/lvm.go @@ -279,11 +279,26 @@ func umountLV(targetPath string) { } func createGetCapacityPod(ctx context.Context, va volumeAction) (int64, error) { + // Prior to running the pvs command, run pvcreate with the device pattern as physical volumes aren't initialised + // if the node is new. This would result in 0 capacity causing PVCs to never be scheduled onto a new node. + pvCreateVA := va + pvCreateVA.action = "pvcreate" + _, deleteFunc, err := createPod( + ctx, + "sh", + []string{"-c", fmt.Sprintf("pvcreate %s", va.devicesPattern)}, + pvCreateVA, + ) + if err != nil { + return 0, err + } + defer deleteFunc() + // Wrap command in a shell or the device pattern is wrapped in quotes causing pvs to error provisionerPod, deleteFunc, err := createPod( ctx, "sh", - []string{"-c", fmt.Sprintf("pvs %s %s %s %s", va.devicesPattern, "--units=B", "--reportformat=json", "--nosuffix")}, + []string{"-c", fmt.Sprintf("pvs %s %s %s %s %s", va.devicesPattern, "--units=B", "--reportformat=json", "--nosuffix", "2>/dev/null")}, va, ) if err != nil { @@ -318,7 +333,7 @@ func createGetCapacityPod(ctx context.Context, va volumeAction) (int64, error) { resp := podLogRequest.Do(ctx) if resp.Error() != nil { - return 0, fmt.Errorf("failed to get logs from pv capacity pod: %w node:%s", err, va.nodeName) + return 0, fmt.Errorf("failed to get logs from pv capacity pod: %w node:%s", resp.Error(), va.nodeName) } logs, err := resp.Raw() if err != nil { @@ -629,8 +644,6 @@ func CreateLVS(vg string, name string, size uint64, lvmType string) (string, err return "", fmt.Errorf("lvmType is incorrect: %s", lvmType) } - // TODO: check available capacity, fail if request doesn't fit - args := []string{"-v", "--yes", "-n", name, "-W", "y", "-L", fmt.Sprintf("%db", size)} pvs, err := pvCount(vg) diff --git a/tests/bats/test.bats b/tests/bats/test.bats index 01eb564a..e55b4405 100644 --- a/tests/bats/test.bats +++ b/tests/bats/test.bats @@ -124,6 +124,11 @@ [ "$status" -eq 0 ] } +@test "check capacity tracking" { + run kubectl wait --for=jsonpath='{.status.phase}'=Running -f files/pod.inline.vol.xfs.yaml --timeout=10s + [ "$status" -eq 0 ] +} + @test "delete csi-lvm-controller" { echo "⏳ Wait 10s for all PVCs to be cleaned up..." >&3 sleep 10