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

feat(resize): adding resize support for lvm volumes #4

Merged
merged 3 commits into from
Jan 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
3 changes: 0 additions & 3 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ jobs:
- name: License test
run: make license-check

- name: Lint test
run: make golint

- name: Shellcheck
uses: reviewdog/action-shellcheck@v1
with:
Expand Down
2 changes: 1 addition & 1 deletion buildscripts/lvm-driver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

FROM alpine:3.12
RUN apk add --no-cache lvm2 lvm2-extra util-linux device-mapper
RUN apk add --no-cache btrfs-progs xfsprogs e2fsprogs e2fsprogs-extra
RUN apk add --no-cache btrfs-progs xfsprogs xfsprogs-extra e2fsprogs e2fsprogs-extra
akhilerm marked this conversation as resolved.
Show resolved Hide resolved
RUN apk add --no-cache ca-certificates libc6-compat

ARG DBUILD_DATE
Expand Down
1 change: 1 addition & 0 deletions changelog/unreleased/1-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adding multi arch build process for LVM Driver
1 change: 1 addition & 0 deletions changelog/unreleased/2-pawanpraka1
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
adding resize support for lvm volumes
20 changes: 18 additions & 2 deletions deploy/lvm-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -626,7 +626,10 @@ rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: ["*"]
- apiGroups: [""]
resources: ["pods"]
akhilerm marked this conversation as resolved.
Show resolved Hide resolved
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: ["local.openebs.io"]
resources: ["lvmvolumes"]
verbs: ["*"]
---
Expand Down Expand Up @@ -681,6 +684,19 @@ spec:
priorityClassName: system-cluster-critical
serviceAccount: openebs-lvm-controller-sa
containers:
- name: csi-resizer
image: quay.io/k8scsi/csi-resizer:v1.1.0
args:
- "--v=5"
- "--csi-address=$(ADDRESS)"
- "--leader-election"
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
imagePullPolicy: IfNotPresent
volumeMounts:
- name: socket-dir
mountPath: /var/lib/csi/sockets/pluginproxy/
- name: csi-provisioner
image: k8s.gcr.io/sig-storage/csi-provisioner:v2.1.0
imagePullPolicy: IfNotPresent
Expand Down Expand Up @@ -802,7 +818,7 @@ rules:
- apiGroups: [""]
resources: ["persistentvolumes", "nodes", "services"]
verbs: ["get", "list"]
- apiGroups: ["*"]
- apiGroups: ["local.openebs.io"]
resources: ["lvmvolumes"]
verbs: ["get", "list", "watch", "create", "update", "patch"]

Expand Down
20 changes: 18 additions & 2 deletions deploy/yamls/lvm-driver.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,10 @@ rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list", "watch"]
- apiGroups: ["*"]
- apiGroups: [""]
resources: ["pods"]
verbs: ["get", "list", "watch", "update", "patch"]
- apiGroups: ["local.openebs.io"]
resources: ["lvmvolumes"]
verbs: ["*"]
---
Expand Down Expand Up @@ -532,6 +535,19 @@ spec:
priorityClassName: system-cluster-critical
serviceAccount: openebs-lvm-controller-sa
containers:
- name: csi-resizer
image: quay.io/k8scsi/csi-resizer:v1.1.0
args:
- "--v=5"
- "--csi-address=$(ADDRESS)"
- "--leader-election"
env:
- name: ADDRESS
value: /var/lib/csi/sockets/pluginproxy/csi.sock
imagePullPolicy: IfNotPresent
volumeMounts:
- name: socket-dir
mountPath: /var/lib/csi/sockets/pluginproxy/
- name: csi-provisioner
image: k8s.gcr.io/sig-storage/csi-provisioner:v2.1.0
imagePullPolicy: IfNotPresent
Expand Down Expand Up @@ -653,7 +669,7 @@ rules:
- apiGroups: [""]
resources: ["persistentvolumes", "nodes", "services"]
verbs: ["get", "list"]
- apiGroups: ["*"]
- apiGroups: ["local.openebs.io"]
resources: ["lvmvolumes"]
verbs: ["get", "list", "watch", "create", "update", "patch"]

Expand Down
31 changes: 30 additions & 1 deletion pkg/driver/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,37 @@ func (ns *node) NodeExpandVolume(
ctx context.Context,
req *csi.NodeExpandVolumeRequest,
) (*csi.NodeExpandVolumeResponse, error) {
volumeID := req.GetVolumeId()
if req.GetVolumePath() == "" || volumeID == "" {
return nil, status.Errorf(
codes.InvalidArgument,
"path not provided for NodeExpandVolume Request %s",
volumeID,
)
}

return nil, status.Error(codes.Unimplemented, "")
vol, err := lvm.GetLVMVolume(volumeID)

if err != nil {
return nil, status.Errorf(
codes.NotFound,
"failed to handle NodeExpandVolume Request for %s, {%s}",
req.VolumeId,
err.Error(),
)
}
if err = lvm.ResizeLVMVolume(vol, req.GetVolumePath()); err != nil {
akhilerm marked this conversation as resolved.
Show resolved Hide resolved
return nil, status.Errorf(
codes.Internal,
"failed to handle NodeExpandVolume Request for %s, {%s}",
req.VolumeId,
err.Error(),
)
}

return &csi.NodeExpandVolumeResponse{
CapacityBytes: req.GetCapacityRange().GetRequiredBytes(),
}, nil
}

// NodeGetVolumeStats returns statistics for the
Expand Down
55 changes: 54 additions & 1 deletion pkg/driver/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,59 @@ func (cs *controller) ControllerExpandVolume(
req *csi.ControllerExpandVolumeRequest,
) (*csi.ControllerExpandVolumeResponse, error) {

return nil, status.Error(codes.Unimplemented, "")
volumeID := strings.ToLower(req.GetVolumeId())
if volumeID == "" {
return nil, status.Errorf(
codes.InvalidArgument,
"ControllerExpandVolume: no volumeID provided",
)
}

/* round off the new size */
updatedSize := getRoundedCapacity(req.GetCapacityRange().GetRequiredBytes())

vol, err := lvm.GetLVMVolume(volumeID)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"ControllerExpandVolumeRequest: failed to get LVMVolume for %s, {%s}",
volumeID,
err.Error(),
)
}

volsize, err := strconv.ParseInt(vol.Spec.Capacity, 10, 64)
if err != nil {
return nil, status.Errorf(
codes.Internal,
"ControllerExpandVolumeRequest: failed to parse volsize in for %s, {%s}",
volumeID,
err.Error(),
)
}
/*
* Controller expand volume must be idempotent. If a volume corresponding
* to the specified volume ID is already larger than or equal to the target
* capacity of the expansion request, the plugin should reply 0 OK.
*/
if volsize >= updatedSize {
return csipayload.NewControllerExpandVolumeResponseBuilder().
WithCapacityBytes(volsize).
Build(), nil
}

if err := lvm.ResizeVolume(vol, updatedSize); err != nil {
return nil, status.Errorf(
codes.Internal,
"failed to handle ControllerExpandVolumeRequest for %s, {%s}",
volumeID,
err.Error(),
)
}
return csipayload.NewControllerExpandVolumeResponseBuilder().
WithCapacityBytes(updatedSize).
WithNodeExpansionRequired(true).
Build(), nil
}

// CreateSnapshot creates a snapshot for given volume
Expand Down Expand Up @@ -530,6 +582,7 @@ func newControllerCapabilities() []*csi.ControllerServiceCapability {
var capabilities []*csi.ControllerServiceCapability
for _, cap := range []csi.ControllerServiceCapability_RPC_Type{
csi.ControllerServiceCapability_RPC_CREATE_DELETE_VOLUME,
csi.ControllerServiceCapability_RPC_EXPAND_VOLUME,
} {
capabilities = append(capabilities, fromType(cap))
}
Expand Down
30 changes: 30 additions & 0 deletions pkg/lvm/lvm_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ const (
VGCreate = "vgcreate"
LVCreate = "lvcreate"
LVRemove = "lvremove"
LVExtend = "lvextend"
)

// builldLVMCreateArgs returns lvcreate command for the volume
Expand Down Expand Up @@ -119,3 +120,32 @@ func GetVolumeDevPath(vol *apis.LVMVolume) (string, error) {

return dev, nil
}

// builldVolumeResizeArgs returns resize command for the lvm volume
func buildVolumeResizeArgs(vol *apis.LVMVolume) []string {
var LVMVolArg []string

dev := DevPath + vol.Spec.VolGroup + "/" + vol.Name
size := vol.Spec.Capacity + "b"

LVMVolArg = append(LVMVolArg, dev, "-L", size, "-r")

return LVMVolArg
}

// ResizeLVMVolume resizes the volume
func ResizeLVMVolume(vol *apis.LVMVolume, mountpath string) error {
volume := vol.Spec.VolGroup + "/" + vol.Name

args := buildVolumeResizeArgs(vol)
cmd := exec.Command(LVExtend, args...)
out, err := cmd.CombinedOutput()

if err != nil {
klog.Errorf(
"lvm: could not resize the volume %v cmd %v error: %s", volume, args, string(out),
akhilerm marked this conversation as resolved.
Show resolved Hide resolved
)
}

return err
}
10 changes: 10 additions & 0 deletions pkg/lvm/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package lvm

import (
"os"
"strconv"

apis "github.com/openebs/lvm-localpv/pkg/apis/openebs.io/lvm/v1alpha1"
"github.com/openebs/lvm-localpv/pkg/builder/volbuilder"
Expand Down Expand Up @@ -147,3 +148,12 @@ func RemoveVolFinalizer(vol *apis.LVMVolume) error {
_, err := volbuilder.NewKubeclient().WithNamespace(LvmNamespace).Update(vol)
return err
}

// ResizeVolume resizes the lvm volume
func ResizeVolume(vol *apis.LVMVolume, newSize int64) error {

vol.Spec.Capacity = strconv.FormatInt(int64(newSize), 10)

_, err := volbuilder.NewKubeclient().WithNamespace(LvmNamespace).Update(vol)
return err
}