From 6a53af68b27f03274eff1521cda1b24b18063719 Mon Sep 17 00:00:00 2001 From: NiallTwomey2 Date: Tue, 29 Sep 2026 14:06:28 +0100 Subject: [PATCH 1/6] fix: add log-level option to install-rhdh-catalog-source.sh --- .rhdh/docs/installing-ci-builds.adoc | 2 + .rhdh/scripts/install-rhdh-catalog-source.sh | 79 +++++++++++++++++++- 2 files changed, 80 insertions(+), 1 deletion(-) diff --git a/.rhdh/docs/installing-ci-builds.adoc b/.rhdh/docs/installing-ci-builds.adoc index 2ffd3455e..82e6c7aec 100644 --- a/.rhdh/docs/installing-ci-builds.adoc +++ b/.rhdh/docs/installing-ci-builds.adoc @@ -44,6 +44,8 @@ chmod +x install-rhdh-catalog-source.sh # install catalog source and operator subscription, for the latest downstream stable, RC or GA build from the release-1.yy branch ./install-rhdh-catalog-source.sh --latest --install-operator rhdh +# quieter by default; use --debug or --log-level debug for verbose output + # OR, install catalog source and operator subscription, for the next donwstream CI build from the main branch ./install-rhdh-catalog-source.sh --next --install-operator rhdh ---- diff --git a/.rhdh/scripts/install-rhdh-catalog-source.sh b/.rhdh/scripts/install-rhdh-catalog-source.sh index 8172e970d..7e3e2a453 100755 --- a/.rhdh/scripts/install-rhdh-catalog-source.sh +++ b/.rhdh/scripts/install-rhdh-catalog-source.sh @@ -6,6 +6,10 @@ set -euo pipefail +LOG_LEVEL="${LOG_LEVEL:-info}" +LOG_FILE="" + + NC='\033[0m' IS_OPENSHIFT="" @@ -34,6 +38,10 @@ function logf() { local msg=$3 local fullMsg="[${prefix}] ${msg}" + if [[ -n "${LOG_FILE}" ]]; then + printf '%s\n' "${fullMsg}" >> "${LOG_FILE}" + fi + if [[ "$TERM" == *"color"* ]]; then echo -e "${color}${fullMsg}${NC}" else @@ -50,7 +58,9 @@ function warnf() { } function debugf() { - logf "DEBUG" "\033[0;90m" "$1" + if [[ "${LOG_LEVEL}" == "debug" ]]; then + logf "DEBUG" "\033[0;90m" "$1" + fi } function errorf() { @@ -80,6 +90,8 @@ Options: --install-operator : Install operator named \$NAME after creating CatalogSource --install-plan-approval : Specify the install plan strategy for the subscription (default: Automatic) --olm-version v0|v1|auto : Force OLM version for catalog/operator resources (default: auto-detect) + --log-level error|warn|info|debug : Log verbosity (default: info) + --debug : Same as --log-level debug Examples: $0 \\ @@ -160,6 +172,14 @@ function resolve_olm_version() { fi } +function dump_logs_on_error() { + local rc=$? + if [[ "${rc}" -ne 0 && -n "${LOG_FILE}" && -f "${LOG_FILE}" ]]; then + echo "[ERROR] Command failed (exit ${rc}). Full log:" >&2 + cat "${LOG_FILE}" >&2 || true + fi +} + # On failure, print ClusterCatalog / ClusterExtension status so CI logs show why Serving/Installed never became True. function dump_olm_v1_diagnostics() { local catalog_name="${1:-}" @@ -810,6 +830,40 @@ if [[ "$#" -lt 1 ]]; then exit 0 fi +for arg in "$@"; do + case "$arg" in + -h|--help) + usage + exit 0 + ;; + esac +done + +args=("$@") +for ((i=0; i<${#args[@]}; i++)); do + case "${args[$i]}" in + --debug) + LOG_LEVEL="debug" + ;; + --log-level) + if [[ $((i+1)) -ge ${#args[@]} ]]; then + errorf "--log-level requires a value: error, warn, info, or debug." + usage + exit 1 + fi + LOG_LEVEL="${args[$((i+1))]}" + case "${LOG_LEVEL}" in + error|warn|info|debug) ;; + *) + errorf "Unknown log level: ${LOG_LEVEL}. Must be error, warn, info, or debug." + usage + exit 1 + ;; + esac + ;; + esac +done + # minimum requirements if ! command -v jq &> /dev/null; then errorf "Please install jq 1.2+ from an RPM or https://pypi.org/project/jq/" @@ -821,10 +875,13 @@ if ! command -v skopeo &> /dev/null; then fi TMPDIR=$(mktemp -d) +LOG_FILE="${TMPDIR}/install.log" +touch "${LOG_FILE}" pushd "${TMPDIR}" > /dev/null debugf ">>> WORKING DIR: $TMPDIR <<<" # shellcheck disable=SC2064 +trap dump_logs_on_error ERR trap "rm -fr '$TMPDIR' || true; jobs -p | xargs -r kill 2>/dev/null; wait 2>/dev/null" EXIT trap "exit 1" INT TERM @@ -921,6 +978,26 @@ while [[ "$#" -gt 0 ]]; do OLM_VERSION="$2" shift 1 ;; + '--debug') + LOG_LEVEL="debug" + ;; + '--log-level') + if [[ $# -lt 2 ]]; then + errorf "--log-level requires a value: error, warn, info, or debug." + usage + exit 1 + fi + case "$2" in + error|warn|info|debug) ;; + *) + errorf "Unknown log level: $2. Must be error, warn, info, or debug." + usage + exit 1 + ;; + esac + LOG_LEVEL="$2" + shift 1 + ;; '-h'|'--help') usage exit 0 From 0c60be316682d9b90c087dbb8e46044fa1b7e211 Mon Sep 17 00:00:00 2001 From: NiallTwomey2 Date: Tue, 29 Sep 2026 15:14:28 +0100 Subject: [PATCH 2/6] fix: relocate shellcheck --- .rhdh/scripts/install-rhdh-catalog-source.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.rhdh/scripts/install-rhdh-catalog-source.sh b/.rhdh/scripts/install-rhdh-catalog-source.sh index 7e3e2a453..b9b8a8096 100755 --- a/.rhdh/scripts/install-rhdh-catalog-source.sh +++ b/.rhdh/scripts/install-rhdh-catalog-source.sh @@ -880,8 +880,8 @@ touch "${LOG_FILE}" pushd "${TMPDIR}" > /dev/null debugf ">>> WORKING DIR: $TMPDIR <<<" -# shellcheck disable=SC2064 trap dump_logs_on_error ERR +# shellcheck disable=SC2064 trap "rm -fr '$TMPDIR' || true; jobs -p | xargs -r kill 2>/dev/null; wait 2>/dev/null" EXIT trap "exit 1" INT TERM From 136b9311cd55f5edccc8cb9c5795db762b263ef0 Mon Sep 17 00:00:00 2001 From: NiallTwomey2 Date: Mon, 5 Oct 2026 15:13:35 +0100 Subject: [PATCH 3/6] fix: removing {LOG_FILE}, removing the --debug option to simplify --log-level to set verbosity --- .rhdh/docs/installing-ci-builds.adoc | 2 +- .rhdh/scripts/install-rhdh-catalog-source.sh | 199 +++++++++---------- 2 files changed, 92 insertions(+), 109 deletions(-) diff --git a/.rhdh/docs/installing-ci-builds.adoc b/.rhdh/docs/installing-ci-builds.adoc index 82e6c7aec..a543873f8 100644 --- a/.rhdh/docs/installing-ci-builds.adoc +++ b/.rhdh/docs/installing-ci-builds.adoc @@ -44,7 +44,7 @@ chmod +x install-rhdh-catalog-source.sh # install catalog source and operator subscription, for the latest downstream stable, RC or GA build from the release-1.yy branch ./install-rhdh-catalog-source.sh --latest --install-operator rhdh -# quieter by default; use --debug or --log-level debug for verbose output +# add --log-level debug for verbose output # OR, install catalog source and operator subscription, for the next donwstream CI build from the main branch ./install-rhdh-catalog-source.sh --next --install-operator rhdh diff --git a/.rhdh/scripts/install-rhdh-catalog-source.sh b/.rhdh/scripts/install-rhdh-catalog-source.sh index b9b8a8096..5fe2b6086 100755 --- a/.rhdh/scripts/install-rhdh-catalog-source.sh +++ b/.rhdh/scripts/install-rhdh-catalog-source.sh @@ -7,7 +7,7 @@ set -euo pipefail LOG_LEVEL="${LOG_LEVEL:-info}" -LOG_FILE="" + NC='\033[0m' @@ -38,8 +38,24 @@ function logf() { local msg=$3 local fullMsg="[${prefix}] ${msg}" - if [[ -n "${LOG_FILE}" ]]; then - printf '%s\n' "${fullMsg}" >> "${LOG_FILE}" + local msg_rank=2 + case "${prefix}" in + ERROR) msg_rank=0 ;; + WARN) msg_rank=1 ;; + INFO) msg_rank=2 ;; + DEBUG) msg_rank=3 ;; + esac + + local current_rank=2 + case "${LOG_LEVEL}" in + error) current_rank=0 ;; + warn) current_rank=1 ;; + info) current_rank=2 ;; + debug) current_rank=3 ;; + esac + + if [[ "${msg_rank}" -gt "${current_rank}" ]]; then + return 0 fi if [[ "$TERM" == *"color"* ]]; then @@ -58,9 +74,7 @@ function warnf() { } function debugf() { - if [[ "${LOG_LEVEL}" == "debug" ]]; then logf "DEBUG" "\033[0;90m" "$1" - fi } function errorf() { @@ -91,7 +105,6 @@ Options: --install-plan-approval : Specify the install plan strategy for the subscription (default: Automatic) --olm-version v0|v1|auto : Force OLM version for catalog/operator resources (default: auto-detect) --log-level error|warn|info|debug : Log verbosity (default: info) - --debug : Same as --log-level debug Examples: $0 \\ @@ -172,12 +185,12 @@ function resolve_olm_version() { fi } -function dump_logs_on_error() { - local rc=$? - if [[ "${rc}" -ne 0 && -n "${LOG_FILE}" && -f "${LOG_FILE}" ]]; then - echo "[ERROR] Command failed (exit ${rc}). Full log:" >&2 - cat "${LOG_FILE}" >&2 || true - fi + + +function cleanup() { + rm -fr "${TMPDIR}" || true + jobs -p | xargs -r kill 2>/dev/null || true + wait 2>/dev/null || true } # On failure, print ClusterCatalog / ClusterExtension status so CI logs show why Serving/Installed never became True. @@ -839,98 +852,8 @@ for arg in "$@"; do esac done -args=("$@") -for ((i=0; i<${#args[@]}; i++)); do - case "${args[$i]}" in - --debug) - LOG_LEVEL="debug" - ;; - --log-level) - if [[ $((i+1)) -ge ${#args[@]} ]]; then - errorf "--log-level requires a value: error, warn, info, or debug." - usage - exit 1 - fi - LOG_LEVEL="${args[$((i+1))]}" - case "${LOG_LEVEL}" in - error|warn|info|debug) ;; - *) - errorf "Unknown log level: ${LOG_LEVEL}. Must be error, warn, info, or debug." - usage - exit 1 - ;; - esac - ;; - esac -done - -# minimum requirements -if ! command -v jq &> /dev/null; then - errorf "Please install jq 1.2+ from an RPM or https://pypi.org/project/jq/" - exit 1 -fi -if ! command -v skopeo &> /dev/null; then - errorf "Please install skopeo 1.11+" - exit 1 -fi - -TMPDIR=$(mktemp -d) -LOG_FILE="${TMPDIR}/install.log" -touch "${LOG_FILE}" -pushd "${TMPDIR}" > /dev/null -debugf ">>> WORKING DIR: $TMPDIR <<<" - -trap dump_logs_on_error ERR -# shellcheck disable=SC2064 -trap "rm -fr '$TMPDIR' || true; jobs -p | xargs -r kill 2>/dev/null; wait 2>/dev/null" EXIT -trap "exit 1" INT TERM - -detect_ocp_and_set_env_var -if [[ "${IS_OPENSHIFT}" = "true" ]]; then - debugf "Detected an OpenShift cluster" - if ! command -v oc &> /dev/null; then - errorf "Please install oc 4.10+ from an RPM or https://mirror.openshift.com/pub/openshift-v4/clients/ocp/" - exit 1 - fi - # Check we're logged into a cluster - if ! oc whoami &> /dev/null; then - errorf "Not logged into an OpenShift cluster" - exit 1 - fi -else - if ! command -v oc &> /dev/null && ! command -v kubectl &> /dev/null; then - errorf "Please install kubectl or invoke_cluster_cli 4.10+ (from an RPM or https://mirror.openshift.com/pub/openshift-v4/clients/ocp/)" - exit 1 - fi - debugf "Falling back to a standard K8s cluster" - # Check that OLM is installed (v0 or v1) - if ! invoke_cluster_cli get crd catalogsources.operators.coreos.com &> /dev/null && \ - ! invoke_cluster_cli get crd clusterextensions.olm.operatorframework.io &> /dev/null; then - errorf " -OLM not installed (neither CatalogSource nor ClusterExtension CRD found) or you don't have enough permissions. -Check that you are correctly logged into the cluster and that OLM is installed. -See https://olm.operatorframework.io/docs/getting-started/#installing-olm-in-your-cluster to install OLM." - exit 1 - fi -fi - -OCP_VER="v4.21" -OCP_ARCH="x86_64" -if [[ "${IS_OPENSHIFT}" = "true" ]]; then - # log into your OCP cluster before running this or you'll get null values for OCP vars! - ocpVerJson=$(invoke_cluster_cli version -o json) - OCP_VER="v$(echo "$ocpVerJson" | jq -r '.openshiftVersion' | sed -r -e "s#([0-9]+\.[0-9]+)\..+#\1#")" - if [[ $OCP_VER == "vnull" ]]; then # try releaseClientVersion = 4.16.14 - OCP_VER="v$(echo "$ocpVerJson" | jq -r '.releaseClientVersion' | sed -r -e "s#([0-9]+\.[0-9]+)\..+#\1#")" - fi - OCP_ARCH="$(echo "$ocpVerJson" | jq -r '.serverVersion.platform' | sed -r -e "s#linux/##")" - if [[ $OCP_ARCH == "amd64" ]]; then - OCP_ARCH="x86_64" - fi -fi - # if logged in, this should return something like latest-v4.12-x86_64 -IIB_TAG="latest-${OCP_VER}-${OCP_ARCH}" +IIB_STREAM="latest" TO_INSTALL="" while [[ "$#" -gt 0 ]]; do @@ -941,10 +864,10 @@ while [[ "$#" -gt 0 ]]; do ;; '--next'|'--latest') # if logged in, this should return something like latest-v4.12-x86_64 or next-v4.12-x86_64 - IIB_TAG="${1/--/}-${OCP_VER}-$OCP_ARCH" + IIB_STREAM="${1/--/}" ;; '-v') - IIB_TAG="${2}-${OCP_VER}-$OCP_ARCH" + IIB_STREAM="${2}" OLM_CHANNEL="fast-${2}" shift 1 ;; @@ -978,9 +901,6 @@ while [[ "$#" -gt 0 ]]; do OLM_VERSION="$2" shift 1 ;; - '--debug') - LOG_LEVEL="debug" - ;; '--log-level') if [[ $# -lt 2 ]]; then errorf "--log-level requires a value: error, warn, info, or debug." @@ -1011,6 +931,69 @@ while [[ "$#" -gt 0 ]]; do shift 1 done +# minimum requirements +if ! command -v jq &> /dev/null; then + errorf "Please install jq 1.2+ from an RPM or https://pypi.org/project/jq/" + exit 1 +fi +if ! command -v skopeo &> /dev/null; then + errorf "Please install skopeo 1.11+" + exit 1 +fi + +TMPDIR=$(mktemp -d) +pushd "${TMPDIR}" > /dev/null +debugf ">>> WORKING DIR: $TMPDIR <<<" + +trap cleanup EXIT +trap "exit 1" INT TERM + +detect_ocp_and_set_env_var +if [[ "${IS_OPENSHIFT}" = "true" ]]; then + debugf "Detected an OpenShift cluster" + if ! command -v oc &> /dev/null; then + errorf "Please install oc 4.10+ from an RPM or https://mirror.openshift.com/pub/openshift-v4/clients/ocp/" + exit 1 + fi + # Check we're logged into a cluster + if ! oc whoami &> /dev/null; then + errorf "Not logged into an OpenShift cluster" + exit 1 + fi +else + if ! command -v oc &> /dev/null && ! command -v kubectl &> /dev/null; then + errorf "Please install kubectl or invoke_cluster_cli 4.10+ (from an RPM or https://mirror.openshift.com/pub/openshift-v4/clients/ocp/)" + exit 1 + fi + debugf "Falling back to a standard K8s cluster" + # Check that OLM is installed (v0 or v1) + if ! invoke_cluster_cli get crd catalogsources.operators.coreos.com &> /dev/null && \ + ! invoke_cluster_cli get crd clusterextensions.olm.operatorframework.io &> /dev/null; then + errorf " +OLM not installed (neither CatalogSource nor ClusterExtension CRD found) or you don't have enough permissions. +Check that you are correctly logged into the cluster and that OLM is installed. +See https://olm.operatorframework.io/docs/getting-started/#installing-olm-in-your-cluster to install OLM." + exit 1 + fi +fi + +OCP_VER="v4.21" +OCP_ARCH="x86_64" +if [[ "${IS_OPENSHIFT}" = "true" ]]; then + # log into your OCP cluster before running this or you'll get null values for OCP vars! + ocpVerJson=$(invoke_cluster_cli version -o json) + OCP_VER="v$(echo "$ocpVerJson" | jq -r '.openshiftVersion' | sed -r -e "s#([0-9]+\.[0-9]+)\..+#\1#")" + if [[ $OCP_VER == "vnull" ]]; then # try releaseClientVersion = 4.16.14 + OCP_VER="v$(echo "$ocpVerJson" | jq -r '.releaseClientVersion' | sed -r -e "s#([0-9]+\.[0-9]+)\..+#\1#")" + fi + OCP_ARCH="$(echo "$ocpVerJson" | jq -r '.serverVersion.platform' | sed -r -e "s#linux/##")" + if [[ $OCP_ARCH == "amd64" ]]; then + OCP_ARCH="x86_64" + fi +fi + +IIB_TAG="${IIB_STREAM}-${OCP_VER}-${OCP_ARCH}" + if [[ $UPSTREAM_IIB_OVERRIDE ]]; then UPSTREAM_IIB="$UPSTREAM_IIB_OVERRIDE" else From c4968e953d803fc537c54f401b39ba4d2bd88a4e Mon Sep 17 00:00:00 2001 From: NiallTwomey2 Date: Thu, 15 Oct 2026 09:15:13 +0100 Subject: [PATCH 4/6] fix: hide subcommand noise unless using the --log-level debug option Signed-off-by: NiallTwomey2 --- .rhdh/scripts/install-rhdh-catalog-source.sh | 81 ++++++++++++-------- 1 file changed, 51 insertions(+), 30 deletions(-) diff --git a/.rhdh/scripts/install-rhdh-catalog-source.sh b/.rhdh/scripts/install-rhdh-catalog-source.sh index 5fe2b6086..dff573707 100755 --- a/.rhdh/scripts/install-rhdh-catalog-source.sh +++ b/.rhdh/scripts/install-rhdh-catalog-source.sh @@ -7,13 +7,8 @@ set -euo pipefail LOG_LEVEL="${LOG_LEVEL:-info}" - - - NC='\033[0m' - IS_OPENSHIFT="" - NAMESPACE_SUBSCRIPTION="rhdh-operator" if [[ -n "${CI_X_VERSION:-}" && -n "${CI_Y_VERSION:-}" ]]; then OLM_CHANNEL="fast-${CI_X_VERSION}.${CI_Y_VERSION}" @@ -44,6 +39,8 @@ function logf() { WARN) msg_rank=1 ;; INFO) msg_rank=2 ;; DEBUG) msg_rank=3 ;; + *) + ;; esac local current_rank=2 @@ -52,6 +49,8 @@ function logf() { warn) current_rank=1 ;; info) current_rank=2 ;; debug) current_rank=3 ;; + *) + ;; esac if [[ "${msg_rank}" -gt "${current_rank}" ]]; then @@ -74,13 +73,34 @@ function warnf() { } function debugf() { - logf "DEBUG" "\033[0;90m" "$1" + logf "DEBUG" "\033[0;90m" "$1" } function errorf() { logf "ERROR" "\033[0;31m" "$1" } +# Run a command. At debug, stream it. Otherwise hide stdout/stderr, +# and print the captured output only if the command fails. +function run_cmd() { + local out rc + if [[ "${LOG_LEVEL}" == "debug" ]]; then + "$@" + return $? + fi + out="$(mktemp)" + set +e + "$@" >"${out}" 2>&1 + rc=$? + set -e + if [[ "${rc}" -ne 0 ]]; then + errorf "Command failed (${rc}): $*" + cat "${out}" >&2 + fi + rm -f "${out}" + return "${rc}" +} + function usage() { echo " This script streamlines testing IIB images by configuring an OpenShift or Kubernetes cluster to enable it to use the specified IIB image @@ -299,7 +319,11 @@ function render_iib() { mkdir -p "${TMPDIR}/rhdh/rhdh" debugf "Rendering IIB $UPSTREAM_IIB as a local file..." - opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml" + if [[ "${LOG_LEVEL}" == "debug" ]]; then + opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml" + else + opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml" 2>/dev/null + fi if [ ! -s "${TMPDIR}/rhdh/rhdh/render.yaml" ]; then errorf " [ERROR] 'opm render $UPSTREAM_IIB' returned an empty output, which likely means that this IIB Image does not contain any operators in it. @@ -357,7 +381,7 @@ function process_bundle() { local pull_attempt local pull_ok=false for pull_attempt in $(seq 1 "$max_retries"); do - if skopeo copy "docker://$bundleImg" "oci:./${bundle_dir}/src:latest" 2>"${bundle_dir}/copy.err"; then + if run_cmd skopeo copy "docker://$bundleImg" "oci:./${bundle_dir}/src:latest"; then pull_ok=true break fi @@ -365,12 +389,12 @@ function process_bundle() { sleep "$retry_delay" done if [[ "$pull_ok" != "true" ]]; then - debugf "bundle #${bundle_id}: skopeo copy failed after ${max_retries} attempts, skipping (see ${bundle_dir}/copy.err)" >&2 + debugf "bundle #${bundle_id}: skopeo copy failed after ${max_retries} attempts, skipping" >&2 return 0 fi debugf "bundle #${bundle_id}: pulled ${bundleImg}" >&2 - umoci unpack --image "./${bundle_dir}/src:latest" "./${bundle_dir}/unpacked" --rootless + run_cmd umoci unpack --image "./${bundle_dir}/src:latest" "./${bundle_dir}/unpacked" --rootless for folder in manifests metadata; do for file in "./${bundle_dir}/unpacked/rootfs/${folder}"/*; do @@ -382,13 +406,13 @@ function process_bundle() { done done - umoci repack --image "./${bundle_dir}/src:latest" "./${bundle_dir}/unpacked" + run_cmd umoci repack --image "./${bundle_dir}/src:latest" "./${bundle_dir}/unpacked" local newBundleImage="${my_registry}/rhdh/rhdh-operator-bundle:${digest}" local push_attempt local push_ok=false for push_attempt in $(seq 1 "$max_retries"); do - if skopeo copy --dest-tls-verify=false "oci:./${bundle_dir}/src:latest" "docker://${newBundleImage}" 2>"${bundle_dir}/push.err"; then + if run_cmd skopeo copy --dest-tls-verify=false "oci:./${bundle_dir}/src:latest" "docker://${newBundleImage}"; then push_ok=true break fi @@ -396,7 +420,7 @@ function process_bundle() { sleep "$retry_delay" done if [[ "$push_ok" != "true" ]]; then - errorf "bundle #${bundle_id}: push to registry failed after ${max_retries} attempts (see ${bundle_dir}/push.err)" >&2 + errorf "bundle #${bundle_id}: push to registry failed after ${max_retries} attempts" >&2 return 1 fi debugf "bundle #${bundle_id}: pushed to ${newBundleImage}" >&2 @@ -475,7 +499,7 @@ function update_refs_in_iib_bundles() { fi debugf "Regenerating IIB Dockerfile with updated refs..." >&2 - opm generate dockerfile rhdh/rhdh + run_cmd opm generate dockerfile rhdh/rhdh } # Enabling the route does not mean that the router and registry backends are ready. @@ -527,6 +551,7 @@ function ocp_install() { if ! my_registry=$(wait_for_ocp_registry); then return 1 fi + run_cmd skopeo login -u kubeadmin -p "$(oc whoami -t)" --tls-verify=false "$my_registry" oc -n openshift-marketplace delete secret internal-reg-auth-for-rhdh --ignore-not-found >&2 oc -n openshift-marketplace delete secret internal-reg-ext-auth-for-rhdh --ignore-not-found >&2 oc -n openshift-marketplace create secret docker-registry internal-reg-ext-auth-for-rhdh \ @@ -559,10 +584,10 @@ function ocp_install() { debugf "Submitting in-cluster build request for the updated IIB..." >&2 if ! oc -n rhdh get buildconfig.build.openshift.io/iib >& /dev/null; then - oc -n rhdh new-build --strategy docker --binary --name iib >&2 + run_cmd oc -n rhdh new-build --strategy docker --binary --name iib fi oc -n rhdh patch buildconfig.build.openshift.io/iib -p '{"spec": {"strategy": {"dockerStrategy": {"dockerfilePath": "rhdh.Dockerfile"}}}}' >&2 - oc -n rhdh start-build iib --wait --follow --from-dir=rhdh >&2 + run_cmd oc -n rhdh start-build iib --wait --follow --from-dir=rhdh local imageStreamWithTag="rhdh/iib:${IIB_TAG}" oc tag rhdh/iib:latest "${imageStreamWithTag}" >&2 @@ -722,7 +747,7 @@ EOF debugf "Port-forwarding from localhost:${portFwdLocalPort} to the cluster registry..." >&2 local internal_registry_url internal_registry_url="localhost:${registrySvcNodePort}" - skopeo login -u "${username}" -p "${password}" --tls-verify=false "localhost:$portFwdLocalPort" >&2 + run_cmd skopeo login -u "${username}" -p "${password}" --tls-verify=false "localhost:$portFwdLocalPort" local kaniko_internal_registry_url kaniko_internal_registry_url="${registry_name}.${namespace}.svc.cluster.local:5000" @@ -822,15 +847,20 @@ EOF return 1 fi debugf "Waiting for Kaniko pod $kanikoPod to be ready..." >&2 - invoke_cluster_cli -n "${namespace}" wait --for=condition=Ready "pod/$kanikoPod" --timeout=60s >&2 - invoke_cluster_cli -n "${namespace}" logs -f "${kanikoPod}" >&2 & + + run_cmd invoke_cluster_cli -n "${namespace}" wait --for=condition=Ready "pod/$kanikoPod" --timeout=60s + if [[ "${LOG_LEVEL}" == "debug" ]]; then + invoke_cluster_cli -n "${namespace}" logs -f "${kanikoPod}" >&2 & + fi localContext=context.tar.gz tar -czf "${localContext}" -C rhdh . >&2 invoke_cluster_cli -n "${namespace}" cp "${localContext}" "${kanikoPod}:/workspace/${localContext}" >&2 - invoke_cluster_cli -n "${namespace}" wait --for=condition=complete "job/${kanikoJobName}" --timeout=300s >&2 - + if ! run_cmd invoke_cluster_cli -n "${namespace}" wait --for=condition=complete "job/${kanikoJobName}" --timeout=300s; then + invoke_cluster_cli -n "${namespace}" logs "${kanikoPod}" >&2 + return 1 + fi debugf "IIB built and pushed to internal cluster registry: $result..." >&2 printf "%s" "${result}" } @@ -843,15 +873,6 @@ if [[ "$#" -lt 1 ]]; then exit 0 fi -for arg in "$@"; do - case "$arg" in - -h|--help) - usage - exit 0 - ;; - esac -done - # if logged in, this should return something like latest-v4.12-x86_64 IIB_STREAM="latest" TO_INSTALL="" From ff04aeb3ed8ac0813b399135aefe71307efc798b Mon Sep 17 00:00:00 2001 From: NiallTwomey2 Date: Fri, 16 Oct 2026 17:54:06 +0100 Subject: [PATCH 5/6] fix: keep and redirect the opm render errors and remove security vulnerability for run_cmd Signed-off-by: NiallTwomey2 --- .rhdh/scripts/install-rhdh-catalog-source.sh | 21 +++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/.rhdh/scripts/install-rhdh-catalog-source.sh b/.rhdh/scripts/install-rhdh-catalog-source.sh index dff573707..9db54dd56 100755 --- a/.rhdh/scripts/install-rhdh-catalog-source.sh +++ b/.rhdh/scripts/install-rhdh-catalog-source.sh @@ -83,18 +83,15 @@ function errorf() { # Run a command. At debug, stream it. Otherwise hide stdout/stderr, # and print the captured output only if the command fails. function run_cmd() { - local out rc + local out rc=0 if [[ "${LOG_LEVEL}" == "debug" ]]; then "$@" return $? fi out="$(mktemp)" - set +e - "$@" >"${out}" 2>&1 - rc=$? - set -e + "$@" >"${out}" 2>&1 || rc=$? if [[ "${rc}" -ne 0 ]]; then - errorf "Command failed (${rc}): $*" + errorf "Command failed (${rc})" cat "${out}" >&2 fi rm -f "${out}" @@ -205,8 +202,6 @@ function resolve_olm_version() { fi } - - function cleanup() { rm -fr "${TMPDIR}" || true jobs -p | xargs -r kill 2>/dev/null || true @@ -319,11 +314,19 @@ function render_iib() { mkdir -p "${TMPDIR}/rhdh/rhdh" debugf "Rendering IIB $UPSTREAM_IIB as a local file..." + local render_err + render_err="$(mktemp)" if [[ "${LOG_LEVEL}" == "debug" ]]; then opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml" else - opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml" 2>/dev/null + if ! opm render "$UPSTREAM_IIB" --output=yaml > "${TMPDIR}/rhdh/rhdh/render.yaml" 2>"${render_err}"; then + errorf "opm render failed" + cat "${render_err}" >&2 + rm -f "${render_err}" + return 1 + fi fi + rm -f "${render_err}" if [ ! -s "${TMPDIR}/rhdh/rhdh/render.yaml" ]; then errorf " [ERROR] 'opm render $UPSTREAM_IIB' returned an empty output, which likely means that this IIB Image does not contain any operators in it. From bb33e291bb8f7a7db66780aab208baff4bd8bd71 Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Wed, 28 Oct 2026 22:01:44 +0100 Subject: [PATCH 6/6] Apply batched suggestions from code review Co-authored-by: Armel Soro --- .rhdh/scripts/install-rhdh-catalog-source.sh | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.rhdh/scripts/install-rhdh-catalog-source.sh b/.rhdh/scripts/install-rhdh-catalog-source.sh index 9db54dd56..b2ca7ecdc 100755 --- a/.rhdh/scripts/install-rhdh-catalog-source.sh +++ b/.rhdh/scripts/install-rhdh-catalog-source.sh @@ -876,7 +876,6 @@ if [[ "$#" -lt 1 ]]; then exit 0 fi -# if logged in, this should return something like latest-v4.12-x86_64 IIB_STREAM="latest" TO_INSTALL="" @@ -887,7 +886,6 @@ while [[ "$#" -gt 0 ]]; do shift 1 ;; '--next'|'--latest') - # if logged in, this should return something like latest-v4.12-x86_64 or next-v4.12-x86_64 IIB_STREAM="${1/--/}" ;; '-v') @@ -1016,6 +1014,7 @@ if [[ "${IS_OPENSHIFT}" = "true" ]]; then fi fi +# if logged in, this should return something like latest-v4.22-x86_64 IIB_TAG="${IIB_STREAM}-${OCP_VER}-${OCP_ARCH}" if [[ $UPSTREAM_IIB_OVERRIDE ]]; then