Skip to content

Commit

Permalink
Update PVC claims to match KubeVirt API changes
Browse files Browse the repository at this point in the history
Ref:  https://git.io/JuRMP

Signed-off-by: Weihang Lo <weihang.lo@suse.com>
  • Loading branch information
weihanglo authored and bk201 committed Oct 6, 2021
1 parent e0662b7 commit 2f9e7bc
Show file tree
Hide file tree
Showing 6 changed files with 148 additions and 65 deletions.
7 changes: 5 additions & 2 deletions pkg/api/vm/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -453,8 +453,11 @@ func (h *vmActionHandler) addVolume(ctx context.Context, namespace, name string,
},
},
VolumeSource: &kv1.HotplugVolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: input.VolumeSourceName,
PersistentVolumeClaim: &kv1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: input.VolumeSourceName,
},
Hotpluggable: true,
},
},
})
Expand Down
21 changes: 12 additions & 9 deletions pkg/builder/disk.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,22 @@ func (v *VMBuilder) Volume(diskName string, volume kubevirtv1.Volume) *VMBuilder
return v
}

func (v *VMBuilder) ExistingPVCVolume(diskName, pvcName string) *VMBuilder {
func (v *VMBuilder) ExistingPVCVolume(diskName, pvcName string, hotpluggable bool) *VMBuilder {
return v.Volume(diskName, kubevirtv1.Volume{
Name: diskName,
VolumeSource: kubevirtv1.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: pvcName,
PersistentVolumeClaim: &kubevirtv1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: pvcName,
},
Hotpluggable: hotpluggable,
},
},
})
}

func (v *VMBuilder) ExistingVolumeDisk(diskName, diskBus string, isCDRom bool, bootOrder int, pvcName string) *VMBuilder {
return v.Disk(diskName, diskBus, isCDRom, bootOrder).ExistingPVCVolume(diskName, pvcName)
func (v *VMBuilder) ExistingVolumeDisk(diskName, diskBus string, isCDRom, hotpluggable bool, bootOrder int, pvcName string) *VMBuilder {
return v.Disk(diskName, diskBus, isCDRom, bootOrder).ExistingPVCVolume(diskName, pvcName, hotpluggable)
}

func (v *VMBuilder) ContainerDiskVolume(diskName, imageName, ImagePullPolicy string) *VMBuilder {
Expand All @@ -152,7 +155,7 @@ func (v *VMBuilder) ContainerDisk(diskName, diskBus string, isCDRom bool, bootOr
return v.Disk(diskName, diskBus, isCDRom, bootOrder).ContainerDiskVolume(diskName, imageName, ImagePullPolicy)
}

func (v *VMBuilder) PVCVolume(diskName, diskSize, pvcName string, opt *PersistentVolumeClaimOption) *VMBuilder {
func (v *VMBuilder) PVCVolume(diskName, diskSize, pvcName string, hotpluggable bool, opt *PersistentVolumeClaimOption) *VMBuilder {
if opt == nil {
defaultStorageClass := "longhorn"
opt = &PersistentVolumeClaimOption{
Expand Down Expand Up @@ -207,9 +210,9 @@ func (v *VMBuilder) PVCVolume(diskName, diskSize, pvcName string, opt *Persisten
v.VirtualMachine.Annotations[util.AnnotationVolumeClaimTemplates] = string(toUpdateVolumeClaimTemplates)
}

return v.ExistingPVCVolume(diskName, pvcName)
return v.ExistingPVCVolume(diskName, pvcName, hotpluggable)
}

func (v *VMBuilder) PVCDisk(diskName, diskBus string, isCDRom bool, bootOrder int, diskSize, pvcName string, opt *PersistentVolumeClaimOption) *VMBuilder {
return v.Disk(diskName, diskBus, isCDRom, bootOrder).PVCVolume(diskName, diskSize, pvcName, opt)
func (v *VMBuilder) PVCDisk(diskName, diskBus string, isCDRom, hotpluggable bool, bootOrder int, diskSize, pvcName string, opt *PersistentVolumeClaimOption) *VMBuilder {
return v.Disk(diskName, diskBus, isCDRom, bootOrder).PVCVolume(diskName, diskSize, pvcName, hotpluggable, opt)
}
128 changes: 92 additions & 36 deletions pkg/controller/master/virtualmachine/vm_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,12 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",

PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -394,8 +398,11 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -478,8 +485,11 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -535,8 +545,11 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -597,8 +610,11 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -673,8 +689,11 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -757,8 +776,11 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -836,8 +858,11 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -920,8 +945,12 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "attached-pvc-disk",

PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "attached-pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1017,8 +1046,11 @@ func TestVMController_SetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "attached-pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "attached-pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1392,8 +1424,11 @@ func TestVMController_UnsetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1491,8 +1526,11 @@ func TestVMController_UnsetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1572,8 +1610,11 @@ func TestVMController_UnsetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1631,8 +1672,11 @@ func TestVMController_UnsetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1695,8 +1739,11 @@ func TestVMController_UnsetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1774,8 +1821,11 @@ func TestVMController_UnsetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1855,8 +1905,11 @@ func TestVMController_UnsetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down Expand Up @@ -1934,8 +1987,11 @@ func TestVMController_UnsetOwnerOfPVCs(t *testing.T) {
{
Name: "disk2",
VolumeSource: kubevirtapis.VolumeSource{
PersistentVolumeClaim: &corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
PersistentVolumeClaim: &kubevirtapis.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
ClaimName: "pvc-disk",
},
Hotpluggable: true,
},
},
},
Expand Down
Loading

0 comments on commit 2f9e7bc

Please sign in to comment.