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

Unverified Commit d4168574 authored by Flavius Lacatusu's avatar Flavius Lacatusu Committed by GitHub
Browse files

Implement OLM operator tests on PRs (#177)



* create testCatalog source file and add logic to support installation of custom catalog for kubernetes
Signed-off-by: default avatarFlavius Lacatusu <flacatus@redhat.com>
parent 46c98c20
#!/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
trap 'Catch_Finish $?' EXIT SIGINT
# Catch errors and force to delete minikube VM.
Catch_Finish() {
rm -rf ~/.kube && yes | minikube delete && yes | minishift delete --force --clear-cache
}
init() {
SCRIPT=$(readlink -f "$0")
SCRIPTPATH=$(dirname "$SCRIPT")
if [[ ${WORKSPACE} ]] && [[ -d ${WORKSPACE} ]]; then OPERATOR_REPO=${WORKSPACE}; else OPERATOR_REPO=$(dirname "$SCRIPTPATH"); fi
RAM_MEMORY=8192
NAMESPACE="che-default"
CHANNEL="nightly"
}
install_Dependencies() {
installYQ
install_VirtPackages
installStartDocker
minikube_installation
}
run_olm_tests() {
for platform in 'openshift' 'kubernetes'
do
if [[ ${platform} == 'openshift' ]]; then
printInfo "Starting minishift VM to test openshift olm files..."
minishift start --memory=${RAM_MEMORY}
oc login -u system:admin
oc adm policy add-cluster-role-to-user cluster-admin developer && oc login -u developer -p developer
sh "${OPERATOR_REPO}"/olm/testCatalogSource.sh ${platform} ${CHANNEL} ${NAMESPACE}
printInfo "Successfully verified olm files on openshift platform."
rm -rf ~/.kube .minishift && yes | minishift delete --force --clear-cache
fi
if [[ ${platform} == 'kubernetes' ]]; then
printInfo "Starting minikube VM to test kubernetes olm files..."
minikube start --memory=${RAM_MEMORY}
sh "${OPERATOR_REPO}"/olm/testCatalogSource.sh ${platform} ${CHANNEL} ${NAMESPACE}
printInfo "Successfully verified olm files on kubernetes platform."
rm -rf ~/.kube && yes | minikube delete
fi
done
}
init
source "${OPERATOR_REPO}"/.ci/util/ci_common.sh
install_Dependencies
run_olm_tests
......@@ -28,35 +28,35 @@ init() {
oc_tls_mode() {
# generate self signed cert
echo "[INFO] Generate self signed certificate"
printInfo "Generate self signed certificate"
cd "$OPERATOR_REPO/tmp"
generate_self_signed_certs
# replace default router cert
echo "[INFO] Update OpenShift router tls secret"
printInfo "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"
printInfo "Initiate a new router deployment"
sleep 20
oc rollout latest dc/router -n=default || true
}
run_tests() {
echo "[INFO] Register a custom resource definition"
printInfo "Register a custom resource definition"
oc apply -f ${OPERATOR_REPO}/deploy/crds/org_v1_che_crd.yaml
oc_tls_mode
echo "[INFO] Compile tests binary"
printInfo "Starting to compile e2e 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..."
printInfo "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 $(minishift docker-env) && docker load -i operator.tar && rm operator.tar
echo "[INFO] Run tests..."
printInfo "Runing e2e tests..."
${OPERATOR_REPO}/tmp/run-tests
}
......@@ -64,7 +64,7 @@ init
source ${OPERATOR_REPO}/.ci/util/ci_common.sh
installStartDocker
install_required_packages
install_VirtPackages
start_libvirt
setup_kvm_machine_driver
minishift_installation
......
......@@ -11,24 +11,42 @@
set -e
printInfo() {
set +x
echo ""
echo "[=============== [INFO] $1 ===============]"
}
printWarn() {
set +x
echo ""
echo "[=============== [WARN] $1 ===============]"
}
printError() {
set +x
echo ""
echo "[=============== [ERROR] $1 ===============]"
}
installStartDocker() {
if [ -x "$(command -v docker)" ]; then
echo "[INFO] Docker already installed"
printWarn "Docker already installed"
else
echo "[INFO] Installing docker..."
printInfo "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
printInfo "Starting docker service..."
yum install --assumeyes -d1 docker-ce
systemctl start docker
docker version
fi
}
install_required_packages() {
# Install EPEL repo
# Get all the deps in
yum -y install libvirt qemu-kvm
echo '[INFO]CICO: Required virtualization packages installed'
install_VirtPackages() {
printInfo 'Installing required virtualization packages installed'
sudo yum -y install libvirt qemu-kvm
}
start_libvirt() {
......@@ -36,7 +54,7 @@ start_libvirt() {
}
setup_kvm_machine_driver() {
echo "[INFO] Installing docker machine kvm drivers..."
printInfo "Installing docker machine kvm drivers"
curl -L https://github.com/dhiltgen/docker-machine-kvm/releases/download/v0.10.0/docker-machine-driver-kvm-centos7 -o /usr/bin/docker-machine-driver-kvm
chmod +x /usr/bin/docker-machine-driver-kvm
check_libvirtd=$(systemctl is-active libvirtd)
......@@ -47,14 +65,15 @@ setup_kvm_machine_driver() {
minishift_installation() {
MSFT_RELEASE="1.34.2"
echo "[INFO] Downloading Minishift binaries..."
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
echo "[INFO] Starting a new OC cluster."
printInfo "Starting 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
printInfo "Successfully started OCv3.X on minishift machine"
}
generate_self_signed_certs() {
......@@ -67,3 +86,28 @@ generate_self_signed_certs() {
-subj "/CN=*.${IP_ADDRESS}.nip.io" \
-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."
else
#excluding mirror1.ci.centos.org
printInfo "Installing epel..."
yum install -d1 --assumeyes epel-release
yum update --assumeyes -d1
fi
}
installYQ() {
printInfo "Installing yq portable command-line YAML processor..."
sudo yum install --assumeyes -d1 python3-pip
pip3 install --upgrade setuptools
pip3 install yq
}
......@@ -70,4 +70,12 @@ Where are:
- `package_version` - your generated che-operator package version(for example: `7.8.0` or `9.9.9-nightly.1562083645`)
- `optional-namespace` - kubernetes namespace to deploy che-operator. Optional parameter, by default operator will be deployed to the namespace `eclipse-che-preview-test`
This script should install che-operator using OLM and check that the Che server was deployed.
To test che-operator with OLM files without push to a related Quay.io application, we can build a required docker image of a dedicated catalog,
in order to install directly through a CatalogSource. To test this options start minikube and after that launch
test script in the olm folder:
```shell
$ ./testCatalogSource.sh sh {platform} ${channel} ${namespace}
```
This scripts should install che-operator using OLM and check that the Che server was deployed.
FROM quay.io/operator-framework/upstream-registry-builder as builder
COPY deploy manifests/eclipse-che-preview-kubernetes
RUN ./bin/linux-amd64-initializer -o ./bundles.db
RUN ./bin/initializer -o ./bundles.db
FROM scratch
COPY --from=builder /build/bundles.db /bundles.db
COPY --from=builder /build/bin/linux-amd64-registry-server /registry-server
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"]
......
FROM quay.io/operator-framework/upstream-registry-builder as builder
COPY deploy manifests/eclipse-che-preview-openshift
RUN ./bin/linux-amd64-initializer -o ./bundles.db
RUN ./bin/initializer -o ./bundles.db
FROM scratch
COPY --from=builder /build/bundles.db /bundles.db
COPY --from=builder /build/bin/linux-amd64-registry-server /registry-server
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"]
......
......@@ -12,11 +12,14 @@
#
# Scripts to prepare OLM(operator lifecycle manager) and install che-operator package
# with specific version using OLM.
BASE_DIR=$(cd "$(dirname "$0")" && pwd)
source ${BASE_DIR}/check-yq.sh
SOURCE_INSTALL=$4
if [ -z ${SOURCE_INSTALL} ]; then SOURCE_INSTALL="Marketplace"; fi
platform=$1
if [ "${platform}" == "" ]; then
echo "Please specify platform ('openshift' or 'kubernetes') as the first argument."
......@@ -59,12 +62,30 @@ then
exit 1
fi
catalog_source() {
echo "--- Use default eclipse che application registry ---"
if [ ${SOURCE_INSTALL} == "LocalCatalog" ]; then
marketplaceNamespace=${namespace};
kubectl apply -f - <<EOF
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: ${packageName}
namespace: ${namespace}
spec:
sourceType: grpc
image: ${CATALOG_IMAGENAME}
EOF
else
cat ${platformPath}/operator-source.yaml
kubectl apply -f ${platformPath}/operator-source.yaml
fi
}
applyCheOperatorSource() {
echo "Apply che-operator source"
if [ "${APPLICATION_REGISTRY}" == "" ]; then
echo "--- Use default eclipse che application registry ---"
kubectl apply -f ${platformPath}/operator-source.yaml
catalog_source
else
echo "---- Use non default application registry ${APPLICATION_REGISTRY} ---"
......@@ -76,11 +97,16 @@ applyCheOperatorSource() {
installOperatorMarketPlace() {
echo "Installing test pre-requisistes"
kubectl apply -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
name: ${namespace}
EOF
marketplaceNamespace="marketplace"
if [ "${platform}" == "openshift" ]
if [ "${platform}" == "openshift" ];
then
marketplaceNamespace="openshift-marketplace"
marketplaceNamespace="openshift-marketplace";
applyCheOperatorSource
else
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/0.12.0/install.sh | bash -s 0.12.0
......@@ -112,18 +138,16 @@ installOperatorMarketPlace() {
echo "Catalog source not created after 2 minutes"
exit 1
fi
kubectl get catalogsource/"${packageName}" -n "${marketplaceNamespace}" -o json | jq '.metadata.namespace = "olm" | del(.metadata.creationTimestamp) | del(.metadata.uid) | del(.metadata.resourceVersion) | del(.metadata.generation) | del(.metadata.selfLink) | del(.status)' | kubectl apply -f -
marketplaceNamespace="olm"
if [ "${SOURCE_INSTALL}" == "Marketplace" ]; then
kubectl get catalogsource/"${packageName}" -n "${marketplaceNamespace}" -o json | jq '.metadata.namespace = "olm" | del(.metadata.creationTimestamp) | del(.metadata.uid) | del(.metadata.resourceVersion) | del(.metadata.generation) | del(.metadata.selfLink) | del(.status)' | kubectl apply -f -
marketplaceNamespace="olm"
fi
fi
echo "Subscribing to version: ${CSV}"
kubectl apply -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
name: ${namespace}
---
apiVersion: operators.coreos.com/v1alpha2
apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: operatorgroup
......@@ -131,11 +155,7 @@ metadata:
spec:
targetNamespaces:
- ${namespace}
EOF
echo "Subscribing to version: ${CSV}"
kubectl apply -f - <<EOF
---
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
......@@ -160,6 +180,7 @@ EOF
fi
kubectl describe subscription/"${packageName}" -n "${namespace}"
}
installPackage() {
......
#!/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
platform=$1
if [ "${platform}" == "" ]; then
echo "Please specify platform ('openshift' or 'kubernetes') as the first argument."
echo ""
echo "testUpdate.sh <platform> [<channel>] [<namespace>]"
exit 1
fi
channel=$2
if [ "${channel}" == "" ]; then
channel="nightly"
fi
#Check if minikube is installed.
if ! hash minikube 2>/dev/null; then
echo "Minikube is not installed."
exit 1
fi
init() {
#Setting current directory
BASE_DIR=$(cd "$(dirname "$0")" && pwd)
# Setting The catalog image and the image and tag; and install type
Install_Type="LocalCatalog"
CATALOG_IMAGENAME="testing_catalog:0.0.1"
# GET the package version to apply
packageName=eclipse-che-preview-${platform}
packageFolderPath="${BASE_DIR}/eclipse-che-preview-${platform}/deploy/olm-catalog/${packageName}"
packageFilePath="${packageFolderPath}/${packageName}.package.yaml"
CSV=$(yq -r ".channels[] | select(.name == \"${channel}\") | .currentCSV" "${packageFilePath}")
PackageVersion=$(echo "${CSV}" | sed -e "s/${packageName}.v//")
}
docker_build() {
docker build -t ${CATALOG_IMAGENAME} -f "${BASE_DIR}"/eclipse-che-preview-"${platform}"/Dockerfile \
"${BASE_DIR}"/eclipse-che-preview-"${platform}"
}
build_Catalog_Image() {
if [ "${platform}" == "kubernetes" ]; then
eval "$(minikube -p minikube docker-env)"
docker_build
minikube addons enable ingress
else
docker_build
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/0.12.0/install.sh | bash -s 0.12.0
docker save ${CATALOG_IMAGENAME} > /tmp/catalog.tar
eval "$(minishift docker-env)"
docker load -i /tmp/catalog.tar && rm -rf /tmp/catalog.tar
fi
}
run_olm_functions() {
build_Catalog_Image
installOperatorMarketPlace
installPackage
applyCRCheCluster
waitCheServerDeploy
}
init
# $3 -> namespace
source ${BASE_DIR}/check-yq.sh
source ${BASE_DIR}/olm.sh ${platform} ${PackageVersion} $3 ${Install_Type}
run_olm_functions
......@@ -38,7 +38,7 @@ previousCSV=$(sed -n 's|^ *replaces: *\([^ ]*\) *|\1|p' "${packageFolderPath}/${
previousPackageVersion=$(echo "${previousCSV}" | sed -e "s/${packageName}.v//")
# $3 -> namespace
source olm.sh ${platform} ${previousPackageVersion} $3
source ${BASE_DIR}/olm.sh ${platform} ${previousPackageVersion} $3
installOperatorMarketPlace
installPackage
......
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