new way of doin
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
root
2023-11-16 19:42:02 +10:00
parent 77ec717184
commit 1eaf295724
341 changed files with 19416 additions and 0 deletions

View File

@@ -0,0 +1,144 @@
{{/* Contains the auto-permissions job */}}
{{- define "tc.v1.common.lib.util.autoperms" -}}
{{- $permAllowedTypes := (list "hostPath" "emptyDir" "nfs" "ixVolume") -}}
{{/* If you change this path, you must change it under _volumeMounts.tpl too*/}}
{{- $basePath := "/mounts" -}}
{{/* Init an empty dict to hold data */}}
{{- $mounts := dict -}}
{{/* Go over persistence and gather needed data */}}
{{- range $name, $mount := .Values.persistence -}}
{{- if and $mount.enabled $mount.autoPermissions -}}
{{/* If autoPermissions is enabled...*/}}
{{- if $mount.autoPermissions.enabled -}}
{{- if or $mount.autoPermissions.chown $mount.autoPermissions.chmod -}}
{{- $type := $.Values.fallbackDefaults.persistenceType -}}
{{- if $mount.type -}}
{{- $type = $mount.type -}}
{{- end -}}
{{- if not (mustHas $type $permAllowedTypes) -}}
{{- fail (printf "Auto Permissions - Allowed persistent types for auto permissions are [%v], but got [%v] on [%v]" (join ", " $permAllowedTypes) $type $name) -}}
{{- end -}}
{{- if $mount.readOnly -}}
{{- fail (printf "Auto Permissions - You cannot change permissions/ownership automatically on [%v] with readOnly enabled" $name) -}}
{{- end -}}
{{/* Add some data regarding what actions to perform */}}
{{- $_ := set $mounts $name $mount.autoPermissions -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $mounts }}
enabled: true
type: Job
annotations:
"helm.sh/hook": pre-install, pre-upgrade
"helm.sh/hook-weight": "3"
"helm.sh/hook-delete-policy": hook-succeeded,before-hook-creation,hook-failed
podSpec:
restartPolicy: Never
containers:
# If you change this name, you must change it under _volumeMounts.tpl
autopermissions:
enabled: true
primary: true
imageSelector: alpineImage
securityContext:
runAsNonRoot: false
runAsUser: 0
capabilities:
disableS6Caps: true
add:
- CHOWN
- DAC_OVERRIDE
- FOWNER
resources:
limits:
cpu: 2000m
memory: 2Gi
probes:
liveness:
type: exec
command:
- cat
- /tmp/healthy
readiness:
type: exec
command:
- cat
- /tmp/healthy
startup:
type: exec
command:
- cat
- /tmp/healthy
command:
- /bin/sh
- -c
args:
- |
echo "Starting auto permissions job..."
touch /tmp/healthy
echo "Automatically correcting ownership and permissions..."
{{- range $name, $vol := $mounts }}
{{- $mountPath := (printf "%v/%v" $basePath $name) -}}
{{- $user := "" -}}
{{- if $vol.user -}}
{{- $user = $vol.user -}}
{{- end -}}
{{- $group := $.Values.securityContext.pod.fsGroup -}}
{{- if $vol.group -}}
{{- $group = $vol.group -}}
{{- end -}}
{{- $r := "" -}}
{{- if $vol.recursive -}}
{{- $r = "-$" -}}
{{- end -}}
{{/* Permissions */}}
{{- if $vol.chmod }}
echo "Automatically correcting permissions for {{ $mountPath }}..."
before=$(stat -c "%a" {{ $mountPath }})
chmod {{ $r }} {{ $vol.chmod }} {{ $mountPath }} || echo "Failed setting permissions using chmod..."
echo "Permissions after: [$before]"
echo "Permissions after: [$(stat -c "%a" {{ $mountPath }})]"
echo ""
{{- end -}}
{{/* Ownership */}}
{{- if $vol.chown }}
echo "Automatically correcting ownership for {{ $mountPath }}..."
before=$(stat -c "%u:%g" {{ $mountPath }})
{{- if $.Values.global.ixChartContext }}{{/* TODO: Add user here too? */}}
/usr/sbin/nfs4xdr_winacl -a chown -G {{ $group }} {{ $r | lower }} -c "{{ $mountPath }}" -p "{{ $mountPath }}" || echo "Failed setting ownership using winacl..."
{{- else }}
chown {{ $r }} -f {{ $user }}:{{ $group }} {{ $mountPath }} || echo "Failed setting ownership using chown..."
{{- end }}
echo "Ownership before: [$before]"
echo "Ownership after: [$(stat -c "%u:%g" {{ $mountPath }})]"
echo ""
{{- end -}}
{{- end }}
echo "Finished auto permissions job..."
{{- end -}}
{{- end -}}
{{- define "tc.v1.common.lib.util.autoperms.job" -}}
{{- $job := (include "tc.v1.common.lib.util.autoperms" $) | fromYaml -}}
{{- if $job -}}
# If you change this name, you must change it under _volumes.tpl
{{- $_ := set $.Values.workload "autopermissions" $job -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,152 @@
{{/* Returns the primary Workload object */}}
{{- define "tc.v1.common.lib.util.chartcontext" -}}
{{/* Create defaults */}}
{{- $protocol := "https" -}}
{{- $host := "127.0.0.1" -}}
{{- $port := "443" -}}
{{- $url := "" -}}
{{- $podCIDR := "172.16.0.0/16" -}}
{{- $svcCIDR := "172.17.0.0/16" -}}
{{/* set temporary storage for ingress name and port */}}
{{- $targetIngress := "" -}}
{{- $selectedIngress := "" -}}
{{/* Get service, default to primary */}}
{{- $selectedService := fromYaml (include "tc.v1.common.lib.helpers.getSelectedServiceValues" (dict "rootCtx" $ )) -}}
{{/* read loadbalancer IPs for metallb */}}
{{- if eq $selectedService.type "LoadBalancer" -}}
{{- with $selectedService.loadBalancerIP -}}
{{- $host = toString . -}}
{{- end -}}
{{/* set temporary storage for port name and port */}}
{{- $targetPort := "" -}}
{{- $selectedPort := "" -}}
{{/* Fetch port values */}}
{{- $targetPort = include "tc.v1.common.lib.util.service.ports.primary" (dict "svcName" $selectedService.shortName "svcValues" $selectedService) -}}
{{- $selectedPort = get $selectedService.ports $targetPort -}}
{{/* store port number */}}
{{- $port = $selectedPort.port -}}
{{- end -}}
{{/* Fetch ingress values */}}
{{- $targetIngress = include "tc.v1.common.lib.util.ingress.primary" $ -}}
{{- $selectedIngress = get $.Values.ingress $targetIngress -}}
{{/* store host from ingress number */}}
{{- if $selectedIngress -}}
{{- if $selectedIngress.enabled -}}
{{- with (index $selectedIngress.hosts 0) -}}
{{- $host = .host -}}
{{- end -}}
{{/* Get the port for the ingress entrypoint */}}
{{- $namespace := "tc-system" -}}
{{- if $.Values.operator.traefik -}}
{{- if $.Values.operator.traefik.namespace -}}
{{- $namespace = $.Values.operator.traefik.namespace -}}
{{- end -}}
{{- end -}}
{{- if $selectedIngress.ingressClassName -}}
{{- if $.Values.global.ixChartContext -}}
{{- $namespace = (printf "ix-%s" $selectedIngress.ingressClassName) -}}
{{- else -}}
{{- $namespace = $selectedIngress.ingressClassName -}}
{{- end -}}
{{- end -}}
{{- $traefikportalhook := lookup "v1" "ConfigMap" $namespace "portalhook" | default dict -}}
{{/* If there is no portalhook */}}
{{- if not $traefikportalhook -}}
{{/* Get all configmaps */}}
{{- $hooks := lookup "v1" "ConfigMap" $namespace "" -}}
{{- $portalHooks := list -}}
{{- range $hook := ($hooks.items | default list) -}}
{{- $hookData := (get $hook "data") -}}
{{- $hookMetaData := (get $hook "metadata") -}}
{{- if and $hookData $hookMetaData -}}
{{/* Filter portalhook-* */}}
{{- if $hookMetaData.name -}}
{{- if hasPrefix "portalhook-" $hookMetaData.name -}}
{{- $portalHooks = mustAppend $portalHooks $hook -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* use the first available portalhook */}}
{{- if $portalHooks -}}
{{- $traefikportalhook = index $portalHooks 0 -}}
{{- end -}}
{{- end -}}
{{- $entrypoint := "websecure" -}}
{{- if $selectedIngress.entrypoint -}}
{{- $entrypoint = $selectedIngress.entrypoint -}}
{{- end -}}
{{- if $traefikportalhook -}}
{{- if (get $traefikportalhook.data $entrypoint) -}}
{{- $port = (get $traefikportalhook.data $entrypoint) -}}
{{- else if $traefikportalhook.data.websecure -}}
{{- $port = $traefikportalhook.data.websecure -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $port = toString $port -}}
{{/* sanitise */}}
{{- if eq $port "443" -}}
{{- $protocol = "https" -}}
{{- end -}}
{{- if eq $port "80" -}}
{{- $protocol = "http" -}}
{{- end -}}
{{- if or (and (eq $protocol "https") (eq $port "443")) (and (eq $protocol "http") (eq $port "80")) -}}
{{- $port = "" -}}
{{- end -}}
{{/* Construct URL*/}}
{{- if $port -}}
{{- $url = printf "%s://%s:%s" $protocol $host $port -}}
{{- else -}}
{{- $url = printf "%s://%s" $protocol $host -}}
{{- end -}}
{{/* TrueNAS SCALE specific code */}}
{{- if $.Values.global.ixChartContext -}}
{{- if $.Values.global.ixChartContext.kubernetes_config -}}
{{- $podCIDR = $.Values.global.ixChartContext.kubernetes_config.cluster_cidr -}}
{{- $svcCIDR = $.Values.global.ixChartContext.kubernetes_config.service_cidr -}}
{{- end -}}
{{- else -}}
{{/* TODO: Find ways to implement CIDR detection */}}
{{- end -}}
{{- if $.Values.chartContext -}}
{{- if $.Values.chartContext.APPURL -}}
{{- $url = $.Values.chartContext.APPURL -}}
{{- end -}}
{{- if $.Values.chartContext.podCIDR -}}
{{- $podCIDR = $.Values.chartContext.podCIDR -}}
{{- end -}}
{{- if $.Values.chartContext.svcCIDR -}}
{{- $svcCIDR = $.Values.chartContext.svcCIDR -}}
{{- end -}}
{{- end -}}
{{- $_ := set $.Values.chartContext "APPURL" $url -}}
{{- $_ := set $.Values.chartContext "podCIDR" $podCIDR -}}
{{- $_ := set $.Values.chartContext "svcCIDR" $svcCIDR -}}
{{- end -}}

View File

@@ -0,0 +1,23 @@
{{/* Return the name of the primary Cert object */}}
{{- define "tc.v1.common.lib.util.cert.primary" -}}
{{- $Certs := $.Values.cert -}}
{{- $enabledCerts := dict -}}
{{- range $name, $cert := $Certs -}}
{{- if $cert.enabled -}}
{{- $_ := set $enabledCerts $name . -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $cert := $enabledCerts -}}
{{- if and (hasKey $cert "primary") $cert.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- $result = keys $Certs | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View File

@@ -0,0 +1,23 @@
{{/* Return the name of the primary cnpg object */}}
{{- define "tc.v1.common.lib.util.cnpg.primary" -}}
{{- $cnpgs := .Values.cnpg -}}
{{- $enabledcnpges := dict -}}
{{- range $name, $cnpg := $cnpgs -}}
{{- if $cnpg.enabled -}}
{{- $_ := set $enabledcnpges $name . -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $cnpg := $enabledcnpges -}}
{{- if and (hasKey $cnpg "primary") $cnpg.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- $result = keys $enabledcnpges | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View File

@@ -0,0 +1,23 @@
{{/* Return the name of the primary ingress object */}}
{{- define "tc.v1.common.lib.util.ingress.primary" -}}
{{- $ingresses := $.Values.ingress -}}
{{- $enabledIngresses := dict -}}
{{- range $name, $ingress := $ingresses -}}
{{- if $ingress.enabled -}}
{{- $_ := set $enabledIngresses $name . -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $ingress := $enabledIngresses -}}
{{- if and (hasKey $ingress "primary") $ingress.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- $result = keys $enabledIngresses | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View File

@@ -0,0 +1,30 @@
{{/* Return the name of the primary metrics object */}}
{{- define "tc.v1.common.lib.util.metrics.primary" -}}
{{- $metrics := .Values.metrics -}}
{{- $enabledMetrics := dict -}}
{{- range $name, $metrics := $metrics -}}
{{- if $metrics.enabled -}}
{{- $_ := set $enabledMetrics $name $metrics -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $metrics := $enabledMetrics -}}
{{- if (hasKey $metrics "primary") -}}
{{- if $metrics.primary -}}
{{- if $result -}}
{{- fail "More than one metrics are set as primary. This is not supported." -}}
{{- end -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- if eq (len $enabledMetrics) 1 -}}
{{- $result = keys $enabledMetrics | mustFirst -}}
{{- end -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View File

@@ -0,0 +1,41 @@
{{/* A dict containing .values and .serviceName is passed when this function is called */}}
{{/* Return the primary port for a given Service object. */}}
{{- define "tc.v1.common.lib.util.service.ports.primary" -}}
{{- $svcName := .svcName -}}
{{- $svcValues := .svcValues -}}
{{- $enabledPorts := dict -}}
{{- range $name, $port := $svcValues.ports -}}
{{- if $port.enabled -}}
{{- $_ := set $enabledPorts $name $port -}}
{{- end -}}
{{- end -}}
{{- if not $enabledPorts -}}
{{- fail (printf "No ports are enabled for the service: (%s)" $svcName) -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $port := $enabledPorts -}}
{{- if (hasKey $port "primary") -}}
{{- if $port.primary -}}
{{- if $result -}}
{{- fail (printf "More than one ports are set as primary in the (%s) service. This is not supported." $svcName ) -}}
{{- end -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- if eq (len $enabledPorts) 1 -}}
{{- $result = keys $enabledPorts | mustFirst -}}
{{- else -}}
{{- if $enabledPorts -}}
{{- fail (printf "At least one port must be set as primary in service (%s)" $svcName) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View File

@@ -0,0 +1,23 @@
{{/* Return the name of the primary route object */}}
{{- define "tc.v1.common.lib.util.route.primary" -}}
{{- $routees := $.Values.route -}}
{{- $enabledroutees := dict -}}
{{- range $name, $route := $routees -}}
{{- if $route.enabled -}}
{{- $_ := set $enabledroutees $name . -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $route := $enabledroutees -}}
{{- if and (hasKey $route "primary") $route.primary -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- $result = keys $enabledroutees | first -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View File

@@ -0,0 +1,39 @@
{{/* Returns the primary service object */}}
{{- define "tc.v1.common.lib.util.service.primary" -}}
{{- $services := .services -}}
{{- $enabledServices := dict -}}
{{- range $name, $service := $services -}}
{{- if $service.enabled -}}
{{- $_ := set $enabledServices $name $service -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $service := $enabledServices -}}
{{- if (hasKey $service "primary") -}}
{{- if $service.primary -}}
{{- if $result -}}
{{- fail "More than one services are set as primary. This is not supported." -}}
{{- end -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- if eq (len $enabledServices) 1 -}}
{{- $result = keys $enabledServices | mustFirst -}}
{{- else -}}
{{- if $enabledServices -}}
{{- fail "At least one Service must be set as primary" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $result -}}
{{- $result -}}
{{- else -}}
{{- fail "No primary and enabled service found" -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,35 @@
{{/* Returns the primary Workload object */}}
{{- define "tc.v1.common.lib.util.workload.primary" -}}
{{- $Workloads := .workload -}}
{{- $enabledWorkloads := dict -}}
{{- range $name, $Workload := $Workloads -}}
{{- if $Workload.enabled -}}
{{- $_ := set $enabledWorkloads $name $Workload -}}
{{- end -}}
{{- end -}}
{{- $result := "" -}}
{{- range $name, $Workload := $enabledWorkloads -}}
{{- if (hasKey $Workload "primary") -}}
{{- if $Workload.primary -}}
{{- if $result -}}
{{- fail "More than one Workloads are set as primary. This is not supported." -}}
{{- end -}}
{{- $result = $name -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not $result -}}
{{- if eq (len $enabledWorkloads) 1 -}}
{{- $result = keys $enabledWorkloads | mustFirst -}}
{{- else -}}
{{- if $enabledWorkloads -}}
{{- fail "At least one Workload must be set as primary" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $result -}}
{{- end -}}

View File

@@ -0,0 +1,25 @@
{{- define "tc.v1.common.lib.util.operator.register" -}}
{{- if .Values.operator.register -}}
{{/* If it is an install operator check the operator does not exist */}}
{{/* We do not want to fail on upgrades, as the operator will always be present */}}
{{- if $.Release.IsInstall -}}
{{- $opExists := include "tc.v1.common.lib.util.operator.verify" (dict "rootCtx" $ "opName" $.Chart.Name) -}}
{{/* If the operator exists, fail to continue */}}
{{- if eq $opExists "true" -}}
{{- fail (printf "Operator [%v] is already installed. Can only be installed once" $.Chart.Name) -}}
{{- end -}}
{{- end -}}
{{/* Create/Update the ConfigMap */}}
{{- $objectData := (dict "enabled" true
"data" (dict "tc-operator-name" $.Chart.Name
"tc-operator-version" $.Chart.Version)) -}}
{{/* data.tc-operator-name - The name the operator */}}
{{/* data.tc-operator-version - The version of the installed operator */}}
{{/* Create a configmap with the above data */}}
{{/* Name will be expanded to "release-name-chart-name-tc-data" */}}
{{- $_ := set $.Values.configmap "tc-data" $objectData -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,16 @@
{{- define "tc.v1.common.lib.util.stopAll" -}}
{{- $rootCtx := . -}}
{{- $stop := "" -}}
{{- if $rootCtx.Values.global.stopAll -}}
{{- $stop = true -}}
{{- end -}}
{{- with $rootCtx.Values.global.ixChartContext -}}
{{- if .isStopped -}}
{{- $stop = true -}}
{{- end -}}
{{- end -}}
{{- $stop -}}
{{- end -}}

View File

@@ -0,0 +1,135 @@
{{- define "tc.v1.common.lib.util.operator.verifyAll" -}}
{{- if .Values.operator.verify.enabled -}}
{{/* Go over all operators that need to be verified */}}
{{- $operatorList := .Values.operator.verify.additionalOperators -}}
{{- $cnpg := false -}}
{{- range $opName := $.Values.cnpg -}}
{{- if .enabled -}}
{{- $cnpg = true -}}
{{- end -}}
{{- end -}}
{{- if $cnpg -}}
{{- $operatorList = mustAppend $operatorList "cloudnative-pg" -}}
{{- end -}}
{{- $ingress := false -}}
{{- range $opName := $.Values.ingress -}}
{{- if .enabled -}}
{{- $ingress = true -}}
{{- end -}}
{{- end -}}
{{- if $ingress -}}
{{- $operatorList = mustAppend $operatorList "traefik" -}}
{{- end -}}
{{- $clusterCertificate := false -}}
{{- if $.Values.clusterCertificates -}}
{{- range $opName := $.Values.clusterCertificates.certificates -}}
{{- if .enabled -}}
{{- $clusterCertificate = true -}}
{{- end -}}
{{- end -}}
{{- if $clusterCertificate -}}
{{- $operatorList = mustAppend $operatorList "kubernetes-reflector" -}}
{{- end -}}
{{- end -}}
{{- $metrics := false -}}
{{- range $opName := $.Values.metrics -}}
{{- if .enabled -}}
{{- $metrics = true -}}
{{- end -}}
{{- end -}}
{{- if $metrics -}}
{{- $operatorList = mustAppend $operatorList "prometheus-operator" -}}
{{- end -}}
{{- range $opName := $operatorList -}}
{{- $fetchedOpData := include "tc.v1.common.lib.util.operator.verify" (dict "rootCtx" $ "opName" $opName) -}}
{{/* If the operator was not found */}}
{{- if eq $fetchedOpData "false" -}}
{{/* Fail only if explicitly asked */}}
{{- if $.Values.operator.verify.failOnError -}}
{{- fail (printf "Operator [%s] has to be installed first" $opName) -}}
{{- end -}}
{{/* If $fetchedOpData is not false, we should have JSON data */}}
{{- else -}}
{{- $opData := ($fetchedOpData | fromJson) -}}
{{- $_ := set $.Values.operator $opName $opData -}}
{{/* Prepare the data for the cache ConfigMap */}}
{{- $cacheDataWrite := (dict "enabled" true "data" $opData) -}}
{{/* Create/Update the Configmap - ConfigMap name will be expanded to "$fullname-operator-$opName" */}}
{{- $_ := set $.Values.configmap (printf "operator-%s" $opName) $cacheDataWrite -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "tc.v1.common.lib.util.operator.verify" -}}
{{- $rootCtx := .rootCtx -}}
{{- $opName := .opName -}}
{{- $opExists := false -}}
{{- $opData := dict -}}
{{- $fullname := (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) -}}
{{- $cache := (lookup "v1" "ConfigMap" $rootCtx.Release.Namespace (printf "%v-operator-%v" $fullname $opName)) | default dict -}}
{{- if $cache.data -}}
{{/* Fetch data that the operator itself stored in the tc-data configmap */}}
{{- $viaCache := (lookup "v1" "ConfigMap" $cache.data.namespace (printf "%v-tc-data" $fullname)) | default dict -}}
{{- if $viaCache -}}
{{- if not $viaCache.data -}}
{{- fail (printf "Operator - Expected [tc-data] ConfigMap to have non-empty [data] for operator [%v]" $opName) -}}
{{- end -}}
{{- $name := (get $viaCache.data "tc-operator-name") -}}
{{- $version := (get $viaCache.data "tc-operator-version") -}}
{{/* If fetched name does not matches the "$opName"... */}}
{{- if ne $name $opName -}}
{{- fail (printf "Operator - ConfigMap [tc-data] does not contain the operator [%v] name. Something went wrong." $opName) -}}
{{- end -}}
{{/* If matches continue and mark operator as found */}}
{{- $opExists = true -}}
{{/* Prepare the data */}}
{{- $opData = (dict "name" $name
"namespace" $viaCache.metadata.namespace
"version" $version) -}}
{{- end -}}
{{- end -}}
{{/* Go over all configmaps */}}
{{- if not $opExists -}}
{{- range $index, $cm := (lookup "v1" "ConfigMap" "" "").items -}}
{{- if $cm.data -}}
{{/* If "tc-operator-name" does not exist will return "" */}}
{{- $name := (get $cm.data "tc-operator-name") -}}
{{- $version := (get $cm.data "tc-operator-version") -}}
{{/* If fetched name matches the "$opName"... */}}
{{- if eq $name $opName -}}
{{- if $opExists -}}
{{- fail (printf "Found duplicate configmaps for operator [%s]" $opName) -}}
{{- end -}}
{{/* Mark operator as found*/}}
{{- $opExists = true -}}
{{- $opData = (dict "name" $name
"namespace" $cm.metadata.namespace
"version" $version) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $opExists -}} {{/* If operator was found, return its data as JSON */}}
{{- $opData | toJson -}}
{{- else -}} {{/* If operator was not found, return stringified false */}}
{{- $opExists | toString -}}
{{- end -}}
{{- end -}}