Skip to content

Commit d0f64e0

Browse files
bouskaJastefanutti
authored andcommitted
[TEST] Add cross-channel upgrade test feature
1 parent eec8dbb commit d0f64e0

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

e2e/upgrade/olm_upgrade_test.go

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,34 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
5050
newIIB := os.Getenv("CAMEL_K_NEW_IIB")
5151
kamel := os.Getenv("RELEASED_KAMEL_BIN")
5252

53+
// optional options
54+
prevUpdateChannel := os.Getenv("CAMEL_K_PREV_UPGRADE_CHANNEL")
55+
newUpdateChannel := os.Getenv("CAMEL_K_NEW_UPGRADE_CHANNEL")
56+
5357
if prevIIB == "" || newIIB == "" {
5458
t.Skip("OLM Upgrade test requires the CAMEL_K_PREV_IIB and CAMEL_K_NEW_IIB environment variables")
5559
}
5660

61+
crossChannelUpgrade := false
62+
if prevUpdateChannel != "" && newUpdateChannel != "" && prevUpdateChannel != newUpdateChannel {
63+
crossChannelUpgrade = true
64+
t.Logf("Testing cross-OLM channel upgrade %s -> %s", prevUpdateChannel, newUpdateChannel)
65+
}
66+
5767
WithNewTestNamespace(t, func(ns string) {
5868
Expect(createOrUpdateCatalogSource(ns, catalogSourceName, prevIIB)).To(Succeed())
5969
Eventually(catalogSourcePhase(ns, catalogSourceName), TestTimeoutMedium).Should(Equal("READY"))
6070

6171
// Set KAMEL_BIN only for this test - don't override the ENV variable for all tests
6272
Expect(os.Setenv("KAMEL_BIN", kamel)).To(Succeed())
6373

64-
Expect(Kamel("install", "-n", ns, "--olm=true", "--olm-source", catalogSourceName, "--olm-source-namespace", ns).Execute()).To(Succeed())
74+
args := []string{"install", "-n", ns, "--olm=true", "--olm-source", catalogSourceName, "--olm-source-namespace", ns}
75+
76+
if crossChannelUpgrade {
77+
args = append(args, "--olm-channel", os.Getenv("CAMEL_K_PREV_UPGRADE_CHANNEL"))
78+
}
79+
80+
Expect(Kamel(args...).Execute()).To(Succeed())
6581

6682
// Find the only one Camel-K CSV
6783
noAdditionalConditions := func(csv olm.ClusterServiceVersion) bool {
@@ -102,6 +118,14 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
102118
// Trigger Camel K operator upgrade by updating the CatalogSource with the new index image
103119
Expect(createOrUpdateCatalogSource(ns, catalogSourceName, newIIB)).To(Succeed())
104120

121+
if crossChannelUpgrade {
122+
t.Log("Updating Camel-K subscription OLM update channel.")
123+
s := ckSubscription(ns)()
124+
ctrlutil.CreateOrUpdate(TestContext, TestClient(), s, func() error {
125+
s.Spec.Channel = newUpdateChannel
126+
return nil
127+
})
128+
}
105129
// Check the previous CSV is being replaced
106130
Eventually(clusterServiceVersionPhase(func(csv olm.ClusterServiceVersion) bool {
107131
return csv.Spec.Version.Version.String() == prevCSVVersion.Version.String()

e2e/upgrade/util.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,18 @@ func catalogSourcePhase(ns, name string) func() string {
9191
return ""
9292
}
9393
}
94+
95+
func ckSubscription(ns string) func() *olm.Subscription {
96+
return func() *olm.Subscription {
97+
lst := olm.SubscriptionList{}
98+
if err := TestClient().List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil {
99+
panic(err)
100+
}
101+
for _, s := range lst.Items {
102+
if strings.Contains(s.Name, "camel-k") {
103+
return &s
104+
}
105+
}
106+
return nil
107+
}
108+
}

0 commit comments

Comments
 (0)