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

fix: rollback tests #1900

Merged
merged 4 commits into from
Dec 17, 2021
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
4 changes: 3 additions & 1 deletion .ci/oci_chectl_rollback.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ init() {
export SCRIPT=$(readlink -f "$0")
export SCRIPT_DIR=$(dirname "$SCRIPT")

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

# Suggested namespace
Expand All @@ -47,6 +47,8 @@ init() {
}

run() {
echo "[INFO] Environment:"
env
# Before running the e2e tests we need to install all deps with yarn
yarn --cwd ${CHECTL_REPO}
export PLATFORM=openshift
Expand Down
37 changes: 37 additions & 0 deletions .github/workflows/e2e-minikube-operator-rollback.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#
# Copyright (c) 2019-2021 Red Hat, Inc.
# This program and the accompanying materials are made
# available under the terms of the Eclipse Public License 2.0
# which is available at https://www.eclipse.org/legal/epl-2.0/
#
# SPDX-License-Identifier: EPL-2.0
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
#

name: Minikube E2E
on: pull_request
jobs:
minikube-e2e-operator-rollback:
name: Operator installer rollback update
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v1
- name: Start minikube cluster
id: run-minikube
uses: che-incubator/setup-minikube-action@next
with:
minikube-version: v1.21.0
- name: Install chectl dependencies
run: yarn
- name: Run e2e rollback tests for Operator installer
run: |
export PLATFORM=minikube
export INSTALLER=operator
yarn test --coverage=false --forceExit --testRegex=test/e2e/e2e-rollback.test.ts
- uses: actions/upload-artifact@v2
if: ${{ always() }}
with:
name: test-artifacts
path: /tmp/logs/*
2 changes: 1 addition & 1 deletion src/api/kube.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1687,7 +1687,7 @@ export class KubeHelper {
cheClusterCR.spec.devWorkspace.enable = true
}

if (cheClusterCR.spec.devWorkspace.enable) {
if (cheClusterCR.spec.devWorkspace && cheClusterCR.spec.devWorkspace.enable) {
cheClusterCR.spec.auth.nativeUserMode = true
}

Expand Down
23 changes: 15 additions & 8 deletions test/e2e/e2e-rollback.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ jest.setTimeout(1000000)

const binChectl = E2eHelper.getChectlBinaries()

const PLATFORM = process.env.PLATFORM || 'minikube'

const INSTALLER = 'olm'
const OLM_CHANNEL = 'stable'
const PLATFORM = process.env.PLATFORM || 'openshift'
const INSTALLER = process.env.INSTALLER || 'olm'
const OLM_CHANNEL = process.env.OLM_CHANNEL || 'stable'

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

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`
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`
if (INSTALLER === 'olm') {
deployCommand += ` --olm-channel=${OLM_CHANNEL}`
}
await helper.runCliCommand(deployCommand)

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

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

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

it('Wait previous Che', async () => {
// It is possible to reduce awaiting timeout, because rollback itself waits for the restore to complete.
await helper.waitForVersionInCheCR(previousCheVersion, 2 * 60 * 1000)
await helper.waitForVersionInCheCR(previousCheVersion, 5 * 60 * 1000)
})
})
})
56 changes: 52 additions & 4 deletions test/e2e/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import { Octokit } from '@octokit/rest'
import * as execa from 'execa'
import { spawn } from 'child_process'
import * as fs from 'fs-extra'
import * as semver from 'semver'

import { CheHelper } from '../../src/api/che'
import { CheGithubClient, TagInfo } from '../../src/api/github-client'
Expand Down Expand Up @@ -286,6 +287,43 @@ export class E2eHelper {
return tags
}

/**
* Returns list of sorted CSVs in stable OLM channel of Che Operator published in community-operators repository.
* The CSVs are sorted from the latest to oldest.
*/
private async listOLMReleasedCSV(): Promise<string[]> {
const response = await this.octokit.repos.getContent({
owner: 'redhat-openshift-ecosystem',
repo: 'community-operators-prod',
path: 'operators/eclipse-che',
})
// There is an array in the response as given path points to a directory
const data = response.data as {name: string}[]
const csvsNames: string[] = []
data.map(item => csvsNames.push(item.name))
const stableChannelCSVNames = csvsNames.filter(csvName => {
// Filter versions like 7.37.2-all-namespaces
if (csvName.indexOf('-') !== -1) {
return false
}

// Filter non x.y.z
const versionParts = csvName.split('.')
if (versionParts.length !== 3) {
return false
}
// Ensure each part is a number
for (const versionPart of versionParts) {
if (!versionPart.match(/^[0-9]+$/)) {
return false
}
}
return true
})

return stableChannelCSVNames.sort((verA: string, verB: string) => semver.lt(verA, verB) ? 1 : -1)
}

/**
* Get previous version from chectl repository
*/
Expand All @@ -298,10 +336,20 @@ export class E2eHelper {
/**
* Gets pre-latest and latest released version from chectl repository
*/
async getTwoLatestReleasedVersions(): Promise<[string, string]> {
const githubClient = new CheGithubClient()
const latestTags = (githubClient as any).sortSemanticTags(await this.listLatestTags(CHECTL_REPONAME))
return [latestTags[1].name, latestTags[0].name]
async getTwoLatestReleasedVersions(installer: string): Promise<[string, string]> {
if (installer === 'olm') {
// OLM installer uses community-operators marketplace.
// To list available versions see the following folder:
// https://github.com/redhat-openshift-ecosystem/community-operators-prod/tree/main/operators/eclipse-che
const csvs = await this.listOLMReleasedCSV()
return [csvs[1], csvs[0]]
} else if (installer === 'operator') {
// Operator installer uses templates from GitHub releases, which are marked with tags
const githubClient = new CheGithubClient()
const latestTags = (githubClient as any).sortSemanticTags(await this.listLatestTags(CHECTL_REPONAME))
return [latestTags[1].name, latestTags[0].name]
}
throw new Error(`Failed to get latest versions: unknown installer '${installer}'`)
}

/**
Expand Down