home

My NixOS systems configurations.
Log | Files | Refs | LICENSE

op-inst (3691B)


      1 #!/usr/bin/env bash
      2 # Install OpenShift Pipelines on the current cluster
      3 
      4 set -o errexit
      5 set -o nounset
      6 set -o pipefail
      7 
      8 readonly export DEPLOYMENT_TIMEOUT="${DEPLOYMENT_TIMEOUT:-5m}"
      9 
     10 function fail() {
     11     echo "ERROR: ${*}" >&2
     12     exit 1
     13 }
     14 
     15 function 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 
     25 function install_channel() {
     26     local channel="${1}"
     27     echo "Installing OpenShift Pipelines from channel ${channel}"
     28     cat <<EOF | oc apply -f-
     29 apiVersion: operators.coreos.com/v1alpha1
     30 kind: Subscription
     31 metadata:
     32   name: openshift-pipelines-operator-rh
     33   namespace: openshift-operators
     34 spec:
     35   channel: ${channel}
     36   name: openshift-pipelines-operator-rh
     37   source: redhat-operators
     38   sourceNamespace: openshift-marketplace
     39 EOF
     40 }
     41 
     42 function 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-
     53 apiVersion: operators.coreos.com/v1alpha1
     54 kind: CatalogSource
     55 metadata:                      
     56   name: custom-osp-nightly
     57   namespace: openshift-marketplace         
     58 spec:                                                                                                                                                                                                                                                
     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                                                                                                                                                                                                                                  
     65 EOF
     66     sleep 10
     67     # Create the "correct" subscription
     68     oc delete subscription pipelines -n openshift-operators || true
     69     cat <<EOF | oc apply -f-
     70 apiVersion: operators.coreos.com/v1alpha1
     71 kind: Subscription
     72 metadata:
     73   name: openshift-pipelines-operator
     74   namespace: openshift-operators
     75 spec:
     76   channel: latest
     77   name: openshift-pipelines-operator-rh
     78   source: custom-osp-nightly
     79   sourceNamespace: openshift-marketplace
     80 EOF
     81 }
     82 
     83 OSP_VERSION=${1:-latest}
     84 shift
     85 
     86 case "$OSP_VERSION" in
     87     nightly)
     88 	install_nightly
     89 	;;
     90     latest)
     91 	install_channel latest
     92 	;;
     93     *)
     94 	install_channel "pipelines-$OSP_VERSION"
     95 	;;
     96 esac
     97 
     98 # wait until tekton pipelines operator is created
     99 echo "Waiting for OpenShift Pipelines Operator to be created..."
    100 timeout 2m bash <<- EOF
    101   until oc get deployment openshift-pipelines-operator -n openshift-operators; do
    102     sleep 5
    103   done
    104 EOF
    105 oc rollout status -n openshift-operators deployment/openshift-pipelines-operator --timeout 10m
    106 
    107 # wait until clustertasks tekton CRD is properly deployed
    108 timeout 10m bash <<- EOF
    109   until oc get crd tasks.tekton.dev; do
    110     sleep 5
    111   done
    112 EOF
    113 
    114 timeout 2m bash <<- EOF
    115   until oc get deployment tekton-pipelines-controller -n openshift-pipelines; do
    116     sleep 5
    117   done
    118 EOF
    119 rollout_status "openshift-pipelines" "tekton-pipelines-controller"
    120 rollout_status "openshift-pipelines" "tekton-pipelines-webhook"
    121 
    122 oc get -n openshift-pipelines pods
    123 tkn version
    124