#!/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 # # Scripts to prepare OLM(operator lifecycle manager) and install che-operator package # with specific version using OLM. BASE_DIR=$(dirname $(readlink -f "${BASH_SOURCE[0]}")) ROOT_DIR=$(dirname "${BASE_DIR}") source ${ROOT_DIR}/olm/check-yq.sh function getPackageName() { platform="${1}" if [ -z "${1}" ]; then echo "[ERROR] Please specify first argument: 'platform'" exit 1 fi echo "eclipse-che-preview-${platform}" } function getBundlePath() { platform="${1}" if [ -z "${platform}" ]; then echo "[ERROR] Please specify first argument: 'platform'" exit 1 fi channel="${2}" if [ -z "${channel}" ]; then echo "[ERROR] Please specify second argument: 'channel'" exit 1 fi echo "${ROOT_DIR}/bundle/${channel}/$(getPackageName "${platform}")" } createCatalogSource() { platform="${1}" if [ -z "${platform}" ]; then echo "[ERROR] Please specify first argument: 'platform'" exit 1 fi namespace="${2}" if [ -z "${namespace}" ]; then echo "[ERROR] Please specify second argument: 'namespace'" exit 1 fi CATALOG_IMAGENAME="${3}" if [ -z "${CATALOG_IMAGENAME}" ]; then echo "[ERROR] Please specify third argument: 'catalog image'" exit 1 fi packageName=$(getPackageName "${platform}") kubectl apply -f - <&1 1>&3 3>&-)"; } 3>&1 || \ { exitCode="$?"; echo "[INFO] ${exitCode}"; true; } echo "${output}" if [[ "${output}" == *"already exists, Bundle already added that provides package and csv"* ]] && [[ "${forceBuildAndPush}" == "true" ]]; then echo "[INFO] Ignore error 'Bundle already added'" # Catalog bundle image contains bundle reference, continue without unnecessary push operation return else echo "[INFO] ${exitCode}" if [ "${exitCode}" != 0 ]; then exit "${exitCode}" fi fi make catalog-push CATALOG_IMG="${CATALOG_IMAGENAME}" popd || exit } # HACK. Unfortunately catalog source image bundle job has image pull policy "IfNotPresent". # It makes troubles for test scripts, because image bundle could be outdated with # such pull policy. That's why we launch job to fource image bundle pulling before Che installation. forcePullingOlmImages() { namespace="${1}" if [ -z "${namespace}" ]; then echo "[ERROR] Please specify first argument: 'namespace'" exit 1 fi CATALOG_BUNDLE_IMAGE_NAME_LOCAL="${2}" if [ -z "${CATALOG_BUNDLE_IMAGE_NAME_LOCAL}" ]; then echo "[ERROR] Please specify second argument: opm bundle image" exit 1 fi yq -r "(.spec.template.spec.containers[0].image) = \"${CATALOG_BUNDLE_IMAGE_NAME_LOCAL}\"" "${BASE_DIR}/force-pulling-olm-images-job.yaml" | kubectl apply -f - -n "${namespace}" kubectl wait --for=condition=complete --timeout=30s job/force-pulling-olm-images-job -n "${namespace}" kubectl delete job/force-pulling-olm-images-job -n "${namespace}" } installOPM() { OPM_BINARY=$(command -v opm) || true if [[ ! -x $OPM_BINARY ]]; then OPM_TEMP_DIR="$(mktemp -q -d -t "OPM_XXXXXX" 2>/dev/null || mktemp -q -d)" pushd "${OPM_TEMP_DIR}" || exit echo "[INFO] Downloading 'opm' cli tool..." curl -sLo opm "$(curl -sL https://api.github.com/repos/operator-framework/operator-registry/releases/33432389 | jq -r '[.assets[] | select(.name == "linux-amd64-opm")] | first | .browser_download_url')" export OPM_BINARY="${OPM_TEMP_DIR}/opm" chmod +x "${OPM_BINARY}" echo "[INFO] Downloading completed!" echo "[INFO] 'opm' binary path: ${OPM_BINARY}" ${OPM_BINARY} version popd || exit fi } createNamespace() { namespace="${1}" if [ -z "${namespace}" ]; then echo "[ERROR] Please specify first argument: 'namespace'" exit 1 fi kubectl apply -f - </dev/null 2>&1 then break fi sleep 1 ((i++)) done if [ $i -gt 240 ] then echo "[ERROR] Catalog source not created after 4 minutes" exit 1 fi } subscribeToInstallation() { platform="${1}" if [ -z "${platform}" ]; then echo "[ERROR] Please specify first argument: 'platform'" exit 1 fi namespace="${2}" if [ -z "${namespace}" ]; then echo "[ERROR] Please specify second argument: 'namespace'" exit 1 fi channel="${3}" if [ -z "${channel}" ]; then echo "[ERROR] Please specify third argument: 'channel'" exit 1 fi # fourth argument is an optional CSV_NAME="${4-${CSV_NAME}}" if [ -n "${CSV_NAME}" ]; then echo "[INFO] Subscribing to the version: '${CSV_NAME}'" else echo "[INFO] Subscribing to latest version for channel: '${channel}'" fi packageName=$(getPackageName "${platform}") kubectl apply -f - <