Merge pull request #564 from flacatus/nightly_olm_tests

feat: Create CI scripts to test new nightly bundles using new Openshift CI bundles workflow
pull/571/head
Flavius Lacatusu 2020-12-11 15:23:22 +01:00 committed by GitHub
commit 335c6ff332
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
16 changed files with 220 additions and 225 deletions

View File

@ -1,35 +0,0 @@
#!/bin/bash
#
# Copyright (c) 2012-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
#
set -e
set -x
# Component is defined in Openshift CI job configuration. See: https://github.com/openshift/release/blob/master/ci-operator/config/devfile/devworkspace-operator/devfile-devworkspace-operator-master__v4.yaml#L8
export CI_COMPONENT="che-operator-catalog"
export CATALOG_SOURCE_IMAGE_NAME=${CI_COMPONENT}:stable
export OPERATOR_REPO=$(dirname $(dirname $(readlink -f "$0")));
source "${OPERATOR_REPO}"/.github/bin/common.sh
trap "catchFinish" EXIT SIGINT
# run function run the tests in ci of custom catalog source.
function runTests() {
# see olm.sh
export OAUTH="false"
# Execute test catalog source script
"${OPERATOR_REPO}"/olm/testCatalogSource.sh "openshift" "nightly" ${NAMESPACE} "catalog" "che-catalog"
startNewWorkspace
waitWorkspaceStart
}
init
runTests

View File

@ -1,43 +0,0 @@
#!/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 -e
set -x
export OPERATOR_REPO=$(dirname $(dirname $(readlink -f "$0")));
source "${OPERATOR_REPO}"/.github/bin/common.sh
overrideDefaults() {
# CHE_OPERATOR_IMAGE is exposed in openshift ci pod. This image is build in every job and used then to deploy Che
# More info about how images are builded in Openshift CI: https://github.com/openshift/ci-tools/blob/master/TEMPLATES.md#parameters-available-to-templates
export OPERATOR_IMAGE=${CHE_OPERATOR_IMAGE}
echo "[INFO] Che Operator Image used is: ${CHE_OPERATOR_IMAGE}"
}
prepareTemplates() {
disableOpenShiftOAuth ${TEMPLATES}
disableUpdateAdminPassword ${TEMPLATES}
setCustomOperatorImage ${TEMPLATES} ${OPERATOR_IMAGE}
setServerExposureStrategy ${TEMPLATES} "single-host"
}
runTests() {
deployEclipseChe "operator" "openshift" ${OPERATOR_IMAGE} ${TEMPLATES}
startNewWorkspace
waitWorkspaceStart
}
init
overrideDefaults
initLatestTemplates
prepareTemplates
runTests

View File

@ -16,6 +16,9 @@ set -x
export OPERATOR_REPO=$(dirname $(dirname $(readlink -f "$0")));
source "${OPERATOR_REPO}"/.github/bin/common.sh
#Stop execution on any error
trap "catchFinish" EXIT SIGINT
runTests() {
"${OPERATOR_REPO}"/olm/testUpdate.sh "openshift" "stable" ${NAMESPACE}
waitEclipseCheDeployed ${LAST_PACKAGE_VERSION}

15
.ci/devfile-test.yaml Normal file
View File

@ -0,0 +1,15 @@
#!/bin/bash
#
# Copyright (c) 2012-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
metadata:
name: e2e-tests
apiVersion: 1.0.0

46
.ci/oci-nightly-olm.sh Executable file
View File

@ -0,0 +1,46 @@
#!/bin/bash
#
# Copyright (c) 2012-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
#
################################ !!! IMPORTANT !!! ################################
########### THIS JOB USE openshift ci operators workflows to run #####################
########## More info about how it is configured can be found here: https://docs.ci.openshift.org/docs/how-tos/testing-operator-sdk-operators #############
#######################################################################################################################################################
# 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
export OPERATOR_REPO=$(dirname $(dirname $(readlink -f "$0")));
source "${OPERATOR_REPO}"/.github/bin/common.sh
#Stop execution on any error
trap "catchFinish" EXIT SIGINT
overrideDefaults() {
# CI_CHE_OPERATOR_IMAGE it is che operator image builded in openshift CI job workflow. More info about how works image dependencies in ci:https://github.com/openshift/ci-tools/blob/master/TEMPLATES.md#parameters-available-to-templates
export OPERATOR_IMAGE=${CI_CHE_OPERATOR_IMAGE:-"quay.io/eclipse/che-operator:nightly"}
}
runTests() {
# Deploy Eclipse Che applying CR
applyOlmCR
waitEclipseCheDeployed "nightly"
startNewWorkspace
waitWorkspaceStart
}
init
overrideDefaults
patchEclipseCheOperatorSubscription
printOlmCheObjects
runTests

47
.ci/oci-single-host.sh Executable file
View File

@ -0,0 +1,47 @@
#!/bin/bash
#
# Copyright (c) 2012-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
#
################################ !!! IMPORTANT !!! ################################
########### THIS JOB USE openshift ci operators workflows to run #####################
########## More info about how it is configured can be found here: https://docs.ci.openshift.org/docs/how-tos/testing-operator-sdk-operators #############
#######################################################################################################################################################
# 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
export OPERATOR_REPO=$(dirname $(dirname $(readlink -f "$0")));
source "${OPERATOR_REPO}"/.github/bin/common.sh
#Stop execution on any error
trap "catchFinish" EXIT SIGINT
overrideDefaults() {
# CI_CHE_OPERATOR_IMAGE it is che operator image builded in openshift CI job workflow. More info about how works image dependencies in ci:https://github.com/openshift/ci-tools/blob/master/TEMPLATES.md#parameters-available-to-templates
export OPERATOR_IMAGE=${CI_CHE_OPERATOR_IMAGE:-"quay.io/eclipse/che-operator:nightly"}
export CHE_EXPOSURE_STRATEGY="single-host"
}
runTests() {
# Deploy Eclipse Che applying CR
applyOlmCR
waitEclipseCheDeployed "nightly"
startNewWorkspace
waitWorkspaceStart
}
init
overrideDefaults
patchEclipseCheOperatorSubscription
printOlmCheObjects
runTests

View File

@ -1,3 +1,15 @@
#!/bin/bash
#
# Copyright (c) 2012-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
**/*.diff
**/*.sh
**/*Dockerfile

View File

@ -1,3 +1,14 @@
#!/bin/bash
#
# Copyright (c) 2012-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
# Dockerfile to bootstrap build and test in openshift-ci

View File

@ -1,15 +0,0 @@
FROM quay.io/operator-framework/upstream-registry-builder as builder
# Docker build in ci needs the complete route of the che operator repo dir...
COPY olm/eclipse-che-preview-openshift/deploy manifests/eclipse-che-preview-openshift
RUN ./bin/initializer --permissive -o ./bundles.db
FROM openshift/origin-base
COPY --from=builder /build/bin/initializer /initializer
COPY --from=builder /build/bin/configmap-server /bin/configmap-server
COPY --from=builder /build/bundles.db /bundles.db
COPY --from=builder /build/bin/registry-server /registry-server
COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe
EXPOSE 50051
ENTRYPOINT ["/registry-server"]
CMD ["--database", "bundles.db"]

View File

@ -1,101 +0,0 @@
#
# Copyright (c) 2012-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 -e
# Get the access token from keycloak in openshift platforms and kubernetes
function getCheAcessToken() {
if [[ ${PLATFORM} == "openshift" ]]
then
export CHE_API_ENDPOINT=$(oc get route -n ${NAMESPACE} che --template={{.spec.host}})/api
KEYCLOAK_HOSTNAME=$(oc get route -n ${NAMESPACE} keycloak --template={{.spec.host}})
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)
else
export CHE_API_ENDPOINT=che-che.$(minikube ip).nip.io/api
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
}
# Utility to wait for a workspace to be started after workspace:create.
function waitWorkspaceStart() {
set +e
export x=0
while [ $x -le 180 ]
do
getCheAcessToken
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
}
# Utility to get all logs from che
function getCheClusterLogs() {
mkdir -p /tmp/artifacts-che
cd /tmp/artifacts-che
for POD in $(kubectl get pods -o name -n ${NAMESPACE}); do
for CONTAINER in $(kubectl get -n ${NAMESPACE} ${POD} -o jsonpath="{.spec.containers[*].name}"); do
echo ""
echo "[INFO] Getting logs from $POD"
echo ""
kubectl logs ${POD} -c ${CONTAINER} -n ${NAMESPACE} |tee $(echo ${POD}-${CONTAINER}.log | sed 's|pod/||g')
done
done
echo "[INFO] Get events"
kubectl get events -n ${NAMESPACE}| tee get_events.log
kubectl get all | tee get_all.log
}
function installYq() {
YQ=$(command -v yq) || true
if [[ ! -x "${YQ}" ]]; then
pip3 install wheel
pip3 install yq
fi
echo "[INFO] $(yq --version)"
echo "[INFO] $(jq --version)"
}
# Graps Eclipse Che logs
collectCheLogWithChectl() {
mkdir -p ${ARTIFACTS_DIR}
chectl server:logs --directory=${ARTIFACTS_DIR}
}
# Build latest operator image
buildCheOperatorImage() {
docker build -t "${OPERATOR_IMAGE}" -f Dockerfile . && docker save "${OPERATOR_IMAGE}" > operator.tar
}
copyCheOperatorImageToMinikube() {
eval $(minikube docker-env) && docker load -i operator.tar && rm operator.tar
}

View File

@ -1,3 +0,0 @@
metadata:
name: e2e-tests
apiVersion: 1.0.0

64
.github/bin/common.sh vendored
View File

@ -31,15 +31,20 @@ init() {
export SCRIPT=$(readlink -f "$0")
export SCRIPT_DIR=$(dirname "$SCRIPT")
export RAM_MEMORY=8192
export NAMESPACE="che"
export NAMESPACE="eclipse-che"
export ARTIFACTS_DIR="/tmp/artifacts-che"
export TEMPLATES=${OPERATOR_REPO}/tmp
export OPERATOR_IMAGE="quay.io/eclipse/che-operator:test"
export CHE_EXPOSURE_STRATEGY="multi-host"
export OAUTH="false"
export XDG_DATA_HOME=/tmp/chectl/data
export XDG_CACHE_HOME=/tmp/chectl/cache
export XDG_CONFIG_HOME=/tmp/chectl/config
export OPENSHIFT_NIGHTLY_CSV_FILE="${OPERATOR_REPO}/deploy/olm-catalog/eclipse-che-preview-openshift/manifests/che-operator.clusterserviceversion.yaml"
# prepare templates directory
rm -rf ${TEMPLATES}
mkdir -p "${TEMPLATES}/che-operator" && chmod 777 "${TEMPLATES}"
@ -89,8 +94,8 @@ waitWorkspaceStart() {
export x=0
while [ $x -le 180 ]
do
chectl auth:login -u admin -p admin
chectl workspace:list
chectl auth:login -u admin -p admin --chenamespace=${NAMESPACE}
chectl workspace:list --chenamespace=${NAMESPACE}
workspaceList=$(chectl workspace:list --chenamespace=${NAMESPACE})
workspaceStatus=$(echo "$workspaceList" | grep RUNNING | awk '{ print $4} ')
@ -123,7 +128,7 @@ installYq() {
# Graps Eclipse Che logs
collectCheLogWithChectl() {
mkdir -p ${ARTIFACTS_DIR}
chectl server:logs --directory=${ARTIFACTS_DIR}
chectl server:logs --chenamespace=${NAMESPACE} --directory=${ARTIFACTS_DIR}
}
# Build latest operator image
@ -190,27 +195,27 @@ updateEclipseChe() {
local image=$1
local templates=$2
chectl server:update -y --che-operator-image=${image} --templates=${templates}
chectl server:update --chenamespace=${NAMESPACE} -y --che-operator-image=${image} --templates=${templates}
}
startNewWorkspace() {
# Create and start a workspace
sleep 5s
chectl auth:login -u admin -p admin
chectl workspace:create --start --devfile=$OPERATOR_REPO/.ci/util/devfile-test.yaml
chectl auth:login -u admin -p admin --chenamespace=${NAMESPACE}
chectl workspace:create --start --chenamespace=${NAMESPACE} --devfile=$OPERATOR_REPO/.ci/devfile-test.yaml
}
createWorkspace() {
sleep 5s
chectl auth:login -u admin -p admin
chectl workspace:create --devfile=${OPERATOR_REPO}/.ci/util/devfile-test.yaml
chectl auth:login -u admin -p admin --chenamespace=${NAMESPACE}
chectl workspace:create --chenamespace=${NAMESPACE} --devfile=${OPERATOR_REPO}/.ci/devfile-test.yaml
}
startExistedWorkspace() {
sleep 5s
chectl auth:login -u admin -p admin
chectl workspace:list
workspaceList=$(chectl workspace:list)
chectl auth:login -u admin -p admin --chenamespace=${NAMESPACE}
chectl workspace:list --chenamespace=${NAMESPACE}
workspaceList=$(chectl workspace:list --chenamespace=${NAMESPACE})
# Grep applied to MacOS
workspaceID=$(echo "$workspaceList" | grep workspace | awk '{ print $1} ')
@ -267,3 +272,38 @@ insecurePrivateDockerRegistry() {
sudo service docker restart
fi
}
# Utility to print objects created by Openshift CI automatically
printOlmCheObjects() {
echo -e "[INFO] Operator Group object created in namespace: ${NAMESPACE}"
oc get operatorgroup -n "${NAMESPACE}" -o yaml
echo -e "[INFO] Catalog Source object created in namespace: ${NAMESPACE}"
oc get catalogsource -n "${NAMESPACE}" -o yaml
echo -e "[INFO] Subscription object created in namespace: ${NAMESPACE}"
oc get subscription -n "${NAMESPACE}" -o yaml
}
# Patch subscription with image builded from source in Openshift CI job.
patchEclipseCheOperatorSubscription() {
OPERATOR_POD=$(oc get pods -o json -n ${NAMESPACE} | jq -r '.items[] | select(.metadata.name | test("che-operator-")).metadata.name')
oc patch pod ${OPERATOR_POD} -n ${NAMESPACE} --type='json' -p='[{"op": "replace", "path": "/spec/containers/0/image", "value":'${OPERATOR_IMAGE}'}]'
# The following command retrieve the operator image
OPERATOR_POD_IMAGE=$(oc get pods -n ${NAMESPACE} -o json | jq -r '.items[] | select(.metadata.name | test("che-operator-")).spec.containers[].image')
echo -e "[INFO] CHE operator image is ${OPERATOR_POD_IMAGE}"
}
# Create CheCluster object in Openshift ci with desired values
applyOlmCR() {
echo "Creating Custom Resource"
CRs=$(yq -r '.metadata.annotations["alm-examples"]' "${OPENSHIFT_NIGHTLY_CSV_FILE}")
CR=$(echo "$CRs" | yq -r ".[0]")
CR=$(echo "$CR" | yq -r ".spec.auth.openShiftoAuth = ${OAUTH}")
CR=$(echo "$CR" | yq -r ".spec.server.serverExposureStrategy = \"${CHE_EXPOSURE_STRATEGY}\"")
echo -e "$CR"
echo "$CR" | oc apply -n "${NAMESPACE}" -f -
}

View File

@ -9,6 +9,7 @@
#
# Contributors:
# Red Hat, Inc. - initial API and implementation
set -ex
# Minikube environments config
export MINIKUBE_VERSION=v1.8.2

View File

@ -52,12 +52,12 @@ sleep 60
eval $(minishift oc-env)
oc login -u system:admin --insecure-skip-tls-verify=true
oc create namespace che
oc create namespace eclipse-che
oc project default
oc delete secret router-certs
cat domain.crt domain.key > minishift.crt
oc create secret tls router-certs --key=domain.key --cert=minishift.crt
oc rollout latest router
oc create secret generic self-signed-certificate --from-file=ca.crt -n=che
oc create secret generic self-signed-certificate --from-file=ca.crt -n=eclipse-che
oc adm policy add-cluster-role-to-user cluster-admin developer && oc login -u developer -p developer

View File

@ -1,17 +1,25 @@
FROM quay.io/operator-framework/upstream-registry-builder:v1.15.1 as builder
#!/bin/bash
#
# Copyright (c) 2012-2018 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
FROM quay.io/operator-framework/upstream-registry-builder:v1.15.3 as builder
COPY deploy manifests/eclipse-che-preview-kubernetes
RUN ./bin/initializer -o ./bundles.db
RUN /bin/initializer -o ./bundles.db
FROM openshift/origin-base
COPY --from=builder /bin/initializer /initializer
COPY --from=builder /bin/configmap-server /bin/configmap-server
FROM scratch
COPY --from=builder /bundles.db /bundles.db
COPY --from=builder /bin/registry-server /registry-server
COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe
EXPOSE 50051
ENTRYPOINT ["/registry-server"]
CMD ["--database", "bundles.db"]

View File

@ -1,17 +1,26 @@
FROM quay.io/operator-framework/upstream-registry-builder:v1.15.1 as builder
#!/bin/bash
#
# Copyright (c) 2012-2018 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
FROM quay.io/operator-framework/upstream-registry-builder:v1.15.3 as builder
COPY deploy manifests/eclipse-che-preview-openshift
RUN ./bin/initializer -o ./bundles.db
RUN /bin/initializer -o ./bundles.db
FROM openshift/origin-base
COPY --from=builder /bin/initializer /initializer
COPY --from=builder /bin/configmap-server /bin/configmap-server
FROM scratch
COPY --from=builder /bundles.db /bundles.db
COPY --from=builder /bin/registry-server /registry-server
COPY --from=builder /bin/grpc_health_probe /bin/grpc_health_probe
EXPOSE 50051
ENTRYPOINT ["/registry-server"]
CMD ["--database", "bundles.db"]