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

Unverified Commit 3f1de6fd authored by Oleksandr Andriienko's avatar Oleksandr Andriienko Committed by GitHub
Browse files

Merge pull request #167 from eclipse/improveTestScripts

Improve test scripts to test che-operator installed via OLM locally
parents 152758c9 b8cad938
...@@ -21,13 +21,53 @@ A script is generating new folders/files that can be edited. ...@@ -21,13 +21,53 @@ A script is generating new folders/files that can be edited.
In `olm` folder In `olm` folder
- If all dependencies are installed on the system: - If all dependencies are installed on the system:
```
```shell
$ update-nightly-olm-files.sh $ update-nightly-olm-files.sh
``` ```
- To use a docker environment - To use a docker environment
```
```shell
$ docker-run.sh update-nightly-olm-files.sh $ docker-run.sh update-nightly-olm-files.sh
``` ```
Then the changes can be applied in the newly created CSV files. Then the changes can be applied in the newly created CSV files.
## Local testing che-operator development version using OLM
To test a che-operator with OLM you need to have an application registry. You can register on the quay.io and
use application registry from this service.
Build your custom che-operator image and push it to the image registry(you also can use quay.io).
Change in the `deploy/operator.yaml` operator image from official to development.
Generate new nightly olm bundle packages:
```shell
$ ./update-nightly-olm-files.sh
```
Olm bundle packages will be generated in the folders `olm/eclipse-che-preview-${platform}`.
Push che-operator bundles to your application registry:
```shell
$ export QUAY_USERNAME=${username} && \
export QUAY_PASSWORD=${password} && \
export APPLICATION_REGISTRY=${application_registry_namespace} && \
./push-olm-files-to-quay.sh
```
Go to the quay.io and use ui(tab Settings) to make your application public.
Start minikube(or CRC) and after that launch test script in the olm folder:
```shell
$ export APPLICATION_REGISTRY=${application_registry_namespace} && ./testCSV.sh ${platform} ${package_version} ${optional-namespace}
```
Where are:
- `platform` - 'openshift' or 'kubernetes'
- `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.
#!/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
#
# 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
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
PACKAGE_VERSION=$2
if [ "${PACKAGE_VERSION}" == "" ]; then
echo "Please specify PACKAGE_VERSION version"
exit 1
fi
namespace=$3
if [ "${namespace}" == "" ]; then
namespace="eclipse-che-preview-test"
fi
channel="stable"
if [[ "${PACKAGE_VERSION}" =~ "nightly" ]]
then
channel="nightly"
fi
packageName=eclipse-che-preview-${platform}
platformPath=${BASE_DIR}/${packageName}
packageFolderPath="${platformPath}/deploy/olm-catalog/${packageName}"
packageFilePath="${packageFolderPath}/${packageName}.package.yaml"
CSV="eclipse-che-preview-${platform}.v${PACKAGE_VERSION}"
echo -e "\u001b[32m PACKAGE_VERSION=${PACKAGE_VERSION} \u001b[0m"
echo -e "\u001b[32m CSV=${CSV} \u001b[0m"
echo -e "\u001b[32m Channel=${channel} \u001b[0m"
echo -e "\u001b[32m Namespace=${namespace} \u001b[0m"
if kubectl get namespace "${namespace}" >/dev/null 2>&1
then
echo "You should delete namespace '${namespace}' before running the update test first."
exit 1
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
else
echo "---- Use non default application registry ${APPLICATION_REGISTRY} ---"
cat ${platformPath}/operator-source.yaml | \
sed -e "s/registryNamespace:.*$/registryNamespace: \"${APPLICATION_REGISTRY}\"/" | \
kubectl apply -f -
fi
}
installOperatorMarketPlace() {
echo "Installing test pre-requisistes"
marketplaceNamespace="marketplace"
if [ "${platform}" == "openshift" ]
then
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
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/01_namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/02_catalogsourceconfig.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/03_operatorsource.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/04_service_account.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/05_role.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/06_role_binding.yaml
sleep 1
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/07_upstream_operatorsource.cr.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/08_operator.yaml
applyCheOperatorSource
i=0
while [ $i -le 120 ]
do
if kubectl get catalogsource/"${packageName}" -n "${marketplaceNamespace}" >/dev/null 2>&1
then
break
fi
sleep 1
((i++))
done
if [ $i -gt 120 ]
then
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"
fi
kubectl apply -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
name: ${namespace}
---
apiVersion: operators.coreos.com/v1alpha2
kind: OperatorGroup
metadata:
name: operatorgroup
namespace: ${namespace}
spec:
targetNamespaces:
- ${namespace}
EOF
echo "Subscribing to version: ${CSV}"
kubectl apply -f - <<EOF
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: ${packageName}
namespace: ${namespace}
spec:
channel: ${channel}
installPlanApproval: Manual
name: ${packageName}
source: ${packageName}
sourceNamespace: ${marketplaceNamespace}
startingCSV: ${CSV}
EOF
kubectl describe subscription/"${packageName}" -n "${namespace}"
kubectl wait subscription/"${packageName}" -n "${namespace}" --for=condition=InstallPlanPending --timeout=240s
if [ $? -ne 0 ]
then
echo Subscription failed to install the operator
exit 1
fi
kubectl describe subscription/"${packageName}" -n "${namespace}"
}
installPackage() {
echo "Install operator package ${packageName} into namespace ${namespace}"
installPlan=$(kubectl get subscription/"${packageName}" -n "${namespace}" -o jsonpath='{.status.installplan.name}')
kubectl patch installplan/"${installPlan}" -n "${namespace}" --type=merge -p '{"spec":{"approved":true}}'
kubectl wait installplan/"${installPlan}" -n "${namespace}" --for=condition=Installed --timeout=240s
if [ $? -ne 0 ]
then
echo InstallPlan failed to install the operator
exit 1
fi
}
applyCRCheCluster() {
echo "Creating Custom Resource"
CRs=$(yq -r '.metadata.annotations["alm-examples"]' "${packageFolderPath}/${PACKAGE_VERSION}/${packageName}.v${PACKAGE_VERSION}.clusterserviceversion.yaml")
CR=$(echo "$CRs" | yq -r ".[0]")
if [ "${platform}" == "kubernetes" ]
then
CR=$(echo "$CR" | yq -r ".spec.k8s.ingressDomain = \"$(minikube ip).nip.io\"")
fi
echo "$CR" | kubectl apply -n "${namespace}" -f -
}
waitCheServerDeploy() {
echo "Waiting for Che server to be deployed"
i=0
while [ $i -le 360 ]
do
status=$(kubectl get checluster/eclipse-che -n "${namespace}" -o jsonpath={.status.cheClusterRunning})
if [ "${status}" == "Available" ]
then
break
fi
sleep 1
((i++))
done
if [ $i -gt 360 ]
then
echo "Che server did't start after 6 minutes"
exit 1
fi
}
...@@ -18,7 +18,13 @@ BASE_DIR=$(cd "$(dirname "$0")"; pwd) ...@@ -18,7 +18,13 @@ BASE_DIR=$(cd "$(dirname "$0")"; pwd)
for platform in 'kubernetes' 'openshift' for platform in 'kubernetes' 'openshift'
do do
packageName="eclipse-che-preview-${platform}" packageName="eclipse-che-preview-${platform}"
quayNamespace="eclipse-che-operator-${platform}"
if [ "${APPLICATION_REGISTRY}" == "" ]; then
quayNamespace="eclipse-che-operator-${platform}"
else
quayNamespace="${APPLICATION_REGISTRY}"
fi
echo echo
echo "## Pushing the OperatorHub package '${packageName}' for platform '${platform}' to the Quay.io '${quayNamespace}' organization" echo "## Pushing the OperatorHub package '${packageName}' for platform '${platform}' to the Quay.io '${quayNamespace}' organization"
...@@ -29,7 +35,7 @@ do ...@@ -29,7 +35,7 @@ do
flattenFolderPath="${packageBaseFolderPath}/generated/flatten" flattenFolderPath="${packageBaseFolderPath}/generated/flatten"
echo " - Flatten package to temporary folder: ${flattenFolderPath}" echo " - Flatten package to temporary folder: ${flattenFolderPath}"
rm -Rf "${flattenFolderPath}" rm -Rf "${flattenFolderPath}"
mkdir -p "${flattenFolderPath}" mkdir -p "${flattenFolderPath}"
operator-courier flatten "${packageFolderPath}" generated/flatten operator-courier flatten "${packageFolderPath}" generated/flatten
......
#!/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
source olm.sh
installOperatorMarketPlace
installPackage
applyCRCheCluster
waitCheServerDeploy
echo -e "\u001b[32m Installation of the che-operator version: ${CSV} succesfully completed \u001b[0m"
...@@ -27,11 +27,6 @@ if [ "${channel}" == "" ]; then ...@@ -27,11 +27,6 @@ if [ "${channel}" == "" ]; then
channel="nightly" channel="nightly"
fi fi
namespace=$3
if [ "${namespace}" == "" ]; then
namespace="eclipse-che-preview-test"
fi
packageName=eclipse-che-preview-${platform} packageName=eclipse-che-preview-${platform}
platformPath=${BASE_DIR}/${packageName} platformPath=${BASE_DIR}/${packageName}
packageFolderPath="${platformPath}/deploy/olm-catalog/${packageName}" packageFolderPath="${platformPath}/deploy/olm-catalog/${packageName}"
...@@ -42,150 +37,17 @@ lastPackageVersion=$(echo "${lastCSV}" | sed -e "s/${packageName}.v//") ...@@ -42,150 +37,17 @@ lastPackageVersion=$(echo "${lastCSV}" | sed -e "s/${packageName}.v//")
previousCSV=$(sed -n 's|^ *replaces: *\([^ ]*\) *|\1|p' "${packageFolderPath}/${lastPackageVersion}/${packageName}.v${lastPackageVersion}.clusterserviceversion.yaml") previousCSV=$(sed -n 's|^ *replaces: *\([^ ]*\) *|\1|p' "${packageFolderPath}/${lastPackageVersion}/${packageName}.v${lastPackageVersion}.clusterserviceversion.yaml")
previousPackageVersion=$(echo "${previousCSV}" | sed -e "s/${packageName}.v//") previousPackageVersion=$(echo "${previousCSV}" | sed -e "s/${packageName}.v//")
echo "lastPackageVersion=${lastPackageVersion}" # $3 -> namespace
echo "lastCSV=${lastCSV}" source olm.sh ${platform} ${previousPackageVersion} $3
echo "previousCSV=${previousCSV}"
echo "previousPackageVersion=${previousPackageVersion}"
if kubectl get namespace "${namespace}" >/dev/null 2>&1
then
echo "You should delete namespace '${namespace}' before running the update test first."
exit 1
fi
echo "Installing test pre-requisistes"
marketplaceNamespace="marketplace"
if [ "${platform}" == "openshift" ]
then
marketplaceNamespace="openshift-marketplace"
kubectl apply -f ${platformPath}/operator-source.yaml
else
curl -sL https://github.com/operator-framework/operator-lifecycle-manager/releases/download/0.12.0/install.sh | bash -s 0.12.0
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/01_namespace.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/02_catalogsourceconfig.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/03_operatorsource.crd.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/04_service_account.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/05_role.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/06_role_binding.yaml
sleep 1
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/07_upstream_operatorsource.cr.yaml
kubectl apply -f https://raw.githubusercontent.com/operator-framework/operator-marketplace/master/deploy/upstream/08_operator.yaml
kubectl apply -f ${platformPath}/operator-source.yaml
i=0
while [ $i -le 120 ]
do
if kubectl get catalogsource/"${packageName}" -n "${marketplaceNamespace}" >/dev/null 2>&1
then
break
fi
sleep 1
((i++))
done
if [ $i -gt 120 ]
then
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 create -f -
marketplaceNamespace="olm"
fi
kubectl apply -f - <<EOF
apiVersion: v1
kind: Namespace
metadata:
name: ${namespace}
---
apiVersion: operators.coreos.com/v1alpha2
kind: OperatorGroup
metadata:
name: operatorgroup
namespace: ${namespace}
spec:
targetNamespaces:
- ${namespace}
EOF
echo "Subscribing to previous version: ${previousCSV}"
kubectl apply -f - <<EOF
apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: ${packageName}
namespace: ${namespace}
spec:
channel: ${channel}
installPlanApproval: Manual
name: ${packageName}
source: ${packageName}
sourceNamespace: ${marketplaceNamespace}
startingCSV: ${previousCSV}
EOF
kubectl wait subscription/"${packageName}" -n "${namespace}" --for=condition=InstallPlanPending --timeout=240s
if [ $? -ne 0 ]
then
echo Subscription failed to install the operator
exit 1
fi
installPlan=$(kubectl get subscription/"${packageName}" -n "${namespace}" -o jsonpath='{.status.installplan.name}')
kubectl patch installplan/"${installPlan}" -n "${namespace}" --type=merge -p '{"spec":{"approved":true}}' installOperatorMarketPlace
installPackage
kubectl wait installplan/"${installPlan}" -n "${namespace}" --for=condition=Installed --timeout=240s applyCRCheCluster
if [ $? -ne 0 ] waitCheServerDeploy
then
echo InstallPlan failed to install the operator
exit 1
fi
echo "Creating Custom Resource"
CRs=$(yq -r '.metadata.annotations["alm-examples"]' "${packageFolderPath}/${previousPackageVersion}/${packageName}.v${previousPackageVersion}.clusterserviceversion.yaml")
CR=$(echo "$CRs" | yq -r ".[0]")
if [ "${platform}" == "kubernetes" ]
then
CR=$(echo "$CR" | yq -r ".spec.k8s.ingressDomain = \"$(minikube ip).nip.io\"")
fi
echo "$CR" | kubectl apply -n "${namespace}" -f - echo -e "\u001b[32m Installation of the previous che-operator version: ${previousCSV} succesfully completed \u001b[0m"
echo -e "\u001b[34m Check installation last version che-operator... \u001b[0m"
echo "Waiting for Che server to be deployed" installPackage
i=0 echo -e "\u001b[32m Installed latest version che-operator: ${lastCSV} \u001b[0m"
while [ $i -le 360 ]
do
status=$(kubectl get checluster/eclipse-che -n "${namespace}" -o jsonpath={.status.cheClusterRunning})
if [ "${status}" == "Available" ]
then
break
fi
sleep 1
((i++))
done
if [ $i -gt 360 ]
then
echo "Che server did't start after 6 minutes"
exit 1
fi
echo "Approve installation of last version: ${lastCSV}"
installPlan=$(kubectl get subscription/${packageName} -n "${namespace}" -o jsonpath='{.status.installplan.name}')
kubectl patch installplan/"${installPlan}" -n "${namespace}" --type=merge -p '{"spec":{"approved":true}}'
kubectl wait installplan/"${installPlan}" -n "${namespace}" --for=condition=Installed --timeout=240s
if [ $? -ne 0 ]
then
echo InstallPlan failed to install the latest version of the operator
exit 1
fi
...@@ -42,8 +42,8 @@ do ...@@ -42,8 +42,8 @@ do
-e "s/createdAt:.*$/createdAt: \"${createdAt}\"/" \ -e "s/createdAt:.*$/createdAt: \"${createdAt}\"/" \
"${packageFolderPath}/${newNightlyPackageVersion}/${packageName}.v${newNightlyPackageVersion}.clusterserviceversion.yaml" \ "${packageFolderPath}/${newNightlyPackageVersion}/${packageName}.v${newNightlyPackageVersion}.clusterserviceversion.yaml" \
> "${packageFolderPath}/${newNightlyPackageVersion}/${packageName}.v${newNightlyPackageVersion}.clusterserviceversion.yaml.new" > "${packageFolderPath}/${newNightlyPackageVersion}/${packageName}.v${newNightlyPackageVersion}.clusterserviceversion.yaml.new"
mv "${packageFolderPath}/${newNightlyPackageVersion}/${packageName}.v${newNightlyPackageVersion}.clusterserviceversion.yaml.new" \ mv "${packageFolderPath}/${newNightlyPackageVersion}/${packageName}.v${newNightlyPackageVersion}.clusterserviceversion.yaml.new" \
"${packageFolderPath}/${newNightlyPackageVersion}/${packageName}.v${newNightlyPackageVersion}.clusterserviceversion.yaml" "${packageFolderPath}/${newNightlyPackageVersion}/${packageName}.v${newNightlyPackageVersion}.clusterserviceversion.yaml"
echo " - Copying the CRD file" echo " - Copying the CRD file"
cp "${BASE_DIR}/../deploy/crds/org_v1_che_crd.yaml" "${packageFolderPath}/${newNightlyPackageVersion}/eclipse-che-preview-${platform}.crd.yaml" cp "${BASE_DIR}/../deploy/crds/org_v1_che_crd.yaml" "${packageFolderPath}/${newNightlyPackageVersion}/eclipse-che-preview-${platform}.crd.yaml"
......
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