@@ -8,6 +8,8 @@ set -euo pipefail
88action=" apply" # Default action
99branch=" main" # Default branch
1010cicd=false # Default CICD mode
11+ olm_version=" auto" # Default OLM version (v0, v1, or auto-detect)
12+ resolved_olm_version=" "
1113
1214# Parse command-line options
1315while [[ $# -gt 0 ]]; do
@@ -16,6 +18,10 @@ while [[ $# -gt 0 ]]; do
1618 cicd=true
1719 shift
1820 ;;
21+ --olm-version)
22+ olm_version=" $2 "
23+ shift 2
24+ ;;
1925 apply|delete)
2026 action=" $1 "
2127 shift
@@ -31,6 +37,52 @@ while [[ $# -gt 0 ]]; do
3137 esac
3238done
3339
40+ case " ${olm_version} " in
41+ v0|v1|auto) ;;
42+ * )
43+ echo " Unknown --olm-version value: ${olm_version} . Must be v0, v1, or auto."
44+ exit 1
45+ ;;
46+ esac
47+
48+ detect_olm_v1_crd () {
49+ kubectl get crd clusterextensions.olm.operatorframework.io & > /dev/null
50+ }
51+
52+ detect_olm_v1_clustercatalog_crd () {
53+ kubectl get crd clustercatalogs.olm.operatorframework.io & > /dev/null
54+ }
55+
56+ resolve_olm_version () {
57+ if [[ " ${olm_version} " == " v0" ]]; then
58+ resolved_olm_version=" v0"
59+ echo " Using OLM v0 (forced via --olm-version)"
60+ return
61+ fi
62+
63+ if [[ " ${olm_version} " == " v1" ]]; then
64+ if ! detect_olm_v1_crd; then
65+ echo " OLM v1 requested but ClusterExtension CRD not found on this cluster"
66+ exit 1
67+ fi
68+ if ! detect_olm_v1_clustercatalog_crd; then
69+ echo " OLM v1 requested but ClusterCatalog CRD not found on this cluster"
70+ exit 1
71+ fi
72+ resolved_olm_version=" v1"
73+ echo " Using OLM v1 (forced via --olm-version)"
74+ return
75+ fi
76+
77+ if detect_olm_v1_crd && detect_olm_v1_clustercatalog_crd; then
78+ resolved_olm_version=" v1"
79+ echo " Auto-detected OLM v1 (ClusterExtension and ClusterCatalog CRDs found)"
80+ else
81+ resolved_olm_version=" v0"
82+ echo " Auto-detected OLM v0 (OLM v1 CRDs not found)"
83+ fi
84+ }
85+
3486apply_manifest () {
3587 local file=" $1 "
3688 local url=" https://raw.githubusercontent.com/redhat-developer/rhdh-operator/${branch} /config/profile/rhdh/plugin-infra/${file} "
@@ -46,13 +98,35 @@ apply_manifest() {
4698 fi
4799}
48100
101+ wait_for_clusterextension () {
102+ local name=" $1 "
103+ echo " Waiting for ClusterExtension/${name} to be Installed..."
104+ kubectl wait " clusterextension/${name} " --for=condition=Installed --timeout=300s
105+ }
106+
107+ resolve_olm_version
108+
109+ if [[ " ${resolved_olm_version} " == " v1" ]]; then
110+ serverless_manifest=" serverless-v1.yaml"
111+ serverless_logic_manifest=" serverless-logic-v1.yaml"
112+ else
113+ serverless_manifest=" serverless.yaml"
114+ serverless_logic_manifest=" serverless-logic.yaml"
115+ fi
116+
49117# Execution
50118if [[ " $action " == " apply" ]]; then
51- apply_manifest " serverless.yaml"
119+ apply_manifest " ${serverless_manifest} "
120+ if [[ " ${resolved_olm_version} " == " v1" ]]; then
121+ wait_for_clusterextension " serverless-operator"
122+ fi
52123 echo " Waiting for CRDs to be established..."
53124 kubectl wait --for=condition=Established crd --all --timeout=60s
54125 apply_manifest " knative.yaml"
55- apply_manifest " serverless-logic.yaml"
126+ apply_manifest " ${serverless_logic_manifest} "
127+ if [[ " ${resolved_olm_version} " == " v1" ]]; then
128+ wait_for_clusterextension " logic-operator"
129+ fi
56130 if [[ " $cicd " == true ]]; then
57131 echo " CICD enabled. Executing CICD-specific logic..."
58132 apply_manifest " argocd.yaml"
@@ -61,9 +135,9 @@ if [[ "$action" == "apply" ]]; then
61135 apply_manifest " pipeline.yaml"
62136 fi
63137elif [[ " $action " == " delete" ]]; then
64- apply_manifest " serverless-logic.yaml "
138+ apply_manifest " ${serverless_logic_manifest} "
65139 apply_manifest " knative.yaml"
66- apply_manifest " serverless.yaml "
140+ apply_manifest " ${serverless_manifest} "
67141 if [[ " $cicd " == true ]]; then
68142 apply_manifest " argocd.yaml"
69143 apply_manifest " argocd-cr.yaml"
73147 echo " Action '$action ' is not supported. Use 'apply' (default) or 'delete'."
74148 exit 1
75149fi
76-
0 commit comments