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

Add klb to olm_upgrade_test - branch 1.10.x #4323

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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 27 additions & 22 deletions e2e/namespace/upgrade/olm_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ package common

import (
"fmt"
"github.com/apache/camel-k/pkg/apis/camel/v1alpha1"
"os"
"testing"
"time"
Expand Down Expand Up @@ -101,7 +102,7 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
// IntegrationPlatform should match at least on the version prefix
// CSV patch version can be increased with the OperatorHub respin of the same Camel K release
var prevIPVersionPrefix string
var newIPVersionPrefix string
var newIPVersionMajorMinorPatch string

prevCSVVersion = clusterServiceVersion(noAdditionalConditions, ns)().Spec.Version
prevIPVersionPrefix = fmt.Sprintf("%d.%d", prevCSVVersion.Version.Major, prevCSVVersion.Version.Minor)
Expand All @@ -111,16 +112,24 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning))

// Check the IntegrationPlatform has been reconciled
t.Logf("Platform version: %s", PlatformVersion(ns)())
Eventually(PlatformVersion(ns)).Should(ContainSubstring(prevIPVersionPrefix))

name := "yaml"
Expect(Kamel("run", "-n", ns, "files/yaml.yaml").Execute()).To(Succeed())
kbindName := "timer-to-log"
Expect(KamelBind(ns, "timer-source?message=Hello", "log-sink", "--name", kbindName).Execute()).To(Succeed())
// Check the Integration runs correctly
Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue))
Eventually(KameletBindingConditionStatus(ns, kbindName, v1alpha1.KameletBindingConditionReady), TestTimeoutShort).
Should(Equal(corev1.ConditionTrue))
Eventually(IntegrationPodPhase(ns, kbindName), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, kbindName, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue))

// Check the Integration version matches that of the current operator
Expect(IntegrationVersion(ns, name)()).To(ContainSubstring(prevIPVersionPrefix))
Expect(IntegrationVersion(ns, kbindName)()).To(ContainSubstring(prevIPVersionPrefix))

t.Run("OLM upgrade", func(t *testing.T) {
// Trigger Camel K operator upgrade by updating the CatalogSource with the new index image
Expand All @@ -139,11 +148,6 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
Expect(subscription.Spec.Channel).To(Equal(newUpdateChannel))
}

// Check the previous CSV is being replaced
Eventually(clusterServiceVersionPhase(func(csv olm.ClusterServiceVersion) bool {
return csv.Spec.Version.Version.String() == prevCSVVersion.Version.String()
}, ns), TestTimeoutMedium).Should(Equal(olm.CSVPhaseReplacing))

// The new CSV is installed
Eventually(clusterServiceVersionPhase(func(csv olm.ClusterServiceVersion) bool {
return csv.Spec.Version.Version.String() != prevCSVVersion.Version.String()
Expand All @@ -155,15 +159,15 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
}, ns), TestTimeoutMedium).Should(BeNil())

newCSVVersion = clusterServiceVersion(noAdditionalConditions, ns)().Spec.Version
newIPVersionPrefix = fmt.Sprintf("%d.%d", newCSVVersion.Version.Major, newCSVVersion.Version.Minor)
newIPVersionMajorMinorPatch = fmt.Sprintf("%d.%d.%d", newCSVVersion.Version.Major, newCSVVersion.Version.Minor, newCSVVersion.Version.Patch)

Expect(prevCSVVersion.Version.String()).NotTo(Equal(newCSVVersion.Version.String()))

Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Eventually(OperatorImage(ns), TestTimeoutShort).Should(Equal(defaults.OperatorImage()))

// Check the IntegrationPlatform has been reconciled
Eventually(PlatformVersion(ns)).Should(ContainSubstring(newIPVersionPrefix))
Eventually(PlatformVersion(ns)).Should(ContainSubstring(newIPVersionMajorMinorPatch))
})

t.Run("Integration upgrade", func(t *testing.T) {
Expand All @@ -174,42 +178,43 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
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())
Expect(Kamel("rebuild", "--all", "-n", ns).Execute()).To(Succeed())
Eventually(KameletBindingConditionStatus(ns, kbindName, v1alpha1.KameletBindingConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))

// Check the Integration runs correctly
Eventually(IntegrationPodPhase(ns, name), TestTimeoutLong).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutMedium).Should(Equal(corev1.ConditionTrue))

// Check the Integration version has been upgraded
Eventually(IntegrationVersion(ns, name)).Should(ContainSubstring(newIPVersionPrefix))
Eventually(IntegrationVersion(ns, name)).Should(ContainSubstring(newIPVersionMajorMinorPatch))

// Check the previous kit is not garbage collected (skip Build - present in case of respin)
prevCSVVersionMajorMinorPatch := fmt.Sprintf("%d.%d.%d",
prevCSVVersion.Version.Major, prevCSVVersion.Version.Minor, prevCSVVersion.Version.Patch)
Eventually(Kits(ns, KitWithVersion(prevCSVVersionMajorMinorPatch))).Should(HaveLen(1))
Eventually(Kits(ns, KitWithVersionPrefix(prevCSVVersionMajorMinorPatch))).Should(HaveLen(2))
// Check a new kit is created with the current version
Eventually(Kits(ns, KitWithVersion(defaults.Version)),
TestTimeoutMedium).Should(HaveLen(1))
Eventually(Kits(ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch))).Should(HaveLen(2))
// Check the new kit is ready
Eventually(Kits(ns, KitWithVersion(defaults.Version), KitWithPhase(v1.IntegrationKitPhaseReady)),
TestTimeoutMedium).Should(HaveLen(1))
Eventually(Kits(ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithPhase(v1.IntegrationKitPhaseReady)),
TestTimeoutMedium).Should(HaveLen(2))

kit := Kits(ns, KitWithVersion(defaults.Version))()[0]
kit := Kits(ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithLabels(map[string]string{"camel.apache.org/created.by.name": name}))()[0]
kitKbind := Kits(ns, KitWithVersionPrefix(newIPVersionMajorMinorPatch), KitWithLabels(map[string]string{"camel.apache.org/created.by.name": kbindName}))()[0]

// Check the Integration uses the new kit
Eventually(IntegrationKit(ns, name), TestTimeoutMedium).Should(Equal(kit.Name))
Eventually(IntegrationKit(ns, kbindName), TestTimeoutMedium).Should(Equal(kitKbind.Name))
// Check the Integration Pod uses the new image
Eventually(IntegrationPodImage(ns, name)).Should(Equal(kit.Status.Image))
Eventually(IntegrationPodImage(ns, kbindName)).Should(Equal(kitKbind.Status.Image))

// Check the Integration runs correctly
Eventually(IntegrationPodPhase(ns, name)).Should(Equal(corev1.PodRunning))
Eventually(IntegrationPodPhase(ns, kbindName)).Should(Equal(corev1.PodRunning))
Eventually(IntegrationConditionStatus(ns, name, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue))

// Clean up
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
Expect(Kamel("uninstall", "-n", ns).Execute()).To(Succeed())
// Clean up cluster-wide resources that are not removed by OLM
Expect(Kamel("uninstall", "--all", "-n", ns, "--olm=false").Execute()).To(Succeed())
Eventually(IntegrationConditionStatus(ns, kbindName, v1.IntegrationConditionReady), TestTimeoutLong).Should(Equal(corev1.ConditionTrue))
})
// Clean up
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
})
}
12 changes: 8 additions & 4 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,9 @@ func setTestLocus(t *testing.T) {
testLocus = t
}

//
// Only panic the test if absolutely necessary and there is
// no test locus. In most cases, the test should fail gracefully
// using the test locus to error out and fail now.
//
func failTest(err error) {
if testLocus != nil {
testLocus.Error(err)
Expand Down Expand Up @@ -726,9 +724,7 @@ func ServiceType(ns string, name string) func() corev1.ServiceType {
}
}

//
// Find the service in the given namespace with the given type
//
func ServicesByType(ns string, svcType corev1.ServiceType) func() []corev1.Service {
return func() []corev1.Service {
svcs := []corev1.Service{}
Expand Down Expand Up @@ -1058,6 +1054,14 @@ func KitWithVersion(version string) KitFilter {
}
}

func KitWithVersionPrefix(versionPrefix string) KitFilter {
return &kitFilter{
filter: func(kit *v1.IntegrationKit) bool {
return strings.HasPrefix(kit.Status.Version, versionPrefix)
},
}
}

func KitWithLabels(kitLabels map[string]string) ctrl.ListOption {
return ctrl.MatchingLabelsSelector{
Selector: labels.Set(kitLabels).AsSelector(),
Expand Down