diff --git a/.ci/pipelines/install-methods/operator.sh b/.ci/pipelines/install-methods/operator.sh index 844fa26f78..52f1d06bb9 100755 --- a/.ci/pipelines/install-methods/operator.sh +++ b/.ci/pipelines/install-methods/operator.sh @@ -212,14 +212,23 @@ deploy_rhdh_operator() { # Verify Backstage CRD is available k8s_wait::crd "backstages.rhdh.redhat.com" 60 5 || return 1 - rendered_yaml=$(envsubst < "$backstage_crd_path") + rendered_yaml=$(envsubst < "$backstage_crd_path") || { + log::error "Failed to render Backstage CR from $backstage_crd_path" + return 1 + } if [[ -n "${CATALOG_INDEX_IMAGE:-}" ]]; then # Dynamically inject CATALOG_INDEX_IMAGE environment variable if specified - rendered_yaml=$(echo "$rendered_yaml" | yq eval '.spec.application.extraEnvs.envs += [{"name": "CATALOG_INDEX_IMAGE", "value": "'"$CATALOG_INDEX_IMAGE"'", "containers": ["install-dynamic-plugins"]}]' -) + rendered_yaml=$(echo "$rendered_yaml" | yq eval '.spec.application.extraEnvs.envs += [{"name": "CATALOG_INDEX_IMAGE", "value": "'"$CATALOG_INDEX_IMAGE"'", "containers": ["install-dynamic-plugins"]}]' -) || { + log::error "Failed to inject CATALOG_INDEX_IMAGE into the Backstage CR" + return 1 + } fi log::info "Applying Backstage CR from: $backstage_crd_path" log::debug "$rendered_yaml" - echo "$rendered_yaml" | oc apply -f - -n "$namespace" + echo "$rendered_yaml" | oc apply -f - -n "$namespace" || { + log::error "Failed to apply Backstage CR from $backstage_crd_path in $namespace" + return 1 + } # Wait for the operator to create the Backstage deployment (5 minutes max) if ! common::poll_until \ diff --git a/.ci/pipelines/jobs/ocp-disconnected-helm.sh b/.ci/pipelines/jobs/ocp-disconnected-helm.sh index d4ef2a0872..fab8e5604b 100644 --- a/.ci/pipelines/jobs/ocp-disconnected-helm.sh +++ b/.ci/pipelines/jobs/ocp-disconnected-helm.sh @@ -121,6 +121,9 @@ handle_ocp_disconnected_helm() { disconnected::patch_idms "${OC_MIRROR_IDMS_FILE}" + local machineconfigpool_snapshot + machineconfigpool_snapshot=$(disconnected::snapshot_machineconfigpool_rendered_configs) || return 1 + oc apply -f "${OC_MIRROR_IDMS_FILE}" || { log::error "Failed to apply IDMS — aborting" return 1 @@ -138,29 +141,35 @@ handle_ocp_disconnected_helm() { # IDMS/ITMS changes trigger a MachineConfig update which rolls worker nodes # (drain → apply config → reboot). Wait for all MachineConfigPools to finish # before deploying workloads, otherwise pods get evicted mid-startup. - disconnected::wait_mcp_updated + disconnected::wait_machineconfigpool_updated "${machineconfigpool_snapshot}" || return 1 log::section "Plugin Mirroring" disconnected::mirror_plugins || return 1 # Pin CATALOG_INDEX_IMAGE to the digest actually pushed (hub profile default - # digest is often absent from the mirror). Homepage package is the digest-pinned - # OCI exported as HOMEPAGE_PLUGIN_PACKAGE (ref:// cannot resolve with includes: []). + # digest is often absent from the mirror). mirror_plugins exported the + # digest-pinned OCI package for each smoke plugin (ref:// cannot resolve with + # includes: []). disconnected::resolve_catalog_index_image || return 1 log::section "Namespace and Secrets" namespace::configure "${NAME_SPACE}" + disconnected::allow_mirror_registry_egress "${NAME_SPACE}" || return 1 if [[ "${LOCAL_DISCONNECTED:-}" == "1" ]]; then disconnected::ensure_local_image_pull_access "${NAME_SPACE}" || return 1 fi disconnected::apply_plugin_mirror_configmap "${NAME_SPACE}" || return 1 - # Mirror CA + registry auth for install-dynamic-plugins (skopeo). - # Post-renderer mounts CA at /etc/containers/certs.d//ca.crt; - # the chart mounts ${RELEASE_NAME}-dynamic-plugins-registry-auth at - # /opt/app-root/src/.config/containers. + # Mirror CA + registry auth for install-dynamic-plugins (skopeo). The + # post-renderer mounts the CA at /etc/containers/certs.d//ca.crt; the + # chart mounts -dynamic-plugins-registry-auth (optional: true) at + # /opt/app-root/src/.config/containers, where fullname is - + # and nameOverride is pinned to developer-hub in the values file. A differently + # named secret leaves the init container without auth.json and the mirror pull + # fails with "authentication required". disconnected::create_mirror_registry_ca_configmap "${NAME_SPACE}" || return 1 - disconnected::create_plugin_registry_auth_secret "${NAME_SPACE}" || return 1 + disconnected::create_plugin_registry_auth_secret "${NAME_SPACE}" \ + "${RELEASE_NAME}-developer-hub-dynamic-plugins-registry-auth" || return 1 log::section "Helm Deployment" @@ -205,11 +214,8 @@ handle_ocp_disconnected_helm() { # to the rendered Deployment, avoiding the Helm "array clobber" pitfall. local post_renderer="${DIR}/resources/disconnected/helm-post-renderer.sh" local helm_values="${DISCONNECTED_TMPDIR}/values_disconnected-smoke.yaml" - common::require_vars HOMEPAGE_PLUGIN_PACKAGE || return 1 - envsubst < "${DIR}/value_files/values_disconnected-smoke.yaml" > "${helm_values}" || { - log::error "Failed to render disconnected Helm values" - return 1 - } + disconnected::render_smoke_plugins_template \ + "${DIR}/value_files/values_disconnected-smoke.yaml" "${helm_values}" || return 1 cp "${helm_values}" "${ARTIFACT_DIR}/values_disconnected-smoke.yaml" 2> /dev/null || true helm upgrade -i "${RELEASE_NAME}" -n "${NAME_SPACE}" \ diff --git a/.ci/pipelines/jobs/ocp-disconnected-operator.sh b/.ci/pipelines/jobs/ocp-disconnected-operator.sh index 8146802b9b..f4dc6f3cb6 100644 --- a/.ci/pipelines/jobs/ocp-disconnected-operator.sh +++ b/.ci/pipelines/jobs/ocp-disconnected-operator.sh @@ -38,8 +38,7 @@ handle_ocp_disconnected_operator() { log::section "Operator Mirroring and Installation" # Fetch prepare-restricted-environment.sh from RELEASE_BRANCH_NAME (default - # main). rhdh-operator#3259 (native oc-mirror cc-* catalogs for OLM v1) is - # merged on main. + # main). local prepare_script_path="${DISCONNECTED_TMPDIR}/prepare-restricted-environment.sh" disconnected::fetch_operator_repo_script "prepare-restricted-environment.sh" \ "${prepare_script_path}" || { @@ -51,32 +50,11 @@ handle_ocp_disconnected_operator() { # default skopeo/umoci/podman-build path. Nested Podman in this CI pod cannot # initialize storage (newuidmap / VFS chown both fail under hostUsers: false). # CATALOG_INDEX_IMAGE is the plugin catalog index — do not pass it as - # --index-image (OLM operator catalog). Used only for mirror-plugins.sh below, - # then cleared so deploy does not inject :next defaults onto the GA hub. + # --index-image (OLM operator catalog). It is consumed by mirror-plugins.sh and + # injected into the Backstage CR by deploy_rhdh_operator. # # OLM version: leave default (auto). On OCP 4.21+ this selects OLM v1. - local filter_versions="${RELEASE_VERSION}" - if [[ "${filter_versions}" == "next" || "${filter_versions}" == "*" ]]; then - filter_versions="*" - fi - - # Mirroring every historical RHDH operator version (* / next) is unnecessary - # for smoke and flakes on quay CDN EOF (CI) or overwhelms the integrated - # registry (local). Pin to the chart major.minor (e.g. 2.0-80-CI → 2.0). - # Release branches already pass a concrete version (e.g. 1.9) and skip this. - if [[ "${filter_versions}" == "*" ]]; then - local chart_mm="" - if [[ -n "${CHART_VERSION:-}" && "${CHART_VERSION}" =~ ^([0-9]+\.[0-9]+) ]]; then - chart_mm="${BASH_REMATCH[1]}" - fi - if [[ -z "${chart_mm}" ]]; then - log::error "Cannot derive --filter-versions from CHART_VERSION='${CHART_VERSION:-unset}'; expected major.minor prefix (e.g. 2.0-80-CI)" - return 1 - fi - filter_versions="${chart_mm}" - log::info "filter-versions=${filter_versions} (from CHART_VERSION=${CHART_VERSION})" - fi - + # # CONTAINER_PLATFORM_VERSION is set by e2e-tests/container-init.sh from the # live cluster (oc version → major.minor). local ocp_version="${CONTAINER_PLATFORM_VERSION:-}" @@ -84,8 +62,62 @@ handle_ocp_disconnected_operator() { log::error "CONTAINER_PLATFORM_VERSION is unset or invalid ('${ocp_version}'); expected OpenShift major.minor" return 1 fi - local index_image="registry.redhat.io/redhat/redhat-operator-index:v${ocp_version}" - log::info "Using OCP ${ocp_version} (CONTAINER_PLATFORM_VERSION); index image ${index_image}" + + # A GA verification run (registry.redhat.io with a released x.y.z chart) pairs + # with the published Red Hat catalog. Every other run mirrors the CI catalog + # built from the same commit as the hub and plugin catalogs. + local filter_versions="" + local index_image="" + local registries_conf="" + if [[ "${IMAGE_REGISTRY}" == "registry.redhat.io" || "${CHART_VERSION:-}" != *-CI ]]; then + # The published catalog declares defaultChannel fast, and oc-mirror rejects a + # channels list that leaves the default channel out, so mirror every version + # of the rhdh package instead of filtering. + filter_versions="*" + index_image="registry.redhat.io/redhat/redhat-operator-index:v${ocp_version}" + log::warn "GA verification: ${index_image} without a version filter mirrors every RHDH operator version" + else + # The operator stream follows the checkout branch: main mirrors the 2.2 + # bundles, release-2.1 the 2.1 ones. TAG_NAME, IMAGE_* and CHART_VERSION do + # not change it: the hub image comes from the bundle, so only the newest + # bundle of the branch's stream can be tested. An unfiltered catalog would + # pull every historical version. + filter_versions=$(common::get_release_stream) || return 1 + log::info "filter-versions=${filter_versions} (from RELEASE_BRANCH_NAME=${RELEASE_BRANCH_NAME})" + + # rhdh-operator publishes one catalog per stream and OCP minor, e.g. + # quay.io/rhdh/iib:2.2-v4.21-x86_64 (amd64 only; the jobs run on amd64). The + # tag follows filter_versions, so the tag and --filter-versions cannot + # disagree, and a stream without a published catalog fails here instead of in + # oc-mirror. + index_image="quay.io/rhdh/iib:${filter_versions}-v${ocp_version}-x86_64" + skopeo inspect --raw "docker://${index_image}" > /dev/null || { + log::error "RHDH CI operator catalog ${index_image} not found or unreadable" + return 1 + } + log::info "Operator and hub come from the newest ${filter_versions} bundle in ${index_image}; TAG_NAME/IMAGE_* do not apply" + + # The CI bundle's RELATED_IMAGE refs point at registry.redhat.io/rhdh/* + # (plus the stage/access aliases), whose digests exist on quay.io/rhdh only. + # Rewrite those pulls for the oc-mirror run via CONTAINERS_REGISTRIES_CONF. + # Images in other repositories (e.g. registry.redhat.io/rhel10/postgresql-18) + # keep their original source and are pulled with the CI credentials. + registries_conf="${DISCONNECTED_TMPDIR}/oc-mirror-registries.conf" + cat > "${registries_conf}" << 'EOF' +[[registry]] +prefix = "registry.redhat.io/rhdh" +location = "quay.io/rhdh" + +[[registry]] +prefix = "registry.stage.redhat.io/rhdh" +location = "quay.io/rhdh" + +[[registry]] +prefix = "registry.access.redhat.com/rhdh" +location = "quay.io/rhdh" +EOF + fi + log::info "Using OCP ${ocp_version} (CONTAINER_PLATFORM_VERSION); index image ${index_image}; filter-versions ${filter_versions}" # Local connected OCP: OCP_INTERNAL sentinel (same as omit-on-OCP). CI bastion # keeps the external MIRROR_REGISTRY_URL. Route URL stays in MIRROR_REGISTRY_URL @@ -115,18 +147,32 @@ handle_ocp_disconnected_operator() { # external registries. Catalogd must trust the mirror CA and authenticate # before ClusterCatalog can reach Serving=True. Skip on LOCAL_DISCONNECTED — # OCP_INTERNAL path configures internal registry trust itself. + local machineconfigpool_snapshot if [[ "${LOCAL_DISCONNECTED:-}" != "1" ]]; then + # Snapshot before the additionalTrustedCA patch: it also rolls the nodes. + machineconfigpool_snapshot=$(disconnected::snapshot_machineconfigpool_rendered_configs) || return 1 + disconnected::ensure_olm_mirror_pull_secret || return 1 disconnected::ensure_mirror_registry_ca || return 1 - disconnected::wait_mcp_updated + disconnected::wait_machineconfigpool_updated "${machineconfigpool_snapshot}" || return 1 else log::info "LOCAL_DISCONNECTED=1: skipping external bastion CA/pull-secret pre-prepare helpers" fi + local -a prepare_cmd=(bash "${prepare_script_path}" "${prepare_args[@]}") + if [[ -n "${registries_conf}" ]]; then + # Scoped to this call: CATALOG_INDEX_IMAGE and the plugin pulls keep their + # own registry configuration. + prepare_cmd=(env CONTAINERS_REGISTRIES_CONF="${registries_conf}" "${prepare_cmd[@]}") + log::info "Redirecting registry.redhat.io/rhdh to quay.io/rhdh via ${registries_conf}" + fi + + machineconfigpool_snapshot=$(disconnected::snapshot_machineconfigpool_rendered_configs) || return 1 + log::info "Running prepare-restricted-environment.sh with: ${prepare_args[*]}" if ! disconnected::retry_on_local_registry 5 \ disconnected::with_unset_registry_auth_file \ - bash "${prepare_script_path}" "${prepare_args[@]}"; then + "${prepare_cmd[@]}"; then log::error "prepare-restricted-environment.sh failed — aborting" return 1 fi @@ -162,7 +208,7 @@ handle_ocp_disconnected_operator() { # prepare-restricted-environment.sh applies IDMS/CatalogSource which triggers # a MachineConfig update and node rolling. Wait for completion before deploying # workloads, same as the Helm path. - disconnected::wait_mcp_updated + disconnected::wait_machineconfigpool_updated "${machineconfigpool_snapshot}" || return 1 if [[ "${LOCAL_DISCONNECTED:-}" == "1" ]]; then # Catalogd needs the registry + image-puller grants above before Serving=True. @@ -193,13 +239,15 @@ handle_ocp_disconnected_operator() { disconnected::mirror_plugins || return 1 # Pin CATALOG_INDEX_IMAGE to the digest actually pushed (hub profile default - # digest is often absent from the mirror). Homepage package is the digest-pinned - # OCI exported as HOMEPAGE_PLUGIN_PACKAGE (ref:// cannot resolve with includes: []). + # digest is often absent from the mirror). mirror_plugins exported the + # digest-pinned OCI package for each smoke plugin (ref:// cannot resolve with + # includes: []). disconnected::resolve_catalog_index_image || return 1 log::section "Namespace and Secrets" namespace::configure "${NAME_SPACE}" + disconnected::allow_mirror_registry_egress "${NAME_SPACE}" || return 1 if [[ "${LOCAL_DISCONNECTED:-}" == "1" ]]; then disconnected::ensure_local_image_pull_access "${NAME_SPACE}" || return 1 fi @@ -208,7 +256,7 @@ handle_ocp_disconnected_operator() { # from the mirror (registries.conf alone is not enough — TLS verify fails). disconnected::create_mirror_registry_ca_configmap "${NAME_SPACE}" || return 1 disconnected::create_plugin_registry_auth_secret "${NAME_SPACE}" || return 1 - disconnected::create_homepage_plugins_configmap "${NAME_SPACE}" || return 1 + disconnected::create_smoke_plugins_configmap "${NAME_SPACE}" || return 1 # Operator mounts one volume per extraFiles ConfigMap name. policy.json cannot # share rhdh-plugin-mirror-conf or reconcile fails with duplicate volume keys. @@ -240,7 +288,11 @@ handle_ocp_disconnected_operator() { cp "${cr_temp}" "${ARTIFACT_DIR}/disconnected-backstage-cr.yaml" 2> /dev/null || true - deploy_rhdh_operator "${NAME_SPACE}" "${cr_temp}" + deploy_rhdh_operator "${NAME_SPACE}" "${cr_temp}" || { + log::error "deploy_rhdh_operator failed in ${NAME_SPACE} — dumping OLM v1 status" + disconnected::dump_olm_v1_status "rhdh-operator" + return 1 + } log::success "Backstage CR deployed in ${NAME_SPACE}" log::section "Smoke Test" diff --git a/.ci/pipelines/jobs/upgrade.sh b/.ci/pipelines/jobs/upgrade.sh index 5b39f85150..997a309de5 100644 --- a/.ci/pipelines/jobs/upgrade.sh +++ b/.ci/pipelines/jobs/upgrade.sh @@ -98,7 +98,7 @@ handle_ocp_helm_upgrade() { # Resolve the previous release's chart and values for the baseline deployment. local current_release_version previous_release_version - current_release_version=$(helm::get_chart_stream) + current_release_version=$(common::get_release_stream) if [[ -z "$current_release_version" ]]; then log::error "Failed to determine current release version. Exiting." save_overall_result 1 diff --git a/.ci/pipelines/lib/README.md b/.ci/pipelines/lib/README.md index 14652fe092..9f3d429cf3 100644 --- a/.ci/pipelines/lib/README.md +++ b/.ci/pipelines/lib/README.md @@ -14,7 +14,8 @@ Functions: `log::info`, `log::warn`, `log::error`, `log::success`, `log::debug`, Common utilities. -Functions: `common::oc_login`, `common::sed_inplace`, `common::get_previous_release_version` +Functions: `common::oc_login`, `common::sed_inplace`, `common::get_release_stream`, +`common::get_previous_release_version` ### `k8s-wait.sh` diff --git a/.ci/pipelines/lib/common.sh b/.ci/pipelines/lib/common.sh index 324627e7c4..723c20fa46 100644 --- a/.ci/pipelines/lib/common.sh +++ b/.ci/pipelines/lib/common.sh @@ -1,7 +1,7 @@ #!/usr/bin/env bash # Common utility functions for pipeline scripts -# Dependencies: oc, kubectl, lib/log.sh +# Dependencies: oc, kubectl, jq, lib/log.sh if [[ -n "${COMMON_LIB_SOURCED:-}" ]]; then return 0 @@ -72,6 +72,51 @@ common::sed_inplace() { return $? } +# Get the release stream this run belongs to: a major.minor pair like "1.10", +# not a bare major. 'main' takes it from package.json; 'release-x.y' from the +# branch name. +# Args: +# $1 - (optional) version_override: Specific stream to use (e.g., "1.8" for upgrade base) +# Returns: +# Prints the stream (e.g., "1.10") +common::get_release_stream() { + local version_override=${1:-} + + if [[ -n "$version_override" ]]; then + echo "$version_override" + return 0 + fi + + if [[ -z "${RELEASE_BRANCH_NAME:-}" ]]; then + log::error "RELEASE_BRANCH_NAME is not set" + return 1 + fi + + if [[ "$RELEASE_BRANCH_NAME" == "main" ]]; then + # main carries no version in its name. The published tags cannot answer + # this either - they hold every stream anyone pushed, so "highest on quay" + # follows whichever stream is ahead, not this checkout's. + local package_json="${DIR}/../../package.json" + if [[ ! -f "$package_json" ]]; then + log::error "Cannot determine the release stream: ${package_json} not found" + return 1 + fi + + local release_stream + release_stream=$(jq -r '.version // empty' "$package_json" | grep -oE '^[0-9]+\.[0-9]+') + if [[ -z "$release_stream" ]]; then + log::error "Cannot determine the release stream: no usable .version in ${package_json}" + return 1 + fi + echo "$release_stream" + elif echo "$RELEASE_BRANCH_NAME" | grep -qE '^release-[0-9]+\.[0-9]+$'; then + echo "$RELEASE_BRANCH_NAME" | grep -oE '[0-9]+\.[0-9]+' + else + log::error "Invalid RELEASE_BRANCH_NAME: $RELEASE_BRANCH_NAME (expected 'main' or 'release-x.y')" + return 1 + fi +} + # Find the highest existing release branch below the current version. # Usage: prev=$(common::get_previous_release_version "1.6") # Returns: "1.5" # prev=$(common::get_previous_release_version "2.0") # Returns: "1.10" diff --git a/.ci/pipelines/lib/disconnected.sh b/.ci/pipelines/lib/disconnected.sh index f8b5b45f71..734addcdbc 100644 --- a/.ci/pipelines/lib/disconnected.sh +++ b/.ci/pipelines/lib/disconnected.sh @@ -55,7 +55,9 @@ export -f disconnected::cluster_mirror_host export -f disconnected::build_imageset_config export -f disconnected::run_oc_mirror export -f disconnected::patch_idms -export -f disconnected::wait_mcp_updated +export -f disconnected::snapshot_machineconfigpool_rendered_configs +export -f disconnected::_machineconfigpool_all_converged +export -f disconnected::wait_machineconfigpool_updated export -f disconnected::_hook_should_add_hub_image export -f disconnected::_hook_adjust_oc_mirror_args export -f disconnected::_hook_run_oc_mirror @@ -63,10 +65,13 @@ export -f disconnected::_hook_rewrite_mirror_host # plugins.sh export -f disconnected::mirror_plugins export -f disconnected::resolve_catalog_index_image -export -f disconnected::create_homepage_plugins_configmap +export -f disconnected::create_smoke_plugins_configmap export -f disconnected::apply_plugin_mirror_configmap export -f disconnected::write_digest_plugin_list -export -f disconnected::set_homepage_plugin_package_from_list +export -f disconnected::write_smoke_plugin_list +export -f disconnected::set_smoke_plugin_packages_from_list +export -f disconnected::render_smoke_plugins_template +export -f disconnected::_smoke_plugin_package_var export -f disconnected::copy_catalog_index_to_mirror export -f disconnected::_catalog_index_source_ref export -f disconnected::_catalog_index_mirror_dest @@ -75,6 +80,7 @@ export -f disconnected::_hook_catalog_index_exports # namespace.sh export -f disconnected::create_mirror_registry_ca_configmap export -f disconnected::create_plugin_registry_auth_secret +export -f disconnected::allow_mirror_registry_egress export -f disconnected::ensure_mirror_registry_ca export -f disconnected::ensure_olm_mirror_pull_secret # operator.sh diff --git a/.ci/pipelines/lib/disconnected/helm.sh b/.ci/pipelines/lib/disconnected/helm.sh index ae9e2c192a..76be44fb32 100644 --- a/.ci/pipelines/lib/disconnected/helm.sh +++ b/.ci/pipelines/lib/disconnected/helm.sh @@ -10,16 +10,17 @@ readonly _DISCONNECTED_HELM_SOURCED=1 # it. Wait for Postgres Ready, then bounce the hub only if it is not Available. # No-op when the hub becomes Ready after Postgres (typical local timing). # -# The bounce uses a rolling `oc rollout restart deployment` (never `oc delete -# pod`): a pod-delete restart was observed to coincide with the PostgreSQL -# StatefulSet pod being rescheduled, which on AWS triggers a slow (~5 min) -# EBS CSI volume detach/re-attach (FailedAttachVolume) and cascades into a -# smoke-test timeout. A rollout restart only touches the hub Deployment. +# The bounce scales the Deployment to 0 and back to 1 instead of using +# `oc rollout restart`: a rolling restart runs two backends against the freshly +# initialised database, which race on the knex migration lock and leave the +# loser never Ready. The wait gives a pod that is still extracting plugins up to +# the grace period to start its backend before the hub is considered stuck. # Args: # $1 - namespace # $2 - Helm release name (default: rhdh) # $3 - Postgres Ready timeout seconds (default: 600) -# $4 - Hub Available grace seconds before restart (default: 180) +# $4 - Hub grace seconds: waits this long for the backend container to start, +# then this long again for the Deployment to become Available (default: 180) # $5 - Hub rollout timeout seconds after restart (default: 420) disconnected::ensure_helm_hub_after_postgres() { local namespace=$1 @@ -35,6 +36,7 @@ disconnected::ensure_helm_hub_after_postgres() { local pg_pod="${release_name}-postgresql-0" local hub_deploy="${release_name}-developer-hub" + local hub_selector="app.kubernetes.io/name=developer-hub" local pg_ready=0 local start=$SECONDS @@ -58,6 +60,24 @@ disconnected::ensure_helm_hub_after_postgres() { return 1 fi + log::info "Waiting for the hub backend container to start (timeout ${hub_grace}s)..." + local backend_started=0 + start=$SECONDS + while ((SECONDS - start < hub_grace)); do + local backend_state + backend_state=$(oc get pods -n "${namespace}" -l "${hub_selector}" \ + -o jsonpath='{range .items[*].status.containerStatuses[?(@.name=="backstage-backend")]}{.started}{"\n"}{end}' \ + 2> /dev/null || true) + if grep -q true <<< "${backend_state}"; then + backend_started=1 + break + fi + sleep 5 + done + if [[ "${backend_started}" -ne 1 ]]; then + log::warn "Hub backend did not start within ${hub_grace}s; checking deployment availability anyway" + fi + if oc wait --for=condition=Available "deployment/${hub_deploy}" \ -n "${namespace}" --timeout="${hub_grace}s"; then log::success "Hub ${hub_deploy} already Available — skipping restart" @@ -66,8 +86,20 @@ disconnected::ensure_helm_hub_after_postgres() { log::warn "Hub ${hub_deploy} not Available after Postgres Ready — restarting to recover from DB connect race" oc get pods -n "${namespace}" || true - if ! oc rollout restart "deployment/${hub_deploy}" -n "${namespace}"; then - log::error "Failed to restart deployment/${hub_deploy} in ${namespace}" + if ! oc scale "deployment/${hub_deploy}" --replicas=0 -n "${namespace}"; then + log::error "Failed to scale deployment/${hub_deploy} down in ${namespace}" + return 1 + fi + # Wait for the old pod to be gone before starting the replacement, otherwise + # both backends initialise at once. kubectl treats --for=delete as satisfied + # when nothing matches, so this only fails while a pod is still there. + if ! oc wait --for=delete pod -l "${hub_selector}" -n "${namespace}" --timeout=180s; then + log::error "Old hub pods still present after 180s — not scaling up next to them" + oc get pods -l "${hub_selector}" -n "${namespace}" -o wide || true + return 1 + fi + if ! oc scale "deployment/${hub_deploy}" --replicas=1 -n "${namespace}"; then + log::error "Failed to scale deployment/${hub_deploy} back up in ${namespace}" return 1 fi if ! oc rollout status "deployment/${hub_deploy}" -n "${namespace}" --timeout="${rollout_timeout}s"; then diff --git a/.ci/pipelines/lib/disconnected/local.sh b/.ci/pipelines/lib/disconnected/local.sh index 6d99bee71f..40d0440613 100644 --- a/.ci/pipelines/lib/disconnected/local.sh +++ b/.ci/pipelines/lib/disconnected/local.sh @@ -7,7 +7,7 @@ # registry.sh integrated-registry bring-up, retry-on-503, MIRROR_* bootstrap # access.sh mirror push-target projects, workload + OLM pull access # mirror-host.sh IDMS/ITMS push-route -> in-cluster registry service rewrite -# plugins.sh homepage-only mirror_plugins override + imagestream tags +# plugins.sh smoke-plugin mirror_plugins override + imagestream tags [[ -n "${_DISCONNECTED_LOCAL_SOURCED:-}" ]] && return 0 readonly _DISCONNECTED_LOCAL_SOURCED=1 diff --git a/.ci/pipelines/lib/disconnected/local/plugins.sh b/.ci/pipelines/lib/disconnected/local/plugins.sh index 2cb87fbfc7..0d89e2a4eb 100644 --- a/.ci/pipelines/lib/disconnected/local/plugins.sh +++ b/.ci/pipelines/lib/disconnected/local/plugins.sh @@ -1,12 +1,12 @@ #!/usr/bin/env bash -# LOCAL_DISCONNECTED plugin mirroring: homepage-only mirror_plugins override +# LOCAL_DISCONNECTED plugin mirroring: smoke-plugin mirror_plugins override # (retry loop, skopeo catalog copy, imagestream tagging). Sourced only when # LOCAL_DISCONNECTED=1. [[ -n "${_DISCONNECTED_LOCAL_PLUGINS_SOURCED:-}" ]] && return 0 readonly _DISCONNECTED_LOCAL_PLUGINS_SOURCED=1 -# Full override: homepage-only plugin list, retry loop, skopeo catalog copy, +# Full override: smoke plugin list, retry loop, skopeo catalog copy, # summary handling, and imagestream tagging. disconnected::mirror_plugins() { local mirror_script="${DISCONNECTED_TMPDIR}/mirror-plugins.sh" @@ -19,10 +19,8 @@ disconnected::mirror_plugins() { local plugin_index plugin_index="oci://$(disconnected::_catalog_index_source_ref)" - local list_file="${DISCONNECTED_TMPDIR}/homepage-plugins.txt" - disconnected::write_digest_plugin_list "${plugin_index}" "${list_file}" \ - "${DISCONNECTED_HOMEPAGE_PLUGIN_NAME}" || return 1 - disconnected::set_homepage_plugin_package_from_list "${list_file}" || return 1 + local list_file="${DISCONNECTED_TMPDIR}/smoke-plugins.txt" + disconnected::write_smoke_plugin_list "${list_file}" || return 1 # --plugin-list only (not --plugin-index): index mode re-adds fragile tags. # Catalog index is mirrored after plugins so the summary still records it. @@ -40,7 +38,7 @@ disconnected::mirror_plugins() { log::warn "mirror-plugins.sh attempt ${attempt}/${max_attempts} failed (registry 503 during Recreate is typical)" done if [[ "${mirrored}" != "1" ]]; then - log::error "mirror-plugins.sh (homepage plugin list) failed after ${max_attempts} attempts -- aborting" + log::error "mirror-plugins.sh (smoke plugin list) failed after ${max_attempts} attempts -- aborting" return 1 fi diff --git a/.ci/pipelines/lib/disconnected/mirror.sh b/.ci/pipelines/lib/disconnected/mirror.sh index b572c615b5..7d435a4ddb 100644 --- a/.ci/pipelines/lib/disconnected/mirror.sh +++ b/.ci/pipelines/lib/disconnected/mirror.sh @@ -1,6 +1,6 @@ #!/usr/bin/env bash -# oc-mirror image mirroring, IDMS/ITMS patching, and MCP wait helpers. +# oc-mirror image mirroring, IDMS/ITMS patching, and MachineConfigPool wait helpers. [[ -n "${_DISCONNECTED_MIRROR_SOURCED:-}" ]] && return 0 readonly _DISCONNECTED_MIRROR_SOURCED=1 @@ -256,13 +256,98 @@ disconnected::patch_idms() { cp "${idms_file}" "${ARTIFACT_DIR}/disconnected-idms-patched.yaml" 2> /dev/null || true } +# Record the rendered MachineConfig every pool currently targets. Fails when the +# read fails or returns nothing, so a caller cannot mistake a broken API call for +# an unchanged cluster. +disconnected::snapshot_machineconfigpool_rendered_configs() { + local attempt snapshot="" + for attempt in 1 2 3; do + if snapshot=$(oc get machineconfigpool \ + -o jsonpath='{range .items[*]}{.metadata.name}={.spec.configuration.name}{"\n"}{end}' \ + 2> /dev/null) && [[ -n "${snapshot}" ]]; then + printf '%s\n' "${snapshot}" + return 0 + fi + log::debug "MachineConfigPool snapshot failed (attempt ${attempt}/3)" + if ((attempt < 3)); then + sleep 5 + fi + done + log::error "Could not read the MachineConfigPool rendered configs" + return 1 +} + +# True when every MachineConfigPool runs its rendered config and no node is +# still updating or degraded. +disconnected::_machineconfigpool_all_converged() { + local snapshot + snapshot=$(oc get machineconfigpool \ + -o jsonpath='{range .items[*]}{.spec.configuration.name}{"|"}{.status.configuration.name}{"|"}{.status.updatedMachineCount}{"|"}{.status.machineCount}{"|"}{.status.degradedMachineCount}{"\n"}{end}' \ + 2> /dev/null) || return 1 + [[ -n "${snapshot}" ]] || return 1 + + local spec_name status_name updated total degraded + while IFS='|' read -r spec_name status_name updated total degraded; do + if [[ "${spec_name}" != "${status_name}" || + "${updated}" != "${total}" || + "${degraded:-0}" != "0" ]]; then + return 1 + fi + done <<< "${snapshot}" + return 0 +} + # Wait for MachineConfigPool updates after IDMS/CatalogSource changes. -# Warns and continues on timeout (same behavior as both handlers historically). -disconnected::wait_mcp_updated() { - log::info "Waiting for MachineConfigPool updates to complete (up to 20m)..." - if oc wait machineconfigpool --all --for=condition=Updated=True --timeout=20m; then - log::success "All MachineConfigPools are Updated" - else - log::warn "MachineConfigPool wait timed out -- proceeding anyway" +# +# `oc wait --for=condition=Updated=True` alone is not enough: right after an +# apply the MCO has not rendered the new config yet, so the condition is still +# True from the previous rollout and the wait returns immediately. With the +# snapshot taken before the change, wait until the MCO picks it up first. A +# config rendered while the rollout is still running is covered: each pool's spec +# moves to the newest render, and convergence compares status against it. +# +# Warns and continues on rollout timeout. +# Args: +# $1 - snapshot from disconnected::snapshot_machineconfigpool_rendered_configs +disconnected::wait_machineconfigpool_updated() { + local before_snapshot=$1 + local render_timeout=180 + local rollout_timeout=1200 + + if [[ -z "${before_snapshot}" ]]; then + log::error "wait_machineconfigpool_updated needs the pre-change MachineConfigPool snapshot" + return 1 + fi + + log::info "Waiting for MachineConfigPool to pick up the new rendered config (up to ${render_timeout}s)..." + local rendered=0 render_start=$SECONDS current="" + while ((SECONDS - render_start < render_timeout)); do + # A failed read is not a change; retry on the next iteration. + if current=$(disconnected::snapshot_machineconfigpool_rendered_configs) \ + && [[ "${current}" != "${before_snapshot}" ]]; then + rendered=1 + break + fi + sleep 5 + done + if ((rendered != 1)); then + # Re-applying identical content (e.g. an unchanged IDMS) does not roll + # the nodes, so there is nothing to wait for. + log::warn "No MachineConfigPool rendered a new config within ${render_timeout}s -- nothing to roll, continuing" + return 0 fi + log::success "MachineConfigPool picked up the new rendered config" + + log::info "Waiting for MachineConfigPool updates to complete (up to ${rollout_timeout}s)..." + local rollout_start=$SECONDS + while ((SECONDS - rollout_start < rollout_timeout)); do + if disconnected::_machineconfigpool_all_converged; then + log::success "All MachineConfigPools are Updated" + return 0 + fi + sleep 10 + done + + log::warn "MachineConfigPool wait timed out -- proceeding anyway" + oc get machineconfigpool 2>&1 | tee -a "${ARTIFACT_DIR}/disconnected-machineconfigpool-status.txt" || true } diff --git a/.ci/pipelines/lib/disconnected/namespace.sh b/.ci/pipelines/lib/disconnected/namespace.sh index 1f6158de14..1ba61c90bf 100644 --- a/.ci/pipelines/lib/disconnected/namespace.sh +++ b/.ci/pipelines/lib/disconnected/namespace.sh @@ -44,7 +44,8 @@ disconnected::create_plugin_registry_auth_secret() { # Ensure the mirror registry CA is trusted cluster-wide via # image.config.openshift.io/cluster additionalTrustedCA so OLM v1 catalogd # can pull ClusterCatalog images (x509 unknown authority otherwise). -# Triggers an MCP update; callers should run disconnected::wait_mcp_updated after. +# Triggers a MachineConfigPool update; callers should run +# disconnected::wait_machineconfigpool_updated after. disconnected::ensure_mirror_registry_ca() { local registry_host="${MIRROR_REGISTRY_URL%%/*}" # OpenShift ConfigMap keys use ".." in place of ":" for host:port. @@ -116,3 +117,78 @@ disconnected::ensure_olm_mirror_pull_secret() { } log::success "Merged mirror registry credentials into openshift-config/pull-secret" } + +# Allow backend egress to the mirror registry. The chart and the Operator both +# default-deny backend egress except DNS, HTTPS, Redis, and PostgreSQL, while CI +# mirrors serve TLS on a non-443 port: the install-dynamic-plugins init container +# (skopeo catalog/plugin pulls) times out without this rule. Kubelet pulls are +# unaffected. NetworkPolicies are additive and separate selectors cover the Helm +# chart and the Operator pod labels (same split as +# resources/network_policy/netpol-ci-allow-backend-egress.yaml). +# +# The rule is scoped by port only. MIRROR_REGISTRY_URL is the bastion's public +# EC2 DNS name, which resolves to a different address from the CI pod and from +# inside the cluster, so there is no stable ipBlock to use. The namespace is +# ephemeral and the connected CI lanes allow all egress, so the port is the +# meaningful boundary here. +# Mirrors served on 443 (e.g. the LOCAL_DISCONNECTED route) need no extra rule. +# Args: +# $1 - namespace +disconnected::allow_mirror_registry_egress() { + local namespace=$1 + local registry_host="${MIRROR_REGISTRY_URL%%/*}" + local registry_port="" + + if [[ "${registry_host}" =~ :([0-9]+)$ ]]; then + registry_port="${BASH_REMATCH[1]}" + fi + + if [[ -z "${registry_port}" || "${registry_port}" == "443" ]]; then + log::info "Mirror registry ${registry_host} is served on port 443; skipping dedicated egress rule" + return 0 + fi + + local policy_file="${DISCONNECTED_TMPDIR}/netpol-mirror-registry-egress.yaml" + cat > "${policy_file}" << EOF +# Allow backend egress to the CI mirror registry (${registry_host}). +# install-dynamic-plugins pulls the catalog index and plugins from this port. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: rhdh-mirror-registry-egress +spec: + podSelector: + matchLabels: + app.kubernetes.io/name: developer-hub + app.kubernetes.io/component: backstage + policyTypes: + - Egress + egress: + - ports: + - port: ${registry_port} + protocol: TCP +--- +# Operator Backend pods derive rhdh.redhat.com/app from the Backstage CR name. +apiVersion: networking.k8s.io/v1 +kind: NetworkPolicy +metadata: + name: rhdh-operator-mirror-registry-egress +spec: + podSelector: + matchLabels: + rhdh.redhat.com/app: backstage-${RELEASE_NAME} + policyTypes: + - Egress + egress: + - ports: + - port: ${registry_port} + protocol: TCP +EOF + + oc apply -f "${policy_file}" -n "${namespace}" || { + log::error "Failed to apply mirror registry egress NetworkPolicy in ${namespace}" + return 1 + } + cp "${policy_file}" "${ARTIFACT_DIR}/disconnected-netpol-mirror-registry-egress.yaml" 2> /dev/null || true + log::success "NetworkPolicy allows backend egress to ${registry_host} in ${namespace}" +} diff --git a/.ci/pipelines/lib/disconnected/operator.sh b/.ci/pipelines/lib/disconnected/operator.sh index eb056234c3..75f1121684 100644 --- a/.ci/pipelines/lib/disconnected/operator.sh +++ b/.ci/pipelines/lib/disconnected/operator.sh @@ -21,6 +21,10 @@ disconnected::dump_olm_v1_status() { } # Wait for OLM v1 ClusterExtension to report Installed, then for the CRD. +# +# A half-failed OLM v1 install still leaves the CRD behind (the bundle is applied +# as a Helm chart), so the CRD alone is not proof of success. Require +# Installed=True as well. # Args: # $1 - extension name (default: rhdh-operator) # $2 - crd name (default: backstages.rhdh.redhat.com) @@ -32,33 +36,30 @@ disconnected::wait_operator_crd_olm_v1() { local interval=15 local elapsed=0 - log::info "Waiting for ClusterExtension/${extension_name} and CRD ${crd_name} (timeout: ${timeout}s)..." + log::info "Waiting for ClusterExtension/${extension_name} Installed=True and CRD ${crd_name} (timeout: ${timeout}s)..." while ((elapsed < timeout)); do - if oc get crd "${crd_name}" > /dev/null 2>&1; then - log::success "CRD '${crd_name}' is available" - return 0 - fi - local installed installed=$(oc get clusterextension "${extension_name}" \ -o jsonpath='{range .status.conditions[?(@.type=="Installed")]}{.status}{end}' 2> /dev/null || true) - if [[ "${installed}" == "True" ]]; then - log::info "ClusterExtension/${extension_name} reports Installed=True; waiting for CRD..." - else - local progressing reason - progressing=$(oc get clusterextension "${extension_name}" \ - -o jsonpath='{range .status.conditions[?(@.type=="Progressing")]}{.status}{end}' 2> /dev/null || true) - reason=$(oc get clusterextension "${extension_name}" \ - -o jsonpath='{range .status.conditions[?(@.type=="Installed")]}{.reason}{" "}{.message}{end}' 2> /dev/null || true) - log::debug "ClusterExtension Installed=${installed:-unknown} Progressing=${progressing:-unknown} ${reason}" + + if [[ "${installed}" == "True" ]] && oc get crd "${crd_name}" > /dev/null 2>&1; then + log::success "ClusterExtension/${extension_name} Installed=True; CRD '${crd_name}' is available" + return 0 fi + local progressing reason + progressing=$(oc get clusterextension "${extension_name}" \ + -o jsonpath='{range .status.conditions[?(@.type=="Progressing")]}{.status}{end}' 2> /dev/null || true) + reason=$(oc get clusterextension "${extension_name}" \ + -o jsonpath='{range .status.conditions[?(@.type=="Installed")]}{.reason}{": "}{.message}{end}' 2> /dev/null || true) + log::info "ClusterExtension/${extension_name} Installed=${installed:-unknown} Progressing=${progressing:-unknown} ${reason}" + sleep "${interval}" elapsed=$((elapsed + interval)) done - log::error "Timeout waiting for CRD '${crd_name}' after ${timeout}s" + log::error "Timeout waiting for ClusterExtension/${extension_name} Installed=True and CRD '${crd_name}' after ${timeout}s" disconnected::dump_olm_v1_status "${extension_name}" return 1 } diff --git a/.ci/pipelines/lib/disconnected/plugins.sh b/.ci/pipelines/lib/disconnected/plugins.sh index 59a265e241..3b5883e151 100644 --- a/.ci/pipelines/lib/disconnected/plugins.sh +++ b/.ci/pipelines/lib/disconnected/plugins.sh @@ -1,13 +1,25 @@ #!/usr/bin/env bash -# Plugin mirroring, catalog index resolution, and homepage ConfigMap. +# Plugin mirroring, catalog index resolution, and smoke plugin ConfigMap. [[ -n "${_DISCONNECTED_PLUGINS_SOURCED:-}" ]] && return 0 readonly _DISCONNECTED_PLUGINS_SOURCED=1 -# Smoke only enables this plugin (includes: []). Full-catalog mirroring is RHIDP-13967. -readonly DISCONNECTED_HOMEPAGE_PLUGIN_NAME="red-hat-developer-hub-backstage-plugin-homepage" -export DISCONNECTED_HOMEPAGE_PLUGIN_NAME +# Smoke only installs this plugin set (includes: []). Full-catalog mirroring is +# RHIDP-13967. On the 2.1+ New Frontend System hub the sign-in page (app-auth), +# sidebar (app-defaults), SCM integrations (app-integrations) and guest auth +# provider are dynamic plugins, so the homepage alone cannot render a login. +readonly -a DISCONNECTED_SMOKE_PLUGIN_NAMES=( + "red-hat-developer-hub-backstage-plugin-app-auth" + "red-hat-developer-hub-backstage-plugin-app-defaults" + "red-hat-developer-hub-backstage-plugin-app-integrations" + "red-hat-developer-hub-backstage-plugin-homepage" + "backstage-plugin-auth-backend-module-guest-provider" +) +# Bash cannot export arrays, so the exported helpers read this string. +DISCONNECTED_SMOKE_PLUGIN_NAMES_STR="${DISCONNECTED_SMOKE_PLUGIN_NAMES[*]}" +readonly DISCONNECTED_SMOKE_PLUGIN_NAMES_STR +export DISCONNECTED_SMOKE_PLUGIN_NAMES_STR # --------------------------------------------------------------------------- # Hooks — overridable by local.sh (or other consumers) to customise CI-only @@ -69,11 +81,11 @@ disconnected::_catalog_index_mirror_dest() { # Args: # $1 - plugin_index (oci://...) # $2 - output list file path -# $3 - optional name substring; keep only matching refs (e.g. homepage) +# $3 - optional space-separated package names; keep only matching refs disconnected::write_digest_plugin_list() { local plugin_index=$1 local list_file=$2 - local name_filter=${3:-} + local name_filters=${3:-} local index_ref="${plugin_index#oci://}" local extract_dir extract_dir=$(mktemp -d) @@ -122,11 +134,12 @@ disconnected::write_digest_plugin_list() { mv "${tmp}" "${list_file}" fi - if [[ -n "${name_filter}" && -s "${list_file}" ]]; then - local filtered + if [[ -n "${name_filters}" && -s "${list_file}" ]]; then + local filtered pattern filtered=$(mktemp) # Path-segment match so "...-homepage" does not also keep "...-homepage-backend". - grep -E "/${name_filter}(@|:)" "${list_file}" > "${filtered}" || true + pattern="${name_filters// /|}" + grep -E "/(${pattern})(@|:)" "${list_file}" > "${filtered}" || true mv "${filtered}" "${list_file}" fi @@ -135,15 +148,15 @@ disconnected::write_digest_plugin_list() { rm -rf "${extract_dir}" if [[ "${count}" -lt 1 ]]; then - if [[ -n "${name_filter}" ]]; then - log::error "No digest-pinned ${name_filter} plugin found in catalog index" + if [[ -n "${name_filters}" ]]; then + log::error "No digest-pinned plugin matched: ${name_filters}" else log::error "No digest-pinned plugins found in catalog index" fi return 1 fi - if [[ -n "${name_filter}" ]]; then - log::info "Plugin list filtered to ${name_filter}: ${count} digest-pinned ref(s)" + if [[ -n "${name_filters}" ]]; then + log::info "Plugin list filtered to ${count} digest-pinned ref(s) for: ${name_filters}" else log::info "${count} digest-pinned plugins (tag-only refs skipped)" fi @@ -173,32 +186,109 @@ disconnected::copy_catalog_index_to_mirror() { fi } -# Export HOMEPAGE_PLUGIN_PACKAGE from a one-line digest plugin list. +# Package name -> env var rendered by the envsubst templates. +# Args: +# $1 - plugin package name (last OCI path segment) +disconnected::_smoke_plugin_package_var() { + case "$1" in + red-hat-developer-hub-backstage-plugin-app-auth) echo "APP_AUTH_PLUGIN_PACKAGE" ;; + red-hat-developer-hub-backstage-plugin-app-defaults) echo "APP_DEFAULTS_PLUGIN_PACKAGE" ;; + red-hat-developer-hub-backstage-plugin-app-integrations) echo "APP_INTEGRATIONS_PLUGIN_PACKAGE" ;; + red-hat-developer-hub-backstage-plugin-homepage) echo "HOMEPAGE_PLUGIN_PACKAGE" ;; + backstage-plugin-auth-backend-module-guest-provider) echo "GUEST_PROVIDER_PLUGIN_PACKAGE" ;; + *) return 1 ;; + esac +} + +# Render a smoke plugin template, mapping DISCONNECTED_SMOKE_PLUGIN_NAMES_STR to +# the _PLUGIN_PACKAGE variables. Fails when a package is unset or a +# template entry renders without one, so a template/array mismatch surfaces here +# instead of at pod runtime. +# Args: +# $1 - template path +# $2 - output path +disconnected::render_smoke_plugins_template() { + local template=$1 output=$2 name var + local -a package_vars=() + + if [[ -z "${DISCONNECTED_SMOKE_PLUGIN_NAMES_STR:-}" ]]; then + log::error "DISCONNECTED_SMOKE_PLUGIN_NAMES_STR is empty; cannot render ${template}" + return 1 + fi + + for name in ${DISCONNECTED_SMOKE_PLUGIN_NAMES_STR}; do + var=$(disconnected::_smoke_plugin_package_var "${name}") || { + log::error "No package variable mapped for plugin ${name}" + return 1 + } + package_vars+=("${var}") + done + common::require_vars "${package_vars[@]}" || return 1 + + envsubst < "${template}" > "${output}" || { + log::error "Failed to render ${template}" + return 1 + } + if grep -qE '^[[:space:]-]*package:[[:space:]]*$' "${output}"; then + log::error "${template} has a plugin entry without a package after rendering" + return 1 + fi +} + +# Export one _PLUGIN_PACKAGE per smoke plugin from the digest plugin list. # Adds !name if the list line has no OCI subpath (install-dynamic-plugins needs it). # Args: # $1 - plugin list file from write_digest_plugin_list -disconnected::set_homepage_plugin_package_from_list() { +disconnected::set_smoke_plugin_packages_from_list() { local list_file=$1 - local line="" - line=$(head -1 "${list_file}" 2> /dev/null || true) - line="${line#"${line%%[![:space:]]*}"}" - line="${line%"${line##*[![:space:]]}"}" - if [[ -z "${line}" ]]; then - log::error "Homepage plugin list is empty: ${list_file}" + local name="" var="" line="" exported=0 + + if [[ -z "${DISCONNECTED_SMOKE_PLUGIN_NAMES_STR:-}" ]]; then + log::error "DISCONNECTED_SMOKE_PLUGIN_NAMES_STR is empty; cannot resolve smoke plugin packages" return 1 fi - if [[ "${line}" != *'!'* ]]; then - line="${line}!${DISCONNECTED_HOMEPAGE_PLUGIN_NAME}" - fi - export HOMEPAGE_PLUGIN_PACKAGE="${line}" - log::success "HOMEPAGE_PLUGIN_PACKAGE=${HOMEPAGE_PLUGIN_PACKAGE}" + + for name in ${DISCONNECTED_SMOKE_PLUGIN_NAMES_STR}; do + line=$(grep -E "/${name}(@|:)" "${list_file}" 2> /dev/null | head -1 || true) + line="${line#"${line%%[![:space:]]*}"}" + line="${line%"${line##*[![:space:]]}"}" + if [[ -z "${line}" ]]; then + log::error "No digest-pinned ${name} plugin in ${list_file}" + return 1 + fi + if [[ "${line}" != *'!'* ]]; then + line="${line}!${name}" + fi + var=$(disconnected::_smoke_plugin_package_var "${name}") || { + log::error "No package variable mapped for plugin ${name}" + return 1 + } + export "${var}=${line}" + log::success "${var}=${line}" + exported=$((exported + 1)) + done + + log::info "Exported ${exported} smoke plugin package(s)" +} + +# Build the digest-pinned smoke plugin list and export its package variables. +# Args: +# $1 - output list file path +disconnected::write_smoke_plugin_list() { + local list_file=$1 + local plugin_index + plugin_index="oci://$(disconnected::_catalog_index_source_ref)" + + disconnected::write_digest_plugin_list "${plugin_index}" "${list_file}" \ + "${DISCONNECTED_SMOKE_PLUGIN_NAMES_STR}" || return 1 + disconnected::set_smoke_plugin_packages_from_list "${list_file}" || return 1 } # --------------------------------------------------------------------------- # mirror_plugins — fetch and run mirror-plugins.sh against the mirror registry # --------------------------------------------------------------------------- -# Smoke: homepage plugin only (--plugin-list) plus the catalog index +# Smoke: the minimal NFS plugin set (--plugin-list) plus the catalog index # (CATALOG_INDEX_IMAGE). --plugin-index would enumerate every catalog plugin, # including unpublished :tag refs. disconnected::mirror_plugins() { @@ -212,10 +302,8 @@ disconnected::mirror_plugins() { local plugin_index plugin_index="oci://$(disconnected::_catalog_index_source_ref)" - local list_file="${DISCONNECTED_TMPDIR}/homepage-plugins.txt" - disconnected::write_digest_plugin_list "${plugin_index}" "${list_file}" \ - "${DISCONNECTED_HOMEPAGE_PLUGIN_NAME}" || return 1 - disconnected::set_homepage_plugin_package_from_list "${list_file}" || return 1 + local list_file="${DISCONNECTED_TMPDIR}/smoke-plugins.txt" + disconnected::write_smoke_plugin_list "${list_file}" || return 1 disconnected::wait_mirror_registry_route 300 || return 1 bash "${mirror_script}" \ @@ -313,24 +401,20 @@ disconnected::resolve_catalog_index_image() { } # --------------------------------------------------------------------------- -# Homepage plugin ConfigMap (Operator) +# Smoke plugin ConfigMap (Operator) # --------------------------------------------------------------------------- -# Create a ConfigMap from the homepage-only dynamic-plugins.yaml -# (digest-pinned OCI package; includes: [] skips catalog defaults). +# Create a ConfigMap from the smoke dynamic-plugins.yaml +# (digest-pinned OCI packages; includes: [] skips catalog defaults). # Args: # $1 - namespace -disconnected::create_homepage_plugins_configmap() { - common::require_vars HOMEPAGE_PLUGIN_PACKAGE || return 1 +disconnected::create_smoke_plugins_configmap() { local namespace=$1 local cm_name="dynamic-plugins-disconnected-smoke" - local template="${DIR}/resources/disconnected/dynamic-plugins-homepage.yaml" + local template="${DIR}/resources/disconnected/dynamic-plugins-smoke.yaml" local tmp_yaml="${DISCONNECTED_TMPDIR}/dynamic-plugins-disconnected-smoke.yaml" - envsubst < "${template}" > "${tmp_yaml}" || { - log::error "Failed to render ${template}" - return 1 - } + disconnected::render_smoke_plugins_template "${template}" "${tmp_yaml}" || return 1 oc create configmap "${cm_name}" \ --from-file="dynamic-plugins.yaml=${tmp_yaml}" \ diff --git a/.ci/pipelines/lib/helm.sh b/.ci/pipelines/lib/helm.sh index e64fa5a393..91891f333a 100644 --- a/.ci/pipelines/lib/helm.sh +++ b/.ci/pipelines/lib/helm.sh @@ -171,51 +171,6 @@ helm::resolve_chart_version() { helm::get_chart_version } -# Get the release stream this run belongs to: a major.minor pair like "1.10", -# not a bare major. 'main' takes it from package.json; 'release-x.y' from the -# branch name. -# Args: -# $1 - (optional) version_override: Specific stream to use (e.g., "1.8" for upgrade base) -# Returns: -# Prints the stream (e.g., "1.10") -helm::get_chart_stream() { - local version_override=${1:-} - - if [[ -n "$version_override" ]]; then - echo "$version_override" - return 0 - fi - - if [[ -z "${RELEASE_BRANCH_NAME:-}" ]]; then - log::error "RELEASE_BRANCH_NAME is not set" - return 1 - fi - - if [[ "$RELEASE_BRANCH_NAME" == "main" ]]; then - # main carries no version in its name. The published tags cannot answer - # this either - they hold every stream anyone pushed, so "highest on quay" - # follows whichever stream is ahead, not this checkout's. - local package_json="${DIR}/../../package.json" - if [[ ! -f "$package_json" ]]; then - log::error "Cannot determine the chart stream: ${package_json} not found" - return 1 - fi - - local chart_stream - chart_stream=$(jq -r '.version // empty' "$package_json" | grep -oE '^[0-9]+\.[0-9]+') - if [[ -z "$chart_stream" ]]; then - log::error "Cannot determine the chart stream: no usable .version in ${package_json}" - return 1 - fi - echo "$chart_stream" - elif echo "$RELEASE_BRANCH_NAME" | grep -qE '^release-[0-9]+\.[0-9]+$'; then - echo "$RELEASE_BRANCH_NAME" | grep -oE '[0-9]+\.[0-9]+' - else - log::error "Invalid RELEASE_BRANCH_NAME: $RELEASE_BRANCH_NAME (expected 'main' or 'release-x.y')" - return 1 - fi -} - # Get the latest chart version based on RELEASE_BRANCH_NAME or an optional version override. # Args: # $1 - (optional) version_override: Specific version to use (e.g., "1.8" for upgrade base) @@ -223,7 +178,7 @@ helm::get_chart_stream() { # Prints the chart version (e.g., "1.4-123-CI") helm::get_chart_version() { local chart_stream - chart_stream=$(helm::get_chart_stream "${1:-}") + chart_stream=$(common::get_release_stream "${1:-}") if [[ -z "$chart_stream" ]]; then return 1 fi diff --git a/.ci/pipelines/resources/disconnected/app-config-rhdh-disconnected-smoke.yaml b/.ci/pipelines/resources/disconnected/app-config-rhdh-disconnected-smoke.yaml index 3a6f4e7a38..cc1fc217da 100644 --- a/.ci/pipelines/resources/disconnected/app-config-rhdh-disconnected-smoke.yaml +++ b/.ci/pipelines/resources/disconnected/app-config-rhdh-disconnected-smoke.yaml @@ -1,11 +1,24 @@ -# Minimal app-config for disconnected operator smoke (guest login only). +# Minimal app-config for disconnected operator smoke (guest login + homepage). app: title: Red Hat Developer Hub + # New Frontend System: the homepage plugin owns page:homepage and its layout; + # disable the community home page so only one Home destination is registered. + # Same extension list as value_files/values_disconnected-smoke.yaml. + extensions: + - page:home: false + - page:homepage: + config: + path: / + title: Home + - translation:app/homepage-translations auth: environment: development providers: guest: dangerouslyAllowOutsideDevelopment: true +# app-auth does not inject the Guest provider (auth.providers is not +# frontend-visible), so the provider list must be explicit. +signInPage: guest # Hub defaults enable permission/RBAC; without a policy module the backend # stays not-ready (readiness 503) even though / can return 200. permission: diff --git a/.ci/pipelines/resources/disconnected/dynamic-plugins-homepage.yaml b/.ci/pipelines/resources/disconnected/dynamic-plugins-homepage.yaml deleted file mode 100644 index 9cf0f851e1..0000000000 --- a/.ci/pipelines/resources/disconnected/dynamic-plugins-homepage.yaml +++ /dev/null @@ -1,15 +0,0 @@ -# Disconnected smoke: homepage-only dynamic plugins (Operator ConfigMap). -# Rendered via envsubst (requires HOMEPAGE_PLUGIN_PACKAGE). -# includes: [] skips dynamic-plugins.default.yaml (unpublished :tag refs). -# package is the digest-pinned OCI from the catalog (ref:// needs includes). -includes: [] -plugins: - - package: ${HOMEPAGE_PLUGIN_PACKAGE} - enabled: true - pluginConfig: - dynamicPlugins: - frontend: - red-hat-developer-hub.backstage-plugin-homepage: - dynamicRoutes: - - path: / - importName: DynamicHomePage diff --git a/.ci/pipelines/resources/disconnected/dynamic-plugins-smoke.yaml b/.ci/pipelines/resources/disconnected/dynamic-plugins-smoke.yaml new file mode 100644 index 0000000000..3a0a08ed60 --- /dev/null +++ b/.ci/pipelines/resources/disconnected/dynamic-plugins-smoke.yaml @@ -0,0 +1,17 @@ +# Disconnected smoke: minimal New Frontend System plugin set (Operator ConfigMap). +# Rendered via envsubst (requires the *_PLUGIN_PACKAGE variables). +# includes: [] skips dynamic-plugins.default.yaml (unpublished :tag refs). +# packages are the digest-pinned OCI refs from the catalog (ref:// needs includes). +# The plugin set is explained in .ci/pipelines/lib/disconnected/plugins.sh. +includes: [] +plugins: + - package: ${APP_AUTH_PLUGIN_PACKAGE} + enabled: true + - package: ${APP_DEFAULTS_PLUGIN_PACKAGE} + enabled: true + - package: ${APP_INTEGRATIONS_PLUGIN_PACKAGE} + enabled: true + - package: ${GUEST_PROVIDER_PLUGIN_PACKAGE} + enabled: true + - package: ${HOMEPAGE_PLUGIN_PACKAGE} + enabled: true diff --git a/.ci/pipelines/resources/rhdh-operator/rhdh-start-disconnected-smoke.yaml b/.ci/pipelines/resources/rhdh-operator/rhdh-start-disconnected-smoke.yaml index dbfb6d09f4..9246c9416d 100644 --- a/.ci/pipelines/resources/rhdh-operator/rhdh-start-disconnected-smoke.yaml +++ b/.ci/pipelines/resources/rhdh-operator/rhdh-start-disconnected-smoke.yaml @@ -1,11 +1,14 @@ # Minimal Backstage CR for disconnected operator smoke test. # Rendered via envsubst (requires MIRROR_REGISTRY_URL, RELEASE_NAME). # -# Guest login + homepage only. flavours: [] disables default flavours -# (lightspeed) to avoid extra sidecar images. +# Guest login + homepage smoke test; installs the minimal NFS plugin set. +# flavours: [] disables default flavours (lightspeed) to avoid extra sidecar +# images. # -# Hub image: CSV RELATED_IMAGE_backstage (GA rhdh-hub-rhel9). prepare + -# oc-mirror IDMS rewrites pulls for kubelet. +# Hub image: CSV RELATED_IMAGE_backstage. CI runs install the CI catalog, whose +# bundle points at the newest stream build; GA runs install the published +# catalog. Either way the CSV ref is mirrored by prepare + oc-mirror and the +# generated IDMS rewrites the kubelet pull. # # CATALOG_INDEX_IMAGE is injected by deploy_rhdh_operator from the mirrored # catalog digest so install-dynamic-plugins does not pull the hub profile diff --git a/.ci/pipelines/value_files/values_disconnected-smoke.yaml b/.ci/pipelines/value_files/values_disconnected-smoke.yaml index c5129b9dff..c54445ad5d 100644 --- a/.ci/pipelines/value_files/values_disconnected-smoke.yaml +++ b/.ci/pipelines/value_files/values_disconnected-smoke.yaml @@ -7,20 +7,27 @@ # Do not include dynamic-plugins.default.yaml from the catalog index: next # catalogs can list :tag refs that do not exist on quay (manifest unknown), # which CrashLoops install-dynamic-plugins after registries.conf rewrites -# those pulls to the mirror. Homepage package is HOMEPAGE_PLUGIN_PACKAGE -# (digest-pinned OCI from the catalog). ref:// needs includes and cannot be used. +# those pulls to the mirror. Every package below is a digest-pinned OCI from +# the catalog. ref:// needs includes and cannot be used. The plugin set is +# explained in .ci/pipelines/lib/disconnected/plugins.sh. +# +# Pins the chart fullname (-developer-hub, also the chart default): the +# job creates the registry-auth secret under that name. The egress NetworkPolicy +# selects on pod labels and does not depend on this. +nameOverride: developer-hub dynamicPlugins: includes: [] plugins: + - package: ${APP_AUTH_PLUGIN_PACKAGE} + enabled: true + - package: ${APP_DEFAULTS_PLUGIN_PACKAGE} + enabled: true + - package: ${APP_INTEGRATIONS_PLUGIN_PACKAGE} + enabled: true + - package: ${GUEST_PROVIDER_PLUGIN_PACKAGE} + enabled: true - package: ${HOMEPAGE_PLUGIN_PACKAGE} enabled: true - pluginConfig: - dynamicPlugins: - frontend: - red-hat-developer-hub.backstage-plugin-homepage: - dynamicRoutes: - - path: / - importName: DynamicHomePage intelligentAssistant: enabled: false orchestrator: @@ -38,3 +45,17 @@ appConfig: providers: guest: dangerouslyAllowOutsideDevelopment: true + # app-auth does not inject the Guest provider (auth.providers is not + # frontend-visible), so the provider list must be explicit. + signInPage: guest + app: + # New Frontend System: the homepage plugin owns page:homepage and its + # layout; disable the community home page so only one Home destination is + # registered. Subset of resources/config_map/dynamic-plugins-config.yaml. + extensions: + - page:home: false + - page:homepage: + config: + path: / + title: Home + - translation:app/homepage-translations