fedora-csb-system-manager
  1#!/usr/bin/env bash
  2# Install OpenShift Pipelines on the current cluster
  3
  4set -o errexit
  5set -o nounset
  6set -o pipefail
  7
  8readonly export DEPLOYMENT_TIMEOUT="${DEPLOYMENT_TIMEOUT:-5m}"
  9
 10function fail() {
 11    echo "ERROR: ${*}" >&2
 12    exit 1
 13}
 14
 15function rollout_status() {
 16    local namespace="${1}"
 17    local deployment="${2}"
 18
 19    if ! kubectl --namespace="${namespace}" --timeout=${DEPLOYMENT_TIMEOUT} \
 20         rollout status deployment "${deployment}"; then
 21        fail "'${namespace}/${deployment}' is not deployed as expected!"
 22    fi
 23}
 24
 25function install_channel() {
 26    local channel="${1}"
 27    echo "Installing OpenShift Pipelines from channel ${channel}"
 28    cat <<EOF | oc apply -f-
 29apiVersion: operators.coreos.com/v1alpha1
 30kind: Subscription
 31metadata:
 32  name: openshift-pipelines-operator-rh
 33  namespace: openshift-operators
 34spec:
 35  channel: ${channel}
 36  name: openshift-pipelines-operator-rh
 37  source: redhat-operators
 38  sourceNamespace: openshift-marketplace
 39EOF
 40}
 41
 42function install_nightly() {
 43    oc patch operatorhub.config.openshift.io/cluster -p='{"spec":{"disableAllDefaultSources":true}}' --type=merge
 44    sleep 2
 45    # Add a custom catalog-source
 46
 47    # Guess the major-minor-candidate to use
 48    version=`oc version -o json | jq '.openshiftVersion' | tr -d \"`
 49    major=`echo $version | cut -d. -f1`
 50    minor=`echo $version | cut -d. -f2`
 51
 52    cat <<EOF | oc apply -f-
 53apiVersion: operators.coreos.com/v1alpha1
 54kind: CatalogSource
 55metadata:                      
 56  name: custom-osp-nightly
 57  namespace: openshift-marketplace         
 58spec:                                                                                                                                                                                                                                                
 59  sourceType: grpc
 60  image: quay.io/openshift-pipeline/openshift-pipelines-pipelines-operator-bundle-container-index:v${major}.${minor}-candidate 
 61  displayName: "Custom OSP Nightly"
 62  updateStrategy:
 63    registryPoll:
 64      interval: 30m                                                                                                                                                                                                                                  
 65EOF
 66    sleep 10
 67    # Create the "correct" subscription
 68    oc delete subscription pipelines -n openshift-operators || true
 69    cat <<EOF | oc apply -f-
 70apiVersion: operators.coreos.com/v1alpha1
 71kind: Subscription
 72metadata:
 73  name: openshift-pipelines-operator
 74  namespace: openshift-operators
 75spec:
 76  channel: latest
 77  name: openshift-pipelines-operator-rh
 78  source: custom-osp-nightly
 79  sourceNamespace: openshift-marketplace
 80EOF
 81}
 82
 83OSP_VERSION=${1:-latest}
 84shift
 85
 86case "$OSP_VERSION" in
 87    nightly)
 88	install_nightly
 89	;;
 90    latest)
 91	install_channel latest
 92	;;
 93    *)
 94	install_channel "pipelines-$OSP_VERSION"
 95	;;
 96esac
 97
 98# wait until tekton pipelines operator is created
 99echo "Waiting for OpenShift Pipelines Operator to be created..."
100timeout 2m bash <<- EOF
101  until oc get deployment openshift-pipelines-operator -n openshift-operators; do
102    sleep 5
103  done
104EOF
105oc rollout status -n openshift-operators deployment/openshift-pipelines-operator --timeout 10m
106
107# wait until clustertasks tekton CRD is properly deployed
108timeout 10m bash <<- EOF
109  until oc get crd tasks.tekton.dev; do
110    sleep 5
111  done
112EOF
113
114timeout 2m bash <<- EOF
115  until oc get deployment tekton-pipelines-controller -n openshift-pipelines; do
116    sleep 5
117  done
118EOF
119rollout_status "openshift-pipelines" "tekton-pipelines-controller"
120rollout_status "openshift-pipelines" "tekton-pipelines-webhook"
121
122oc get -n openshift-pipelines pods
123tkn version
124