|
| 1 | +#!/bin/bash |
| 2 | +set -e -o pipefail |
| 3 | + |
| 4 | +CATALOGSOURCE="test-pattern-operator" |
| 5 | +NS="openshift-operators" |
| 6 | +OPERATOR="patterns-operator" |
| 7 | +VERSION="${VERSION:-6.6.6}" |
| 8 | +REGISTRY="${REGISTRY:-kuemper.int.rhx/bandini}" |
| 9 | + |
| 10 | +wait_for_resource() { |
| 11 | + local resource_type=$1 # Either "packagemanifest", "operator", or "csv" |
| 12 | + local name=$2 # Name of the resource (e.g., Operator or CSV) |
| 13 | + local namespace=$3 # Namespace (optional, required for CSV and Operator) |
| 14 | + local label=$4 # Label selector (only for packagemanifests) |
| 15 | + |
| 16 | + echo "⏳ Waiting for $resource_type: $name" |
| 17 | + while true; do |
| 18 | + set +e |
| 19 | + if [[ "$resource_type" == "packagemanifest" ]]; then |
| 20 | + oc get -n openshift-marketplace packagemanifests -l "catalog=${label}" --field-selector "metadata.name=${name}" &> /dev/null |
| 21 | + elif [[ "$resource_type" == "operator" ]]; then |
| 22 | + oc get operators.operators.coreos.com "${name}.${namespace}" &> /dev/null |
| 23 | + elif [[ "$resource_type" == "csv" ]]; then |
| 24 | + STATUS=$(oc get csv "$name" -n "$namespace" -o jsonpath='{.status.phase}' 2>/dev/null) |
| 25 | + if [[ "$STATUS" == "Succeeded" ]]; then |
| 26 | + echo "✅ Operator installation completed successfully!" |
| 27 | + break |
| 28 | + fi |
| 29 | + echo "⏳ Operator installation in progress... (Current status: ${STATUS:-Not Found})" |
| 30 | + else |
| 31 | + echo "❌ Unknown resource type: $resource_type" |
| 32 | + return 1 |
| 33 | + fi |
| 34 | + ret=$? |
| 35 | + set -e |
| 36 | + |
| 37 | + if [[ $ret -eq 0 && "$resource_type" != "csv" ]]; then |
| 38 | + echo "✅ $resource_type: $name is available!" |
| 39 | + break |
| 40 | + fi |
| 41 | + |
| 42 | + sleep 10 |
| 43 | + done |
| 44 | +} |
| 45 | + |
| 46 | +apply_subscription() { |
| 47 | + oc delete -n ${NS} subscription/${OPERATOR} || /bin/true |
| 48 | + oc delete catalogsource/${CATALOGSOURCE} || /bin/true |
| 49 | + oc apply -f - <<EOF |
| 50 | + apiVersion: operators.coreos.com/v1alpha1 |
| 51 | + kind: Subscription |
| 52 | + metadata: |
| 53 | + name: ${OPERATOR} |
| 54 | + namespace: ${NS} |
| 55 | + spec: |
| 56 | + channel: fast |
| 57 | + installPlanApproval: Automatic |
| 58 | + name: ${OPERATOR} |
| 59 | + source: ${CATALOGSOURCE} |
| 60 | + sourceNamespace: openshift-marketplace |
| 61 | +EOF |
| 62 | +} |
| 63 | + |
| 64 | +if [[ -n $(git status --porcelain) ]]; then |
| 65 | + echo "Uncommitted changes detected." |
| 66 | + exit 1 |
| 67 | +fi |
| 68 | + |
| 69 | +echo "Checking for cluster reachability:" |
| 70 | +OUT=$(oc cluster-info 2>&1) |
| 71 | +ret=$? |
| 72 | +if [ $ret -ne 0 ]; then |
| 73 | + echo "Could not reach cluster: ${OUT}" |
| 74 | + exit 1 |
| 75 | +fi |
| 76 | + |
| 77 | +make VERSION=${VERSION} IMAGE_TAG_BASE=${REGISTRY}/patterns-operator CHANNELS=fast USE_IMAGE_DIGESTS="" \ |
| 78 | + manifests bundle generate docker-build docker-push bundle-build bundle-push catalog-build \ |
| 79 | + catalog-push catalog-install |
| 80 | + |
| 81 | +wait_for_resource "packagemanifest" "${OPERATOR}" "" "${CATALOGSOURCE}" |
| 82 | +apply_subscription |
| 83 | +wait_for_resource "operator" "${OPERATOR}" "${NS}" |
| 84 | + |
| 85 | +while true; do |
| 86 | + set +e |
| 87 | + INSTALLED_CSV=$(oc get subscription "${OPERATOR}" -n "${NS}" -o jsonpath='{.status.installedCSV}') |
| 88 | + if [ -z "${INSTALLED_CSV}" ]; then |
| 89 | + sleep 10 |
| 90 | + else |
| 91 | + break |
| 92 | + fi |
| 93 | +done |
| 94 | + |
| 95 | +wait_for_resource "csv" "${INSTALLED_CSV}" "${NS}" |
| 96 | + |
0 commit comments