THIS IS ONLY A TEST INSTANCE. DON'T DO IMPORTANT WORK HERE!

Unverified Commit 204b24b2 authored by Anatolii Bazko's avatar Anatolii Bazko Committed by GitHub
Browse files

Merge pull request #154 from flacatus/minishift_e2e_tests

Created minishift e2e tests with minishift.
parents 257f2096 7156228b
#!/bin/bash -e
#!/bin/bash
#
# Copyright (c) 2012-2018 Red Hat, Inc.
# 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/
......@@ -10,63 +10,100 @@
# Contributors:
# Red Hat, Inc. - initial API and implementation
# to purge ALL existing docker containers (including unrelated ones!)
# docker rm -f $(docker ps -aq) || true
# # to purge ALL existing docker images (including unrelated ones!)
# docker rmi -f $(docker images -q) || true
# Exit on error
set -e -x
# requires Docker 18+
trap 'Catch_Finish $?' EXIT SIGINT
OC_VERSION="v3.11.0-0cbc58b"
GO_TOOLSET_VERSION="1.11.5-3"
IP_ADDRESS="172.17.0.1"
cleanup() {
echo "[INFO] Deleting minishift VM..."
yes | ./tmp/minishift delete && rm -rf ~/.minishift ${OPERATOR_REPO}/tmp
SCRIPT=$(readlink -f "$0") # this script's absolute path
SCRIPTPATH=$(dirname "$SCRIPT") # /path/to/e2e/ folder
if [[ ${WORKSPACE} ]] && [[ -d ${WORKSPACE} ]]; then OPERATOR_REPO=${WORKSPACE}; else OPERATOR_REPO=$(dirname "$SCRIPTPATH"); fi
}
# download oc client binary
echo "[INFO] Download oc client"
mkdir -p ${OPERATOR_REPO}/tmp
chmod -R 777 ${OPERATOR_REPO}/tmp
curl -s -S -L https://github.com/openshift/origin/releases/download/${OC_VERSION%%-*}/openshift-origin-client-tools-${OC_VERSION}-linux-64bit.tar.gz \
-o ${OPERATOR_REPO}/tmp/oc.tar && tar -xvf ${OPERATOR_REPO}/tmp/oc.tar -C ${OPERATOR_REPO}/tmp --strip-components=1
Catch_Finish() {
if [ $1 != 0 ]; then
echo "[ERROR] Please check the output error"
cleanup
else
echo "[INFO] Script executed successfully: $0!"
cleanup
fi
}
# start OKD
echo "[INFO] Start OKD ${OC_VERSION}"
cd ${OPERATOR_REPO}/tmp
rm -rf openshift.local.clusterup
./oc cluster up --public-hostname=${IP_ADDRESS} --routing-suffix=${IP_ADDRESS}.nip.io
./oc login -u system:admin
./oc adm policy add-cluster-role-to-user cluster-admin developer
./oc login -u developer -p password
sleep 10
echo "[INFO] Register a custom resource definition"
./oc apply -f ${OPERATOR_REPO}/deploy/crds/org_v1_che_crd.yaml
installStartDocker() {
if [ -x "$(command -v docker)" ]; then
echo "[INFO] Docker already installed"
else
echo "[INFO] Installing docker..."
yum install --assumeyes -d1 yum-utils device-mapper-persistent-data lvm2
yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo
yum install --assumeyes -d1 docker-ce
systemctl start docker
docker version
fi
}
# generate self signed cert
echo "[INFO] Generate self signed certificate"
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj "/CN=*.${IP_ADDRESS}.nip.io" -nodes
cat cert.pem key.pem > ca.crt
init() {
installStartDocker
MSFT_RELEASE="1.34.2"
GO_TOOLSET_VERSION="1.11.5-3"
IP_ADDRESS="172.17.0.1"
SCRIPT=$(readlink -f "$0") # this script's absolute path
SCRIPTPATH=$(dirname "$SCRIPT") # /path/to/e2e/ folder
if [[ ${WORKSPACE} ]] && [[ -d ${WORKSPACE} ]]; then OPERATOR_REPO=${WORKSPACE}; else OPERATOR_REPO=$(dirname "$SCRIPTPATH"); fi
}
# replace default router cert
echo "[INFO] Update OpenShift router tls secret"
./oc project default
./oc secrets new router-certs tls.crt=ca.crt tls.key=key.pem -o json --type='kubernetes.io/tls' --confirm | ./oc replace -f -
echo "[INFO] Initiate a new router deployment"
sleep 20
./oc rollout latest dc/router -n=default || true
minishift_installation() {
if [ ! -f "$OPERATOR_REPO/tmp/minishift" ]; then
if [ ! -d "$OPERATOR_REPO/tmp" ]; then mkdir -p "$OPERATOR_REPO/tmp" && chmod 777 "$OPERATOR_REPO/tmp"; fi
echo "[INFO] Downloading Minishift binaries..."
curl -s -S -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 ${OPERATOR_REPO}/tmp --strip-components=1
fi
cd "$OPERATOR_REPO/tmp"
echo "[INFO] Sarting a new OC cluster."
./minishift start --memory=4096 && eval $(./minishift oc-env)
oc login -u system:admin
oc adm policy add-cluster-role-to-user cluster-admin developer && oc login -u developer -p developer
}
echo "[INFO] Compile tests binary"
docker run -t \
-v ${OPERATOR_REPO}/tmp:/operator \
-v ${OPERATOR_REPO}:/opt/app-root/src/go/src/github.com/eclipse/che-operator registry.access.redhat.com/devtools/go-toolset-rhel7:${GO_TOOLSET_VERSION} \
sh -c "OOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /operator/run-tests /opt/app-root/src/go/src/github.com/eclipse/che-operator/e2e/*.go"
oc_tls_mode() {
# generate self signed cert
echo "[INFO] Generate self signed certificate"
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -subj "/CN=*.${IP_ADDRESS}.nip.io" -nodes && cat cert.pem key.pem > ca.crt
# replace default router cert
echo "[INFO] Update OpenShift router tls secret"
oc project default
oc secrets new router-certs tls.crt=ca.crt tls.key=key.pem -o json --type='kubernetes.io/tls' --confirm | oc replace -f -
echo "[INFO] Initiate a new router deployment"
sleep 20
oc rollout latest dc/router -n=default || true
}
cp ${OPERATOR_REPO}/tmp/run-tests ${OPERATOR_REPO}/run-tests
run_tests() {
minishift_installation
echo "[INFO] Register a custom resource definition"
oc apply -f ${OPERATOR_REPO}/deploy/crds/org_v1_che_crd.yaml
echo "[INFO] Build operator docker image..."
cd ${OPERATOR_REPO} && docker build -t che/operator -f Dockerfile .
oc_tls_mode
echo "[INFO] Compile tests binary"
docker run -t \
-v ${OPERATOR_REPO}/tmp:/operator \
-v ${OPERATOR_REPO}:/opt/app-root/src/go/src/github.com/eclipse/che-operator registry.access.redhat.com/devtools/go-toolset-rhel7:${GO_TOOLSET_VERSION} \
sh -c "OOS=linux GOARCH=amd64 CGO_ENABLED=0 go build -o /operator/run-tests /opt/app-root/src/go/src/github.com/eclipse/che-operator/e2e/*.go"
echo "[INFO] Build operator docker image and load in to minishift VM..."
cd ${OPERATOR_REPO} && docker build -t che/operator -f Dockerfile . && docker save che/operator > operator.tar
eval $(./tmp/minishift docker-env) && docker load -i operator.tar && rm operator.tar
echo "[INFO] Run tests..."
./tmp/run-tests
echo "[INFO] Tests passed successfully!"
}
echo "[INFO] Run tests..."
cd ${OPERATOR_REPO} && ./run-tests
init
run_tests
......@@ -12,13 +12,14 @@
package main
import (
"log"
orgv1 "github.com/eclipse/che-operator/pkg/apis/org/v1"
"github.com/eclipse/che-operator/pkg/controller/che"
"github.com/sirupsen/logrus"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/kubernetes/scheme"
"k8s.io/client-go/tools/clientcmd/api"
"log"
)
var (
......@@ -95,26 +96,6 @@ func main() {
logrus.Info("Installation succeeded")
}
// reconfigure CR to enable TLS support
logrus.Info("Patching CR with TLS enabled. This should cause a new Che deployment")
patchPath := "/spec/server/tlsSupport"
if err := patchCustomResource(patchPath, true); err != nil {
logrus.Fatalf("An error occurred while patching CR %s", err)
}
// check if a CR status has changed to Rolling update in progress
redeployed, err := VerifyCheRunning(che.RollingUpdateInProgressStatus)
if redeployed {
logrus.Info("New deployment triggered")
}
// wait for Available status
logrus.Info("Waiting for CR Available status. Timeout 6 min")
deployed, err = VerifyCheRunning(che.AvailableStatus)
if deployed {
logrus.Info("Installation succeeded")
}
// create clusterRole and clusterRoleBinding to let operator service account create oAuthclients
logrus.Info("Creating cluster role for operator service account")
......@@ -133,13 +114,13 @@ func main() {
// reconfigure CR to enable login with OpenShift
logrus.Info("Patching CR with oAuth enabled. This should cause a new Che deployment")
patchPath = "/spec/auth/openShiftoAuth"
patchPath := "/spec/auth/openShiftoAuth"
if err := patchCustomResource(patchPath, true); err != nil {
logrus.Fatalf("An error occurred while patching CR %s", err)
}
// check if a CR status has changed to Rolling update in progress
redeployed, err = VerifyCheRunning(che.RollingUpdateInProgressStatus)
redeployed, err := VerifyCheRunning(che.RollingUpdateInProgressStatus)
if redeployed {
logrus.Info("New deployment triggered")
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment