From d932df50290d55bf9202f5973790f86a7e41b367 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 f48ac50c6..af6a162a8 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" @@ -210,8 +211,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 cd28252acc9be3c7ec2b59a94fcc6cc7ecbebc40 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 af6a162a8..8de65b02d 100755 --- a/.rhdh/scripts/prepare-restricted-environment.sh +++ b/.rhdh/scripts/prepare-restricted-environment.sh @@ -1123,9 +1123,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 dba04aa0c31f962bdf6013fedccc46d4635ff74f 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 8de65b02d..c9973cf26 100755 --- a/.rhdh/scripts/prepare-restricted-environment.sh +++ b/.rhdh/scripts/prepare-restricted-environment.sh @@ -1135,7 +1135,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}]'