Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] feat(shared-vg) : add support for create, delete, publish & unpublish of shared volumes #184

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
removed support for shared thin provisioning
  • Loading branch information
Abhishek Agarwal committed Apr 8, 2022
commit 2f8af972b6ff1a3530a2f1d39e29f7bf8a888e42
6 changes: 6 additions & 0 deletions pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,12 @@ func CreateLVMVolume(ctx context.Context, req *csi.CreateVolumeRequest,
capacity := strconv.FormatInt(getRoundedCapacity(
req.GetCapacityRange().RequiredBytes), 10)

// Thin provisioning is not allowed for shared volumes currently
// TODO add support for thin provisioning for shared volumes
if lvmapi.SharedModeType(params.SharedMode) == lvmapi.LVMExclusiveSharedMode && params.ThinProvision == lvm.YES {
return nil, status.Errorf(codes.Internal, "Thin provisioning not allowed for shared volumes")
}

vol, err := lvm.GetLVMVolume(volName)
if err != nil {
if !k8serror.IsNotFound(err) {
Expand Down
15 changes: 2 additions & 13 deletions pkg/lvm/lvm_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,24 +350,13 @@ func ActivateLVMLogicalVolume(vol *apis.LVMVolume, activate bool) error {
lvStateArg = "-an"
}

// change the state of thin pool first if thin volumes are provisioned
if vol.Spec.ThinProvision == YES {
// check buildLVMCreateArgs() in the current file to see how thin pool name is formed
pool := vol.Spec.VolGroup + "_thinpool"
cmd := exec.Command(LVChange, lvStateArg, vol.Spec.VolGroup+"/"+pool)
_, err := cmd.CombinedOutput()
if err != nil {
klog.Errorf("failed to change thin pool {%s}'s state: %v", pool, err)
return err
}
}

// change the state of the volume
volume := vol.Spec.VolGroup + "/" + vol.Name
cmd := exec.Command(LVChange, lvStateArg, volume)
_, err := cmd.CombinedOutput()
out, err := cmd.CombinedOutput()
if err != nil {
klog.Errorf("failed to change the volume {%s}'s state: %v", volume, err)
err = newExecError(out, err)
return err
}

Expand Down
65 changes: 37 additions & 28 deletions pkg/mgmt/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package volume

import (
"fmt"
"github.com/pkg/errors"
"regexp"
"sort"
"strconv"
Expand Down Expand Up @@ -99,41 +100,49 @@ func (c *VolController) syncVol(vol *apis.LVMVolume) error {
return nil
}

// if there is already a volGroup field set for lvmvolume resource,
// we'll first try to create a volume in that volume group.
if vol.Spec.VolGroup != "" {
err = lvm.CreateVolume(vol)
if err == nil {
return lvm.UpdateVolInfo(vol, lvm.LVMStatusReady)
// Restrict thin volume creation in shared mode
// TODO add support for thin provisioning in shared mode
if vol.Spec.SharedMode == apis.LVMExclusiveSharedMode && vol.Spec.ThinProvision == lvm.YES {
err = errors.Errorf("Thin provisioning is not allowed for shared volume %s", vol.Name)
vol.Status.Error = c.transformLVMError(err)
} else {
// if there is already a volGroup field set for lvmvolume resource,
// we'll first try to create a volume in that volume group.
if vol.Spec.VolGroup != "" {
err = lvm.CreateVolume(vol)
if err == nil {
return lvm.UpdateVolInfo(vol, lvm.LVMStatusReady)
}
}
}

vgs, err := c.getVgPriorityList(vol)
if err != nil {
return err
}
vgs, err := c.getVgPriorityList(vol)
if err != nil {
return err
}

if len(vgs) == 0 {
err = fmt.Errorf("no vg available to serve volume request having regex=%q & capacity=%q",
vol.Spec.VgPattern, vol.Spec.Capacity)
klog.Errorf("lvm volume %v - %v", vol.Name, err)
} else {
for _, vg := range vgs {
// first update volGroup field in lvm volume resource for ensuring
// idempotency and avoiding volume leaks during crash.
if vol, err = lvm.UpdateVolGroup(vol, vg.Name); err != nil {
klog.Errorf("failed to update volGroup to %v: %v", vg.Name, err)
return err
}
if err = lvm.CreateVolume(vol); err == nil {
return lvm.UpdateVolInfo(vol, lvm.LVMStatusReady)
if len(vgs) == 0 {
err = fmt.Errorf("no vg available to serve volume request having regex=%q & capacity=%q",
vol.Spec.VgPattern, vol.Spec.Capacity)
klog.Errorf("lvm volume %v - %v", vol.Name, err)
} else {
for _, vg := range vgs {
// first update volGroup field in lvm volume resource for ensuring
// idempotency and avoiding volume leaks during crash.
if vol, err = lvm.UpdateVolGroup(vol, vg.Name); err != nil {
klog.Errorf("failed to update volGroup to %v: %v", vg.Name, err)
return err
}
if err = lvm.CreateVolume(vol); err == nil {
return lvm.UpdateVolInfo(vol, lvm.LVMStatusReady)
}
}
}

// In case no vg available or lvm.CreateVolume fails for all vgs, mark
// the volume provisioning failed so that controller can reschedule it.
vol.Status.Error = c.transformLVMError(err)
}

// In case no vg available or lvm.CreateVolume fails for all vgs, mark
// the volume provisioning failed so that controller can reschedule it.
vol.Status.Error = c.transformLVMError(err)
return lvm.UpdateVolInfo(vol, lvm.LVMStatusFailed)
}

Expand Down