Skip to content

Commit f14e909

Browse files
authored
Merge pull request #5 from Vicente-Cheng/misc-improvement
misc improvement
2 parents 840ec7c + 94e7c8c commit f14e909

File tree

173 files changed

+8564
-2737
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+8564
-2737
lines changed

Dockerfile.dapper

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
FROM registry.suse.com/bci/golang:1.22
2+
FROM golang:1.22.7-bookworm
33

44
ARG DAPPER_HOST_ARCH
55
ENV HOST_ARCH=${DAPPER_HOST_ARCH} ARCH=${DAPPER_HOST_ARCH}
66

7-
RUN zypper -n rm container-suseconnect && \
8-
zypper -n install git curl docker gzip tar wget awk make binutils
7+
RUN apt update
8+
RUN apt install -y git curl gzip tar gawk docker wget make binutils gcc linux-libc-dev gcc-11-aarch64-linux-gnu
99

1010
## install golangci
1111
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s v1.57.1
@@ -15,13 +15,6 @@ RUN curl -sSfL https://github.com/docker/buildx/releases/download/v0.13.1/buildx
1515
chmod +x buildx-v0.13.1.linux-${ARCH} && \
1616
mv buildx-v0.13.1.linux-${ARCH} /usr/local/bin/buildx
1717

18-
## install controller-gen
19-
RUN go install sigs.k8s.io/controller-tools/cmd/controller-gen@v0.6.2
20-
21-
22-
# install openapi-gen
23-
RUN go install k8s.io/code-generator/cmd/openapi-gen@v0.23.7
24-
2518
ENV DAPPER_ENV REPO TAG
2619
ENV DAPPER_SOURCE /go/src/github.com/harvester/csi-driver-lvm
2720
ENV DAPPER_OUTPUT ./bin

README.md

Lines changed: 40 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,82 +1,65 @@
1-
# csi-driver-lvm #
1+
# Harvester-csi-driver-lvm
22

3-
CSI DRIVER LVM utilizes local storage of Kubernetes nodes to provide persistent storage for pods.
3+
Harvester-CSI-Driver-LVM is derived from [metal-stack/csi-driver-lvm](https://github.com/metal-stack/csi-driver-lvm).
44

5-
It automatically creates hostPath based persistent volumes on the nodes.
5+
## Introduction
66

7-
Underneath it creates a LVM logical volume on the local disks. A comma-separated list of grok pattern, which disks to use must be specified.
7+
Harvester-CSI-Driver-LVM utilizes local storage to provide persistent storage for workloads (Usually VM workloads). It will make the VM unable to be migrated to other nodes, but it can provide better performance.
88

9-
This CSI driver is derived from [csi-driver-host-path](https://github.com/kubernetes-csi/csi-driver-host-path) and [csi-lvm](https://github.com/metal-stack/csi-lvm)
9+
Before you use it, you should have the pre-established Volume Group (VG) on that node. The VG name will be specified in the StorageClass.
1010

11-
## Currently it can create, delete, mount, unmount and resize block and filesystem volumes via lvm ##
11+
The Harvester-CSI-Driver-LVM provides the following features:
12+
- OnDemand Creation of Logical Volume (LV).
13+
- Support LVM type Striped and DM-Thin.
14+
- Support for Raw Block Volume.
15+
- Support Volume Expansion.
16+
- Support Volume Snapshot.
17+
- Support Volume Clone.
1218

13-
For the special case of block volumes, the filesystem-expansion has to be performed by the app using the block device
19+
**NOTE**: The Snapshot/Clone feature only works on the same nodes. Clone works for different Volume Groups.
1420

1521
## Installation ##
1622

17-
**Helm charts for installation are located in a separate repository called [helm-charts](https://github.com/metal-stack/helm-charts). If you would like to contribute to the helm chart, please raise an issue or pull request there.**
23+
You can use Helm to install the Harvester-CSI-Driver-LVM by remote repo or local helm chart files.
1824

19-
You have to set the devicePattern for your hardware to specify which disks should be used to create the volume group.
25+
1. Install the Harvester-CSI-Driver-LVM locally:
2026

21-
```bash
22-
helm install --repo https://helm.metal-stack.io mytest helm/csi-driver-lvm --set lvm.devicePattern='/dev/nvme[0-9]n[0-9]'
27+
```
28+
$ git clone https://github.com/harvester/csi-driver-lvm.git
29+
$ cd csi-driver-lvm/deploy
30+
$ helm install harvester-lvm-csi-driver charts/ -n harvester-system
2331
```
2432

25-
Now you can use one of following storageClasses:
33+
2. Install the Harvester-CSI-Driver-LVM by remote repo:
2634

27-
* `csi-driver-lvm-linear`
28-
* `csi-driver-lvm-mirror`
29-
* `csi-driver-lvm-striped`
35+
```
36+
$ helm repo add harvester https://charts.harvesterhci.io
37+
$ helm install harvester/harvester-lvm-csi-driver -n harvester-system
38+
```
3039

31-
To get the previous old and now deprecated `csi-lvm-sc-linear`, ... storageclasses, set helm-chart value `compat03x=true`.
40+
After the installation, you can check the status of the following pods:
41+
```
42+
$ kubectl get pods -A |grep harvester-csi-driver-lvm
43+
harvester-system harvester-csi-driver-lvm-controller-0 4/4 Running 0 3h2m
44+
harvester-system harvester-csi-driver-lvm-plugin-ctlgp 3/3 Running 1 (14h ago) 14h
45+
harvester-system harvester-csi-driver-lvm-plugin-qxxqs 3/3 Running 1 (14h ago) 14h
46+
harvester-system harvester-csi-driver-lvm-plugin-xktx2 3/3 Running 0 14h
47+
```
3248

33-
## Migration ##
49+
The CSI driver will be installed in the `harvester-system` namespace and provision to each node.
3450

35-
If you want to migrate your existing PVC to / from csi-driver-lvm, you can use [korb](https://github.com/BeryJu/korb).
51+
After installation, you can refer to the `examples` directory for some example CRDs for usage.
3652

3753
### Todo ###
3854

39-
* implement CreateSnapshot(), ListSnapshots(), DeleteSnapshot()
40-
41-
42-
### Test ###
43-
44-
```bash
45-
kubectl apply -f examples/csi-pvc-raw.yaml
46-
kubectl apply -f examples/csi-pod-raw.yaml
47-
48-
49-
kubectl apply -f examples/csi-pvc.yaml
50-
kubectl apply -f examples/csi-app.yaml
55+
* Implement the unittest
56+
* Implement the webhook for the validation
5157

52-
kubectl delete -f examples/csi-pod-raw.yaml
53-
kubectl delete -f examples/csi-pvc-raw.yaml
58+
### HowTo Build
5459

55-
kubectl delete -f examples/csi-app.yaml
56-
kubectl delete -f examples/csi-pvc.yaml
5760
```
58-
59-
### Development ###
60-
61-
In order to run the integration tests locally, you need to create to loop devices on your host machine. Make sure the loop device mount paths are not used on your system (default path is `/dev/loop10{0,1}`).
62-
63-
You can create these loop devices like this:
64-
65-
```bash
66-
for i in 100 101; do fallocate -l 1G loop${i}.img ; sudo losetup /dev/loop${i} loop${i}.img; done
67-
sudo losetup -a
68-
# use this for recreation or cleanup
69-
# for i in 100 101; do sudo losetup -d /dev/loop${i}; rm -f loop${i}.img; done
61+
$ make
7062
```
7163

72-
You can then run the tests against a kind cluster, running:
73-
74-
```bash
75-
make test
76-
```
77-
78-
To recreate or cleanup the kind cluster:
79-
80-
```bash
81-
make test-cleanup
82-
```
64+
The above command will execute the validation and build the target Image.
65+
You can define your REPO and TAG with ENV `REPO` and `TAG`.

cmd/provisioner/clonelv.go

Lines changed: 141 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,141 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
"syscall"
8+
"time"
9+
10+
"github.com/urfave/cli/v2"
11+
"k8s.io/klog/v2"
12+
13+
lvm "github.com/harvester/csi-driver-lvm/pkg/lvm"
14+
)
15+
16+
func cloneLVCmd() *cli.Command {
17+
return &cli.Command{
18+
Name: "clonelv",
19+
Flags: []cli.Flag{
20+
&cli.StringFlag{
21+
Name: flagSrcLVName,
22+
Usage: "Required. Source LV name.",
23+
},
24+
&cli.StringFlag{
25+
Name: flagSrcVGName,
26+
Usage: "Required. Source VG name",
27+
},
28+
&cli.StringFlag{
29+
Name: flagSrcType,
30+
Usage: "Required. Source type, can be either striped or dm-thin",
31+
},
32+
&cli.StringFlag{
33+
Name: flagLVName,
34+
Usage: "Required. Target LV",
35+
},
36+
&cli.StringFlag{
37+
Name: flagVGName,
38+
Usage: "Required. the name of the volumegroup",
39+
},
40+
&cli.StringFlag{
41+
Name: flagLVMType,
42+
Usage: "Required. type of lvs, can be either striped or dm-thin",
43+
},
44+
&cli.Uint64Flag{
45+
Name: flagLVSize,
46+
Usage: "Required. The size of the lv in MiB",
47+
},
48+
},
49+
Action: func(c *cli.Context) error {
50+
if err := clonelv(c); err != nil {
51+
klog.Fatalf("Error creating lv: %v", err)
52+
return err
53+
}
54+
return nil
55+
},
56+
}
57+
}
58+
59+
func clonelv(c *cli.Context) error {
60+
srcLvName := c.String(flagSrcLVName)
61+
if srcLvName == "" {
62+
return fmt.Errorf("invalid empty flag %v", flagSrcLVName)
63+
}
64+
srcVgName := c.String(flagSrcVGName)
65+
if srcVgName == "" {
66+
return fmt.Errorf("invalid empty flag %v", flagSrcVGName)
67+
}
68+
srcType := c.String(flagSrcType)
69+
if srcType == "" {
70+
return fmt.Errorf("invalid empty flag %v", flagSrcType)
71+
}
72+
dstLV := c.String(flagLVName)
73+
if dstLV == "" {
74+
return fmt.Errorf("invalid empty flag %v", flagLVName)
75+
}
76+
dstVGName := c.String(flagVGName)
77+
if dstVGName == "" {
78+
return fmt.Errorf("invalid empty flag %v", flagVGName)
79+
}
80+
dstLVType := c.String(flagLVMType)
81+
if dstLVType == "" {
82+
return fmt.Errorf("invalid empty flag %v", flagLVMType)
83+
}
84+
dstSize := c.Uint64(flagLVSize)
85+
if dstSize == 0 {
86+
return fmt.Errorf("invalid empty flag %v", flagLVSize)
87+
}
88+
89+
klog.Infof("Clone from src: %s, to dst: %s/%s", srcLvName, dstVGName, dstLV)
90+
91+
if !lvm.VgExists(dstVGName) {
92+
lvm.VgActivate()
93+
time.Sleep(1 * time.Second) // jitter
94+
if !lvm.VgExists(dstVGName) {
95+
return fmt.Errorf("vg %s does not exist, please check the corresponding VG is created", dstVGName)
96+
}
97+
}
98+
99+
klog.Infof("clone lv %s, vg: %s, type: %s", srcLvName, srcVgName, srcType)
100+
if strings.HasPrefix(srcLvName, snapshotPrefix) && srcType == lvm.DmThinType && srcType == dstLVType && srcVgName == dstVGName {
101+
// special case for clone dm-thin, so activate the target
102+
_, err := lvm.CreateSnapshot(dstLV, srcLvName, srcVgName, int64(dstSize), dstLVType, createSnapshotForClone)
103+
if err != nil {
104+
return fmt.Errorf("unable to create snapshot: %w", err)
105+
}
106+
klog.Infof("lv: %s/%s cloned from %s", dstVGName, dstLV, srcLvName)
107+
return nil
108+
}
109+
110+
// check source dev
111+
srcDev := fmt.Sprintf("/dev/%s/%s", srcVgName, srcLvName)
112+
src, err := os.OpenFile(srcDev, syscall.O_RDONLY|syscall.O_DIRECT, 0)
113+
if err != nil {
114+
return fmt.Errorf("unable to open source device: %w", err)
115+
}
116+
defer src.Close()
117+
118+
output, err := lvm.CreateLVS(dstVGName, dstLV, dstSize, dstLVType)
119+
if err != nil {
120+
return fmt.Errorf("unable to create lv: %w output:%s", err, output)
121+
}
122+
klog.Infof("lv: %s created, vg:%s size:%d type:%s", dstLV, dstVGName, dstSize, dstLVType)
123+
124+
dst, err := os.OpenFile(fmt.Sprintf("/dev/%s/%s", dstVGName, dstLV), syscall.O_WRONLY|syscall.O_DIRECT, 0)
125+
if err != nil {
126+
return fmt.Errorf("unable to open target device: %w", err)
127+
}
128+
defer dst.Close()
129+
130+
// Clone the source device to the target device
131+
if err := lvm.CloneDevice(src, dst); err != nil {
132+
return fmt.Errorf("unable to clone device: %w", err)
133+
}
134+
if err := dst.Sync(); err != nil {
135+
return fmt.Errorf("unable to sync target device: %w", err)
136+
}
137+
138+
klog.Infof("lv: %s/%s cloned from %s", dstVGName, dstLV, srcDev)
139+
140+
return nil
141+
}

cmd/provisioner/createlv.go

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"fmt"
5+
"time"
56

67
"github.com/urfave/cli/v2"
78
"k8s.io/klog/v2"
@@ -29,10 +30,6 @@ func createLVCmd() *cli.Command {
2930
Name: flagLVMType,
3031
Usage: "Required. type of lvs, can be either striped or mirrored",
3132
},
32-
&cli.StringFlag{
33-
Name: flagDevicesPattern,
34-
Usage: "Required. comma-separated grok patterns of the physical volumes to use.",
35-
},
3633
},
3734
Action: func(c *cli.Context) error {
3835
if err := createLV(c); err != nil {
@@ -61,19 +58,18 @@ func createLV(c *cli.Context) error {
6158
if lvmType == "" {
6259
return fmt.Errorf("invalid empty flag %v", flagLVMType)
6360
}
64-
devicesPattern := c.String(flagDevicesPattern)
65-
if devicesPattern == "" {
66-
return fmt.Errorf("invalid empty flag %v", flagDevicesPattern)
67-
}
6861

69-
klog.Infof("create lv %s size:%d vg:%s devicespattern:%s type:%s", lvName, lvSize, vgName, devicesPattern, lvmType)
62+
klog.Infof("create lv %s size:%d vg:%s type:%s", lvName, lvSize, vgName, lvmType)
7063

71-
output, err := lvm.CreateVG(vgName, devicesPattern)
72-
if err != nil {
73-
return fmt.Errorf("unable to create vg: %w output:%s", err, output)
64+
if !lvm.VgExists(vgName) {
65+
lvm.VgActivate()
66+
time.Sleep(1 * time.Second) // jitter
67+
if !lvm.VgExists(vgName) {
68+
return fmt.Errorf("vg %s does not exist, please check the corresponding VG is created", vgName)
69+
}
7470
}
7571

76-
output, err = lvm.CreateLVS(vgName, lvName, lvSize, lvmType)
72+
output, err := lvm.CreateLVS(vgName, lvName, lvSize, lvmType)
7773
if err != nil {
7874
return fmt.Errorf("unable to create lv: %w output:%s", err, output)
7975
}

0 commit comments

Comments
 (0)