add functional test to validate syncing operator and operand during updates
package tests_test
import (
+ "encoding/json"
"flag"
"fmt"
+ "regexp"
"time"
. "github.com/onsi/ginkgo"
@@ -216,6 +218,35 @@ var _ = Describe("Operator", func() {
}, 10*time.Second, 1*time.Second).ShouldNot(HaveOccurred())
}
+ patchOperatorVersion := func(imageTag string) {
+ Eventually(func() error {
+
+ operator, err := virtClient.AppsV1().Deployments(tests.KubeVirtInstallNamespace).Get("virt-operator", metav1.GetOptions{})
+
+ imageRegEx := regexp.MustCompile(`^(.*)/virt-operator(:.*)?$`)
+ matches := imageRegEx.FindAllStringSubmatch(operator.Spec.Template.Spec.Containers[0].Image, 1)
+ registry := matches[0][1]
+ newImage := fmt.Sprintf("%s/virt-operator:%s", registry, imageTag)
+
+ operator.Spec.Template.Spec.Containers[0].Image = newImage
+ for idx, env := range operator.Spec.Template.Spec.Containers[0].Env {
+ if env.Name == "OPERATOR_IMAGE" {
+ env.Value = newImage
+ operator.Spec.Template.Spec.Containers[0].Env[idx] = env
+ break
+ }
+ }
+
+ newTemplate, _ := json.Marshal(operator.Spec.Template)
+
+ op := fmt.Sprintf(`[{ "op": "replace", "path": "/spec/template", "value": %s }]`, string(newTemplate))
+
+ _, err = virtClient.AppsV1().Deployments(tests.KubeVirtInstallNamespace).Patch("virt-operator", types.JSONPatchType, []byte(op))
+
+ return err
+ }, 10*time.Second, 1*time.Second).ShouldNot(HaveOccurred())
+ }
+
deleteAllKvAndWait := func(ignoreOriginal bool) {
Eventually(func() error {
kvList, err := virtClient.KubeVirt(tests.KubeVirtInstallNamespace).List(&metav1.ListOptions{})
@@ -262,6 +293,7 @@ var _ = Describe("Operator", func() {
if len(kvs) == 0 {
createKv(copyOriginalKv())
}
+ patchOperatorVersion(tests.KubeVirtVersionTag)
waitForKv(originalKv)
allPodsAreReady(tests.KubeVirtVersionTag)
})
@@ -376,6 +408,43 @@ var _ = Describe("Operator", func() {
})
+ It("should be able to update kubevirt install when operator updates if no custom image tag is set", func() {
+
+ if tests.KubeVirtVersionTagAlt == "" {
+ Skip("Skip operator custom image tag test because alt tag is not present")
+ }
+
+ kv := copyOriginalKv()
+
+ allPodsAreReady(tests.KubeVirtVersionTag)
+ sanityCheckDeploymentsExist()
+
+ By("Update Virt-Operator using Alt Tag")
+ patchOperatorVersion(tests.KubeVirtVersionTagAlt)
+
+ // should result in kubevirt cr entering updating state
+ By("Wait for Updating Condition")
+ waitForUpdateCondition(kv)
+
+ By("Waiting for KV to stabilize")
+ waitForKv(kv)
+
+ By("Verifying infrastructure Is Updated")
+ allPodsAreReady(tests.KubeVirtVersionTagAlt)
+
+ By("Restore Operator Version using original image tag. ")
+ patchOperatorVersion(tests.KubeVirtVersionTag)
+
+ By("Wait for Updating Condition")
+ waitForUpdateCondition(kv)
+
+ By("Waiting for KV to stabilize")
+ waitForKv(kv)
+
+ By("Verifying infrastructure Is Restored to original version")
+ allPodsAreReady(tests.KubeVirtVersionTag)
+ })
+
It("should fail if KV object already exists", func() {
newKv := copyOriginalKv()
