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 Pipe test to olm_upgrade_test #4719

Merged
merged 7 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 6 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
65 changes: 39 additions & 26 deletions e2e/install/upgrade/olm_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,23 +24,20 @@ package upgrade

import (
"fmt"
"os"
"testing"
"time"

. "github.com/apache/camel-k/v2/e2e/support"
v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
. "github.com/onsi/gomega"
"github.com/stretchr/testify/assert"

corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"

"os"
ctrl "sigs.k8s.io/controller-runtime/pkg/client"
"testing"
"time"

"github.com/operator-framework/api/pkg/lib/version"
olm "github.com/operator-framework/api/pkg/operators/v1alpha1"
corev1 "k8s.io/api/core/v1"

v1 "github.com/apache/camel-k/v2/pkg/apis/camel/v1"
"github.com/apache/camel-k/v2/pkg/util/defaults"
"github.com/apache/camel-k/v2/pkg/util/openshift"
)
Expand All @@ -67,6 +64,7 @@ func TestOLMOperatorUpgrade(t *testing.T) {
}

WithNewTestNamespace(t, func(ns string) {

Expect(CreateOrUpdateCatalogSource(ns, catalogSourceName, prevIIB)).To(Succeed())
ocp, err := openshift.IsOpenShift(TestClient())
assert.Nil(t, err)
Expand Down Expand Up @@ -115,11 +113,11 @@ func TestOLMOperatorUpgrade(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)
t.Logf("Using Previous CSV Version: %s", prevCSVVersion.Version.String())
prevIPVersionPrefix = fmt.Sprintf("%d.%d", prevCSVVersion.Version.Major, prevCSVVersion.Version.Minor) //1.10
t.Logf("Using Previous CSV Version: %s", prevCSVVersion.Version.String()) //Using Previous CSV Version: 1.10.1+0.1693789561.p

// Check the operator pod is running
Eventually(OperatorPodPhase(ns), TestTimeoutMedium).Should(Equal(corev1.PodRunning))
Expand All @@ -129,13 +127,23 @@ func TestOLMOperatorUpgrade(t *testing.T) {

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))
if prevCSVVersion.Version.String() >= "2" { // since 2.0 Pipe, previously KameletBinding
Eventually(PipeConditionStatus(ns, kbindName, v1.PipeConditionReady), 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 @@ -156,11 +164,6 @@ func TestOLMOperatorUpgrade(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 @@ -172,15 +175,15 @@ func TestOLMOperatorUpgrade(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 @@ -192,38 +195,48 @@ func TestOLMOperatorUpgrade(t *testing.T) {
Should(ContainSubstring(prevIPVersionPrefix))

// Rebuild the Integration
Expect(Kamel("rebuild", name, "-n", ns).Execute()).To(Succeed())
Expect(Kamel("rebuild", "--all", "-n", ns).Execute()).To(Succeed())
if prevCSVVersion.Version.String() >= "2" {
Eventually(PipeConditionStatus(ns, kbindName, v1.PipeConditionReady), 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))
Eventually(IntegrationVersion(ns, kbindName)).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, KitWithVersion(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, KitWithVersion(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))
Eventually(IntegrationConditionStatus(ns, kbindName, v1.IntegrationConditionReady), TestTimeoutLong).
Should(Equal(corev1.ConditionTrue))

// Clean up
Expect(Kamel("delete", "--all", "-n", ns).Execute()).To(Succeed())
Expand Down
8 changes: 8 additions & 0 deletions e2e/support/test_support.go
Original file line number Diff line number Diff line change
Expand Up @@ -1239,6 +1239,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