feat: Add testCatalogFromSources.sh (#1492)

Signed-off-by: Anatolii Bazko <abazko@redhat.com>

Signed-off-by: Anatolii Bazko <abazko@redhat.com>
pull/1493/head
Anatolii Bazko 2022-08-31 18:03:05 +03:00 committed by GitHub
parent 56c91781d5
commit 9ce1337c9d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 183 additions and 100 deletions

View File

@ -68,102 +68,6 @@ discoverEclipseCheSubscription() {
ECLIPSE_CHE_INSTALLED_CSV=$(echo ${ECLIPSE_CHE_SUBSCRIPTION_RECORD} | jq -r '.status.installedCSV')
}
buildBundleFromSources() {
local TMP_BUNDLE_DIR=/tmp/bundle
rm -rf ${TMP_BUNDLE_DIR}
mkdir ${TMP_BUNDLE_DIR}
cp -r $(make bundle-path CHANNEL=next)/* ${TMP_BUNDLE_DIR}
mv ${TMP_BUNDLE_DIR}/bundle.Dockerfile ${TMP_BUNDLE_DIR}/Dockerfile
# Use custom image in a bundle
# CI_CHE_OPERATOR_IMAGE it is che operator image built in openshift CI job workflow.
yq -rYi '.spec.install.spec.deployments[0].spec.template.spec.containers[0].image = "'${CI_CHE_OPERATOR_IMAGE}'"' ${TMP_BUNDLE_DIR}/manifests/che-operator.clusterserviceversion.yaml
oc new-build --binary --strategy docker --name ${BUNDLE_NAME} -n ${NAMESPACE}
oc start-build ${BUNDLE_NAME} --from-dir ${TMP_BUNDLE_DIR} -n ${NAMESPACE} --wait
}
createRpcCatalogSource() {
IMAGE_REGISTRY_USER_NAME=kubeadmin
IMAGE_REGISTRY_USER_TOKEN=$(oc whoami -t)
oc apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: che-registry
namespace: ${NAMESPACE}
spec:
selector:
matchLabels:
app: che-registry
template:
metadata:
labels:
app: che-registry
spec:
containers:
- name: registry
image: quay.io/openshift-knative/index
ports:
- containerPort: 50051
name: grpc
protocol: TCP
livenessProbe:
exec:
command:
- grpc_health_probe
- -addr=localhost:50051
readinessProbe:
exec:
command:
- grpc_health_probe
- -addr=localhost:50051
command:
- /bin/sh
- -c
- |-
podman login -u ${IMAGE_REGISTRY_USER_NAME} -p ${IMAGE_REGISTRY_USER_TOKEN} image-registry.openshift-image-registry.svc:5000
/bin/opm registry add --container-tool=podman -d index.db --mode=semver -b image-registry.openshift-image-registry.svc:5000/${NAMESPACE}/${BUNDLE_NAME}
/bin/opm registry serve -d index.db -p 50051
EOF
oc wait --for=condition=ready "pods" -l app=che-registry --timeout=60s -n "${NAMESPACE}"
local REGISTRY_POD_IP="$(oc get pods -l app=che-registry -n ${NAMESPACE} -o jsonpath='{.items[0].status.podIP}')"
oc apply -f - <<EOF
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: eclipse-che
namespace: ${NAMESPACE}
spec:
address: "${REGISTRY_POD_IP}:50051"
displayName: "Eclipse Che"
publisher: "Eclipse Che"
sourceType: grpc
EOF
}
deployEclipseCheFromSources() {
make create-namespace NAMESPACE=${NAMESPACE}
buildBundleFromSources
createRpcCatalogSource
make create-operatorgroup NAME=eclipse-che NAMESPACE=${NAMESPACE}
make create-subscription \
NAME=eclipse-che-subscription \
NAMESPACE=eclipse-che \
PACKAGE_NAME=${ECLIPSE_CHE_PREVIEW_PACKAGE_NAME} \
SOURCE=eclipse-che \
SOURCE_NAMESPACE=eclipse-che \
INSTALL_PLAN_APPROVAL=Auto \
CHANNEL=next
waitForInstalledEclipseCheCSV
getCheClusterCRFromInstalledCSV | oc apply -n "${NAMESPACE}" -f -
make wait-eclipseche-version VERSION="$(getCheVersionFromInstalledCSV)" NAMESPACE=${NAMESPACE}
}
listCatalogSourceBundles() {
local name=${1}
local CATALOG_SERVICE=$(oc get service "${name}" -n openshift-marketplace -o yaml)

View File

@ -16,15 +16,13 @@ set -ex
export OPERATOR_REPO=$(dirname "$(dirname "$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")")")
source "${OPERATOR_REPO}/build/scripts/oc-tests/oc-common.sh"
#Stop execution on any error
# Stop execution on any error
trap "catchFinish" EXIT SIGINT
[[ -z "${CI_CHE_OPERATOR_IMAGE}" ]] && { echo [ERROR] CI_CHE_OPERATOR_IMAGE not defined; exit 1; }
runTests() {
deployEclipseCheFromSources
. ${OPERATOR_REPO}/build/scripts/olm/testCatalogFromSources -o ${CI_CHE_OPERATOR_IMAGE}
}
runTests

View File

@ -0,0 +1,181 @@
#!/bin/bash
#
# Copyright (c) 2019-2021 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
OPERATOR_REPO=$(dirname "$(dirname "$(dirname "$(dirname "$(readlink -f "${BASH_SOURCE[0]}")")")")")
source "${OPERATOR_REPO}/build/scripts/oc-tests/oc-common.sh"
init() {
unset OPERATOR_IMAGE
while [[ "$#" -gt 0 ]]; do
case $1 in
'--help'|'-h') usage; exit;;
'--operator-image'|'-o') OPERATOR_IMAGE="$2"; shift 1;;
esac
shift 1
done
if [[ ! ${OPERATOR_IMAGE} ]]; then usage; exit 1; fi
}
usage () {
echo "Deploy Eclipse Che from sources"
echo
echo "Usage:"
echo -e "\t$0 -o OPERATOR_IMAGE"
echo
echo "OPTIONS:"
echo -e "\t-o,--operator-image Operator image to include into bundle"
echo
echo "Example:"
echo -e "\t$0 -o quay.io/eclipse/che-operator:next"
}
buildNextBundleFromSources() {
local TMP_BUNDLE_DIR=/tmp/bundle
rm -rf ${TMP_BUNDLE_DIR}
mkdir ${TMP_BUNDLE_DIR}
cp -r $(make bundle-path CHANNEL=next)/* ${TMP_BUNDLE_DIR}
mv ${TMP_BUNDLE_DIR}/bundle.Dockerfile ${TMP_BUNDLE_DIR}/Dockerfile
yq -rYi '.spec.install.spec.deployments[0].spec.template.spec.containers[0].image = "'${OPERATOR_IMAGE}'"' ${TMP_BUNDLE_DIR}/manifests/che-operator.clusterserviceversion.yaml
oc new-build --binary --strategy docker --name ${BUNDLE_NAME} -n ${NAMESPACE}
oc start-build ${BUNDLE_NAME} --from-dir ${TMP_BUNDLE_DIR} -n ${NAMESPACE} --wait
}
createImageRegistryViewerUser() {
IMAGE_REGISTRY_VIEWER_USER_NAME=registry-viewer
IMAGE_REGISTRY_VIEWER_USER_PASSWORD=registry-viewer
if ! oc get secret registry-viewer-htpasswd -n openshift-config >/dev/null 2>&1; then
cat > /tmp/htpasswd.conf <<EOF
registry-viewer:{SHA}4xV+Nga1JF5YDx0fB1LdYbyaVvQ=
EOF
oc create secret generic registry-viewer-htpasswd --from-file=htpasswd=/tmp/htpasswd.conf -n openshift-config
oc apply -f - <<EOF
apiVersion: config.openshift.io/v1
kind: OAuth
metadata:
name: cluster
spec:
identityProviders:
- name: registry-viewer
mappingMethod: claim
type: HTPasswd
htpasswd:
fileData:
name: registry-viewer-htpasswd
EOF
fi
cp "${HOME}/.kube/config" /tmp/${IMAGE_REGISTRY_VIEWER_USER_NAME}.kubeconfig
timeout 240 bash -c "until oc login --kubeconfig=/tmp/${IMAGE_REGISTRY_VIEWER_USER_NAME}.kubeconfig --username=${IMAGE_REGISTRY_VIEWER_USER_NAME} --password=${IMAGE_REGISTRY_VIEWER_USER_PASSWORD} >/dev/null 2>&1; do printf '.'; sleep 1; done"
IMAGE_REGISTRY_VIEWER_USER_TOKEN=$(oc --kubeconfig=/tmp/${IMAGE_REGISTRY_VIEWER_USER_NAME}.kubeconfig whoami -t)
oc policy add-role-to-user registry-viewer ${IMAGE_REGISTRY_VIEWER_USER_NAME} -n ${NAMESPACE}
}
createOLMRegistry() {
oc apply -f - <<EOF
apiVersion: apps/v1
kind: Deployment
metadata:
name: che-registry
namespace: ${NAMESPACE}
spec:
selector:
matchLabels:
app: che-registry
template:
metadata:
labels:
app: che-registry
spec:
containers:
- name: registry
image: quay.io/openshift-knative/index
ports:
- containerPort: 50051
name: grpc
protocol: TCP
livenessProbe:
exec:
command:
- grpc_health_probe
- -addr=localhost:50051
readinessProbe:
exec:
command:
- grpc_health_probe
- -addr=localhost:50051
command:
- /bin/sh
- -c
- |-
podman login -u ${IMAGE_REGISTRY_VIEWER_USER_NAME} -p ${IMAGE_REGISTRY_VIEWER_USER_TOKEN} image-registry.openshift-image-registry.svc:5000
/bin/opm registry add --container-tool=podman -d index.db --mode=semver -b image-registry.openshift-image-registry.svc:5000/${NAMESPACE}/${BUNDLE_NAME}
/bin/opm registry serve -d index.db -p 50051
EOF
oc wait --for=condition=ready "pods" -l app=che-registry --timeout=60s -n "${NAMESPACE}"
}
createEclipseCheCatalogSource() {
buildNextBundleFromSources
createImageRegistryViewerUser
createOLMRegistry
local REGISTRY_POD_IP="$(oc get pods -l app=che-registry -n ${NAMESPACE} -o jsonpath='{.items[0].status.podIP}')"
oc apply -f - <<EOF
apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: eclipse-che
namespace: ${NAMESPACE}
spec:
address: "${REGISTRY_POD_IP}:50051"
displayName: "Eclipse Che"
publisher: "Eclipse Che"
sourceType: grpc
EOF
}
run() {
pushd ${OPERATOR_REPO}
make create-namespace
if [[ $(oc get operatorgroup -n eclipse-che --no-headers | wc -l) == 0 ]]; then
make create-operatorgroup NAME=eclipse-che NAMESPACE=${NAMESPACE}
fi
createEclipseCheCatalogSource
make create-subscription \
NAME=eclipse-che-subscription \
NAMESPACE=eclipse-che \
PACKAGE_NAME=${ECLIPSE_CHE_PREVIEW_PACKAGE_NAME} \
SOURCE=eclipse-che \
SOURCE_NAMESPACE=eclipse-che \
INSTALL_PLAN_APPROVAL=Auto \
CHANNEL=next
waitForInstalledEclipseCheCSV
getCheClusterCRFromInstalledCSV | oc apply -n "${NAMESPACE}" -f -
make wait-eclipseche-version VERSION="$(getCheVersionFromInstalledCSV)" NAMESPACE=${NAMESPACE}
popd
}
init "$@"
run