Skip to content

Commit 2bc4a9d

Browse files
authored
fix: rollback tests (#1900)
Fix rollback test for OLM installer. Add rollback test for Operator installer. Signed-off-by: Mykola Morhun <[email protected]>
1 parent 8631a79 commit 2bc4a9d

File tree

5 files changed

+108
-14
lines changed

5 files changed

+108
-14
lines changed

.ci/oci_chectl_rollback.sh

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ init() {
3232
export SCRIPT=$(readlink -f "$0")
3333
export SCRIPT_DIR=$(dirname "$SCRIPT")
3434

35-
# Env necessary for openshift CI to put che logs inside
35+
# Env necсessary for openshift CI to put che logs inside
3636
export ARTIFACTS_DIR="/tmp/artifacts"
3737

3838
# Suggested namespace
@@ -47,6 +47,8 @@ init() {
4747
}
4848

4949
run() {
50+
echo "[INFO] Environment:"
51+
env
5052
# Before running the e2e tests we need to install all deps with yarn
5153
yarn --cwd ${CHECTL_REPO}
5254
export PLATFORM=openshift
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#
2+
# Copyright (c) 2019-2021 Red Hat, Inc.
3+
# This program and the accompanying materials are made
4+
# available under the terms of the Eclipse Public License 2.0
5+
# which is available at https://www.eclipse.org/legal/epl-2.0/
6+
#
7+
# SPDX-License-Identifier: EPL-2.0
8+
#
9+
# Contributors:
10+
# Red Hat, Inc. - initial API and implementation
11+
#
12+
13+
name: Minikube E2E
14+
on: pull_request
15+
jobs:
16+
minikube-e2e-operator-rollback:
17+
name: Operator installer rollback update
18+
runs-on: ubuntu-20.04
19+
steps:
20+
- uses: actions/checkout@v1
21+
- name: Start minikube cluster
22+
id: run-minikube
23+
uses: che-incubator/setup-minikube-action@next
24+
with:
25+
minikube-version: v1.21.0
26+
- name: Install chectl dependencies
27+
run: yarn
28+
- name: Run e2e rollback tests for Operator installer
29+
run: |
30+
export PLATFORM=minikube
31+
export INSTALLER=operator
32+
yarn test --coverage=false --forceExit --testRegex=test/e2e/e2e-rollback.test.ts
33+
- uses: actions/upload-artifact@v2
34+
if: ${{ always() }}
35+
with:
36+
name: test-artifacts
37+
path: /tmp/logs/*

src/api/kube.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1687,7 +1687,7 @@ export class KubeHelper {
16871687
cheClusterCR.spec.devWorkspace.enable = true
16881688
}
16891689

1690-
if (cheClusterCR.spec.devWorkspace.enable) {
1690+
if (cheClusterCR.spec.devWorkspace && cheClusterCR.spec.devWorkspace.enable) {
16911691
cheClusterCR.spec.auth.nativeUserMode = true
16921692
}
16931693

test/e2e/e2e-rollback.test.ts

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@ jest.setTimeout(1000000)
1818

1919
const binChectl = E2eHelper.getChectlBinaries()
2020

21-
const PLATFORM = process.env.PLATFORM || 'minikube'
22-
23-
const INSTALLER = 'olm'
24-
const OLM_CHANNEL = 'stable'
21+
const PLATFORM = process.env.PLATFORM || 'openshift'
22+
const INSTALLER = process.env.INSTALLER || 'olm'
23+
const OLM_CHANNEL = process.env.OLM_CHANNEL || 'stable'
2524

2625
const CHE_VERSION_TIMEOUT_MS = 12 * 60 * 1000
2726
const CHE_BACKUP_TIMEOUT_MS = 2 * 60 * 1000
@@ -33,9 +32,12 @@ describe('Test rollback Che update', () => {
3332
describe('Prepare pre-latest stable Che', () => {
3433
it(`Deploy Che using ${INSTALLER} installer from ${OLM_CHANNEL} channel`, async () => {
3534
// Retrieve pre-latest and latest stable Che version
36-
[previousCheVersion, latestCheVersion] = await helper.getTwoLatestReleasedVersions()
35+
[previousCheVersion, latestCheVersion] = await helper.getTwoLatestReleasedVersions(INSTALLER)
3736

38-
const deployCommand = `${binChectl} server:deploy --batch --platform=${PLATFORM} --installer=${INSTALLER} --olm-channel=${OLM_CHANNEL} --version=${previousCheVersion} --chenamespace=${NAMESPACE} --telemetry=off --che-operator-cr-patch-yaml=test/e2e/resources/cr-patch.yaml`
37+
let deployCommand = `${binChectl} server:deploy --batch --platform=${PLATFORM} --installer=${INSTALLER} --version=${previousCheVersion} --chenamespace=${NAMESPACE} --telemetry=off --che-operator-cr-patch-yaml=test/e2e/resources/cr-patch.yaml`
38+
if (INSTALLER === 'olm') {
39+
deployCommand += ` --olm-channel=${OLM_CHANNEL}`
40+
}
3941
await helper.runCliCommand(deployCommand)
4042

4143
await helper.waitForVersionInCheCR(previousCheVersion, CHE_VERSION_TIMEOUT_MS)
@@ -46,7 +48,12 @@ describe('Test rollback Che update', () => {
4648
it('Update Eclipse Che Version to the latest', async () => {
4749
console.log(`Updating from ${previousCheVersion} to ${latestCheVersion}`)
4850

49-
await helper.runCliCommand(binChectl, ['server:update', '-y', `-n ${NAMESPACE}`, '--telemetry=off'])
51+
let updateCommand = `${binChectl} server:update -y -n ${NAMESPACE} --telemetry=off`
52+
if (INSTALLER === 'operator') {
53+
// It is required to specify version for Operator installer, otherwise it will update Che to next as chectl is of next version
54+
updateCommand += ` --version=${latestCheVersion}`
55+
}
56+
await helper.runCliCommand(updateCommand)
5057
})
5158

5259
it('Wait backup done', async () => {
@@ -70,7 +77,7 @@ describe('Test rollback Che update', () => {
7077

7178
it('Wait previous Che', async () => {
7279
// It is possible to reduce awaiting timeout, because rollback itself waits for the restore to complete.
73-
await helper.waitForVersionInCheCR(previousCheVersion, 2 * 60 * 1000)
80+
await helper.waitForVersionInCheCR(previousCheVersion, 5 * 60 * 1000)
7481
})
7582
})
7683
})

test/e2e/util.ts

Lines changed: 52 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import { Octokit } from '@octokit/rest'
1414
import * as execa from 'execa'
1515
import { spawn } from 'child_process'
1616
import * as fs from 'fs-extra'
17+
import * as semver from 'semver'
1718

1819
import { CheHelper } from '../../src/api/che'
1920
import { CheGithubClient, TagInfo } from '../../src/api/github-client'
@@ -286,6 +287,43 @@ export class E2eHelper {
286287
return tags
287288
}
288289

290+
/**
291+
* Returns list of sorted CSVs in stable OLM channel of Che Operator published in community-operators repository.
292+
* The CSVs are sorted from the latest to oldest.
293+
*/
294+
private async listOLMReleasedCSV(): Promise<string[]> {
295+
const response = await this.octokit.repos.getContent({
296+
owner: 'redhat-openshift-ecosystem',
297+
repo: 'community-operators-prod',
298+
path: 'operators/eclipse-che',
299+
})
300+
// There is an array in the response as given path points to a directory
301+
const data = response.data as {name: string}[]
302+
const csvsNames: string[] = []
303+
data.map(item => csvsNames.push(item.name))
304+
const stableChannelCSVNames = csvsNames.filter(csvName => {
305+
// Filter versions like 7.37.2-all-namespaces
306+
if (csvName.indexOf('-') !== -1) {
307+
return false
308+
}
309+
310+
// Filter non x.y.z
311+
const versionParts = csvName.split('.')
312+
if (versionParts.length !== 3) {
313+
return false
314+
}
315+
// Ensure each part is a number
316+
for (const versionPart of versionParts) {
317+
if (!versionPart.match(/^[0-9]+$/)) {
318+
return false
319+
}
320+
}
321+
return true
322+
})
323+
324+
return stableChannelCSVNames.sort((verA: string, verB: string) => semver.lt(verA, verB) ? 1 : -1)
325+
}
326+
289327
/**
290328
* Get previous version from chectl repository
291329
*/
@@ -298,10 +336,20 @@ export class E2eHelper {
298336
/**
299337
* Gets pre-latest and latest released version from chectl repository
300338
*/
301-
async getTwoLatestReleasedVersions(): Promise<[string, string]> {
302-
const githubClient = new CheGithubClient()
303-
const latestTags = (githubClient as any).sortSemanticTags(await this.listLatestTags(CHECTL_REPONAME))
304-
return [latestTags[1].name, latestTags[0].name]
339+
async getTwoLatestReleasedVersions(installer: string): Promise<[string, string]> {
340+
if (installer === 'olm') {
341+
// OLM installer uses community-operators marketplace.
342+
// To list available versions see the following folder:
343+
// https://github.com/redhat-openshift-ecosystem/community-operators-prod/tree/main/operators/eclipse-che
344+
const csvs = await this.listOLMReleasedCSV()
345+
return [csvs[1], csvs[0]]
346+
} else if (installer === 'operator') {
347+
// Operator installer uses templates from GitHub releases, which are marked with tags
348+
const githubClient = new CheGithubClient()
349+
const latestTags = (githubClient as any).sortSemanticTags(await this.listLatestTags(CHECTL_REPONAME))
350+
return [latestTags[1].name, latestTags[0].name]
351+
}
352+
throw new Error(`Failed to get latest versions: unknown installer '${installer}'`)
305353
}
306354

307355
/**

0 commit comments

Comments
 (0)