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,9 @@
{{/* Annotations that are added to all objects */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.metadata.allAnnotations" $ }}
*/}}
{{- define "tc.v1.common.lib.metadata.allAnnotations" -}}
{{/* Currently empty but can add later, if needed */}}
{{- include "tc.v1.common.lib.metadata.globalAnnotations" . }}
{{- end -}}

View File

@@ -0,0 +1,15 @@
{{/* Labels that are added to all objects */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.metadata.allLabels" $ }}
*/}}
{{- define "tc.v1.common.lib.metadata.allLabels" -}}
helm.sh/chart: {{ include "tc.v1.common.lib.chart.names.chart" . }}
helm-revision: {{ .Release.Revision | quote }}
app.kubernetes.io/name: {{ include "tc.v1.common.lib.chart.names.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
app.kubernetes.io/managed-by: {{ .Release.Service }}
app: {{ include "tc.v1.common.lib.chart.names.chart" . }}
release: {{ .Release.Name }}
{{- include "tc.v1.common.lib.metadata.globalLabels" . }}
{{- end -}}

View File

@@ -0,0 +1,52 @@
{{/* External Interface Annotations that are added to podSpec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.metadata.externalInterfacePodAnnotations" (dict "rootCtx" $ "podShortName" $podShortName) }}
rootCtx is the root context of the chart
objectData is object containing the data of the pod
*/}}
{{- define "tc.v1.common.lib.metadata.externalInterfacePodAnnotations" -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $ifaceIndexes := list -}}
{{- range $index, $iface := $rootCtx.Values.scaleExternalInterface -}}
{{/* If targetSelectAll is set append the index */}}
{{- if .targetSelectAll -}}
{{- $ifaceIndexes = mustAppend $ifaceIndexes $index -}}
{{/* Else If targetSelector is set and pod is selected append the index */}}
{{- else if and .targetSelector (mustHas $objectData.shortName .targetSelector) -}}
{{- $ifaceIndexes = mustAppend $ifaceIndexes $index -}}
{{/* Else If none of the above, but pod is primary append the index */}}
{{- else if $objectData.primary -}}
{{- $ifaceIndexes = mustAppend $ifaceIndexes $index -}}
{{- end -}}
{{- end -}}
{{- $ifaceNames := list -}}
{{- if $rootCtx.Values.ixExternalInterfacesConfiguration -}}
{{- with $rootCtx.Values.ixExternalInterfacesConfigurationNames -}}
{{- range $ifaceName := . -}}
{{/* Get the index by splitting the iFaceName (ix-release-name-0) */}}
{{- $index := splitList "-" $ifaceName -}}
{{/* And pick the last item on the list */}}
{{- $index = mustLast $index -}}
{{/* If the index is in the list of indexes to be added, append the name */}}
{{- if mustHas (int $index) $ifaceIndexes -}}
{{- $ifaceNames = mustAppend $ifaceNames $ifaceName -}}
{{- end -}}
{{- end -}}
{{- else -}}
{{- fail "External Interface - Expected non empty <ixExternalInterfaceConfigurationNames>" -}}
{{- end -}}
{{- end -}}
{{/* If we have ifaceNames, then add the annotations to the pod calling this template */}}
{{- if $ifaceNames }}
k8s.v1.cni.cncf.io/networks: {{ join ", " $ifaceNames }}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,6 @@
{{/* Returns the global annotations */}}
{{- define "tc.v1.common.lib.metadata.globalAnnotations" -}}
{{- include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $ "annotations" .Values.global.annotations) -}}
{{- end -}}

View File

@@ -0,0 +1,6 @@
{{/* Returns the global labels */}}
{{- define "tc.v1.common.lib.metadata.globalLabels" -}}
{{- include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $ "labels" .Values.global.labels) -}}
{{- end -}}

View File

@@ -0,0 +1,35 @@
{{- define "tc.v1.common.lib.metadata.namespace" -}}
{{- $caller := .caller -}}
{{- $objectData := .objectData -}}
{{- $rootCtx := .rootCtx -}}
{{- $namespace := $rootCtx.Release.Namespace -}}
{{- with $rootCtx.Values.global.namespace -}}
{{- $namespace = tpl . $rootCtx -}}
{{- end -}}
{{- with $rootCtx.Values.namespace -}}
{{- $namespace = tpl . $rootCtx -}}
{{- end -}}
{{- with $objectData.namespace -}}
{{- $namespace = tpl . $rootCtx -}}
{{- end -}}
{{- if not (and (mustRegexMatch "^[a-z0-9]((-?[a-z0-9]-?)*[a-z0-9])?$" $namespace) (le (len $namespace) 63)) -}}
{{- fail (printf "%s - Namespace [%s] is not valid. Must start and end with an alphanumeric lowercase character. It can contain '-'. And must be at most 63 characters." $caller $namespace) -}}
{{- end -}}
{{- if $rootCtx.Values.global.ixChartContext -}}
{{- if not (hasPrefix "ix-" $namespace) -}}
{{/* This is only to be used on CI that do not run in SCALE so we can skip the failure */}}
{{- if not $rootCtx.Values.global.ixChartContext.ci -}}
{{- fail (printf "%s - Namespace [%v] expected to have [ix-] prefix when installed in TrueNAS SCALE" $caller $namespace) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $namespace -}}
{{- end -}}

View File

@@ -0,0 +1,7 @@
{{/* Annotations that are added to podSpec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.metadata.podAnnotations" $ }}
*/}}
{{- define "tc.v1.common.lib.metadata.podAnnotations" -}}
rollme: {{ randAlphaNum 5 | quote }}
{{- end -}}

View File

@@ -0,0 +1,6 @@
{{/* Labels that are added to podSpec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.metadata.podLabels" $ }}
*/}}
{{- define "tc.v1.common.lib.metadata.podLabels" -}}
{{- end -}}

View File

@@ -0,0 +1,37 @@
{{/* Renders a dict of labels */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $ "labels" $labels) }}
{{ include "tc.v1.common.lib.metadata.render" (dict "rootCtx" $ "annotations" $annotations) }}
*/}}
{{- define "tc.v1.common.lib.metadata.render" -}}
{{- $labels := .labels -}}
{{- $annotations := .annotations -}}
{{- $rootCtx := .rootCtx -}}
{{- $seenLabels := list -}}
{{- $seenAnnotations := list -}}
{{- with $labels -}}
{{- range $k, $v := . -}}
{{- if and $k $v -}}
{{- if not (mustHas $k $seenLabels) }}
{{ $k }}: {{ tpl $v $rootCtx | quote }}
{{- $seenLabels = mustAppend $seenLabels $k -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- with $annotations -}}
{{- range $k, $v := . -}}
{{- if and $k $v -}}
{{- if not (mustHas $k $seenAnnotations) }}
{{ $k }}: {{ tpl $v $rootCtx | quote }}
{{- $seenAnnotations = mustAppend $seenAnnotations $k -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,16 @@
{{/* Labels that are used on selectors */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.metadata.selectorLabels" (dict "rootCtx" $rootCtx "objectType" $objectType "objectName" $objectName) }}
podName is the "shortName" of the pod. The one you define in the .Values.workload
*/}}
{{- define "tc.v1.common.lib.metadata.selectorLabels" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectType := .objectType -}}
{{- $objectName := .objectName }}
{{- if and $objectType $objectName }}
{{ printf "%s.name" $objectType }}: {{ $objectName }}
{{- end }}
app.kubernetes.io/name: {{ include "tc.v1.common.lib.chart.names.name" $rootCtx }}
app.kubernetes.io/instance: {{ $rootCtx.Release.Name }}
{{- end -}}

View File

@@ -0,0 +1,22 @@
{{/* Metadata Validation */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.metadata.validation" (dict "objectData" $objectData "caller" $caller) -}}
objectData:
labels: The labels of the configmap.
annotations: The annotations of the configmap.
data: The data of the configmap.
*/}}
{{- define "tc.v1.common.lib.metadata.validation" -}}
{{- $objectData := .objectData -}}
{{- $caller := .caller -}}
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
{{- fail (printf "%s - Expected <labels> to be a dictionary, but got [%v]" $caller (kindOf $objectData.labels)) -}}
{{- end -}}
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
{{- fail (printf "%s - Expected <annotations> to be a dictionary, but got [%v]" $caller (kindOf $objectData.annotations)) -}}
{{- end -}}
{{- end -}}