mirror of
https://github.com/TECHNOFAB11/zfs-localpv.git
synced 2025-12-12 06:20:11 +01:00
feat(block): adding block volume support for ZFSPV (#102)
This commit adds the support for creating a Raw Block Volume request using volumemode as block in PVC :-
```
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: block-claim
spec:
volumeMode: Block
storageClassName: zfspv-block
accessModes:
- ReadWriteOnce
resources:
requests:
storage: 5Gi
```
The driver will create a zvol for this volume and bind mount the block device at the given path.
Signed-off-by: Pawan <pawan@mayadata.io>
This commit is contained in:
parent
49dc99726b
commit
dd059a2f43
10 changed files with 274 additions and 10 deletions
|
|
@ -254,6 +254,29 @@ func (b *Builder) WithVolumeMountsNew(volumeMounts []corev1.VolumeMount) *Builde
|
|||
return b
|
||||
}
|
||||
|
||||
// WithVolumeDevicesNew sets the command arguments of the container
|
||||
func (b *Builder) WithVolumeDevicesNew(volumeDevices []corev1.VolumeDevice) *Builder {
|
||||
if volumeDevices == nil {
|
||||
b.errors = append(
|
||||
b.errors,
|
||||
errors.New("failed to build container object: nil volumeDevices"),
|
||||
)
|
||||
return b
|
||||
}
|
||||
|
||||
if len(volumeDevices) == 0 {
|
||||
b.errors = append(
|
||||
b.errors,
|
||||
errors.New("failed to build container object: missing volumeDevices"),
|
||||
)
|
||||
return b
|
||||
}
|
||||
newvolumeDevices := []corev1.VolumeDevice{}
|
||||
newvolumeDevices = append(newvolumeDevices, volumeDevices...)
|
||||
b.con.VolumeDevices = newvolumeDevices
|
||||
return b
|
||||
}
|
||||
|
||||
// WithImagePullPolicy sets the image pull policy of the container
|
||||
func (b *Builder) WithImagePullPolicy(policy corev1.PullPolicy) *Builder {
|
||||
if len(policy) == 0 {
|
||||
|
|
|
|||
|
|
@ -57,7 +57,20 @@ func zvolCreationTest() {
|
|||
By("Deleting storage class", deleteStorageClass)
|
||||
}
|
||||
|
||||
func blockVolCreationTest() {
|
||||
By("Creating default storage class", createStorageClass)
|
||||
By("creating and verifying PVC bound status", createAndVerifyBlockPVC)
|
||||
|
||||
By("Creating and deploying app pod", createDeployVerifyBlockApp)
|
||||
By("verifying ZFSVolume object", VerifyZFSVolume)
|
||||
By("verifying ZFSVolume property change", VerifyZFSVolumePropEdit)
|
||||
By("Deleting application deployment", deleteAppDeployment)
|
||||
By("Deleting pvc", deletePVC)
|
||||
By("Deleting storage class", deleteStorageClass)
|
||||
}
|
||||
|
||||
func volumeCreationTest() {
|
||||
By("Running dataset creation test", datasetCreationTest)
|
||||
By("Running zvol creation test", zvolCreationTest)
|
||||
By("Running block volume creation test", blockVolCreationTest)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -179,3 +179,13 @@ func (b *Builder) Build() (*corev1.PersistentVolumeClaim, error) {
|
|||
}
|
||||
return b.pvc.object, nil
|
||||
}
|
||||
|
||||
// WithVolumeMode sets the VolumeMode field in PVC with provided arguments
|
||||
func (b *Builder) WithVolumeMode(volumemode *corev1.PersistentVolumeMode) *Builder {
|
||||
if volumemode == nil {
|
||||
b.errs = append(b.errs, errors.New("failed to build PVC object: missing volumemode"))
|
||||
return b
|
||||
}
|
||||
b.pvc.object.Spec.VolumeMode = volumemode
|
||||
return b
|
||||
}
|
||||
|
|
|
|||
137
tests/utils.go
137
tests/utils.go
|
|
@ -127,6 +127,27 @@ func createExt4StorageClass() {
|
|||
Expect(err).To(BeNil(), "while creating a ext4 storageclass {%s}", scName)
|
||||
}
|
||||
|
||||
func createStorageClass() {
|
||||
var (
|
||||
err error
|
||||
)
|
||||
|
||||
parameters := map[string]string{
|
||||
"poolname": POOLNAME,
|
||||
}
|
||||
|
||||
By("building a default storage class")
|
||||
scObj, err = sc.NewBuilder().
|
||||
WithGenerateName(scName).
|
||||
WithParametersNew(parameters).
|
||||
WithProvisioner(ZFSProvisioner).Build()
|
||||
Expect(err).ShouldNot(HaveOccurred(),
|
||||
"while building default storageclass obj with prefix {%s}", scName)
|
||||
|
||||
scObj, err = SCClient.Create(scObj)
|
||||
Expect(err).To(BeNil(), "while creating a default storageclass {%s}", scName)
|
||||
}
|
||||
|
||||
func createZfsStorageClass() {
|
||||
var (
|
||||
err error
|
||||
|
|
@ -322,6 +343,53 @@ func createAndVerifyPVC() {
|
|||
)
|
||||
}
|
||||
|
||||
func createAndVerifyBlockPVC() {
|
||||
var (
|
||||
err error
|
||||
pvcName = "zfspv-pvc"
|
||||
)
|
||||
|
||||
volmode := corev1.PersistentVolumeBlock
|
||||
|
||||
By("building a pvc")
|
||||
pvcObj, err = pvc.NewBuilder().
|
||||
WithName(pvcName).
|
||||
WithNamespace(OpenEBSNamespace).
|
||||
WithStorageClass(scObj.Name).
|
||||
WithAccessModes(accessModes).
|
||||
WithVolumeMode(&volmode).
|
||||
WithCapacity(capacity).Build()
|
||||
Expect(err).ShouldNot(
|
||||
HaveOccurred(),
|
||||
"while building pvc {%s} in namespace {%s}",
|
||||
pvcName,
|
||||
OpenEBSNamespace,
|
||||
)
|
||||
|
||||
By("creating above pvc")
|
||||
pvcObj, err = PVCClient.WithNamespace(OpenEBSNamespace).Create(pvcObj)
|
||||
Expect(err).To(
|
||||
BeNil(),
|
||||
"while creating pvc {%s} in namespace {%s}",
|
||||
pvcName,
|
||||
OpenEBSNamespace,
|
||||
)
|
||||
|
||||
By("verifying pvc status as bound")
|
||||
|
||||
status := IsPVCBoundEventually(pvcName)
|
||||
Expect(status).To(Equal(true),
|
||||
"while checking status equal to bound")
|
||||
|
||||
pvcObj, err = PVCClient.WithNamespace(OpenEBSNamespace).Get(pvcObj.Name, metav1.GetOptions{})
|
||||
Expect(err).To(
|
||||
BeNil(),
|
||||
"while retrieving pvc {%s} in namespace {%s}",
|
||||
pvcName,
|
||||
OpenEBSNamespace,
|
||||
)
|
||||
}
|
||||
|
||||
func resizeAndVerifyPVC() {
|
||||
var (
|
||||
err error
|
||||
|
|
@ -427,6 +495,75 @@ func createAndDeployAppPod() {
|
|||
)
|
||||
}
|
||||
|
||||
func createAndDeployBlockAppPod() {
|
||||
var err error
|
||||
By("building a busybox app pod deployment using above zfs volume")
|
||||
deployObj, err = deploy.NewBuilder().
|
||||
WithName(appName).
|
||||
WithNamespace(OpenEBSNamespace).
|
||||
WithLabelsNew(
|
||||
map[string]string{
|
||||
"app": "busybox",
|
||||
},
|
||||
).
|
||||
WithSelectorMatchLabelsNew(
|
||||
map[string]string{
|
||||
"app": "busybox",
|
||||
},
|
||||
).
|
||||
WithPodTemplateSpecBuilder(
|
||||
pts.NewBuilder().
|
||||
WithLabelsNew(
|
||||
map[string]string{
|
||||
"app": "busybox",
|
||||
},
|
||||
).
|
||||
WithContainerBuilders(
|
||||
container.NewBuilder().
|
||||
WithImage("busybox").
|
||||
WithName("busybox").
|
||||
WithImagePullPolicy(corev1.PullIfNotPresent).
|
||||
WithCommandNew(
|
||||
[]string{
|
||||
"sh",
|
||||
"-c",
|
||||
"date > /mnt/datadir/date.txt; sync; sleep 5; sync; tail -f /dev/null;",
|
||||
},
|
||||
).
|
||||
WithVolumeDevicesNew(
|
||||
[]corev1.VolumeDevice{
|
||||
corev1.VolumeDevice{
|
||||
Name: "datavol1",
|
||||
DevicePath: "/dev/xvda",
|
||||
},
|
||||
},
|
||||
),
|
||||
).
|
||||
WithVolumeBuilders(
|
||||
k8svolume.NewBuilder().
|
||||
WithName("datavol1").
|
||||
WithPVCSource(pvcObj.Name),
|
||||
),
|
||||
).
|
||||
Build()
|
||||
|
||||
Expect(err).ShouldNot(HaveOccurred(), "while building app deployement {%s}", appName)
|
||||
|
||||
deployObj, err = DeployClient.WithNamespace(OpenEBSNamespace).Create(deployObj)
|
||||
Expect(err).ShouldNot(
|
||||
HaveOccurred(),
|
||||
"while creating pod {%s} in namespace {%s}",
|
||||
appName,
|
||||
OpenEBSNamespace,
|
||||
)
|
||||
}
|
||||
|
||||
func createDeployVerifyBlockApp() {
|
||||
By("creating and deploying app pod", createAndDeployBlockAppPod)
|
||||
time.Sleep(30 * time.Second)
|
||||
By("verifying app pod is running", verifyAppPodRunning)
|
||||
}
|
||||
|
||||
func verifyAppPodRunning() {
|
||||
var err error
|
||||
appPod, err = PodClient.WithNamespace(OpenEBSNamespace).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue