diff --git a/.ci/oci-dashboard-happy-path.sh b/.ci/oci-dashboard-happy-path.sh index 166b58117c..22f4b87aa1 100755 --- a/.ci/oci-dashboard-happy-path.sh +++ b/.ci/oci-dashboard-happy-path.sh @@ -8,18 +8,22 @@ # SPDX-License-Identifier: EPL-2.0 # -set +e +set -e +set -o pipefail +set -u set -x -export CHE_REPO_BRANCH=${CHE_REPO_BRANCH:-"main"} -export CHE_REPO_ARCHIVE=${CHE_REPO_ARCHIVE:-"https://github.com/eclipse/che/archive/refs/heads/${CHE_REPO_BRANCH}.zip"} +START=$(date +%s.%N) +SCRIPT_DIR=$(dirname $(readlink -f "$0")) + +export WORKDIR=${WORKDIR:-"${SCRIPT_DIR}/workdir"} +export CHE_NAMESPACE=${CHE_NAMESPACE:-"eclipse-che"} +export HAPPY_PATH_POD_NAME='happy-path-che' +export HAPPY_PATH_POD_FILE="${SCRIPT_DIR}/resources/pod-che-smoke-test.yaml" export ARTIFACT_DIR=${ARTIFACT_DIR:-"/tmp/devworkspace-happy-path-artifacts"} -# debug info regarding system executables -which docker -which podman -which git -which npm +rm -rf ${WORKDIR} +mkdir -p ${WORKDIR} # method originally extracted from eclipse/che/tests/devworkspace-happy-path/common.sh function bumpPodsInfo() { @@ -57,27 +61,141 @@ function collectLogs() { echo "[INFO] Logs are collected and can be found in $ARTIFACT_DIR" } +# method originally extracted from eclipse/che/tests/devworkspace-happy-path/launch.sh +# Create cluster-admin user inside of OpenShift cluster and login +function provisionOpenShiftOAuthUser() { + echo "[INFO] Testing if Che User exists." + KUBECONFIG="${KUBECONFIG:-${HOME}/.kube/config}" + TMP_KUBECONFIG="$WORKDIR/kubeconfig" + cp "$KUBECONFIG" "$TMP_KUBECONFIG" + + if oc login -u che-user -p user --kubeconfig $TMP_KUBECONFIG; then + echo "[INFO] Che User already exists. Using it" + return 0 + fi + echo "[INFO] Che User does not exist. Setting up htpasswd oauth for it." + oc delete secret dev-htpasswd-secret -n openshift-config || true + oc create secret generic dev-htpasswd-secret --from-file=htpasswd="$SCRIPT_DIR/resources/users.htpasswd" -n openshift-config + + if [[ $(oc get oauth/cluster -o=json | jq -e 'select (.spec.identityProviders == null)') ]]; then + # there are no identity providers. We can do merge and set the whole .spec.identityProviders field + echo "[INFO] No identity providers found, provisioning Che one." + oc patch oauth/cluster --type=merge -p "$(cat $SCRIPT_DIR/resources/cluster-oauth-patch.json)" + elif [[ ! $(oc get oauth/cluster -o=json | jq -e '.spec.identityProviders[]?.name? | select ( . == ("dev-htpasswd"))') ]]; then + # there are some identity providers. We should do add patch not to override existing identity providers + echo "[INFO] OAuth Cluster is found but dev-htpasswd provider missing. Provisioning it." + oc patch oauth/cluster --type=json -p '[{ + "op": "add", + "path": "/spec/identityProviders/0", + "value": { + "name":"dev-htpasswd", + "mappingMethod":"add", + "type":"HTPasswd", + "htpasswd": { + "fileData":{"name":"dev-htpasswd-secret"} + } + } + }]' + else + echo "[INFO] dev-htpasswd oauth provider is found. Using it" + fi + + echo "[INFO] rollout oauth-openshift pods for applying OAuth configuration" + # apply just added identity providers, we need to rollout deployment for make sure + # that new IDP item will appear in the IDP table + # https://github.com/eclipse/che/issues/20822 + + oc rollout status -n openshift-authentication deployment/oauth-openshift + echo -e "[INFO] Waiting for htpasswd auth to be working up to 5 minutes" + CURRENT_TIME=$(date +%s) + ENDTIME=$(($CURRENT_TIME + 300)) + while [ $(date +%s) -lt $ENDTIME ]; do + if oc login -u happypath-dev -p dev --kubeconfig $TMP_KUBECONFIG; then + return 0 + fi + sleep 10 + done + echo "[ERROR] Che htpasswd changes are not affected after timeout." + exit 1 +} + +# method originally extracted from eclipse/che/tests/devworkspace-happy-path/launch.sh +startHappyPathTest() { + oc delete pod happy-path-che -n eclipse-che --grace-period=30 --ignore-not-found + # patch happy-path-che.yaml + ECLIPSE_CHE_URL=http://$(oc get route -n "${CHE_NAMESPACE}" che -o jsonpath='{.status.ingress[0].host}') + cp $HAPPY_PATH_POD_FILE ${WORKDIR}/e2e-pod.yaml + sed -i "s@CHE_URL@${ECLIPSE_CHE_URL}@g" ${WORKDIR}/e2e-pod.yaml + sed -i "s@CHE-NAMESPACE@${CHE_NAMESPACE}@g" ${WORKDIR}/e2e-pod.yaml + echo "[INFO] Applying the following patched Che Happy Path Pod:" + cat ${WORKDIR}/e2e-pod.yaml + echo "[INFO] --------------------------------------------------" + oc apply -f ${WORKDIR}/e2e-pod.yaml + # wait for the pod to start + n=0 + while [ $n -le 120 ] + do + PHASE=$(oc get pod -n ${CHE_NAMESPACE} ${HAPPY_PATH_POD_NAME} \ + --template='{{ .status.phase }}') + if [[ ${PHASE} == "Running" ]]; then + echo "[INFO] Happy-path test started successfully." + return + fi + + sleep 5 + n=$(( n+1 )) + done + + echo "[ERROR] Failed to start happy-path test." + exit 1 +} + +########################## +# LOGGING AND EXECUTIOIN # +########################## + # Catch the finish of the job and write logs in artifacts. -###trap 'collectLogs $?' EXIT SIGINT +trap 'collectLogs $?' EXIT SIGINT -run() { - # Deploy Eclipse Che with a custom dashboard image - cat > /tmp/che-cr-patch.yaml < /tmp/che-cr-patch.yaml <