Files
chart/library/common/templates/helpers/_getPortRange.tpl
Stavros Kois 63326effb3 NAS-121481 / 23.10 / Set nvidia caps to void when no gpu is passed, also adds render group when a gpu is selected and other small fixes (#1124)
* Set nvidia caps to void when no gpu is passed

* add tests to init containers too

* Additionally add `render` group when gpu is added

* Correctly handle "0" gpu

* handle fsGroup 0 properly

* fix gh highlight

* Correct nvidia variable and add additional check for runtime

* cast both sides of the comparison

* fix externalinterfaces nesting

* Add dnsConfig missing docs
2023-04-20 01:27:23 +03:00

60 lines
1.9 KiB
Smarty

{{/* Returns Lowest and Highest ports assigned to the any container in the pod */}}
{{/* Call this template:
{{ include "ix.v1.common.lib.helpers.securityContext.getPortRange" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the Pod.
*/}}
{{- define "ix.v1.common.lib.helpers.securityContext.getPortRange" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{ $portRange := (dict "high" 0 "low" 0) }}
{{- range $name, $service := $rootCtx.Values.service -}}
{{- $selected := false -}}
{{/* If service is enabled... */}}
{{- if $service.enabled -}}
{{/* If there is a selector */}}
{{- if $service.targetSelector -}}
{{/* And pod is selected */}}
{{- if eq $service.targetSelector $objectData.shortName -}}
{{- $selected = true -}}
{{- end -}}
{{- else -}}
{{/* If no selector is defined but pod is primary */}}
{{- if $objectData.primary -}}
{{- $selected = true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if $selected -}}
{{- range $name, $portValues := $service.ports -}}
{{- if $portValues.enabled -}}
{{- $portToCheck := ($portValues.targetPort | default $portValues.port) -}}
{{- if kindIs "string" $portToCheck -}}
{{- $portToCheck = (tpl $portToCheck $rootCtx) | int -}}
{{- end -}}
{{- if or (not $portRange.low) (lt ($portToCheck | int) ($portRange.low | int)) -}}
{{- $_ := set $portRange "low" $portToCheck -}}
{{- end -}}
{{- if or (not $portRange.high) (gt ($portToCheck | int) ($portRange.high | int)) -}}
{{- $_ := set $portRange "high" $portToCheck -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $portRange | toJson -}}
{{- end -}}