Skip to content

Commit

Permalink
use lvm node binaries for shared volume group support
Browse files Browse the repository at this point in the history
  • Loading branch information
Abhishek Agarwal committed Jun 2, 2022
1 parent 2f8af97 commit 09de455
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 22 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ EXTERNAL_TOOLS=\
# By default the organization name is `openebs`.

ifeq (${IMAGE_ORG}, )
IMAGE_ORG="openebs"
IMAGE_ORG="abhishek09dh"
export IMAGE_ORG
endif

Expand Down
9 changes: 5 additions & 4 deletions buildscripts/lvm-driver/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM alpine:3.12
RUN apk add --no-cache lvm2 lvm2-extra util-linux device-mapper
RUN apk add --no-cache btrfs-progs xfsprogs xfsprogs-extra e2fsprogs e2fsprogs-extra
RUN apk add --no-cache ca-certificates libc6-compat
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get -y install xfsprogs e2fsprogs
RUN apt-get -y install ca-certificates
RUN apt-get -y install vim

ARG DBUILD_DATE
ARG DBUILD_REPO_URL
Expand Down
9 changes: 5 additions & 4 deletions buildscripts/lvm-driver/Dockerfile.buildx
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,11 @@ COPY . .

RUN make buildx.csi-driver

FROM alpine:3.12
RUN apk add --no-cache lvm2 lvm2-extra util-linux device-mapper
RUN apk add --no-cache btrfs-progs xfsprogs xfsprogs-extra e2fsprogs e2fsprogs-extra
RUN apk add --no-cache ca-certificates libc6-compat
FROM ubuntu:20.04
RUN apt-get update
RUN apt-get -y install xfsprogs e2fsprogs
RUN apt-get -y install ca-certificates
RUN apt-get -y install vim

ARG DBUILD_DATE
ARG DBUILD_REPO_URL
Expand Down
80 changes: 80 additions & 0 deletions deploy/lvm-operator.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1338,6 +1338,74 @@ roleRef:

---

kind: ConfigMap
apiVersion: v1
metadata:
name: openebs-lvmpv-bin
namespace: kube-system # should be the same namespace where it is getting mounted
data:
get_bin_path: |
#!/bin/sh
bin_name=$1
if [ -x /host/bin/which ]; then
echo $(chroot /host /bin/which $bin_name | cut -d ' ' -f 1)
elif [ -x /host/usr/bin/which ]; then
echo $(chroot /host /usr/bin/which $bin_name | cut -d ' ' -f 1)
else
$(chroot /host which $bin_name | cut -d ' ' -f 1)
fi
vgcreate: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "vgcreate")
chroot /host $path "$@"
vgchange: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "vgchange")
chroot /host $path "$@"
vgs: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "vgs")
chroot /host $path "$@"
lvcreate: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "lvcreate")
chroot /host $path "$@"
lvchange: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "lvchange")
chroot /host $path "$@"
lvextend: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "lvextend")
chroot /host $path "$@"
lvremove: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "lvremove")
chroot /host $path "$@"
lvs: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "lvs")
chroot /host $path "$@"
pvs: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "pvs")
chroot /host $path "$@"
pvscan: |
#!/bin/sh
path=$(/sbin/lvm-eg/get_bin_path "pvscan")
chroot /host $path "$@"
---
apiVersion: scheduling.k8s.io/v1
kind: PriorityClass
metadata:
Expand Down Expand Up @@ -1436,6 +1504,10 @@ spec:
mountPath: /plugin
- name: device-dir
mountPath: /dev
- name: chroot-lvm
mountPath: /sbin/lvm-eg
- name: host-root
mountPath: /host
- name: pods-mount-dir
mountPath: /var/lib/kubelet/
# needed so that any mounts setup inside this container are
Expand All @@ -1446,6 +1518,14 @@ spec:
hostPath:
path: /dev
type: Directory
- name: chroot-lvm
configMap:
defaultMode: 0555
name: openebs-lvmpv-bin
- name: host-root
hostPath:
path: /
type: Directory
- name: registration-dir
hostPath:
path: /var/lib/kubelet/plugins_registry/
Expand Down
24 changes: 12 additions & 12 deletions pkg/lvm/lvm_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,18 @@ const (

// lvm command related constants
const (
VGCreate = "vgcreate"
VGList = "vgs"
VGChange = "vgchange"

LVCreate = "lvcreate"
LVRemove = "lvremove"
LVExtend = "lvextend"
LVList = "lvs"
LVChange = "lvchange"

PVList = "pvs"
PVScan = "pvscan"
VGCreate = "/sbin/lvm-eg/vgcreate"
VGList = "/sbin/lvm-eg/vgs"
VGChange = "/sbin/lvm-eg/vgchange"

LVCreate = "/sbin/lvm-eg/lvcreate"
LVRemove = "/sbin/lvm-eg/lvremove"
LVExtend = "/sbin/lvm-eg/lvextend"
LVList = "/sbin/lvm-eg/lvs"
LVChange = "/sbin/lvm-eg/lvchange"

PVList = "/sbin/lvm-eg/pvs"
PVScan = "/sbin/lvm-eg/pvscan"

YES = "yes"
LVThinPool = "thin-pool"
Expand Down
10 changes: 9 additions & 1 deletion pkg/mgmt/volume/volume.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,10 @@ func (c *VolController) getVgPriorityList(vol *apis.LVMVolume) ([]apis.VolumeGro
if err != nil {
return nil, fmt.Errorf("failed to list vgs available on node: %v", err)
}
fmt.Printf("list of vgs = %v", vgs)
filteredVgs := make([]apis.VolumeGroup, 0)
for _, vg := range vgs {
fmt.Printf("vol= %v, object = %v", vol.Name, vol)
if !re.MatchString(vg.Name) {
continue
}
Expand All @@ -177,19 +179,25 @@ func (c *VolController) getVgPriorityList(vol *apis.LVMVolume) ([]apis.VolumeGro
continue
}
}
// skip th vg if the volume is to be created in exclusive shared mode but the underlying
fmt.Printf("sharedmode = %v, attribute = %s, attribute[0] = %v, attribute[5] = %v, filteredvgs = %v", vol.Spec.SharedMode, vg.Attribute, vg.Attribute[0], vg.Attribute[5], filteredVgs)
// skip the vg if the volume is to be created in exclusive shared mode but the underlying
// vg is not shared. Shared VGs are indicated by "s" (for shared) in the sixth attr
// field
if vol.Spec.SharedMode == apis.LVMExclusiveSharedMode && vg.Attribute[5] != 's' {
fmt.Printf("vg = %s is a shared vg", vg.Name)
continue
}
filteredVgs = append(filteredVgs, vg)
}

fmt.Println("filtered vgs= ", filteredVgs)

// prioritize the volume group having less free space available.
sort.SliceStable(filteredVgs, func(i, j int) bool {
return filteredVgs[i].Free.Cmp(filteredVgs[j].Free) < 0
})

fmt.Println("sorted filtered vgs= ", filteredVgs)
return filteredVgs, nil
}

Expand Down

0 comments on commit 09de455

Please sign in to comment.