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..7d6392ded --- /dev/null +++ b/.ci/cico_updates_minishift.sh @@ -0,0 +1,133 @@ +#!/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 + +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() { + 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}; + else + OPERATOR_REPO=$(dirname "$SCRIPT_DIR"); + fi + + # 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() { + installYQ + installJQ + install_VirtPackages + installStartDocker + start_libvirt + minishift_installation + installChectl + load_jenkins_vars +} + +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}" + 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//") + + # 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 + installLatestCheStable + + # Create an workspace + getCheAcessToken # Function from ./util/ci_common.sh + chectl workspace:create --devfile=$OPERATOR_REPO/.ci/util/devfile-test.yaml + + # 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" + + # Patch images and tag the latest release + 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}'"}]' + + 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 +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() {