|
| 1 | +#!/bin/bash |
| 2 | +# install a helm chart with the correct global.clusterRouterBase |
| 3 | + |
| 4 | +# default namespace if none set |
| 5 | +namespace="rhdh-helm" |
| 6 | +# chartrepo=0 # by default don't create a new chart repo unless the version chart version includes "CI" suffix |
| 7 | + |
| 8 | +usage () |
| 9 | +{ |
| 10 | + echo "Usage: $0 CHART_VERSION [-n namespace] |
| 11 | +
|
| 12 | +Requires an existing connection to an OCP or k8s cluster |
| 13 | +Requires helm, plus oc or kubectl, to be installed and on the path |
| 14 | +
|
| 15 | +Examples: |
| 16 | + $0 1.5.1 |
| 17 | + $0 1.7-zzz-CI -n rhdh-ci |
| 18 | +
|
| 19 | +Options: |
| 20 | + -n, --namespace Project or namespace into which to install specified chart; default: $namespace |
| 21 | + --chartrepo If set, a Helm Chart Repo will be applied to the cluster, based on the chart version. |
| 22 | + If CHART_VERSION ends in CI, this is done by default. |
| 23 | + --router If set, the cluster router base is manually set. |
| 24 | + Required for non-admin users |
| 25 | + Redundant for admin users |
| 26 | +" |
| 27 | +} |
| 28 | + |
| 29 | +if [[ $# -lt 1 ]]; then usage; exit 0; fi |
| 30 | + |
| 31 | +while [[ "$#" -gt 0 ]]; do |
| 32 | + case $1 in |
| 33 | + '--chartrepo') chartrepo=1;; |
| 34 | + '-n'|'--namespace') namespace="$2"; shift 1;; |
| 35 | + '-h') usage; exit 0;; |
| 36 | + '--router') CLUSTER_ROUTER_BASE="$2"; shift 1;; |
| 37 | + *) CV="$1";; |
| 38 | + esac |
| 39 | + shift 1 |
| 40 | +done |
| 41 | + |
| 42 | +if [[ ! "$CV" ]]; then usage; exit 1; fi |
| 43 | + |
| 44 | +CHART_URL="oci://quay.io/rhdh/chart" |
| 45 | + |
| 46 | +if ! helm show chart $CHART_URL --version "$CV" &> /dev/null; then |
| 47 | + echo "Error: could not load chart $CV from $CHART_URL !" |
| 48 | + echo |
| 49 | + usage |
| 50 | + exit 1 |
| 51 | + fi |
| 52 | + |
| 53 | +echo "Using ${CHART_URL} to install Helm chart" |
| 54 | + |
| 55 | +# choose namespace for the install (or create if non-existant) |
| 56 | +oc new-project "$namespace" || oc project "$namespace" |
| 57 | + |
| 58 | +# generate repo.yaml and index.yaml so we don't have to publish a new file every time |
| 59 | +if [[ "$CV" == *"-CI" ]] || [[ $chartrepo -eq 1 ]]; then |
| 60 | + mkdir -p /tmp/"$CV"-unpacked && pushd /tmp/"$CV"-unpacked >/dev/null 2>&1 || exit 1 |
| 61 | + helm pull oci://quay.io/rhdh/chart --version "$CV" -d /tmp/"$CV"-unpacked # get tarball |
| 62 | + helm repo index /tmp/"$CV"-unpacked # create index.yaml |
| 63 | + cat <<EOF > repo.yaml |
| 64 | +apiVersion: helm.openshift.io/v1beta1 |
| 65 | +kind: HelmChartRepository |
| 66 | +metadata: |
| 67 | + name: rhdh-next-ci-repo |
| 68 | +spec: |
| 69 | + connectionConfig: |
| 70 | + file: >- |
| 71 | + ./index.yaml |
| 72 | +EOF |
| 73 | + |
| 74 | + oc apply -f repo.yaml || kubctl apply -f repo.yaml |
| 75 | + popd >/dev/null 2>&1 || exit 1 |
| 76 | + |
| 77 | + # clean up temp files |
| 78 | + rm -fr /tmp/"$CV"-unpacked |
| 79 | +fi |
| 80 | + |
| 81 | +# 1. install (or upgrade) |
| 82 | +helm upgrade redhat-developer-hub -i "${CHART_URL}" --version "$CV" |
| 83 | + |
| 84 | +# 2. collect values |
| 85 | +PASSWORD=$(kubectl get secret redhat-developer-hub-postgresql -o jsonpath="{.data.password}" | base64 -d) |
| 86 | +if [[ $(oc auth can-i get route/openshift-console) == "yes" ]]; then |
| 87 | + CLUSTER_ROUTER_BASE=$(oc get route console -n openshift-console -o=jsonpath='{.spec.host}' | sed 's/^[^.]*\.//') |
| 88 | +elif [[ -z $CLUSTER_ROUTER_BASE ]]; then |
| 89 | + echo "Error: openshift-console routes cannot be accessed with user permissions" |
| 90 | + echo "Rerun command installation script with --router <cluster router base>" |
| 91 | + echo |
| 92 | + usage |
| 93 | + exit 1 |
| 94 | +fi |
| 95 | + |
| 96 | +# 3. change values |
| 97 | +helm upgrade redhat-developer-hub -i "${CHART_URL}" --version "$CV" \ |
| 98 | + --set global.clusterRouterBase="${CLUSTER_ROUTER_BASE}" \ |
| 99 | + --set global.postgresql.auth.password="$PASSWORD" |
| 100 | + |
| 101 | +echo " |
| 102 | +Once deployed, Developer Hub $CV will be available at |
| 103 | +https://redhat-developer-hub-${namespace}.${CLUSTER_ROUTER_BASE} |
| 104 | +" |
0 commit comments