@@ -48,3 +48,153 @@ Referenced from: https://github.com/bitnami/charts/blob/main/bitnami/postgresql/
4848 {{- printf " %s " (include " common.names.fullname" . ) -}}
4949 {{- end -}}
5050{{- end -}}
51+
52+ {{/* Helepr functions */ }}
53+
54+ {{- define " unmanaged-resource-exists" -}}
55+ {{- $api := index . 0 -}}
56+ {{- $kind := index . 1 -}}
57+ {{- $namespace := index . 2 -}}
58+ {{- $name := index . 3 -}}
59+ {{- $releaseName := index . 4 -}}
60+ {{- $apiCapabilities := index . 5 -}}
61+ {{- $unmanagedSubscriptionExists := " true" -}}
62+ {{- if $apiCapabilities .Has (printf " %s /%s " $api $kind ) }}
63+ {{- $existingOperator := lookup $api $kind $namespace $name -}}
64+ {{- if empty $existingOperator -}}
65+ {{- " false" -}}
66+ {{- else -}}
67+ {{- $isManagedResource := include " is-managed-resource" (list $existingOperator $releaseName ) -}}
68+ {{- if eq $isManagedResource " true" -}}
69+ {{- " false" -}}
70+ {{- else -}}
71+ {{- " true" -}}
72+ {{- end -}}
73+ {{- end -}}
74+ {{- else -}}
75+ {{- " false" -}}
76+ {{- end -}}
77+ {{- end -}}
78+
79+ {{- define " is-managed-resource" -}}
80+ {{- $resource := index . 0 -}}
81+ {{- $releaseName := index . 1 -}}
82+ {{- $resourceReleaseName := dig " metadata" " annotations" (dict " meta.helm.sh/release-name" " NA" ) $resource -}}
83+ {{- if eq (get $resourceReleaseName " meta.helm.sh/release-name" ) $releaseName -}}
84+ {{- " true" -}}
85+ {{- else -}}
86+ {{- " false" -}}
87+ {{- end -}}
88+ {{- end -}}
89+
90+
91+ {{- define " cluster.domain" -}}
92+ {{- if .Capabilities.APIVersions.Has " config.openshift.io/v1/Ingress" -}}
93+ {{- $cluster := (lookup " config.openshift.io/v1" " Ingress" " " " cluster" ) -}}
94+ {{- if and (hasKey $cluster " spec" ) (hasKey $cluster .spec " domain" ) -}}
95+ {{- printf " %s " $cluster .spec.domain -}}
96+ {{- else -}}
97+ {{ fail " Unable to obtain cluster domain, OCP Ingress Resource is missing the `spec.domain` field." }}
98+ {{- end }}
99+ {{- else -}}
100+ {{ fail " Unable to obtain cluster domain, config.openshift.io/v1/Ingress is missing" }}
101+ {{- end -}}
102+ {{- end -}}
103+
104+
105+ {{- define " install-tekton-task" -}}
106+ {{- if and (and (and .Values.orchestrator.tekton.enabled .Values.orchestrator.argocd.enabled ) (ne .Values.orchestrator.rhdhOperator.secretRef.k8s.clusterToken " " )) (.Capabilities.APIVersions.Has " tekton.dev/v1/Task" ) }}
107+ {{- " true" -}}
108+ {{- else }}
109+ {{- " false" -}}
110+ {{- end -}}
111+ {{- end -}}
112+
113+ {{- define " install-tekton-pipeline" -}}
114+ {{- if and (and (and .Values.orchestrator.tekton.enabled .Values.orchestrator.argocd.enabled ) (ne .Values.orchestrator.rhdhOperator.secretRef.k8s.clusterToken " " )) (.Capabilities.APIVersions.Has " tekton.dev/v1/Pipeline" ) }}
115+ {{- " true" -}}
116+ {{- else }}
117+ {{- " false" -}}
118+ {{- end -}}
119+ {{- end -}}
120+
121+ {{- define " install-argocd-project" -}}
122+ {{- if and (.Values.orchestrator.argocd.enabled ) (.Capabilities.APIVersions.Has " argoproj.io/v1alpha1/AppProject" ) }}
123+ {{- " true" -}}
124+ {{- else }}
125+ {{- " false" -}}
126+ {{- end -}}
127+ {{- end -}}
128+
129+
130+ {{- define " get-namespace-with-label" -}}
131+ {{- $paramValue := index . 0 -}}
132+ {{- $matchingLabel := index . 1 -}}
133+ {{- if $paramValue -}}
134+ {{- $paramValue -}}
135+ {{- else -}}
136+ {{- $ns := " " }}
137+ {{- $list := lookup " v1" " Namespace" " " " " -}}
138+ {{- if eq 0 (len (dig " items" (dict " " " " ) $list ) )}}
139+ {{- fail (printf " No namespaces found: %d " (len (dig " items" (dict " " " " ) $list )) ) }}
140+ {{- end -}}
141+ {{- range (dig " items" (dict " " " " ) $list ) }}
142+ {{- $labels := dig " metadata" " labels" (dict " " " " ) . -}}
143+ {{- if (hasKey $labels $matchingLabel ) }}
144+ {{- if not $ns }}
145+ {{- $ns = dig " metadata" " name" " " . -}}
146+ {{- else -}}
147+ {{- fail (printf " More than one namespace found with label %s : %s and %s " $matchingLabel $ns (dig " metadata" " name" " " . ) )}}
148+ {{- end }}
149+ {{- end -}}
150+ {{- end -}}
151+ {{- if not $ns -}}
152+ {{- fail (printf " No namespace found with label '%s '. Please follow the installation instructions to properly configure the environment" $matchingLabel ) -}}
153+ {{- end }}
154+ {{- $ns }}
155+ {{- end -}}
156+ {{- end -}}
157+
158+ {{- define " get-workflow-namespace" -}}
159+ {{- if (not (hasKey . " workflowNamespace" ) ) -}}
160+ {{- $workflowNamespace := include " get-namespace-with-label" (list .Values.orchestrator.orchestrator.namespace " rhdh.redhat.com/workflow-namespace" ) }}
161+ {{- $_ := set . " workflowNamespace" $workflowNamespace }}
162+ {{- end -}}
163+ {{- .workflowNamespace -}}
164+ {{- end -}}
165+
166+ {{- define " get-argocd-namespace" -}}
167+ {{- if .Values.orchestrator.argocd.enabled }}
168+ {{- if (not (hasKey . " argoCDNamespace" ) ) -}}
169+ {{- $argoCDNamespace := include " get-namespace-with-label" (list .Values.orchestrator.argocd.namespace " rhdh.redhat.com/argocd-namespace" ) }}
170+ {{- $_ := set . " argoCDNamespace" $argoCDNamespace }}
171+ {{- end -}}
172+ {{- .argoCDNamespace -}}
173+ {{- end -}}
174+ {{- end -}}
175+
176+ {{- define " get-cluster-version" -}}
177+ {{- $v := " " }}
178+ {{- $version := (lookup " config.openshift.io/v1" " ClusterVersion" " " " version" ) }}
179+ {{- range $version .status.history }}
180+ {{- if eq .state " Completed" }}
181+ {{- $v = (semver .version ) }}
182+ {{- end }}
183+ {{- end }}
184+
185+ {{- $validMinors := list " 4.13" " 4.14" " 4.15" " 4.16" -}}
186+ {{- $versionString := printf " %d .%d " $v .Major $v .Minor -}}
187+ {{- if not (semverCompare " >=4.13 <=4.16" $versionString ) -}}
188+ {{- fail (printf " Unsupported OCP version: %s . Supported versions: %s ." $versionString $validMinors ) -}}
189+ {{- end -}}
190+ {{- $versionString -}}
191+ {{- end -}}
192+
193+ {{- define " get-tekton-version" -}}
194+ {{- $pipelinesSubs := lookup " operators.coreos.com/v1alpha1" " Subscription" " openshift-operators" " openshift-pipelines-operator-rh" -}}
195+ {{- $pipelineInstalledVersion := $pipelinesSubs .status.installedCSV }}
196+ {{- $pipelineVersion := substr 33 ( len $pipelineInstalledVersion ) $pipelineInstalledVersion }}
197+ {{- $pipelineVersion = semver $pipelineVersion }}
198+ {{- $pipelineVersionString := printf " %d .%d " $pipelineVersion .Major $pipelineVersion .Minor -}}
199+ {{- $pipelineVersionString -}}
200+ {{- end -}}
0 commit comments