Skip to content

Instantly share code, notes, and snippets.

@nickboldt
Last active August 21, 2020 18:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nickboldt/ed43f390756527a567b168689f409e4f to your computer and use it in GitHub Desktop.
Save nickboldt/ed43f390756527a567b168689f409e4f to your computer and use it in GitHub Desktop.
installing CRW 2.3 via operatorhub / olm method v2, based on https://gitlab.cee.redhat.com/flacatus/custom-catalog
#!/bin/bash
set +e +x
tmpdir=$(mktemp -d)
CONTAINERS=(\
crw-2-rhel8-operator-metadata \
devfileregistry-rhel8 \
pluginregistry-rhel8 \
server-rhel8 \
crw-2-rhel8-operator \
\
jwtproxy-rhel8 \
imagepuller-rhel8 \
machineexec-rhel8 \
pluginbroker-metadata-rhel8 \
pluginbroker-artifacts-rhel8 \
\
theia-dev-rhel8 theia-rhel8 theia-endpoint-rhel8 \
plugin-java8-rhel8 plugin-java11-rhel8 plugin-kubernetes-rhel8 plugin-openshift-rhel8 \
stacks-cpp-rhel8 stacks-golang-rhel8 stacks-php-rhel8 stacks-dotnet-rhel8 \
)
# for a specific version, see either quay or redhat folders:
# https://codeready-workspaces-jenkins.rhev-ci-vms.eng.rdu2.redhat.com/view/CRW_CI/view/Pipelines/job/crwctl_master/lastSuccessfulBuild/artifact/codeready-workspaces-chectl/dist/channels/quay/
# https://codeready-workspaces-jenkins.rhev-ci-vms.eng.rdu2.redhat.com/view/CRW_CI/view/Pipelines/job/crwctl_master/lastSuccessfulBuild/artifact/codeready-workspaces-chectl/dist/channels/redhat/codeready-workspaces-2.3.0-GA-crwctl-linux-x64.tar.gz
VER=2.3.0-CI # or specific release like 2.3.0-GA
CHANNEL="quay" # for CI, use Quay, for GA, use redhat
usage () {
echo "
Usage:
$0 -n [namespace] -v [CRW_TAG] [--quay] [--stage] [--osbs]
Example:
$0 ${USER}-$(date -u +%m%da%H%M) # on x64
$0 crw-qe # on Z or P
Options:
-n - namespace to use when deploying CRW
--quay - resolve images references using quay.io/crw/* images
--stage - resolve images references using registry.stage.redhat.io/codeready-workspaces/* images
--osbs - resolve images references using registry-proxy.engineering.redhat.com/rh-osbs/codeready-workspaces-* images
"
exit
}
if [[ $# -lt 1 ]]; then usage; fi
notLoggedIn ()
{
echo "You must 'oc login ...' in before you can proceed with this script."
exit 1
}
# check if logged into a cluster for deployment
oc project || notLoggedIn
# defaults
# X = 0, Z = 1, P = 2
# TODO support all three arches with cmdline flags
archKey=1
# default to quay images
REGISTRY_NAME="quay"
REGISTRY="quay.io/crw/"
CRW_TAG="2.3"
for key in "$@"; do
case $key in
'--stage') REGISTRY_NAME="stage"; REGISTRY="registry.stage.redhat.io/codeready-workspaces/"; shift 0;;
'--osbs') REGISTRY_NAME="osbs"; REGISTRY="registry-proxy.engineering.redhat.com/rh-osbs/codeready-workspaces-"; shift 0;;
'--quay') REGISTRY_NAME="quay"; REGISTRY="quay.io/crw/"; shift 0;;
'-v') CRW_TAG="$2"; shift 0;;
'-n') NAMESPACE="$2"; shift 0;;
'-h') usage; shift 0;;
esac
shift 1
done
echo "* namespace = ${NAMESPACE}
* CRW tag = ${CRW_TAG}
* registry = ${REGISTRY}"
customCatalog=(quay.io/nickboldt/crw-2-catalog:${CRW_TAG} quay.io/kcrane/crw-custom-catalog:2.2 quay.io/foobar/crw-custom-catalog:2.5)
startingCSV=(crwoperator.v${CRW_TAG}.0 crwoperator.v2.2.0 crwoperator.v2.2.0)
checkVersion() {
if [[ "$1" = "`echo -e "$1\n$2" | sort -V | head -n1`" ]]; then
echo "OpenShift server version $2 >= $1, can proceed."
else
echo "Please connect to an OpenShift instance >= $1"
exit 1
fi
}
# check version >=4.2 (minimum version of OCP needed for OLM)
# but note that CRW 2.3 only supports OCP 4.4+
checkVersion 4.2 "$(oc version | grep Server | sed -r -e "s#.+Version: ##")"
echo "Generating configuration files in $tmpdir ..."
# create catalog source file
# TODO should namespace be custom one or the defaul openshift-marketplace?
# https://docs.openshift.com/container-platform/4.5/operators/olm-managing-custom-catalogs.html#olm-creating-catalog-from-index_olm-managing-custom-catalogs
echo "apiVersion: operators.coreos.com/v1alpha1
kind: CatalogSource
metadata:
name: codeready-workspaces-latest
namespace: ${NAMESPACE}
spec:
sourceType: grpc
image: ${customCatalog[${archKey}]}
displayName: CodeReady Workspaces Catalog
updateStrategy:
registryPoll:
interval: 30m" > $tmpdir/catalog_source.yaml
echo " - $tmpdir/catalog_source.yaml"
# create operator group file
echo "apiVersion: operators.coreos.com/v1
kind: OperatorGroup
metadata:
name: codeready-operator
namespace: ${NAMESPACE}
spec:
targetNamespaces:
- ${NAMESPACE}" > $tmpdir/operator_group.yaml
echo " - $tmpdir/operator_group.yaml"
# create subscription file
echo "apiVersion: operators.coreos.com/v1alpha1
kind: Subscription
metadata:
name: codeready-workspaces
namespace: ${NAMESPACE}
spec:
channel: stable
installPlanApproval: Automatic
name: crwoperator
source: codeready-workspaces
sourceNamespace: ${NAMESPACE}
startingCSV: ${startingCSV[${archKey}]}" > $tmpdir/subscription.yaml
echo " - $tmpdir/subscription.yaml"
# create ImageContentSourcePolicy file
echo "apiVersion: operator.openshift.io/v1alpha1
kind: ImageContentSourcePolicy
metadata:
name: crw$(echo ${CRW_TAG} | tr -d ".")repos
spec:
repositoryDigestMirrors:" > $tmpdir/image_content_source_policy.yaml
# TODO: can we include all the registries in a single mapping?
#REGISTRIES="quay.io/crw/ registry-proxy.engineering.redhat.com/rh-osbs/codeready-workspaces- registry.stage.redhat.io/codeready-workspaces/"
REGISTRIES="${REGISTRY}"
for ((i = 0; i < ${#CONTAINERS[@]}; ++i)); do
# echo "$i: ${CONTAINERS[$i]}"
source="registry.redhat.io/codeready-workspaces/${CONTAINERS[$i]}:${CRW_TAG}"
mirrors=""
for REGISTRY in $REGISTRIES; do
mirror_container=${CONTAINERS[$i]}
# operator and metadata have a different container name in OSBS
if [[ $mirror_container == *"operator"* ]] && [[ ${REGISTRY_NAME} == "osbs" ]]; then mirror_container=${mirror_container#*-rhel8-}; fi
mirrors="${mirrors} ${REGISTRY}${mirror_container}:${CRW_TAG}"
done
echo " - mirrors:
-${mirrors}
source: ${source}" >> $tmpdir/image_content_source_policy.yaml
echo " - $source = $mirrors"
done
echo " - $tmpdir/image_content_source_policy.yaml"
# cat $tmpdir/image_content_source_policy.yaml
oc create namespace ${NAMESPACE}
# create CatalogSource
oc apply -n ${NAMESPACE} -f $tmpdir/catalog_source.yaml
# verify catalog source
oc get catalogsource -n ${NAMESPACE} | egrep "codeready|workspaces|crw"
oc get packagemanifests -n ${NAMESPACE} | egrep "codeready|workspaces|crw"
# create OperatorGroup
oc apply -n ${NAMESPACE} -f $tmpdir/operator_group.yaml
# create Subscription
oc apply -n ${NAMESPACE} -f $tmpdir/subscription.yaml
# create ImageContentSourcePolicy
oc apply -n ${NAMESPACE} -f $tmpdir/image_content_source_policy.yaml
# cleanup
rm -fr ${tmpdir}
# get latest crwctl version from Jenkins; if latest build is not a 2.0.0-CI build, set different VER value above
cd /tmp
rm -f ${HOME}/crwctl || true
rm -fr ${HOME}/crwctl_${VER} || true
echo "Fetch codeready-workspaces-${VER}-crwctl-linux-x64.tar.gz ..."
if [[ ${VER} == *"-CI" ]]; then
curl -sSLo /tmp/codeready-workspaces-${VER}-crwctl-linux-x64.tar.gz https://codeready-workspaces-jenkins.rhev-ci-vms.eng.rdu2.redhat.com/view/CRW_CI/view/Pipelines/job/crwctl_master/lastSuccessfulBuild/artifact/codeready-workspaces-chectl/dist/channels/latest/crwctl-linux-x64.tar.gz || exit 1
else
curl -sSLo /tmp/codeready-workspaces-${VER}-crwctl-linux-x64.tar.gz https://codeready-workspaces-jenkins.rhev-ci-vms.eng.rdu2.redhat.com/view/CRW_CI/view/Pipelines/job/crwctl_master/lastSuccessfulBuild/artifact/codeready-workspaces-chectl/dist/channels/${CHANNEL}/codeready-workspaces-${VER}-crwctl-linux-x64.tar.gz || exit 1
fi
tar xzf /tmp/codeready-workspaces-${VER}-crwctl-linux-x64.tar.gz -C ${HOME} && rm -f /tmp/codeready-workspaces-${VER}-crwctl-linux-x64.tar.gz
mv ${HOME}/crwctl{,_${VER}} && ln -s ${HOME}/crwctl_${VER} ${HOME}/crwctl
${HOME}/crwctl/bin/crwctl version
# install CodeReady Workspaces 2.3 on OCP 4.4+ into ${USER}-crw namespace
${HOME}/crwctl/bin/crwctl server:start -a olm -n ${NAMESPACE} \
--catalog-source-name=codeready-workspaces-latest \
--catalog-source-namespace=${NAMESPACE} \
--package-manifest-name=codeready-workspaces \
--olm-channel=latest
# patch deployment so we can run more than one workspace at a time
oc project ${NAMESPACE}
oc patch checluster codeready-workspaces --type=merge -p '{ "spec": { "server": { "customCheProperties": { "CHE_LIMITS_USER_WORKSPACES_RUN_COUNT": "-1" } } } }'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment