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

chore(e2e): Assert upgraded integration Pod uses new version Kit #2285

Merged
merged 2 commits into from
May 12, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}

Expand Down
14 changes: 13 additions & 1 deletion e2e/support/util/dump.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (

// Dump prints all information about the given namespace to debug errors
func Dump(ctx context.Context, c client.Client, ns string, t *testing.T) error {

t.Logf("-------------------- start dumping namespace %s --------------------\n", ns)

camelClient, err := versioned.NewForConfig(c.GetConfig())
Expand Down Expand Up @@ -84,6 +83,19 @@ func Dump(ctx context.Context, c client.Client, ns string, t *testing.T) error {
t.Logf("---\n%s\n---\n", string(pdata))
}

builds, err := camelClient.CamelV1().Builds(ns).List(ctx, metav1.ListOptions{})
if err != nil {
return err
}
t.Logf("Found %d Builds:\n", len(builds.Items))
for _, build := range builds.Items {
data, err := kubernetes.ToYAML(&build)
if err != nil {
return err
}
t.Logf("---\n%s\n---\n", string(data))
}

cms, err := c.CoreV1().ConfigMaps(ns).List(ctx, metav1.ListOptions{})
if err != nil {
return err
Expand Down
33 changes: 25 additions & 8 deletions e2e/upgrade/cli_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())

Expand All @@ -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))
Expand All @@ -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 }
}
30 changes: 25 additions & 5 deletions e2e/upgrade/olm_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import (
"fmt"
"os"
"testing"
"time"

. "github.com/onsi/gomega"

Expand All @@ -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"
Expand Down Expand Up @@ -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))

Expand Down Expand Up @@ -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())
Expand Down