Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
Signed-off-by: yaroslavborbat <[email protected]>
  • Loading branch information
yaroslavborbat committed Sep 5, 2024
1 parent eb0cc63 commit 00728e3
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 46 deletions.
2 changes: 2 additions & 0 deletions images/cdi-artifact/patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,5 @@ Add capabilities for deckhouse provisioners to cdi StorageProfile.
#### `013-converting-images-in-filesystem-to-qcow2.patch`

Converting images in the file system to qcow2.

CDI can currently upload virtual machine images to persistent volumes (PVCs). Regardless of the target, whether it's a block device or a file, CDI converts the image to raw format. We're changing this behavior, but only for file targets. Conversion will now happen to the qcow2 format.
4 changes: 4 additions & 0 deletions images/virt-artifact/patches/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,3 +90,7 @@ Stop managing VirtualMachine and VirtualMachineInstance CRDs with virt-operator.
#### `021-support-qcow2-for-filesystem.patch`

Support format qcow2 for pvc with filesystem mode.

When generating XML for libvirt, we utilize converters that translate the virtual machine instance specification into a Domain. We're making a slight adjustment to this process.
We're changing the raw format for disks to qcow2 for all images created on the file system. These values are hardcoded as we can't determine the disk format used by the virtual machine through qemu-img.
Additionally, kubevirt can create images on an empty PVC. We're changing this behavior as well, altering the format of the created disk to qcow2. This is achieved using qemu-img.
18 changes: 0 additions & 18 deletions images/virtualization-artifact/pkg/common/pvc/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,10 @@ limitations under the License.
package pvc

import (
"os"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/resource"
)

// ForceDVReadWriteOnceVar enables accessMode ReadWriteOnce for testing in local environments.
const ForceDVReadWriteOnceVar = "FORCE_DV_READ_WRITE_ONCE"

func CreateSpec(storageClassName *string,
size resource.Quantity,
accessMode corev1.PersistentVolumeAccessMode,
Expand All @@ -42,16 +37,3 @@ func CreateSpec(storageClassName *string,
VolumeMode: &volumeMode,
}
}

// CreateSpecForDataVolume returns pvc spec with accessMode ReadWriteMany or
// with accessMode ReadWriteOnce, depending on environment variable.
func CreateSpecForDataVolume(storageClassName *string,
size resource.Quantity,
accessMode corev1.PersistentVolumeAccessMode,
volumeMode corev1.PersistentVolumeMode,
) *corev1.PersistentVolumeClaimSpec {
if os.Getenv(ForceDVReadWriteOnceVar) == "yes" {
return CreateSpec(storageClassName, size, corev1.ReadWriteOnce, volumeMode)
}
return CreateSpec(storageClassName, size, accessMode, volumeMode)
}
3 changes: 0 additions & 3 deletions images/virtualization-artifact/pkg/controller/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,9 +187,6 @@ const (
// AnnVMLastAppliedSpec is an annotation on KVVM. It contains a JSON with VM spec.
AnnVMLastAppliedSpec = AnnAPIGroup + "/vm.last-applied-spec"

// AnnUnpackFormat is an annotation on DataVolume. It contains type of image. qcow2,raw,etc..
AnnUnpackFormat = AnnAPIGroup + "/unpack.format"

// LastPropagatedVMAnnotationsAnnotation is a marshalled map of previously applied virtual machine annotations.
LastPropagatedVMAnnotationsAnnotation = AnnAPIGroup + "/last-propagated-vm-annotations"
// LastPropagatedVMLabelsAnnotation is a marshalled map of previously applied virtual machine labels.
Expand Down
25 changes: 1 addition & 24 deletions images/virtualization-artifact/pkg/controller/kvbuilder/dv.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@ import (

"github.com/deckhouse/virtualization-controller/pkg/common"
"github.com/deckhouse/virtualization-controller/pkg/common/pvc"
cc "github.com/deckhouse/virtualization-controller/pkg/controller/common"
"github.com/deckhouse/virtualization-controller/pkg/sdk/framework/helper"
)

const (
unpackFormatQcow2 = "qcow2"
unpackFormatRaw = "raw"
)

// DV is a helper to construct DataVolume to import an image from DVCR onto PVC.
type DV struct {
helper.ResourceBuilder[*cdiv1.DataVolume]
Expand All @@ -52,7 +46,6 @@ func NewDV(name types.NamespacedName) *DV {
Name: name.Name,
Annotations: map[string]string{
"cdi.kubevirt.io/storage.deleteAfterCompletion": "false",
cc.AnnUnpackFormat: unpackFormatQcow2,
},
},
Spec: cdiv1.DataVolumeSpec{
Expand All @@ -68,7 +61,7 @@ func (b *DV) SetPVC(storageClassName *string,
accessMode corev1.PersistentVolumeAccessMode,
volumeMode corev1.PersistentVolumeMode,
) {
b.Resource.Spec.PVC = pvc.CreateSpecForDataVolume(storageClassName,
b.Resource.Spec.PVC = pvc.CreateSpec(storageClassName,
size,
accessMode,
volumeMode,
Expand All @@ -79,22 +72,6 @@ func (b *DV) SetDataSource(source *cdiv1.DataVolumeSource) {
b.Resource.Spec.Source = source
}

func (b *DV) SetUnpackFormat(mode corev1.PersistentVolumeMode) {
format := unpackFormatRaw
switch mode {
case corev1.PersistentVolumeBlock:
format = unpackFormatRaw
case corev1.PersistentVolumeFilesystem:
format = unpackFormatQcow2
}
annos := b.Resource.ObjectMeta.GetAnnotations()
if annos == nil {
annos = map[string]string{}
}
annos[cc.AnnUnpackFormat] = format
b.Resource.ObjectMeta.SetAnnotations(annos)
}

func (b *DV) SetRegistryDataSource(imageName, authSecret, caBundleConfigMap string) {
url := common.DockerRegistrySchemePrefix + imageName

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,6 @@ func (s DiskService) Start(
storageCaps := s.parseVolumeMode(sprofile.Status)

dvBuilder.SetPVC(ptr.To(sprofile.GetName()), pvcSize, storageCaps.AccessMode, storageCaps.VolumeMode)
dvBuilder.SetUnpackFormat(storageCaps.VolumeMode)

err = s.client.Create(ctx, dvBuilder.GetResource())
if err != nil && !k8serrors.IsAlreadyExists(err) {
Expand Down

0 comments on commit 00728e3

Please sign in to comment.