Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
This reverts commit 3522f9b.

Signed-off-by: Isteb4k <[email protected]>
Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
Isteb4k authored and yaroslavborbat committed Jan 16, 2025
1 parent da55a16 commit 2c323a4
Showing 1 changed file with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,9 @@ func (s AttachmentService) HotPlugDisk(ctx context.Context, ad *AttachmentDisk,
Serial: ad.Name,
},
}
switch ad.Kind {
case virtv2.DiskDevice:

switch {
case ad.PVCName != "":
hotplugRequest.VolumeSource = &kvapi.HotplugVolumeSource{
PersistentVolumeClaim: &virtv1.PersistentVolumeClaimVolumeSource{
PersistentVolumeClaimVolumeSource: corev1.PersistentVolumeClaimVolumeSource{
Expand All @@ -164,15 +165,15 @@ func (s AttachmentService) HotPlugDisk(ctx context.Context, ad *AttachmentDisk,
Hotpluggable: true,
},
}
case virtv2.ClusterImageDevice, virtv2.ImageDevice:
case ad.Image != "":
hotplugRequest.VolumeSource = &kvapi.HotplugVolumeSource{
ContainerDisk: &kvapi.ContainerDiskSource{
Image: ad.Image,
Hotpluggable: true,
},
}
default:
return fmt.Errorf("unexpected disk kind %s", ad.Kind)
return errors.New("unexpected volume source for attachment")
}

kv, err := kubevirt.New(ctx, s.client, s.controllerNamespace)
Expand Down Expand Up @@ -330,14 +331,20 @@ func NewAttachmentDiskFromVirtualDisk(vd *virtv2.VirtualDisk) *AttachmentDisk {
}

func NewAttachmentDiskFromVirtualImage(vi *virtv2.VirtualImage) *AttachmentDisk {
return &AttachmentDisk{
ad := AttachmentDisk{
Kind: virtv2.ImageDevice,
Name: vi.GetName(),
Namespace: vi.GetNamespace(),
GenerateName: kvbuilder.GenerateVMIDiskName(vi.GetName()),
PVCName: vi.Status.Target.PersistentVolumeClaim,
Image: vi.Status.Target.RegistryURL,
}

if vi.Spec.Storage == virtv2.StorageContainerRegistry {
ad.Image = vi.Status.Target.RegistryURL
} else {
ad.Image = vi.Status.Target.PersistentVolumeClaim
}

return &ad
}

func NewAttachmentDiskFromClusterVirtualImage(cvi *virtv2.ClusterVirtualImage) *AttachmentDisk {
Expand Down

0 comments on commit 2c323a4

Please sign in to comment.