This is an automated email from the ASF dual-hosted git repository. astefanutti pushed a commit to branch release-1.4.x in repository https://gitbox.apache.org/repos/asf/camel-k.git
commit 10b35ece5b550e85ea4ad301fe57bdf3f04cd496 Author: Antonin Stefanutti <anto...@stefanutti.fr> AuthorDate: Wed May 12 10:06:12 2021 +0200 chore(e2e): Assert upgraded integration Pod uses new version Kit --- e2e/support/test_support.go | 34 +++++++++++++++++++++------------- e2e/upgrade/cli_upgrade_test.go | 33 +++++++++++++++++++++++++-------- e2e/upgrade/olm_upgrade_test.go | 30 +++++++++++++++++++++++++----- 3 files changed, 71 insertions(+), 26 deletions(-) diff --git a/e2e/support/test_support.go b/e2e/support/test_support.go index a65ca10..cdc0998 100644 --- a/e2e/support/test_support.go +++ b/e2e/support/test_support.go @@ -575,25 +575,33 @@ func ScaleIntegration(ns string, name string, replicas int32) error { }) } -func Kits(ns string) func() []v1.IntegrationKit { +func Kits(ns string, filters ...func(*v1.IntegrationKit) bool) func() []v1.IntegrationKit { return func() []v1.IntegrationKit { - lst := v1.NewIntegrationKitList() - if err := TestClient().List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil { + list := v1.NewIntegrationKitList() + if err := TestClient().List(TestContext, &list, ctrl.InNamespace(ns)); err != nil { panic(err) } - return lst.Items - } -} -func KitsWithVersion(ns string, version string) func() int { - return func() int { - count := 0 - for _, k := range Kits(ns)() { - if k.Status.Version == version { - count++ + if len(filters) == 0 { + filters = []func(*v1.IntegrationKit) bool{ + func(kit *v1.IntegrationKit) bool { + return true + }, } } - return count + + var kits []v1.IntegrationKit + kits: + for _, kit := range list.Items { + for _, filter := range filters { + if !filter(&kit) { + continue kits + } + } + kits = append(kits, kit) + } + + return kits } } diff --git a/e2e/upgrade/cli_upgrade_test.go b/e2e/upgrade/cli_upgrade_test.go index 55bed82..b324633 100644 --- a/e2e/upgrade/cli_upgrade_test.go +++ b/e2e/upgrade/cli_upgrade_test.go @@ -66,15 +66,14 @@ func TestOperatorUpgrade(t *testing.T) { Expect(Kamel("run", "-n", ns, "files/yaml.yaml").Execute()).To(Succeed()) Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + // Check the Integration version Eventually(IntegrationVersion(ns, name)).Should(Equal(version)) - kit := IntegrationKit(ns, name)() // Clear the KAMEL_BIN environment variable so that the current version is used from now on Expect(os.Setenv("KAMEL_BIN", "")).To(Succeed()) // Upgrade the operator by installing the current version - // FIXME: it seems forcing the installation does not re-install the CRDs Expect(Kamel("install", "--olm=false", "--cluster-setup", "--force").Execute()).To(Succeed()) Expect(Kamel("install", "-n", ns, "--olm=false", "--force", "--operator-image", image).Execute()).To(Succeed()) @@ -86,19 +85,29 @@ func TestOperatorUpgrade(t *testing.T) { Eventually(PlatformVersion(ns), TestTimeoutMedium).Should(Equal(defaults.Version)) // Check the Integration hasn't been upgraded - Consistently(IntegrationVersion(ns, name), 3*time.Second).Should(Equal(version)) + Consistently(IntegrationVersion(ns, name), 5*time.Second, 1*time.Second).Should(Equal(version)) // Force the Integration upgrade Expect(Kamel("rebuild", name, "-n", ns).Execute()).To(Succeed()) - // Check the Integration version change + // Check the Integration version has been upgraded Eventually(IntegrationVersion(ns, name)).Should(Equal(defaults.Version)) + // Check the previous kit is not garbage collected - Eventually(KitsWithVersion(ns, version)).Should(Equal(1)) + Eventually(Kits(ns, kitWithVersion(version))).Should(HaveLen(1)) // Check a new kit is created with the current version - Eventually(KitsWithVersion(ns, defaults.Version)).Should(Equal(1)) - // Check the Integration uses the new kit - Eventually(IntegrationKit(ns, name), TestTimeoutMedium).ShouldNot(Equal(kit)) + Eventually(Kits(ns, kitWithVersion(defaults.Version))).Should(HaveLen(1)) + // Check the new kit is ready + Eventually(Kits(ns, kitWithVersion(defaults.Version), kitWithPhase(v1.IntegrationKitPhaseReady)), + TestTimeoutMedium).Should(HaveLen(1)) + + kit := Kits(ns, kitWithVersion(defaults.Version))()[0] + + // Check the Integration uses the new image + Eventually(IntegrationKit(ns, name), TestTimeoutMedium).Should(Equal(kit.Name)) + // Check the Integration Pod uses the new kit + Eventually(IntegrationPodImage(ns, name)).Should(Equal(kit.Status.Image)) + // Check the Integration runs correctly Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) @@ -108,3 +117,11 @@ func TestOperatorUpgrade(t *testing.T) { Expect(Kamel("uninstall", "--all", "--olm=false").Execute()).To(Succeed()) }) } + +func kitWithVersion(version string) func(kit *v1.IntegrationKit) bool { + return func(kit *v1.IntegrationKit) bool { return kit.Status.Version == version } +} + +func kitWithPhase(phase v1.IntegrationKitPhase) func(kit *v1.IntegrationKit) bool { + return func(kit *v1.IntegrationKit) bool { return kit.Status.Phase == phase } +} diff --git a/e2e/upgrade/olm_upgrade_test.go b/e2e/upgrade/olm_upgrade_test.go index 3a3bc8d..5641959 100644 --- a/e2e/upgrade/olm_upgrade_test.go +++ b/e2e/upgrade/olm_upgrade_test.go @@ -25,6 +25,7 @@ import ( "fmt" "os" "testing" + "time" . "github.com/onsi/gomega" @@ -38,6 +39,7 @@ import ( . "github.com/apache/camel-k/e2e/support" v1 "github.com/apache/camel-k/pkg/apis/camel/v1" + "github.com/apache/camel-k/pkg/util/defaults" ) const catalogSourceName = "test-camel-k-source" @@ -88,9 +90,10 @@ func TestOLMAutomaticUpgrade(t *testing.T) { name := "yaml" Expect(Kamel("run", "-n", ns, "files/yaml.yaml").Execute()).To(Succeed()) - Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) // Check the Integration runs correctly + Eventually(IntegrationPodPhase(ns, name), TestTimeoutMedium).Should(Equal(corev1.PodRunning)) Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) + // Check the Integration version matches that of the current operator Expect(IntegrationVersion(ns, name)()).To(ContainSubstring(prevIPVersionPrefix)) @@ -128,16 +131,33 @@ func TestOLMAutomaticUpgrade(t *testing.T) { // Clear the KAMEL_BIN environment variable so that the current version is used from now on Expect(os.Setenv("KAMEL_BIN", "")).To(Succeed()) - // Check the Integration is still running the old version - Expect(IntegrationVersion(ns, name)()).To(ContainSubstring(prevIPVersionPrefix)) + // Check the Integration hasn't been upgraded + Consistently(IntegrationVersion(ns, name), 5*time.Second, 1*time.Second).Should(ContainSubstring(prevIPVersionPrefix)) // Rebuild the Integration Expect(Kamel("rebuild", name, "-n", ns).Execute()).To(Succeed()) + // Check the Integration version has been upgraded + Eventually(IntegrationVersion(ns, name)).Should(ContainSubstring(newIPVersionPrefix)) + + // Check the previous kit is not garbage collected + Eventually(Kits(ns, kitWithVersion(prevCSVVersion.String()))).Should(HaveLen(1)) + // Check a new kit is created with the current version + Eventually(Kits(ns, kitWithVersion(defaults.Version))).Should(HaveLen(1)) + // Check the new kit is ready + Eventually(Kits(ns, kitWithVersion(defaults.Version), kitWithPhase(v1.IntegrationKitPhaseReady)), + TestTimeoutMedium).Should(HaveLen(1)) + + kit := Kits(ns, kitWithVersion(defaults.Version))()[0] + + // Check the Integration uses the new kit + Eventually(IntegrationKit(ns, name), TestTimeoutMedium).Should(Equal(kit.Name)) + // Check the Integration Pod uses the new image + Eventually(IntegrationPodImage(ns, name)).Should(Equal(kit.Status.Image)) + // Check the Integration runs correctly Eventually(IntegrationPodPhase(ns, name)).Should(Equal(corev1.PodRunning)) - // Check the Integration has upgraded - Eventually(IntegrationVersion(ns, name), TestTimeoutMedium).Should(ContainSubstring(newIPVersionPrefix)) + Eventually(IntegrationCondition(ns, name, v1.IntegrationConditionReady), TestTimeoutShort).Should(Equal(corev1.ConditionTrue)) // Clean up Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())