|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e |
| 4 | +set -u |
| 5 | +set -o pipefail |
| 6 | + |
| 7 | +# Set XDG_RUNTIME_DIR/containers to be used by oc mirror |
| 8 | +export HOME=/tmp/home |
| 9 | +export XDG_RUNTIME_DIR="${HOME}/run" |
| 10 | +export REGISTRY_AUTH_PREFERENCE=podman |
| 11 | +mkdir -p "${XDG_RUNTIME_DIR}/containers" |
| 12 | +cd "$HOME" || exit 1 |
| 13 | + |
| 14 | +function run_command() { |
| 15 | + local CMD="$1" |
| 16 | + echo "Running Command: ${CMD}" |
| 17 | + eval "${CMD}" |
| 18 | +} |
| 19 | + |
| 20 | +# Mirror operator and test images to the Mirror registry. Create Catalog sources and Image Content Source Policy. |
| 21 | +function mirror_catalog_icsp() { |
| 22 | + registry_cred=$(head -n 1 "/var/run/vault/mirror-registry/registry_creds" | base64 -w 0) |
| 23 | + |
| 24 | + optional_auth_user=$(cat "/var/run/vault/mirror-registry/registry_quay.json" | jq -r '.user') |
| 25 | + optional_auth_password=$(cat "/var/run/vault/mirror-registry/registry_quay.json" | jq -r '.password') |
| 26 | + qe_registry_auth=$(echo -n "${optional_auth_user}:${optional_auth_password}" | base64 -w 0) |
| 27 | + |
| 28 | + openshifttest_auth_user=$(cat "/var/run/vault/mirror-registry/registry_quay_openshifttest.json" | jq -r '.user') |
| 29 | + openshifttest_auth_password=$(cat "/var/run/vault/mirror-registry/registry_quay_openshifttest.json" | jq -r '.password') |
| 30 | + openshifttest_registry_auth=$(echo -n "${openshifttest_auth_user}:${openshifttest_auth_password}" | base64 -w 0) |
| 31 | + |
| 32 | + brew_auth_user=$(cat "/var/run/vault/mirror-registry/registry_brew.json" | jq -r '.user') |
| 33 | + brew_auth_password=$(cat "/var/run/vault/mirror-registry/registry_brew.json" | jq -r '.password') |
| 34 | + brew_registry_auth=$(echo -n "${brew_auth_user}:${brew_auth_password}" | base64 -w 0) |
| 35 | + |
| 36 | + stage_auth_user=$(cat "/var/run/vault/mirror-registry/registry_stage.json" | jq -r '.user') |
| 37 | + stage_auth_password=$(cat "/var/run/vault/mirror-registry/registry_stage.json" | jq -r '.password') |
| 38 | + stage_registry_auth=$(echo -n "${stage_auth_user}:${stage_auth_password}" | base64 -w 0) |
| 39 | + |
| 40 | + redhat_auth_user=$(cat "/var/run/vault/mirror-registry/registry_redhat.json" | jq -r '.user') |
| 41 | + redhat_auth_password=$(cat "/var/run/vault/mirror-registry/registry_redhat.json" | jq -r '.password') |
| 42 | + redhat_registry_auth=$(echo -n "${redhat_auth_user}:${redhat_auth_password}" | base64 -w 0) |
| 43 | + |
| 44 | + # run_command "cat ${CLUSTER_PROFILE_DIR}/pull-secret" |
| 45 | + # Running Command: cat /tmp/.dockerconfigjson |
| 46 | + # {"auths":{"ec2-3-92-162-185.compute-1.amazonaws.com:5000":{"auth":"XXXXXXXXXXXXXXXX"}}} |
| 47 | + run_command "oc extract secret/pull-secret -n openshift-config --confirm --to /tmp" |
| 48 | + ret=$? |
| 49 | + MIRROR_REGISTRY_HOST=$(head -n 1 "${SHARED_DIR}/mirror_registry_url") |
| 50 | + echo $MIRROR_REGISTRY_HOST |
| 51 | + if [[ $ret -eq 0 ]]; then |
| 52 | + jq --argjson a "{\"registry.stage.redhat.io\": {\"auth\": \"$stage_registry_auth\"}, \"brew.registry.redhat.io\": {\"auth\": \"$brew_registry_auth\"}, \"registry.redhat.io\": {\"auth\": \"$redhat_registry_auth\"}, \"${MIRROR_REGISTRY_HOST}\": {\"auth\": \"$registry_cred\"}, \"quay.io/openshift-qe-optional-operators\": {\"auth\": \"${qe_registry_auth}\", \"email\":\"jiazha@redhat.com\"},\"quay.io/openshifttest\": {\"auth\": \"${openshifttest_registry_auth}\"}}" '.auths |= . + $a' "/tmp/.dockerconfigjson" >${XDG_RUNTIME_DIR}/containers/auth.json |
| 53 | + export REG_CREDS=${XDG_RUNTIME_DIR}/containers/auth.json |
| 54 | + else |
| 55 | + echo "!!! fail to extract the auth of the cluster" |
| 56 | + return 1 |
| 57 | + fi |
| 58 | + |
| 59 | + # prepare ImageSetConfiguration |
| 60 | + run_command "mkdir /tmp/images" |
| 61 | + cat <<EOF >/tmp/image-set.yaml |
| 62 | +
|
| 63 | +kind: ImageSetConfiguration |
| 64 | +apiVersion: mirror.openshift.io/v1alpha2 |
| 65 | +archiveSize: 30 |
| 66 | +storageConfig: |
| 67 | + local: |
| 68 | + path: /tmp/images |
| 69 | +mirror: |
| 70 | + additionalImages: |
| 71 | + # Used for running disconnected tests |
| 72 | + - name: quay.io/redhat-user-workloads/rhpm-tenant/power-monitoring-operator-bundle:v0.4.0 |
| 73 | + - name: quay.io/redhat-user-workloads/rhpm-tenant/power-monitoring-operator:v0.15.0 |
| 74 | + - name: quay.io/redhat-user-workloads/rhpm-tenant/kepler:v0.7.12 |
| 75 | +EOF |
| 76 | + |
| 77 | + run_command "cd /tmp" |
| 78 | + run_command "curl -L -o oc-mirror.tar.gz https://mirror.openshift.com/pub/openshift-v4/amd64/clients/ocp/latest/oc-mirror.tar.gz && tar -xvzf oc-mirror.tar.gz && chmod +x oc-mirror" |
| 79 | + run_command "./oc-mirror --config=/tmp/image-set.yaml docker://${MIRROR_REGISTRY_HOST} --continue-on-error --ignore-history --source-skip-tls --dest-skip-tls || true" |
| 80 | + run_command "cp oc-mirror-workspace/results-*/mapping.txt ." |
| 81 | + # run_command "sed -e 's|registry.redhat.io|registry.stage.redhat.io|g' -e 's|brew.registry.stage.redhat.io/rh-osbs/tempo|brew.registry.redhat.io/rh-osbs/iib|g' -e 's|brew.registry.stage.redhat.io/rh-osbs/otel|brew.registry.redhat.io/rh-osbs/iib|g' -e 's|brew.registry.stage.redhat.io/rh-osbs/jaeger|brew.registry.redhat.io/rh-osbs/iib|g' mapping.txt > mapping-stage.txt" |
| 82 | + run_command "oc image mirror -a ${REG_CREDS} -f mapping.txt --insecure --filter-by-os='.*'" |
| 83 | + |
| 84 | + echo "Creating Image Content Source Policy" |
| 85 | + oc apply -f - <<EOF |
| 86 | + apiVersion: operator.openshift.io/v1alpha1 |
| 87 | + kind: ImageContentSourcePolicy |
| 88 | + metadata: |
| 89 | + name: test-registry |
| 90 | + spec: |
| 91 | + repositoryDigestMirrors: |
| 92 | + - mirrors: |
| 93 | + - $MIRROR_REGISTRY_HOST |
| 94 | + source: quay.io |
| 95 | +EOF |
| 96 | + echo "Install operator-sdk and dependencies" |
| 97 | + export OPERATOR_SDK_VERSION=1.36.1 |
| 98 | + export ARCH=$(case $(uname -m) in x86_64) echo -n amd64 ;; aarch64) echo -n arm64 ;; *) echo -n $(uname -m) ;; esac) |
| 99 | + export OPERATOR_SDK_DL_URL=https://github.com/operator-framework/operator-sdk/releases/download/v${OPERATOR_SDK_VERSION} |
| 100 | + curl -Lo operator-sdk ${OPERATOR_SDK_DL_URL}/operator-sdk_linux_${ARCH} |
| 101 | + chmod +x operator-sdk |
| 102 | + ./operator-sdk version |
| 103 | + |
| 104 | + ./operator-sdk run bundle --timeout=5m --namespace "openshift-operators" "quay.io/redhat-user-workloads/rhpm-tenant/power-monitoring-operator-bundle:v0.4.0" --verbose |
| 105 | + |
| 106 | + oc logs -n openshift-operators -f deployment/kepler-operator-controller |
| 107 | + |
| 108 | +} |
| 109 | + |
| 110 | +run_command "oc whoami" |
| 111 | +run_command "oc version -o yaml" |
| 112 | + |
| 113 | +mirror_catalog_icsp |
| 114 | + |
| 115 | +while [[ -f /tmp/unsleep ]]; do |
| 116 | + echo "sleeping for 10 seconds" |
| 117 | + sleep 10 |
| 118 | +done |
0 commit comments