From b6fda13cdd45064f475aeb0c3dc16a19e57e24b8 Mon Sep 17 00:00:00 2001 From: Flavius Lacatusu Date: Mon, 5 Oct 2020 12:40:24 +0200 Subject: [PATCH] Change single host action Signed-off-by: Flavius Lacatusu --- .../nightly/minikube/function-utilities.sh | 63 +++++++++ .../nightly/minikube/single-host-gateway.sh | 131 ++++++++++++++++++ .github/workflows/single-host-tests.yaml | 2 +- 3 files changed, 195 insertions(+), 1 deletion(-) create mode 100644 .github/action_scripts/nightly/minikube/function-utilities.sh create mode 100644 .github/action_scripts/nightly/minikube/single-host-gateway.sh diff --git a/.github/action_scripts/nightly/minikube/function-utilities.sh b/.github/action_scripts/nightly/minikube/function-utilities.sh new file mode 100644 index 000000000..7800c9fff --- /dev/null +++ b/.github/action_scripts/nightly/minikube/function-utilities.sh @@ -0,0 +1,63 @@ +#!/usr/bin/env 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 + +# exit immediately when a command fails +set -e +# only exit with zero if all commands of the pipeline exit successfully +set -o pipefail +# error on unset variables +set -u +# print each command before executing it +set -x + +# Build latest operator image +function buildCheOperatorImage() { + docker build -t "${OPERATOR_IMAGE}" -f Dockerfile . && docker save "${OPERATOR_IMAGE}" > operator.tar + eval $(minikube docker-env) && docker load -i operator.tar && rm operator.tar +} + +# Utility to wait for a workspace to be started after workspace:create. +function waitSingleHostWorkspaceStart() { + set +e + export x=0 + while [ $x -le 180 ] + do + getSingleHostToken + + # List Workspaces and get the status + echo "[INFO] Getting workspace status:" + chectl workspace:list + workspaceList=$(chectl workspace:list --chenamespace=${NAMESPACE}) + workspaceStatus=$(echo "$workspaceList" | grep RUNNING | awk '{ print $4} ') + + if [ "${workspaceStatus:-NOT_RUNNING}" == "RUNNING" ] + then + echo "[INFO] Workspace started successfully" + break + fi + sleep 10 + x=$(( x+1 )) + done + + if [ $x -gt 180 ] + then + echo "[ERROR] Workspace didn't start after 3 minutes." + exit 1 + fi +} + +# Get Token from single host mode deployment +function getSingleHostToken() { + export GATEWAY_HOSTNAME=$(minikube ip).nip.io + export TOKEN_ENDPOINT="https://${GATEWAY_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) +} diff --git a/.github/action_scripts/nightly/minikube/single-host-gateway.sh b/.github/action_scripts/nightly/minikube/single-host-gateway.sh new file mode 100644 index 000000000..b42b22578 --- /dev/null +++ b/.github/action_scripts/nightly/minikube/single-host-gateway.sh @@ -0,0 +1,131 @@ +#!/usr/bin/env 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 + +# exit immediately when a command fails +set -e +# only exit with zero if all commands of the pipeline exit successfully +set -o pipefail +# error on unset variables +set -u +# print each command before executing it +set -x + +# Stop execution on any error +trap "catchFinish" EXIT SIGINT + +# Define global environments +export OPERATOR_REPO="${GITHUB_WORKSPACE}" +export RAM_MEMORY=8192 +export NAMESPACE="che" +export PLATFORM="kubernetes" + +# Directory where che artifacts will be stored and uploded to GH actions artifacts +export ARTIFACTS_DIR="/tmp/artifacts-che" + +# Set operator root directory +export OPERATOR_IMAGE="che-operator:tests" + +# Catch_Finish is executed after finish script. +catchFinish() { + result=$? + + if [ "$result" != "0" ]; then + echo "[ERROR] Please check the github actions artifacts" + collectCheLogWithChectl + exit 1 + fi + + echo "[INFO] Job finished Successfully.Please check github actions artifacts" + collectCheLogWithChectl + + exit $result +} + +# Utility to get che events and pod logs from openshift cluster +function collectCheLogWithChectl() { + mkdir -p ${ARTIFACTS_DIR} + chectl server:logs --directory=${ARTIFACTS_DIR} +} + +# Utility to wait for a workspace to be started after workspace:create. +function waitSingleHostWorkspaceStart() { + set +e + export x=0 + while [ $x -le 180 ] + do + getSingleHostToken + + # List Workspaces and get the status + echo "[INFO] Getting workspace status:" + chectl workspace:list + workspaceList=$(chectl workspace:list --chenamespace=${NAMESPACE}) + workspaceStatus=$(echo "$workspaceList" | grep RUNNING | awk '{ print $4} ') + + if [ "${workspaceStatus:-NOT_RUNNING}" == "RUNNING" ] + then + echo "[INFO] Workspace started successfully" + break + fi + sleep 10 + x=$(( x+1 )) + done + + if [ $x -gt 180 ] + then + echo "[ERROR] Workspace didn't start after 3 minutes." + exit 1 + fi +} + +# Deploy Eclipse Che in single host mode(gateway exposure type) +function runSHostGatewayExposure() { + # Patch file to pass to chectl + cat >/tmp/che-cr-patch.yaml <