From 97240dc9b3e174c3392706e4492f2a92efee7bbb Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Mon, 31 Mar 2025 18:24:40 +0200 Subject: [PATCH 1/3] fix: Detect if the OCP cluster has a hosted control plane or not This will allow the script to handle situations where there can be limitations on the kind of resources that can be created/updated/deleted --- .rhdh/scripts/prepare-restricted-environment.sh | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/.rhdh/scripts/prepare-restricted-environment.sh b/.rhdh/scripts/prepare-restricted-environment.sh index 77ded80de..e1d2ee3d4 100755 --- a/.rhdh/scripts/prepare-restricted-environment.sh +++ b/.rhdh/scripts/prepare-restricted-environment.sh @@ -11,6 +11,7 @@ SCRIPT_PATH=$(realpath "$0") NC='\033[0m' IS_OPENSHIFT="" +IS_HOSTED_CONTROL_PLANE="" NAMESPACE_SUBSCRIPTION="rhdh-operator" NAMESPACE_OPERATOR="rhdh-operator" @@ -217,8 +218,22 @@ function is_openshift() { function detect_ocp_and_set_env_var() { set -euo pipefail - if [[ "${IS_OPENSHIFT}" = "" ]]; then + if [[ -z "${IS_OPENSHIFT}" ]]; then IS_OPENSHIFT=$(is_openshift && echo 'true' || echo 'false') + debugf "IS_OPENSHIFT: ${IS_OPENSHIFT}" + fi + if [[ "${IS_OPENSHIFT}" == "true" ]] && [[ -z "${IS_HOSTED_CONTROL_PLANE}" ]]; then + local cpTech + cpTech=$(oc get infrastructure cluster -o jsonpath='{.status.controlPlaneTopology}' || \ + (warnf 'Could not determine the cluster type => defaulting to the hosted control plane behavior' >&2 && echo 'External')) + if [[ "${cpTech}" == "External" ]]; then + # 'External' indicates that the control plane is hosted externally to the cluster + # and that its components are not visible within the cluster. + IS_HOSTED_CONTROL_PLANE="true" + else + IS_HOSTED_CONTROL_PLANE="false" + fi + debugf "IS_HOSTED_CONTROL_PLANE: ${IS_HOSTED_CONTROL_PLANE}" fi } From ffc58a1e56c5964564354e3e926aaafcabe0be6d Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Mon, 31 Mar 2025 18:25:45 +0200 Subject: [PATCH 2/3] fix: Skip the creation of the IDMS resource on clusters with hosted control planes, like ROSA or HyperShift They actually never worked on such clusters (but were still being created), so it should be safe to skip that part. --- .rhdh/scripts/prepare-restricted-environment.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.rhdh/scripts/prepare-restricted-environment.sh b/.rhdh/scripts/prepare-restricted-environment.sh index e1d2ee3d4..55f2b54ae 100755 --- a/.rhdh/scripts/prepare-restricted-environment.sh +++ b/.rhdh/scripts/prepare-restricted-environment.sh @@ -1139,9 +1139,12 @@ EOF EOF done - # Create the IDMS (OCP-specific) and CatalogSource - if [[ "${IS_OPENSHIFT}" = "true" ]]; then - invoke_cluster_cli apply -f "${manifestsTargetDir}/imageDigestMirrorSet.yaml" + # Create the IDMS (OCP-specific) and CatalogSource. + # IDMS resources never really worked on clusters with hosted control planes, and it looks like it is no longer + # possible to create them in ROSA/HyperShift 4.18. So skipping the IDMS creation for such clusters. + # More details in https://issues.redhat.com/browse/RHIDP-6684 + if [[ "${IS_OPENSHIFT}" == "true" ]] && [[ "${IS_HOSTED_CONTROL_PLANE}" != "true" ]]; then + invoke_cluster_cli apply -f "${manifestsTargetDir}/imageDigestMirrorSet.yaml" fi debugf "Adding the internal cluster creds as pull secrets to be able to pull images from this internal registry by default" invoke_cluster_cli apply -f "${manifestsTargetDir}/catalogSource.yaml" From b1ee2b5d6a3fdaa1074302ff25ea9683f39d389c Mon Sep 17 00:00:00 2001 From: Armel Soro Date: Mon, 31 Mar 2025 18:26:33 +0200 Subject: [PATCH 3/3] fix: Skip disabling default sources of the cluster-wide OperatorHub resource on clusters with hosted control planes, like ROSA or HyperShift This also appears to be restricted on such clusters --- .rhdh/scripts/prepare-restricted-environment.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.rhdh/scripts/prepare-restricted-environment.sh b/.rhdh/scripts/prepare-restricted-environment.sh index 55f2b54ae..7e2b88989 100755 --- a/.rhdh/scripts/prepare-restricted-environment.sh +++ b/.rhdh/scripts/prepare-restricted-environment.sh @@ -1151,7 +1151,9 @@ EOF fi fi -if [[ -n "${TO_REGISTRY}" && "${IS_OPENSHIFT}" = "true" ]]; then +# No longer possible to patch the OperatorHub resource on clusters with hosted control planes (ROSA 4.18). +# More details in https://issues.redhat.com/browse/OCPBUGS-43431?focusedId=26463911&page=com.atlassian.jira.plugin.system.issuetabpanels%3Acomment-tabpanel#comment-26463911 +if [[ -n "${TO_REGISTRY}" ]] && [[ "${IS_OPENSHIFT}" == "true" ]] && [[ "${IS_HOSTED_CONTROL_PLANE}" != "true" ]]; then infof "Disabling the default Red Hat Ecosystem Catalog." invoke_cluster_cli patch OperatorHub cluster --type json \ --patch '[{"op": "add", "path": "/spec/disableAllDefaultSources", "value": true}]'