Skip to content

Commit

Permalink
Merge pull request kubevirt#6378 from rmohr/operator-migrate-again
Browse files Browse the repository at this point in the history
Ensure that we can migrate a VM multiple times after update
  • Loading branch information
kubevirt-bot authored Sep 10, 2021
2 parents bf16f26 + 916cfee commit 3c96a02
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 24 deletions.
20 changes: 20 additions & 0 deletions tests/framework/matcher/getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,23 @@ func ThisPVCWith(namespace string, name string) func() (*v1.PersistentVolumeClai
return
}
}

// ThisMigration fetches the latest state of the Migration. If the object does not exist, nil is returned.
func ThisMigration(migration *virtv1.VirtualMachineInstanceMigration) func() (*virtv1.VirtualMachineInstanceMigration, error) {
return ThisMigrationWith(migration.Namespace, migration.Name)
}

// ThisMigrationWith fetches the latest state of the Migration based on namespace and name. If the object does not exist, nil is returned.
func ThisMigrationWith(namespace string, name string) func() (*virtv1.VirtualMachineInstanceMigration, error) {
return func() (p *virtv1.VirtualMachineInstanceMigration, err error) {
virtClient, err := kubecli.GetKubevirtClient()
if err != nil {
return nil, err
}
p, err = virtClient.VirtualMachineInstanceMigration(namespace).Get(name, &k8smetav1.GetOptions{})
if errors.IsNotFound(err) {
return nil, nil
}
return
}
}
31 changes: 7 additions & 24 deletions tests/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"path/filepath"

"kubevirt.io/kubevirt/pkg/virt-operator/resource/apply"
. "kubevirt.io/kubevirt/tests/framework/matcher"
util2 "kubevirt.io/kubevirt/tests/util"

"regexp"
Expand Down Expand Up @@ -1226,30 +1227,6 @@ spec:
launcherSha := getVirtLauncherSha()
Expect(launcherSha).ToNot(Equal(""))

// Disable HonorWaitForFirstCustomer, since we don't know if previous versions
// already support this setting.
// TODO drop this step after a few releases after 0.36
cdis, err := virtClient.CdiClient().CdiV1beta1().CDIs().List(context.Background(), metav1.ListOptions{})
Expect(err).ToNot(HaveOccurred())
Expect(cdis.Items).To(HaveLen(1))
cdi := &cdis.Items[0]
if cdi.Spec.Config != nil {
features := []string{}
needsUpdate := false
for _, feature := range cdi.Spec.Config.FeatureGates {
if feature != "HonorWaitForFirstConsumer" {
features = append(features, feature)
} else {
needsUpdate = true
}
}
if needsUpdate {
cdi.Spec.Config.FeatureGates = features
_, err := virtClient.CdiClient().CdiV1beta1().CDIs().Update(context.Background(), cdi, metav1.UpdateOptions{})
Expect(err).ToNot(HaveOccurred())
}
}

previousImageTag := flags.PreviousReleaseTag
previousImageRegistry := flags.PreviousReleaseRegistry
if previousImageTag == "" {
Expand Down Expand Up @@ -1448,6 +1425,12 @@ spec:
By("Verifying all migratable vmi workloads are updated via live migration")
verifyVMIsUpdated(migratableVMIs, launcherSha)

By("Verifying that a once migrated VMI after an update can be migrated again")
vmi := migratableVMIs[0]
migration, err := virtClient.VirtualMachineInstanceMigration(vmi.Namespace).Create(tests.NewRandomMigration(vmi.Name, vmi.Namespace))
Expect(err).ToNot(HaveOccurred())
Eventually(ThisMigration(migration), 180).Should(HaveSucceeded())

By("Deleting migratable VMIs")
deleteAllVMIs(migratableVMIs)

Expand Down

0 comments on commit 3c96a02

Please sign in to comment.