Skip to content

Commit

Permalink
Instantiate drives and ignore pvs errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jleeh committed Aug 13, 2024
1 parent c569d36 commit e0765c4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
21 changes: 17 additions & 4 deletions pkg/lvm/lvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions tests/bats/test.bats
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e0765c4

Please sign in to comment.