Skip to content

Commit

Permalink
[TEST] Add cross-channel upgrade test feature
Browse files Browse the repository at this point in the history
  • Loading branch information
bouskaJ authored and astefanutti committed Oct 27, 2021
1 parent eec8dbb commit d0f64e0
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
26 changes: 25 additions & 1 deletion e2e/upgrade/olm_upgrade_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,34 @@ func TestOLMAutomaticUpgrade(t *testing.T) {
newIIB := os.Getenv("CAMEL_K_NEW_IIB")
kamel := os.Getenv("RELEASED_KAMEL_BIN")

// optional options
prevUpdateChannel := os.Getenv("CAMEL_K_PREV_UPGRADE_CHANNEL")
newUpdateChannel := os.Getenv("CAMEL_K_NEW_UPGRADE_CHANNEL")

if prevIIB == "" || newIIB == "" {
t.Skip("OLM Upgrade test requires the CAMEL_K_PREV_IIB and CAMEL_K_NEW_IIB environment variables")
}

crossChannelUpgrade := false
if prevUpdateChannel != "" && newUpdateChannel != "" && prevUpdateChannel != newUpdateChannel {
crossChannelUpgrade = true
t.Logf("Testing cross-OLM channel upgrade %s -> %s", prevUpdateChannel, newUpdateChannel)
}

WithNewTestNamespace(t, func(ns string) {
Expect(createOrUpdateCatalogSource(ns, catalogSourceName, prevIIB)).To(Succeed())
Eventually(catalogSourcePhase(ns, catalogSourceName), TestTimeoutMedium).Should(Equal("READY"))

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

Expect(Kamel("install", "-n", ns, "--olm=true", "--olm-source", catalogSourceName, "--olm-source-namespace", ns).Execute()).To(Succeed())
args := []string{"install", "-n", ns, "--olm=true", "--olm-source", catalogSourceName, "--olm-source-namespace", ns}

if crossChannelUpgrade {
args = append(args, "--olm-channel", os.Getenv("CAMEL_K_PREV_UPGRADE_CHANNEL"))
}

Expect(Kamel(args...).Execute()).To(Succeed())

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

if crossChannelUpgrade {
t.Log("Updating Camel-K subscription OLM update channel.")
s := ckSubscription(ns)()
ctrlutil.CreateOrUpdate(TestContext, TestClient(), s, func() error {
s.Spec.Channel = newUpdateChannel
return nil
})
}
// Check the previous CSV is being replaced
Eventually(clusterServiceVersionPhase(func(csv olm.ClusterServiceVersion) bool {
return csv.Spec.Version.Version.String() == prevCSVVersion.Version.String()
Expand Down
15 changes: 15 additions & 0 deletions e2e/upgrade/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,18 @@ func catalogSourcePhase(ns, name string) func() string {
return ""
}
}

func ckSubscription(ns string) func() *olm.Subscription {
return func() *olm.Subscription {
lst := olm.SubscriptionList{}
if err := TestClient().List(TestContext, &lst, ctrl.InNamespace(ns)); err != nil {
panic(err)
}
for _, s := range lst.Items {
if strings.Contains(s.Name, "camel-k") {
return &s
}
}
return nil
}
}

0 comments on commit d0f64e0

Please sign in to comment.