Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow image-upload to recover from PendingPopulation phase #10380

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 14 additions & 1 deletion pkg/virtctl/imageupload/imageupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ const (
forceImmediateBindingAnnotation = "cdi.kubevirt.io/storage.bind.immediate.requested"
contentTypeAnnotation = "cdi.kubevirt.io/storage.contentType"
deleteAfterCompletionAnnotation = "cdi.kubevirt.io/storage.deleteAfterCompletion"
UsePopulatorAnnotation = "cdi.kubevirt.io/storage.usePopulator"
PVCPrimeNameAnnotation = "cdi.kubevirt.io/storage.populator.pvcPrime"

uploadReadyWaitInterval = 2 * time.Second

Expand Down Expand Up @@ -762,7 +764,7 @@ func getAndValidateUploadPVC(client kubecli.KubevirtClient, namespace, name stri
}

if !createPVC {
_, err = client.CdiClient().CdiV1beta1().DataVolumes(namespace).Get(context.Background(), name, metav1.GetOptions{})
dv, err := client.CdiClient().CdiV1beta1().DataVolumes(namespace).Get(context.Background(), name, metav1.GetOptions{})
if err != nil {
// When the PVC exists but the DV doesn't, there are two possible outcomes:
if k8serrors.IsNotFound(err) {
Expand All @@ -776,6 +778,17 @@ func getAndValidateUploadPVC(client kubecli.KubevirtClient, namespace, name stri
}
return nil, err
}
// When using populators, the upload happens on the PVC Prime. We need to check it instead.
if dv.Annotations[UsePopulatorAnnotation] == "true" {
pvcPrimeName, ok := pvc.Annotations[PVCPrimeNameAnnotation]
if !ok {
return nil, fmt.Errorf("Unable to get PVC Prime name from PVC %s/%s", namespace, name)
}
pvc, err = client.CoreV1().PersistentVolumeClaims(namespace).Get(context.Background(), pvcPrimeName, metav1.GetOptions{})
if err != nil {
return nil, fmt.Errorf("Unable to get PVC Prime %s/%s", namespace, name)
}
}
}

// for PVCs that exist, we ony want to use them if
Expand Down
36 changes: 36 additions & 0 deletions pkg/virtctl/imageupload/imageupload_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ const (
podPhaseAnnotation = "cdi.kubevirt.io/storage.pod.phase"
podReadyAnnotation = "cdi.kubevirt.io/storage.pod.ready"
deleteAfterCompletionAnnotation = "cdi.kubevirt.io/storage.deleteAfterCompletion"
UsePopulatorAnnotation = "cdi.kubevirt.io/storage.usePopulator"
PVCPrimeNameAnnotation = "cdi.kubevirt.io/storage.populator.pvcPrime"
)

const (
Expand Down Expand Up @@ -718,6 +720,40 @@ var _ = Describe("ImageUpload", func() {
Expect(err.Error()).Should(ContainSubstring("doesn't have archive contentType annotation"))
})

It("DV is using populators but PVC has no PVC Prime annotation", func() {
dv := dvSpecWithPhase(cdiv1.UploadReady)
dv.Annotations = map[string]string{UsePopulatorAnnotation: "true"}
testInitAsyncWithCdiObjects(
http.StatusOK,
true,
[]runtime.Object{pvcSpecWithUploadAnnotation()},
[]runtime.Object{dv},
)
cmd := clientcmd.NewRepeatableVirtctlCommand(commandName, "dv", targetName, "--size", pvcSize,
"--uploadproxy-url", server.URL, "--insecure", "--archive-path", archiveFilePath)
err := cmd()
Expect(err).To(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("Unable to get PVC Prime name from PVC"))
})

It("DV is using populators but PVC Prime doesn't exist", func() {
dv := dvSpecWithPhase(cdiv1.UploadReady)
dv.Annotations = map[string]string{UsePopulatorAnnotation: "true"}
pvc := pvcSpecWithUploadAnnotation()
pvc.Annotations = map[string]string{PVCPrimeNameAnnotation: "pvc-prime-name"}
testInitAsyncWithCdiObjects(
http.StatusOK,
true,
[]runtime.Object{pvc},
[]runtime.Object{dv},
)
cmd := clientcmd.NewRepeatableVirtctlCommand(commandName, "dv", targetName, "--size", pvcSize,
"--uploadproxy-url", server.URL, "--insecure", "--archive-path", archiveFilePath)
err := cmd()
Expect(err).To(HaveOccurred())
Expect(err.Error()).Should(ContainSubstring("Unable to get PVC Prime"))
})

DescribeTable("when DV in phase", func(phase cdiv1.DataVolumePhase, forcebind bool) {
testInitAsyncWithCdiObjects(
http.StatusOK,
Expand Down
52 changes: 52 additions & 0 deletions tests/storage/imageupload.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"kubevirt.io/kubevirt/tests/errorhandling"
execute "kubevirt.io/kubevirt/tests/exec"
"kubevirt.io/kubevirt/tests/flags"
"kubevirt.io/kubevirt/tests/framework/matcher"
"kubevirt.io/kubevirt/tests/libstorage"
)

Expand Down Expand Up @@ -254,6 +255,57 @@ var _ = SIGDescribe("[Serial]ImageUpload", Serial, func() {
)
})

Context("Upload fails when DV is in WFFC/PendingPopulation phase", func() {
It("but uploads after consumer is created", func() {
storageClass, exists := libstorage.GetRWOFileSystemStorageClass()
if !exists || !libstorage.IsStorageClassBindingModeWaitForFirstConsumer(storageClass) {
Skip("Skip no wffc storage class available")
}
defer deleteDataVolume("target-dv")

By("Upload image")
virtctlCmd := clientcmd.NewRepeatableVirtctlCommand(imageUploadCmd,
"dv", "target-dv",
namespaceArg, testsuite.GetTestNamespace(nil),
"--image-path", imagePath,
sizeArg, pvcSize,
"--storage-class", storageClass,
"--access-mode", "ReadWriteOnce",
insecureArg)

err := virtctlCmd()
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(ContainSubstring("make sure the PVC is Bound, or use force-bind flag"))

By("Start VM")
vmi := tests.NewRandomVMIWithDataVolume("target-dv")
vmi, err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Create(context.Background(), vmi)
Expect(err).ToNot(HaveOccurred())
defer func() {
err = virtClient.VirtualMachineInstance(testsuite.GetTestNamespace(vmi)).Delete(context.Background(), vmi.Name, &metav1.DeleteOptions{})
Expect(err).ToNot(HaveOccurred())
}()

By("Wait for DV to be in UploadReady phase")
dataVolume, err := virtClient.CdiClient().CdiV1beta1().DataVolumes(testsuite.GetTestNamespace(nil)).Get(context.Background(), "target-dv", metav1.GetOptions{})
Expect(err).ToNot(HaveOccurred())
libstorage.EventuallyDV(dataVolume, 240, matcher.BeInPhase(cdiv1.UploadReady))

By("Upload image, now should succeed")
virtctlCmd = clientcmd.NewRepeatableVirtctlCommand(imageUploadCmd,
"dv", "target-dv",
namespaceArg, testsuite.GetTestNamespace(nil),
"--image-path", imagePath,
sizeArg, pvcSize,
"--storage-class", storageClass,
"--access-mode", "ReadWriteOnce",
insecureArg)

Expect(virtctlCmd()).To(Succeed())
validateDataVolume("target-dv", storageClass)
})
})

Context("Create upload archive volume", func() {
var archivePath string

Expand Down