From 40d6f4f215b0804867c1979ac1a6ec95b9fe5d21 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Thu, 17 Sep 2026 11:58:20 +0100 Subject: [PATCH 1/4] feat(plugin-infra): add OLM v1 ClusterExtension manifests for orchestrator Add serverless-v1.yaml and serverless-logic-v1.yaml with installer RBAC and ClusterExtension resources, and teach plugin-infra.sh to auto-detect OLM version (or force via --olm-version) mirroring orchestrator-infra chart. Address Qodo review: safe v1 teardown ordering, ClusterCatalog prerequisite checks, reliable CRD detection, delete both v0/v1 families, Helm ownership guards, Makefile OLM_VERSION forwarding, nonempty catalog list checks, per-resource v0 delete with ownership labels, --olm-version arg validation, CRD-guarded delete paths for unavailable OLM APIs, and Sonar literal constants. Document OLM v1 behavior in orchestrator, developer, and orchestrator-cicd guides. RHIDP-14791 Signed-off-by: Fortune Ndlovu --- Makefile | 5 +- .../profile/rhdh/plugin-infra/plugin-infra.sh | 360 +++++++++++++++++- .../plugin-infra/serverless-logic-v1.yaml | 55 +++ .../rhdh/plugin-infra/serverless-logic.yaml | 6 + .../rhdh/plugin-infra/serverless-v1.yaml | 54 +++ .../profile/rhdh/plugin-infra/serverless.yaml | 8 +- docs/developer.md | 9 +- docs/orchestrator-cicd.md | 2 +- docs/orchestrator.md | 24 +- 9 files changed, 505 insertions(+), 18 deletions(-) create mode 100644 config/profile/rhdh/plugin-infra/serverless-logic-v1.yaml create mode 100644 config/profile/rhdh/plugin-infra/serverless-v1.yaml diff --git a/Makefile b/Makefile index 2ddf0dd02..732765983 100644 --- a/Makefile +++ b/Makefile @@ -7,6 +7,7 @@ PROFILES := $(shell find config/manifests -mindepth 1 -maxdepth 1 -type d -exec # to use other config - add a directory with config, # use it as following commands: 'PROFILE= make test|integration-test|run|deploy|deployment-manifest' PROFILE ?= rhdh +OLM_VERSION ?= auto # Enable operator dynamic plugins processing (default: true) OPERATOR_DP_PROCESSING ?= true @@ -424,7 +425,7 @@ undeploy: kustomize ## Undeploy controller from the K8s cluster specified in ~/. .PHONY: plugin-infra plugin-infra: @if [ -f "config/profile/$(PROFILE)/plugin-infra/plugin-infra.sh" ]; then \ - config/profile/$(PROFILE)/plugin-infra/plugin-infra.sh; \ + config/profile/$(PROFILE)/plugin-infra/plugin-infra.sh --olm-version $(OLM_VERSION); \ else \ echo "File config/profile/$(PROFILE)/plugin-infra/plugin-infra.sh does not exist."; \ fi @@ -432,7 +433,7 @@ plugin-infra: .PHONY: plugin-infra-undeploy plugin-infra-undeploy: @if [ -f "config/profile/$(PROFILE)/plugin-infra/plugin-infra.sh" ]; then \ - config/profile/$(PROFILE)/plugin-infra/plugin-infra.sh delete; \ + config/profile/$(PROFILE)/plugin-infra/plugin-infra.sh delete --olm-version $(OLM_VERSION); \ else \ echo "File config/profile/$(PROFILE)/plugin-infra/plugin-infra.sh does not exist."; \ fi diff --git a/config/profile/rhdh/plugin-infra/plugin-infra.sh b/config/profile/rhdh/plugin-infra/plugin-infra.sh index 88cb694a4..501167c4e 100755 --- a/config/profile/rhdh/plugin-infra/plugin-infra.sh +++ b/config/profile/rhdh/plugin-infra/plugin-infra.sh @@ -8,6 +8,14 @@ set -euo pipefail action="apply" # Default action branch="main" # Default branch cicd=false # Default CICD mode +olm_version="auto" # Default OLM version (v0, v1, or auto-detect) +resolved_olm_version="" + +PLUGIN_INFRA_LABEL_KEY="rhdh.redhat.com/managed-by" +PLUGIN_INFRA_LABEL_VALUE="plugin-infra" +REDHAT_OPERATORS_CATALOG_LABEL="olm.operatorframework.io/metadata.name=openshift-redhat-operators" +SERVERLESS_OPERATOR_NAME="serverless-operator" +LOGIC_OPERATOR_NAME="logic-operator" # Parse command-line options while [[ $# -gt 0 ]]; do @@ -16,6 +24,10 @@ while [[ $# -gt 0 ]]; do cicd=true shift ;; + --olm-version) + olm_version="${2:?--olm-version requires v0, v1, or auto}" + shift 2 + ;; apply|delete) action="$1" shift @@ -31,28 +43,359 @@ while [[ $# -gt 0 ]]; do esac done +case "${olm_version}" in + v0|v1|auto) ;; + *) + echo "Unknown --olm-version value: ${olm_version}. Must be v0, v1, or auto." + exit 1 + ;; +esac + +script_dir="$(dirname "$(realpath "$0")")" + +kubectl_get() { + kubectl get "$@" 2>&1 +} + +resource_exists() { + local err + if kubectl_get "$@" >/dev/null; then + return 0 + fi + err="$(kubectl_get "$@" || true)" + if grep -qiE '(not found|NotFound)' <<<"${err}"; then + return 1 + fi + echo "${err}" >&2 + exit 1 +} + +crd_exists() { + resource_exists "crd/${1}" +} + +is_helm_managed() { + local api_resource="$1" + local name="$2" + local namespace="${3:-}" + local release_name + local args=("${api_resource}/${name}" -o "jsonpath={.metadata.annotations.meta\\.helm\\.sh/release-name}") + + if [[ -n "${namespace}" ]]; then + args=(-n "${namespace}" "${args[@]}") + fi + + release_name="$(kubectl get "${args[@]}" 2>/dev/null || true)" + [[ -n "${release_name}" ]] +} + +is_plugin_infra_managed() { + local api_resource="$1" + local name="$2" + local namespace="${3:-}" + local managed_by + local resource="${api_resource}/${name}" + + if [[ -n "${namespace}" ]]; then + managed_by="$(kubectl get -n "${namespace}" "${resource}" \ + -o "jsonpath={.metadata.labels['${PLUGIN_INFRA_LABEL_KEY}']}" 2>/dev/null || true)" + else + managed_by="$(kubectl get "${resource}" \ + -o "jsonpath={.metadata.labels['${PLUGIN_INFRA_LABEL_KEY}']}" 2>/dev/null || true)" + fi + + [[ "${managed_by}" == "${PLUGIN_INFRA_LABEL_VALUE}" ]] +} + +should_skip_resource_mutation() { + local api_resource="$1" + local name="$2" + local namespace="${3:-}" + + if ! resource_exists "${api_resource}/${name}" ${namespace:+-n "${namespace}"}; then + return 1 + fi + + if is_helm_managed "${api_resource}" "${name}" "${namespace}"; then + echo "Skipping ${api_resource}/${name}: managed by Helm" + return 0 + fi + + if is_plugin_infra_managed "${api_resource}" "${name}" "${namespace}"; then + return 1 + fi + + echo "Skipping ${api_resource}/${name}: not managed by plugin-infra" + return 0 +} + +detect_olm_v1_crd() { + crd_exists "clusterextensions.olm.operatorframework.io" +} + +detect_olm_v1_clustercatalog_crd() { + crd_exists "clustercatalogs.olm.operatorframework.io" +} + +detect_olm_v0_subscription_crd() { + crd_exists "subscriptions.operators.coreos.com" +} + +detect_olm_v0_operatorgroup_crd() { + crd_exists "operatorgroups.operators.coreos.com" +} + +redhat_operators_catalog_exists() { + local catalogs err exit_code + + catalogs="$(kubectl get clustercatalog -l "${REDHAT_OPERATORS_CATALOG_LABEL}" -o name 2>&1)" + exit_code=$? + if [[ ${exit_code} -eq 0 && -n "${catalogs}" ]]; then + return 0 + fi + if [[ ${exit_code} -ne 0 ]]; then + if grep -qiE '(not found|NotFound)' <<<"${catalogs}"; then + : + else + echo "${catalogs}" >&2 + exit 1 + fi + fi + + catalogs="$(kubectl get clustercatalog openshift-redhat-operators -o name 2>&1)" + exit_code=$? + if [[ ${exit_code} -eq 0 && -n "${catalogs}" ]]; then + return 0 + fi + if [[ ${exit_code} -ne 0 ]]; then + if grep -qiE '(not found|NotFound)' <<<"${catalogs}"; then + return 1 + fi + echo "${catalogs}" >&2 + exit 1 + fi + + return 1 +} + +verify_redhat_operators_catalog() { + if redhat_operators_catalog_exists; then + return 0 + fi + + echo "OLM v1 requires a ClusterCatalog labeled ${REDHAT_OPERATORS_CATALOG_LABEL}." + echo "On OpenShift this catalog is platform-provided; it is not created by plugin-infra.sh." + exit 1 +} + +resolve_olm_version() { + if [[ "${olm_version}" == "v0" ]]; then + resolved_olm_version="v0" + echo "Using OLM v0 (forced via --olm-version)" + return + fi + + if [[ "${olm_version}" == "v1" ]]; then + if ! detect_olm_v1_crd; then + echo "OLM v1 requested but ClusterExtension CRD not found on this cluster" + exit 1 + fi + if ! detect_olm_v1_clustercatalog_crd; then + echo "OLM v1 requested but ClusterCatalog CRD not found on this cluster" + exit 1 + fi + verify_redhat_operators_catalog + resolved_olm_version="v1" + echo "Using OLM v1 (forced via --olm-version)" + return + fi + + if detect_olm_v1_crd && detect_olm_v1_clustercatalog_crd; then + if redhat_operators_catalog_exists; then + resolved_olm_version="v1" + echo "Auto-detected OLM v1 (ClusterExtension and ClusterCatalog CRDs found)" + else + resolved_olm_version="v0" + echo "Auto-detected OLM v0 (openshift-redhat-operators ClusterCatalog not found)" + fi + else + resolved_olm_version="v0" + echo "Auto-detected OLM v0 (OLM v1 CRDs not found)" + fi +} + apply_manifest() { local file="$1" local url="https://raw.githubusercontent.com/redhat-developer/rhdh-operator/${branch}/config/profile/rhdh/plugin-infra/${file}" - local script_dir - script_dir="$(dirname "$(realpath "$0")")" + local path="${script_dir}/${file}" - if [[ -f "${script_dir}/${file}" ]]; then + if [[ -f "${path}" ]]; then echo "Using local file: ${file}" - kubectl "$action" -f "${script_dir}/${file}" + kubectl "$action" -f "${path}" else echo "Local file not found. Fetching from URL: ${url}" curl -s "$url" | kubectl "$action" -f - fi } +apply_v1_operator_manifest() { + local file="$1" + local extension_name="$2" + + if should_skip_resource_mutation clusterextension "${extension_name}"; then + return 0 + fi + + apply_manifest "${file}" +} + +delete_plugin_infra_v0_operator() { + local namespace="$1" + local operatorgroup_name="$2" + local subscription_name="$3" + + if detect_olm_v0_subscription_crd; then + if ! should_skip_resource_mutation subscription "${subscription_name}" "${namespace}"; then + kubectl delete "subscription/${subscription_name}" -n "${namespace}" --ignore-not-found + fi + fi + + if detect_olm_v0_operatorgroup_crd; then + if ! should_skip_resource_mutation operatorgroup "${operatorgroup_name}" "${namespace}"; then + kubectl delete "operatorgroup/${operatorgroup_name}" -n "${namespace}" --ignore-not-found + fi + fi + + if ! should_skip_resource_mutation namespace "${namespace}"; then + kubectl delete "namespace/${namespace}" --ignore-not-found + fi +} + +wait_for_clusterextension() { + local name="$1" + echo "Waiting for ClusterExtension/${name} to be Installed..." + kubectl wait "clusterextension/${name}" --for=condition=Installed --timeout=300s +} + +wait_for_clusterextension_if_relevant() { + local name="$1" + + if ! resource_exists "clusterextension/${name}"; then + return 0 + fi + + if is_helm_managed clusterextension "${name}"; then + echo "ClusterExtension/${name} is managed by Helm; skipping wait" + return 0 + fi + + wait_for_clusterextension "${name}" +} + +wait_for_clusterextension_deleted() { + local name="$1" + local timeout="${2:-300}" + local elapsed=0 + + if ! detect_olm_v1_crd; then + return 0 + fi + + echo "Waiting for ClusterExtension/${name} to be removed..." + while resource_exists "clusterextension/${name}"; do + if (( elapsed >= timeout )); then + echo "Timed out waiting for ClusterExtension/${name} deletion" + exit 1 + fi + sleep 5 + elapsed=$((elapsed + 5)) + done +} + +delete_plugin_infra_v1_operator() { + local extension_name="$1" + local namespace="$2" + local sa_name="$3" + local crb_name="$4" + + if detect_olm_v1_crd; then + if resource_exists "clusterextension/${extension_name}"; then + if should_skip_resource_mutation clusterextension "${extension_name}"; then + : + else + kubectl delete "clusterextension/${extension_name}" --ignore-not-found + wait_for_clusterextension_deleted "${extension_name}" + fi + fi + fi + + if ! should_skip_resource_mutation serviceaccount "${sa_name}" "${namespace}"; then + kubectl delete "serviceaccount/${sa_name}" -n "${namespace}" --ignore-not-found + fi + + if ! should_skip_resource_mutation clusterrolebinding "${crb_name}"; then + kubectl delete "clusterrolebinding/${crb_name}" --ignore-not-found + fi + + if ! should_skip_resource_mutation namespace "${namespace}"; then + kubectl delete "namespace/${namespace}" --ignore-not-found + fi +} + +delete_orchestrator_v1_operators() { + delete_plugin_infra_v1_operator \ + "${LOGIC_OPERATOR_NAME}" \ + "openshift-serverless-logic" \ + "serverless-logic-operator-installer" \ + "logic-operator-installer-binding" + delete_plugin_infra_v1_operator \ + "${SERVERLESS_OPERATOR_NAME}" \ + "openshift-serverless" \ + "serverless-operator-installer" \ + "serverless-operator-installer-binding" +} + +delete_orchestrator_v0_operators() { + delete_plugin_infra_v0_operator \ + "openshift-serverless-logic" \ + "openshift-serverless-logic" \ + "${LOGIC_OPERATOR_NAME}" + delete_plugin_infra_v0_operator \ + "openshift-serverless" \ + "serverless-operator-group" \ + "${SERVERLESS_OPERATOR_NAME}" +} + +resolve_olm_version + +if [[ "${resolved_olm_version}" == "v1" ]]; then + serverless_manifest="serverless-v1.yaml" + serverless_logic_manifest="serverless-logic-v1.yaml" +else + serverless_manifest="serverless.yaml" + serverless_logic_manifest="serverless-logic.yaml" +fi + # Execution if [[ "$action" == "apply" ]]; then - apply_manifest "serverless.yaml" + if [[ "${resolved_olm_version}" == "v1" ]]; then + apply_v1_operator_manifest "${serverless_manifest}" "${SERVERLESS_OPERATOR_NAME}" + wait_for_clusterextension_if_relevant "${SERVERLESS_OPERATOR_NAME}" + else + apply_manifest "${serverless_manifest}" + fi + echo "Waiting for CRDs to be established..." kubectl wait --for=condition=Established crd --all --timeout=60s apply_manifest "knative.yaml" - apply_manifest "serverless-logic.yaml" + + if [[ "${resolved_olm_version}" == "v1" ]]; then + apply_v1_operator_manifest "${serverless_logic_manifest}" "${LOGIC_OPERATOR_NAME}" + wait_for_clusterextension_if_relevant "${LOGIC_OPERATOR_NAME}" + else + apply_manifest "${serverless_logic_manifest}" + fi + if [[ "$cicd" == true ]]; then echo "CICD enabled. Executing CICD-specific logic..." apply_manifest "argocd.yaml" @@ -61,9 +404,9 @@ if [[ "$action" == "apply" ]]; then apply_manifest "pipeline.yaml" fi elif [[ "$action" == "delete" ]]; then - apply_manifest "serverless-logic.yaml" + delete_orchestrator_v1_operators apply_manifest "knative.yaml" - apply_manifest "serverless.yaml" + delete_orchestrator_v0_operators if [[ "$cicd" == true ]]; then apply_manifest "argocd.yaml" apply_manifest "argocd-cr.yaml" @@ -73,4 +416,3 @@ else echo "Action '$action' is not supported. Use 'apply' (default) or 'delete'." exit 1 fi - diff --git a/config/profile/rhdh/plugin-infra/serverless-logic-v1.yaml b/config/profile/rhdh/plugin-infra/serverless-logic-v1.yaml new file mode 100644 index 000000000..bb732734f --- /dev/null +++ b/config/profile/rhdh/plugin-infra/serverless-logic-v1.yaml @@ -0,0 +1,55 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: openshift-serverless-logic + labels: + rhdh.redhat.com/managed-by: plugin-infra +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: serverless-logic-operator-installer + namespace: openshift-serverless-logic + labels: + rhdh.redhat.com/managed-by: plugin-infra +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: logic-operator-installer-binding + labels: + rhdh.redhat.com/managed-by: plugin-infra +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: + - kind: ServiceAccount + name: serverless-logic-operator-installer + namespace: openshift-serverless-logic +--- +apiVersion: olm.operatorframework.io/v1 +kind: ClusterExtension +metadata: + name: logic-operator + labels: + rhdh.redhat.com/managed-by: plugin-infra +spec: + install: + preflight: + crdUpgradeSafety: + enforcement: None + namespace: openshift-serverless-logic + serviceAccount: + name: serverless-logic-operator-installer + source: + sourceType: Catalog + catalog: + packageName: logic-operator + channels: + - stable + version: "1.38.0" + selector: + matchLabels: + olm.operatorframework.io/metadata.name: openshift-redhat-operators + upgradeConstraintPolicy: CatalogProvided diff --git a/config/profile/rhdh/plugin-infra/serverless-logic.yaml b/config/profile/rhdh/plugin-infra/serverless-logic.yaml index c6e03683a..b1d78e9b3 100644 --- a/config/profile/rhdh/plugin-infra/serverless-logic.yaml +++ b/config/profile/rhdh/plugin-infra/serverless-logic.yaml @@ -2,12 +2,16 @@ apiVersion: v1 kind: Namespace metadata: name: openshift-serverless-logic + labels: + rhdh.redhat.com/managed-by: plugin-infra --- apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name: openshift-serverless-logic namespace: openshift-serverless-logic + labels: + rhdh.redhat.com/managed-by: plugin-infra spec: --- apiVersion: operators.coreos.com/v1alpha1 @@ -15,6 +19,8 @@ kind: Subscription metadata: name: logic-operator namespace: openshift-serverless-logic + labels: + rhdh.redhat.com/managed-by: plugin-infra spec: channel: stable # channel of an operator package to subscribe to installPlanApproval: Automatic # whether the update should be installed automatically diff --git a/config/profile/rhdh/plugin-infra/serverless-v1.yaml b/config/profile/rhdh/plugin-infra/serverless-v1.yaml new file mode 100644 index 000000000..85643c647 --- /dev/null +++ b/config/profile/rhdh/plugin-infra/serverless-v1.yaml @@ -0,0 +1,54 @@ +apiVersion: v1 +kind: Namespace +metadata: + name: openshift-serverless + labels: + rhdh.redhat.com/managed-by: plugin-infra +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + name: serverless-operator-installer + namespace: openshift-serverless + labels: + rhdh.redhat.com/managed-by: plugin-infra +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + name: serverless-operator-installer-binding + labels: + rhdh.redhat.com/managed-by: plugin-infra +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: cluster-admin +subjects: + - kind: ServiceAccount + name: serverless-operator-installer + namespace: openshift-serverless +--- +apiVersion: olm.operatorframework.io/v1 +kind: ClusterExtension +metadata: + name: serverless-operator + labels: + rhdh.redhat.com/managed-by: plugin-infra +spec: + install: + preflight: + crdUpgradeSafety: + enforcement: None + namespace: openshift-serverless + serviceAccount: + name: serverless-operator-installer + source: + sourceType: Catalog + catalog: + packageName: serverless-operator + channels: + - stable + selector: + matchLabels: + olm.operatorframework.io/metadata.name: openshift-redhat-operators + upgradeConstraintPolicy: CatalogProvided diff --git a/config/profile/rhdh/plugin-infra/serverless.yaml b/config/profile/rhdh/plugin-infra/serverless.yaml index fb49e4216..60e4eda2e 100644 --- a/config/profile/rhdh/plugin-infra/serverless.yaml +++ b/config/profile/rhdh/plugin-infra/serverless.yaml @@ -2,12 +2,16 @@ apiVersion: v1 kind: Namespace metadata: name: openshift-serverless + labels: + rhdh.redhat.com/managed-by: plugin-infra --- apiVersion: operators.coreos.com/v1 kind: OperatorGroup metadata: name: serverless-operator-group namespace: openshift-serverless + labels: + rhdh.redhat.com/managed-by: plugin-infra spec: --- apiVersion: operators.coreos.com/v1alpha1 @@ -15,9 +19,11 @@ kind: Subscription metadata: name: serverless-operator namespace: openshift-serverless + labels: + rhdh.redhat.com/managed-by: plugin-infra spec: channel: stable installPlanApproval: Automatic name: serverless-operator source: redhat-operators - sourceNamespace: openshift-marketplace \ No newline at end of file + sourceNamespace: openshift-marketplace diff --git a/docs/developer.md b/docs/developer.md index c963e565d..ac6489075 100644 --- a/docs/developer.md +++ b/docs/developer.md @@ -124,9 +124,16 @@ make undeploy In a case if Profile contain plugin infrastructure manifests `/config/profile//plugin-infra` it can be deployed by: ```sh -make plugin-infra [PROFILE=] +make plugin-infra [PROFILE=] [OLM_VERSION=auto|v0|v1] ``` +To remove plugin infrastructure installed by the same script: +```sh +make plugin-infra-undeploy [PROFILE=] [OLM_VERSION=auto|v0|v1] +``` + +`OLM_VERSION` is forwarded to `plugin-infra.sh` as `--olm-version`. See [orchestrator guide](orchestrator.md#rhdh-helper-script) for details on OLM v0 vs v1 manifest selection. + **UnDeploy the controller from the cluster:** ```sh diff --git a/docs/orchestrator-cicd.md b/docs/orchestrator-cicd.md index 4bdbba86b..633638c73 100644 --- a/docs/orchestrator-cicd.md +++ b/docs/orchestrator-cicd.md @@ -11,7 +11,7 @@ There are three methods to install GitOps/Pipelines Operator ### Method 1: Install the Operators using Scripts Refer to the `RHDH helper script` section in [orchestrator guide](orchestrator.md) and set the `--with-cicd` flag to -true when running the script. +true when running the script. GitOps and Pipelines are installed via OLM v0 Subscriptions; only OpenShift Serverless and Serverless Logic follow the script's OLM version selection (`--olm-version` or auto-detect). ### Method 2: Install the Operators from Demo Charts diff --git a/docs/orchestrator.md b/docs/orchestrator.md index ad53288c2..1346ddde6 100644 --- a/docs/orchestrator.md +++ b/docs/orchestrator.md @@ -51,14 +51,30 @@ This script provides a quick way to install the OpenShift Serverless infrastruct You can specify the RHDH version in the URL (`/release-X.Y/`, e.g., `1.7` in this example) or use main. 2. Run the script: ```bash - bash plugin-infra.sh [--with-cicd] [delete] [--branch ] + bash plugin-infra.sh [--with-cicd] [delete] [--branch ] [--olm-version auto|v0|v1] ``` Flags: -* `--with-cicd` flag will also install the OpenShift Pipelines Operator (Tekton) and OpenShift GitOps Operator (ArgoCD) in addition to the required components for the Orchestrator plugin. To continue the configuration for CICD, please follow this [guide](orchestrator-cicd.md). -* `delete` will delete the installed components instead of installing them. +* `--with-cicd` flag will also install the OpenShift Pipelines Operator (Tekton) and OpenShift GitOps Operator (ArgoCD) in addition to the required components for the Orchestrator plugin. To continue the configuration for CICD, please follow this [guide](orchestrator-cicd.md). GitOps and Pipelines are still installed via OLM v0 Subscriptions even when Serverless and Serverless Logic use OLM v1. +* `delete` will delete the installed components instead of installing them. Delete removes OLM v1 ClusterExtensions first, then Knative CRs, then OLM v0 Subscriptions when present. Resources managed by Helm or not labeled by the script are skipped. * `--branch ` flag allows to specify the branch of the RHDH Operator repository where the configuration yaml files will be taken (ignored if you have local yaml files). If not specified, it defaults to the `main` branch. +* `--olm-version` selects the OLM API used for OpenShift Serverless and Serverless Logic (`auto`, `v0`, or `v1`; default `auto`). In `auto` mode the script uses OLM v1 when ClusterExtension and ClusterCatalog CRDs exist and a platform `ClusterCatalog` labeled `openshift-redhat-operators` is present; otherwise it uses OLM v0 Subscriptions. -The script is checking if the directory where plugin-infra.sh is located contains the corresponding configuration files, e.g., serverless.yaml, knative.yaml, serverless-logic.yaml... (see [plugin-infra directory](../config/profile/rhdh/plugin-infra) for the complete list). If the files are not found, it will download them from the specified branch of the RHDH Operator repository. +The script checks whether the directory where `plugin-infra.sh` is located contains the corresponding configuration files (see [plugin-infra directory](../config/profile/rhdh/plugin-infra) for the complete list). If the files are not found, it downloads them from the specified branch of the RHDH Operator repository. + +Manifest files for orchestrator operators: + +| OLM version | Serverless | Serverless Logic | +|-------------|------------|------------------| +| v0 | `serverless.yaml` | `serverless-logic.yaml` | +| v1 | `serverless-v1.yaml` | `serverless-logic-v1.yaml` | + +Both paths apply `knative.yaml` after the Serverless operator CRDs are available. OLM v1 manifests use `ClusterExtension` resources and require the platform Red Hat Operators `ClusterCatalog`; they are not created by this script. + +Example: force the legacy Subscription path on a cluster that also has OLM v1: + +```bash +bash plugin-infra.sh --olm-version v0 +``` #### RHDH Orchestrator Infra Helm Chart This method has similar usage and cautions as the RHDH Helper Utility. From d025e4b4a5635843c2e224bed86f517e07a44254 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Mon, 21 Sep 2026 15:58:51 +0100 Subject: [PATCH 2/4] fix(plugin-infra): address PR review comments This commit addresses review feedback from PR #3555: 1. Fix race condition in resource_exists() by combining two kubectl calls into a single call with captured output and exit code. 2. Prevent duplicate operator installations during cluster upgrades by detecting existing v0 Subscriptions before auto-selecting v1. When operators are already installed via v0 and the cluster gains OLM v1 capabilities, the script now stays with v0 and advises the user to explicitly migrate. 3. Replace polling loop in wait_for_clusterextension_deleted() with kubectl wait --for=delete for cleaner implementation. 4. Remove crdUpgradeSafety enforcement: None from ClusterExtension manifests to enable default safety checks during operator upgrades. Signed-off-by: Fortune Ndlovu --- .../profile/rhdh/plugin-infra/plugin-infra.sh | 48 +++++++++++++------ .../plugin-infra/serverless-logic-v1.yaml | 4 -- .../rhdh/plugin-infra/serverless-v1.yaml | 4 -- 3 files changed, 34 insertions(+), 22 deletions(-) diff --git a/config/profile/rhdh/plugin-infra/plugin-infra.sh b/config/profile/rhdh/plugin-infra/plugin-infra.sh index 501167c4e..c8de4d1fa 100755 --- a/config/profile/rhdh/plugin-infra/plugin-infra.sh +++ b/config/profile/rhdh/plugin-infra/plugin-infra.sh @@ -58,11 +58,12 @@ kubectl_get() { } resource_exists() { - local err - if kubectl_get "$@" >/dev/null; then + local err exit_code + err="$(kubectl_get "$@" 2>&1)" + exit_code=$? + if [[ ${exit_code} -eq 0 ]]; then return 0 fi - err="$(kubectl_get "$@" || true)" if grep -qiE '(not found|NotFound)' <<<"${err}"; then return 1 fi @@ -145,6 +146,22 @@ detect_olm_v0_operatorgroup_crd() { crd_exists "operatorgroups.operators.coreos.com" } +has_v0_operators_installed() { + if ! detect_olm_v0_subscription_crd; then + return 1 + fi + + if resource_exists "subscription/${SERVERLESS_OPERATOR_NAME}" -n openshift-serverless 2>/dev/null; then + return 0 + fi + + if resource_exists "subscription/${LOGIC_OPERATOR_NAME}" -n openshift-serverless-logic 2>/dev/null; then + return 0 + fi + + return 1 +} + redhat_operators_catalog_exists() { local catalogs err exit_code @@ -212,8 +229,15 @@ resolve_olm_version() { if detect_olm_v1_crd && detect_olm_v1_clustercatalog_crd; then if redhat_operators_catalog_exists; then - resolved_olm_version="v1" - echo "Auto-detected OLM v1 (ClusterExtension and ClusterCatalog CRDs found)" + # Check if operators are already installed via v0 + if has_v0_operators_installed; then + resolved_olm_version="v0" + echo "Auto-detected OLM v0 (operators already installed via v0 Subscriptions)" + echo " Note: To migrate to OLM v1, first run 'plugin-infra.sh delete' to remove v0 installations" + else + resolved_olm_version="v1" + echo "Auto-detected OLM v1 (ClusterExtension and ClusterCatalog CRDs found)" + fi else resolved_olm_version="v0" echo "Auto-detected OLM v0 (openshift-redhat-operators ClusterCatalog not found)" @@ -295,21 +319,17 @@ wait_for_clusterextension_if_relevant() { wait_for_clusterextension_deleted() { local name="$1" local timeout="${2:-300}" - local elapsed=0 if ! detect_olm_v1_crd; then return 0 fi + if ! resource_exists "clusterextension/${name}"; then + return 0 + fi + echo "Waiting for ClusterExtension/${name} to be removed..." - while resource_exists "clusterextension/${name}"; do - if (( elapsed >= timeout )); then - echo "Timed out waiting for ClusterExtension/${name} deletion" - exit 1 - fi - sleep 5 - elapsed=$((elapsed + 5)) - done + kubectl wait --for=delete "clusterextension/${name}" --timeout="${timeout}s" } delete_plugin_infra_v1_operator() { diff --git a/config/profile/rhdh/plugin-infra/serverless-logic-v1.yaml b/config/profile/rhdh/plugin-infra/serverless-logic-v1.yaml index bb732734f..7e0540e5a 100644 --- a/config/profile/rhdh/plugin-infra/serverless-logic-v1.yaml +++ b/config/profile/rhdh/plugin-infra/serverless-logic-v1.yaml @@ -35,10 +35,6 @@ metadata: labels: rhdh.redhat.com/managed-by: plugin-infra spec: - install: - preflight: - crdUpgradeSafety: - enforcement: None namespace: openshift-serverless-logic serviceAccount: name: serverless-logic-operator-installer diff --git a/config/profile/rhdh/plugin-infra/serverless-v1.yaml b/config/profile/rhdh/plugin-infra/serverless-v1.yaml index 85643c647..9233b0edb 100644 --- a/config/profile/rhdh/plugin-infra/serverless-v1.yaml +++ b/config/profile/rhdh/plugin-infra/serverless-v1.yaml @@ -35,10 +35,6 @@ metadata: labels: rhdh.redhat.com/managed-by: plugin-infra spec: - install: - preflight: - crdUpgradeSafety: - enforcement: None namespace: openshift-serverless serviceAccount: name: serverless-operator-installer From 32d5d945de817dd019b6edd7e988ad82a217bc76 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 22 Sep 2026 10:08:26 +0100 Subject: [PATCH 3/4] fix(plugin-infra): correct jsonpath for label access in is_plugin_infra_managed The jsonpath syntax for accessing labels with dots in the key name was incorrect. Using bracket notation with variable expansion doesn't work in jsonpath - the dots must be escaped when using dot notation. Without this fix, is_plugin_infra_managed() always returns false, causing deletion to skip all plugin-infra managed resources. Signed-off-by: Fortune Ndlovu --- config/profile/rhdh/plugin-infra/plugin-infra.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/config/profile/rhdh/plugin-infra/plugin-infra.sh b/config/profile/rhdh/plugin-infra/plugin-infra.sh index c8de4d1fa..602dc9bc4 100755 --- a/config/profile/rhdh/plugin-infra/plugin-infra.sh +++ b/config/profile/rhdh/plugin-infra/plugin-infra.sh @@ -99,10 +99,10 @@ is_plugin_infra_managed() { if [[ -n "${namespace}" ]]; then managed_by="$(kubectl get -n "${namespace}" "${resource}" \ - -o "jsonpath={.metadata.labels['${PLUGIN_INFRA_LABEL_KEY}']}" 2>/dev/null || true)" + -o jsonpath="{.metadata.labels.rhdh\.redhat\.com/managed-by}" 2>/dev/null || true)" else managed_by="$(kubectl get "${resource}" \ - -o "jsonpath={.metadata.labels['${PLUGIN_INFRA_LABEL_KEY}']}" 2>/dev/null || true)" + -o jsonpath="{.metadata.labels.rhdh\.redhat\.com/managed-by}" 2>/dev/null || true)" fi [[ "${managed_by}" == "${PLUGIN_INFRA_LABEL_VALUE}" ]] From 12e551bfc85162ee4d832bb41594abe42a4c1e03 Mon Sep 17 00:00:00 2001 From: Fortune-Ndlovu Date: Tue, 22 Sep 2026 10:30:02 +0100 Subject: [PATCH 4/4] fix(plugin-infra): remove unused PLUGIN_INFRA_LABEL_KEY variable ShellCheck was reporting SC2034 warning about PLUGIN_INFRA_LABEL_KEY being unused. The variable was originally used in jsonpath queries but was replaced with a hardcoded label path to fix jsonpath syntax issues. Since the label key is hardcoded in the jsonpath expression and unlikely to change, removing the unused variable. Signed-off-by: Fortune Ndlovu --- config/profile/rhdh/plugin-infra/plugin-infra.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/config/profile/rhdh/plugin-infra/plugin-infra.sh b/config/profile/rhdh/plugin-infra/plugin-infra.sh index 602dc9bc4..c6440adb5 100755 --- a/config/profile/rhdh/plugin-infra/plugin-infra.sh +++ b/config/profile/rhdh/plugin-infra/plugin-infra.sh @@ -11,7 +11,6 @@ cicd=false # Default CICD mode olm_version="auto" # Default OLM version (v0, v1, or auto-detect) resolved_olm_version="" -PLUGIN_INFRA_LABEL_KEY="rhdh.redhat.com/managed-by" PLUGIN_INFRA_LABEL_VALUE="plugin-infra" REDHAT_OPERATORS_CATALOG_LABEL="olm.operatorframework.io/metadata.name=openshift-redhat-operators" SERVERLESS_OPERATOR_NAME="serverless-operator"