diff --git a/.ci/pipelines/cluster/gke/gcloud.sh b/.ci/pipelines/cluster/gke/gcloud.sh index f2b773f73e..cd7a509f1c 100755 --- a/.ci/pipelines/cluster/gke/gcloud.sh +++ b/.ci/pipelines/cluster/gke/gcloud.sh @@ -37,8 +37,16 @@ gcloud_ssl_cert_create() { } cleanup_gke() { - uninstall_olm - delete_rhdh_operator + # OLM stays installed on the long-lived cluster; each deployment removes the + # RHDH operator it created. Failures must not abort the remaining steps. + delete_rhdh_operator || log::warn "Failed to delete the RHDH operator during cleanup." + # The RHDH CatalogSource points at the registry inside the operator namespace. + kubectl get catalogsource --namespace=olm -o name 2> /dev/null \ + | grep '/rhdh-' | xargs -r kubectl delete --namespace=olm --ignore-not-found \ + || log::warn "Failed to delete the RHDH CatalogSource during cleanup." + kubectl delete clusterrole,clusterrolebinding \ + -l "olm.owner.namespace=${OPERATOR_MANAGER:-rhdh-operator}" --ignore-not-found \ + || log::warn "Failed to delete OLM-owned RBAC for the RHDH operator." # The GKE cluster is long-lived; release the Keycloak load balancer. - keycloak::delete + keycloak::delete || log::warn "Failed to delete Keycloak during cleanup." } diff --git a/.ci/pipelines/lib/operators.sh b/.ci/pipelines/lib/operators.sh index f14b830445..8b0144251d 100644 --- a/.ci/pipelines/lib/operators.sh +++ b/.ci/pipelines/lib/operators.sh @@ -27,26 +27,62 @@ operator::install_tekton() { return 0 } -# Install Operator Lifecycle Manager if not present -operator::install_olm() { - if operator-sdk olm status > /dev/null 2>&1; then - log::info "OLM is already installed." +# `operator-sdk olm status` fetches the release manifests and fails on a partial +# installation, which used to leave the shared GKE cluster unusable. +# `operator-sdk olm uninstall` deletes the CRDs before the deployments, so an +# interrupted uninstall leaves the deployments Available without OLM's APIs. +operator::olm_healthy() { + kubectl wait deployment/olm-operator deployment/catalog-operator deployment/packageserver \ + --namespace=olm --for=condition=Available --timeout=120s > /dev/null 2>&1 || return 1 + kubectl wait crd/catalogsources.operators.coreos.com crd/clusterserviceversions.operators.coreos.com \ + crd/installplans.operators.coreos.com crd/operatorgroups.operators.coreos.com \ + crd/subscriptions.operators.coreos.com --for=condition=Established --timeout=30s > /dev/null 2>&1 || return 1 + kubectl wait apiservice/v1.packages.operators.coreos.com \ + --for=condition=Available --timeout=60s > /dev/null 2>&1 +} + +# `operator-sdk olm uninstall` resolves resources from its manifest and leftovers +# of a partial installation break it, so OLM's cluster-scoped resources are +# removed by name instead. +operator::uninstall_olm() { + if [[ "${IS_OPENSHIFT:-}" == "true" ]]; then + log::warn "OLM is managed by the platform on OpenShift; not removing it." return 0 fi - log::info "OLM is not installed. Installing..." - operator-sdk olm install - return $? + log::info "Removing OLM resources" + # Stop the operators first, otherwise they recreate the APIService after it is deleted. + kubectl delete deployment olm-operator catalog-operator packageserver \ + --namespace=olm --ignore-not-found --cascade=foreground --timeout=120s || return 1 + kubectl delete apiservice v1.packages.operators.coreos.com --ignore-not-found || return 1 + # olm-operator is gone, so nothing else removes the finalizer it puts on every CSV. + kubectl get csv --all-namespaces \ + -o jsonpath='{range .items[*]}{.metadata.namespace}{" "}{.metadata.name}{"\n"}{end}' 2> /dev/null \ + | while read -r ns name; do + kubectl patch csv "${name}" --namespace="${ns}" --type=merge -p '{"metadata":{"finalizers":null}}' + done + # The cluster-scoped resources that finalizer deletes for its CSV. + kubectl delete clusterrole,clusterrolebinding,mutatingwebhookconfiguration,validatingwebhookconfiguration \ + -l olm.owner.kind=ClusterServiceVersion --ignore-not-found || return 1 + kubectl get crd -o name | grep '\.operators\.coreos\.com$' | xargs -r kubectl delete --timeout=120s || return 1 + kubectl delete clusterrolebinding olm-operator-binding-olm --ignore-not-found || return 1 + kubectl delete clusterrole aggregate-olm-edit aggregate-olm-view \ + system:controller:operator-lifecycle-manager --ignore-not-found || return 1 + kubectl delete namespace olm operators --ignore-not-found --timeout=300s } -# Uninstall Operator Lifecycle Manager if present -operator::uninstall_olm() { - if operator-sdk olm status > /dev/null 2>&1; then - log::info "OLM is installed. Uninstalling..." - operator-sdk olm uninstall +# `operator-sdk olm install` refuses to run over resources left by a failed attempt. +operator::reinstall_olm() { + operator::uninstall_olm \ + && operator-sdk olm install --timeout=5m +} + +operator::install_olm() { + if operator::olm_healthy; then + log::info "OLM is already installed." return 0 fi - log::info "OLM is not installed. Nothing to uninstall." - return 0 + log::info "Installing OLM..." + common::retry 3 30 operator::reinstall_olm } diff --git a/.ci/pipelines/resources/config_map/app-config-rhdh.yaml b/.ci/pipelines/resources/config_map/app-config-rhdh.yaml index 012e6e1457..e228d44316 100644 --- a/.ci/pipelines/resources/config_map/app-config-rhdh.yaml +++ b/.ci/pipelines/resources/config_map/app-config-rhdh.yaml @@ -111,6 +111,11 @@ auth: signInPage: - guest - oidc +techdocs: + cache: + # TechDocs only creates its cache when this key is set; without it no + # techdocs keys are written to Redis and the cache test cannot pass. + ttl: 3600000 proxy: skipInvalidProxies: true # endpoints: {} diff --git a/e2e-tests/playwright/e2e/verify-redis-cache.spec.ts b/e2e-tests/playwright/e2e/verify-redis-cache.spec.ts index 214ce7d66b..df4d3f54f1 100644 --- a/e2e-tests/playwright/e2e/verify-redis-cache.spec.ts +++ b/e2e-tests/playwright/e2e/verify-redis-cache.spec.ts @@ -25,7 +25,7 @@ test.describe("Verify Redis Cache DB", () => { shellCommand: ` oc login --token="${process.env.K8S_CLUSTER_TOKEN}" --server="${process.env.K8S_CLUSTER_URL}" --insecure-skip-tls-verify=true && kubectl config set-context --current --namespace="${process.env.NAME_SPACE}" && - kubectl port-forward service/redis ${REDIS_LOCAL_PORT}:6379 --namespace="${process.env.NAME_SPACE}" + exec kubectl port-forward service/redis ${REDIS_LOCAL_PORT}:6379 --namespace="${process.env.NAME_SPACE}" `, }, { @@ -63,7 +63,9 @@ test.describe("Verify Redis Cache DB", () => { ); console.log("Verifying Redis keys..."); await expect(async () => { - const keys = (await redis.keys("*")).filter((k) => k.includes("techdocs")); + const allKeys = await redis.keys("*"); + const keys = allKeys.filter((k) => k.includes("techdocs")); + console.log(`Redis DBSIZE: ${allKeys.length}, techdocs keys: ${keys.join(", ")}`); expect(keys).toContainEqual(expect.stringContaining("techdocs")); const key = keys[0]; console.log(`Verifying key format: ${key}`);