From e2f7fa65fce38a4f30ef19c9f512847a222c0a3d Mon Sep 17 00:00:00 2001 From: flacatus Date: Wed, 1 Jul 2020 13:54:14 +0200 Subject: [PATCH 1/4] Add CI script to support updates testing in minishift Signed-off-by: flacatus --- .ci/cico_olm_prcheck.sh | 8 ---- .ci/cico_updates_minikube.sh | 2 + .ci/cico_updates_minishift.sh | 87 +++++++++++++++++++++++++++++++++++ .ci/util/ci_common.sh | 45 ++++++++++++++---- .ci/util/cr-test.yaml | 5 ++ 5 files changed, 129 insertions(+), 18 deletions(-) create mode 100644 .ci/cico_updates_minishift.sh create mode 100644 .ci/util/cr-test.yaml diff --git a/.ci/cico_olm_prcheck.sh b/.ci/cico_olm_prcheck.sh index bdae0411e..078f59414 100644 --- a/.ci/cico_olm_prcheck.sh +++ b/.ci/cico_olm_prcheck.sh @@ -28,14 +28,6 @@ init() { CHANNEL="nightly" } -minishift_olm_installation() { - MSFT_RELEASE="1.34.2" - printInfo "Downloading Minishift binaries" - if [ ! -d "$OPERATOR_REPO/tmp" ]; then mkdir -p "$OPERATOR_REPO/tmp" && chmod 777 "$OPERATOR_REPO/tmp"; fi - curl -L https://github.com/minishift/minishift/releases/download/v$MSFT_RELEASE/minishift-$MSFT_RELEASE-linux-amd64.tgz \ - -o ${OPERATOR_REPO}/tmp/minishift-$MSFT_RELEASE-linux-amd64.tar && tar -xvf ${OPERATOR_REPO}/tmp/minishift-$MSFT_RELEASE-linux-amd64.tar -C /usr/bin --strip-components=1 -} - install_Dependencies() { installYQ installJQ diff --git a/.ci/cico_updates_minikube.sh b/.ci/cico_updates_minikube.sh index 8f1aca9dc..804f77cc1 100644 --- a/.ci/cico_updates_minikube.sh +++ b/.ci/cico_updates_minikube.sh @@ -99,6 +99,8 @@ testUpdates() { workspaceList=$(chectl workspace:list) workspaceID=$(echo "$workspaceList" | grep -oP '\bworkspace.*?\b') chectl workspace:start $workspaceID + + waitWorkspaceStart } init diff --git a/.ci/cico_updates_minishift.sh b/.ci/cico_updates_minishift.sh new file mode 100644 index 000000000..876d87044 --- /dev/null +++ b/.ci/cico_updates_minishift.sh @@ -0,0 +1,87 @@ +#!/bin/bash +# +# Copyright (c) 2020 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 + +set -ex + +init() { + SCRIPT=$(readlink -f "$0") + SCRIPT_DIR=$(dirname "$SCRIPT") + + if [[ ${WORKSPACE} ]] && [[ -d ${WORKSPACE} ]]; then + OPERATOR_REPO=${WORKSPACE}; + else + OPERATOR_REPO=$(dirname "$SCRIPT_DIR"); + fi + + RAM_MEMORY=8192 + PLATFORM="openshift" + NAMESPACE="che" + CHANNEL="stable" +} + +installDependencies() { + installYQ + installJQ + install_VirtPackages + installStartDocker + start_libvirt + minishift_installation + installChectl + load_jenkins_vars +} + +installCheUpdates() { + export packageName=eclipse-che-preview-${PLATFORM} + export platformPath=${OPERATOR_REPO}/olm/${packageName} + export packageFolderPath="${platformPath}/deploy/olm-catalog/${packageName}" + export packageFilePath="${packageFolderPath}/${packageName}.package.yaml" + + export lastCSV=$(yq -r ".channels[] | select(.name == \"${CHANNEL}\") | .currentCSV" "${packageFilePath}") + export lastPackageVersion=$(echo "${lastCSV}" | sed -e "s/${packageName}.v//") + export previousCSV=$(sed -n 's|^ *replaces: *\([^ ]*\) *|\1|p' "${packageFolderPath}/${lastPackageVersion}/${packageName}.v${lastPackageVersion}.clusterserviceversion.yaml") + export previousPackageVersion=$(echo "${previousCSV}" | sed -e "s/${packageName}.v//") + + chectl server:start --platform=minishift --che-operator-cr-patch-yaml=${OPERATOR_REPO}/.ci/util/cr-test.yaml --installer=operator \ + --cheimage=quay.io/eclipse/che-server:${previousPackageVersion} --che-operator-image=quay.io/eclipse/che-operator:${previousPackageVersion} +} + +testUpdates() { + # Install previous stable version of Eclipse Che + installCheUpdates + + # Create an workspace + getCheAcessToken # Function from ./util/ci_common.sh + chectl workspace:create --devfile=$OPERATOR_REPO/.ci/util/devfile-test.yaml + + # Create tmp folder and add che operator templates used by server:update command. + mkdir -p "$OPERATOR_REPO/tmp" && chmod 777 "$OPERATOR_REPO/tmp" + cp -r deploy "$OPERATOR_REPO/tmp/che-operator" + + # Update the server to the latest stable che version + chectl server:update --skip-version-check --installer=operator --platform=minishift \ + --che-operator-image=quay.io/eclipse/che-operator:${lastPackageVersion} --templates="$OPERATOR_REPO/tmp" + echo "[INFO] Successfull installed update in minishift" + + # Start an workspace + getCheAcessToken + workspaceList=$(chectl workspace:list) + workspaceID=$(echo "$workspaceList" | grep -oP '\bworkspace.*?\b') + chectl workspace:start $workspaceID + + # Wait for workspace to be up + waitWorkspaceStart # Function from ./util/ci_common.sh +} + +init +source "${OPERATOR_REPO}"/.ci/util/ci_common.sh +#installDependencies +testUpdates diff --git a/.ci/util/ci_common.sh b/.ci/util/ci_common.sh index c5729a3e3..80a0284a9 100644 --- a/.ci/util/ci_common.sh +++ b/.ci/util/ci_common.sh @@ -108,13 +108,6 @@ generate_self_signed_certs() { -nodes && cat cert.pem key.pem > ca.crt } -minikube_installation() { - start_libvirt - curl -Lo minikube https://storage.googleapis.com/minikube/releases/latest/minikube-linux-amd64 \ - && chmod +x minikube - sudo install minikube /usr/local/bin/ && rm -rf minikube -} - installEpelRelease() { if yum repolist | grep epel; then printWarn "Epel already installed, skipping instalation." @@ -145,9 +138,41 @@ installChectl() { } getCheAcessToken() { - KEYCLOAK_HOSTNAME=keycloak-che.$(minikube ip).nip.io - TOKEN_ENDPOINT="https://${KEYCLOAK_HOSTNAME}/auth/realms/che/protocol/openid-connect/token" - export CHE_ACCESS_TOKEN=$(curl --data "grant_type=password&client_id=che-public&username=admin&password=admin" -k ${TOKEN_ENDPOINT} | jq -r .access_token) + if [[ ${PLATFORM} == "openshift" ]] + then + KEYCLOAK_HOSTNAME=$(oc get route -n ${NAMESPACE} keycloak --template={{.spec.host}}) + TOKEN_ENDPOINT="http://${KEYCLOAK_HOSTNAME}/auth/realms/che/protocol/openid-connect/token" + export CHE_ACCESS_TOKEN=$(curl --data "grant_type=password&client_id=che-public&username=admin&password=admin" -k ${TOKEN_ENDPOINT} | jq -r .access_token) + else + KEYCLOAK_HOSTNAME=keycloak-che.$(minikube ip).nip.io + TOKEN_ENDPOINT="https://${KEYCLOAK_HOSTNAME}/auth/realms/che/protocol/openid-connect/token" + export CHE_ACCESS_TOKEN=$(curl --data "grant_type=password&client_id=che-public&username=admin&password=admin" -k ${TOKEN_ENDPOINT} | jq -r .access_token) + fi +} + +waitWorkspaceStart() { + export x=0 + set +e + getCheAcessToken + while [ $x -le 180 ] + do + workspaceList=$(chectl workspace:list --chenamespace=${NAMESPACE}) + workspaceStatus=$(echo "$workspaceList" | grep -oP '\bRUNNING.*?\b') + + if [ "${workspaceStatus}" == "RUNNING" ] + then + printInfo "Workspace started started successfully" + break + fi + sleep 3 + x=$(( x+1 )) + done + + if [ $x -gt 180 ] + then + echo "Workspace didn't start after 3 minutes." + exit 1 + fi } getCheClusterLogs() { diff --git a/.ci/util/cr-test.yaml b/.ci/util/cr-test.yaml new file mode 100644 index 000000000..84e96376c --- /dev/null +++ b/.ci/util/cr-test.yaml @@ -0,0 +1,5 @@ +spec: + server: + tlsSupport: false + auth: + updateAdminPassword: false From ca5902571d5b6be52b0a9ac9fe1c71295945a388 Mon Sep 17 00:00:00 2001 From: flacatus Date: Wed, 1 Jul 2020 13:58:48 +0200 Subject: [PATCH 2/4] Delete unused variables Signed-off-by: flacatus --- .ci/cico_updates_minishift.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/.ci/cico_updates_minishift.sh b/.ci/cico_updates_minishift.sh index 876d87044..011070960 100644 --- a/.ci/cico_updates_minishift.sh +++ b/.ci/cico_updates_minishift.sh @@ -25,7 +25,6 @@ init() { RAM_MEMORY=8192 PLATFORM="openshift" NAMESPACE="che" - CHANNEL="stable" } installDependencies() { From ef146cdf49ddbbfbdf0dc12a1593a1b15c657996 Mon Sep 17 00:00:00 2001 From: flacatus Date: Thu, 2 Jul 2020 12:06:25 +0200 Subject: [PATCH 3/4] Add oc patch to update che images CR Signed-off-by: flacatus --- .ci/cico_updates_minishift.sh | 85 +++++++++++++++++++++++++++-------- .ci/util/cr-test.yaml | 5 --- 2 files changed, 66 insertions(+), 24 deletions(-) delete mode 100644 .ci/util/cr-test.yaml diff --git a/.ci/cico_updates_minishift.sh b/.ci/cico_updates_minishift.sh index 011070960..1aa3fec79 100644 --- a/.ci/cico_updates_minishift.sh +++ b/.ci/cico_updates_minishift.sh @@ -12,9 +12,20 @@ set -ex +trap 'Catch_Finish $?' EXIT SIGINT + +# Catch errors and force to delete minishift VM. +Catch_Finish() { + rm -rf ${OPERATOR_REPO}/tmp ~/.minishift && yes | minishift delete +} + init() { - SCRIPT=$(readlink -f "$0") - SCRIPT_DIR=$(dirname "$SCRIPT") + export SCRIPT=$(readlink -f "$0") + export SCRIPT_DIR=$(dirname "$SCRIPT") + export RAM_MEMORY=8192 + export PLATFORM="openshift" + export NAMESPACE="che" + export CHANNEL="stable" if [[ ${WORKSPACE} ]] && [[ -d ${WORKSPACE} ]]; then OPERATOR_REPO=${WORKSPACE}; @@ -22,9 +33,9 @@ init() { OPERATOR_REPO=$(dirname "$SCRIPT_DIR"); fi - RAM_MEMORY=8192 - PLATFORM="openshift" - NAMESPACE="che" + # Create tmp folder and add che operator templates used by server:update command. + mkdir -p "$OPERATOR_REPO/tmp" && chmod 777 "$OPERATOR_REPO/tmp" + cp -r deploy "$OPERATOR_REPO/tmp/che-operator" } installDependencies() { @@ -38,7 +49,8 @@ installDependencies() { load_jenkins_vars } -installCheUpdates() { +installLatestCheStable() { + # Get Stable and new release versions from olm files openshift. export packageName=eclipse-che-preview-${PLATFORM} export platformPath=${OPERATOR_REPO}/olm/${packageName} export packageFolderPath="${platformPath}/deploy/olm-catalog/${packageName}" @@ -49,38 +61,73 @@ installCheUpdates() { export previousCSV=$(sed -n 's|^ *replaces: *\([^ ]*\) *|\1|p' "${packageFolderPath}/${lastPackageVersion}/${packageName}.v${lastPackageVersion}.clusterserviceversion.yaml") export previousPackageVersion=$(echo "${previousCSV}" | sed -e "s/${packageName}.v//") - chectl server:start --platform=minishift --che-operator-cr-patch-yaml=${OPERATOR_REPO}/.ci/util/cr-test.yaml --installer=operator \ - --cheimage=quay.io/eclipse/che-server:${previousPackageVersion} --che-operator-image=quay.io/eclipse/che-operator:${previousPackageVersion} + # Add stable Che images and tag to CR + sed -i "s/tlsSupport: true/tlsSupport: false/" ${OPERATOR_REPO}/tmp/che-operator/crds/org_v1_che_cr.yaml + sed -i "s/cheImage: ''/cheImage: quay.io\/eclipse\/che-server/" ${OPERATOR_REPO}/tmp/che-operator/crds/org_v1_che_cr.yaml + sed -i "s/cheImageTag: ''/cheImageTag: ${previousPackageVersion}/" ${OPERATOR_REPO}/tmp/che-operator/crds/org_v1_che_cr.yaml + sed -i "s/devfileRegistryImage: ''/devfileRegistryImage: quay.io\/eclipse\/che-devfile-registry:"${previousPackageVersion}"/" ${OPERATOR_REPO}/tmp/che-operator/crds/org_v1_che_cr.yaml + sed -i "s/pluginRegistryImage: ''/pluginRegistryImage: quay.io\/eclipse\/che-plugin-registry:"${previousPackageVersion}"/" ${OPERATOR_REPO}/tmp/che-operator/crds/org_v1_che_cr.yaml + sed -i "s/identityProviderImage: ''/identityProviderImage: quay.io\/eclipse\/che-keycloak:"${previousPackageVersion}"/" ${OPERATOR_REPO}/tmp/che-operator/crds/org_v1_che_cr.yaml + + # Start last stable version of che + chectl server:start --platform=minishift --che-operator-cr-yaml=${OPERATOR_REPO}/tmp/che-operator/crds/org_v1_che_cr.yaml \ + --che-operator-image=quay.io/eclipse/che-operator:${previousPackageVersion} --installer=operator +} + +# Utility to wait for new release to be up +waitForNewCheVersion() { + export n=0 + + while [ $n -le 360 ] + do + cheVersion=$(oc get checluster/eclipse-che -n "${NAMESPACE}" -o jsonpath={.status.cheVersion}) + oc get pods -n ${NAMESPACE} + if [ "${cheVersion}" == $lastPackageVersion ] + then + echo -e "\u001b[32m Installed latest version che-operator: ${lastCSV} \u001b[0m" + break + fi + sleep 6 + n=$(( n+1 )) + done + + if [ $n -gt 360 ] + then + echo "Latest version install for Eclipse che failed." + exit 1 + fi } testUpdates() { # Install previous stable version of Eclipse Che - installCheUpdates + installLatestCheStable # Create an workspace getCheAcessToken # Function from ./util/ci_common.sh chectl workspace:create --devfile=$OPERATOR_REPO/.ci/util/devfile-test.yaml - # Create tmp folder and add che operator templates used by server:update command. - mkdir -p "$OPERATOR_REPO/tmp" && chmod 777 "$OPERATOR_REPO/tmp" - cp -r deploy "$OPERATOR_REPO/tmp/che-operator" + # Update the operator to the new release + chectl server:update --skip-version-check --installer=operator --platform=minishift --che-operator-image=quay.io/eclipse/che-operator:${lastPackageVersion} --templates="tmp" - # Update the server to the latest stable che version - chectl server:update --skip-version-check --installer=operator --platform=minishift \ - --che-operator-image=quay.io/eclipse/che-operator:${lastPackageVersion} --templates="$OPERATOR_REPO/tmp" - echo "[INFO] Successfull installed update in minishift" + # Patch images and tag the latest release + oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/server/identityProviderImage", "value":"quay.io/eclipse/che-keycloak:'${lastPackageVersion}'"}]' + oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/server/devfileRegistryImage", "value":"quay.io/eclipse/che-devfile-registry:'${lastPackageVersion}'"}]' + oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/server/pluginRegistryImage", "value":"quay.io/eclipse/che-plugin-registry:'${lastPackageVersion}'"}]' + oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/server/cheImageTag", "value":"'${lastPackageVersion}'"}]' - # Start an workspace - getCheAcessToken + waitForNewCheVersion + + getCheAcessToken # Function from ./util/ci_common.sh workspaceList=$(chectl workspace:list) workspaceID=$(echo "$workspaceList" | grep -oP '\bworkspace.*?\b') chectl workspace:start $workspaceID # Wait for workspace to be up waitWorkspaceStart # Function from ./util/ci_common.sh + oc get events -n ${NAMESPACE} } init source "${OPERATOR_REPO}"/.ci/util/ci_common.sh -#installDependencies +installDependencies testUpdates diff --git a/.ci/util/cr-test.yaml b/.ci/util/cr-test.yaml deleted file mode 100644 index 84e96376c..000000000 --- a/.ci/util/cr-test.yaml +++ /dev/null @@ -1,5 +0,0 @@ -spec: - server: - tlsSupport: false - auth: - updateAdminPassword: false From 2e9dad6f212b03f05335f84a8f3935717fc295ad Mon Sep 17 00:00:00 2001 From: flacatus Date: Thu, 2 Jul 2020 12:27:12 +0200 Subject: [PATCH 4/4] Fix keycloak patch image Signed-off-by: flacatus --- .ci/cico_updates_minishift.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.ci/cico_updates_minishift.sh b/.ci/cico_updates_minishift.sh index 1aa3fec79..7d6392ded 100644 --- a/.ci/cico_updates_minishift.sh +++ b/.ci/cico_updates_minishift.sh @@ -110,7 +110,7 @@ testUpdates() { chectl server:update --skip-version-check --installer=operator --platform=minishift --che-operator-image=quay.io/eclipse/che-operator:${lastPackageVersion} --templates="tmp" # Patch images and tag the latest release - oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/server/identityProviderImage", "value":"quay.io/eclipse/che-keycloak:'${lastPackageVersion}'"}]' + oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/auth/identityProviderImage", "value":"quay.io/eclipse/che-keycloak:'${lastPackageVersion}'"}]' oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/server/devfileRegistryImage", "value":"quay.io/eclipse/che-devfile-registry:'${lastPackageVersion}'"}]' oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/server/pluginRegistryImage", "value":"quay.io/eclipse/che-plugin-registry:'${lastPackageVersion}'"}]' oc patch checluster eclipse-che --type='json' -p='[{"op": "replace", "path": "/spec/server/cheImageTag", "value":"'${lastPackageVersion}'"}]'