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,70 @@
{{/* Returns ConfigMap Volume */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.pod.volume.configmap" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the volume.
*/}}
{{- define "tc.v1.common.lib.pod.volume.configmap" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- if not $objectData.objectName -}}
{{- fail "Persistence - Expected non-empty <objectName> on <configmap> type" -}}
{{- end -}}
{{- $objectName := tpl $objectData.objectName $rootCtx -}}
{{- $expandName := true -}}
{{- if kindIs "bool" $objectData.expandObjectName -}}
{{- $expandName = $objectData.expandObjectName -}}
{{- end -}}
{{- if $expandName -}}
{{- $object := (get $rootCtx.Values.configmap $objectName) -}}
{{- if and (not $object) (not $objectData.optional) -}}
{{- fail (printf "Persistence - Expected configmap [%s] defined in <objectName> to exist" $objectName) -}}
{{- end -}}
{{- $objectName = (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $objectName) -}}
{{- end -}}
{{- $optional := false -}}
{{- if hasKey $objectData "optional" -}}
{{- if not (kindIs "bool" $objectData.optional) -}}
{{- fail (printf "Persistence - Expected <optional> to be [bool], but got [%s]" (kindOf $objectData.optional)) -}}
{{- end -}}
{{- $optional = $objectData.optional -}}
{{- end -}}
{{- $defMode := "" -}}
{{- if (and $objectData.defaultMode (not (kindIs "string" $objectData.defaultMode))) -}}
{{- fail (printf "Persistence - Expected <defaultMode> to be [string], but got [%s]" (kindOf $objectData.defaultMode)) -}}
{{- end -}}
{{- with $objectData.defaultMode -}}
{{- $defMode = tpl $objectData.defaultMode $rootCtx -}}
{{- end -}}
{{- if and $defMode (not (mustRegexMatch "^[0-9]{4}$" $defMode)) -}}
{{- fail (printf "Persistence - Expected <defaultMode> to have be in format of [\"0777\"], but got [%q]" $defMode) -}}
{{- end }}
- name: {{ $objectData.shortName }}
configMap:
name: {{ $objectName }}
{{- with $defMode }}
defaultMode: {{ . }}
{{- end }}
optional: {{ $optional }}
{{- with $objectData.items }}
items:
{{- range . -}}
{{- if not .key -}}
{{- fail "Persistence - Expected non-empty <items.key>" -}}
{{- end -}}
{{- if not .path -}}
{{- fail "Persistence - Expected non-empty <items.path>" -}}
{{- end }}
- key: {{ tpl .key $rootCtx }}
path: {{ tpl .path $rootCtx }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,53 @@
{{/* Returns device (hostPath) Volume */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.pod.volume.device" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the volume.
*/}}
{{- define "tc.v1.common.lib.pod.volume.device" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $hostPathType := "" -}}
{{- if $objectData.hostPathType -}}
{{- $hostPathType = tpl $objectData.hostPathType $rootCtx -}}
{{- end -}}
{{- if not $objectData.hostPath -}}
{{- fail "Persistence - Expected non-empty <hostPath> on <device> type" -}}
{{- end -}}
{{- $hostPath := tpl $objectData.hostPath $rootCtx -}}
{{- if not (hasPrefix "/" $hostPath) -}}
{{- fail "Persistence - Expected <hostPath> to start with a forward slash [/] on <device> type" -}}
{{- end -}}
{{- $charDevices := (list "tty") -}}
{{- if not $hostPathType -}}
{{- range $char := $charDevices -}}
{{- if hasPrefix (printf "/dev/%v" $char) $hostPath -}}
{{- $hostPathType = "CharDevice" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $blockDevices := (list "sd" "hd" "nvme") -}}
{{- if not $hostPathType -}}
{{- range $block := $blockDevices -}}
{{- if hasPrefix (printf "/dev/%v" $block) $hostPath -}}
{{- $hostPathType = "BlockDevice" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $types := (list "DirectoryOrCreate" "Directory" "FileOrCreate" "File" "Socket" "CharDevice" "BlockDevice") -}}
{{- if and $hostPathType (not (mustHas $hostPathType $types)) -}}
{{- fail (printf "Persistence - Expected <hostPathType> to be one of [%s], but got [%s]" (join ", " $types) $hostPathType) -}}
{{- end }}
- name: {{ $objectData.shortName }}
hostPath:
path: {{ $hostPath }}
{{- with $hostPathType }}
type: {{ $hostPathType }}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,43 @@
{{/* Returns emptyDir Volume */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.pod.volume.emptyDir" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the volume.
*/}}
{{- define "tc.v1.common.lib.pod.volume.emptyDir" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $medium := "" -}}
{{- $size := "" -}}
{{- with $objectData.medium -}}
{{- $medium = tpl . $rootCtx -}}
{{- end -}}
{{- with $objectData.size -}}
{{- $size = tpl . $rootCtx -}}
{{- end -}}
{{- if $size -}}
{{/* Size: https://regex101.com/r/NNPV2D/1 */}}
{{- if not (mustRegexMatch "^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$" (toString $size)) -}}
{{- $formats := "(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)" -}}
{{- fail (printf "Persistence Expected <size> to have one of the following formats [%s], but got [%s]" $formats $size) -}}
{{- end -}}
{{- end -}}
{{- if and $medium (ne $medium "Memory") -}}
{{- fail (printf "Persistence - Expected [medium] to be one of [\"\", Memory], but got [%s] on <emptyDir> type" $medium) -}}
{{- end }}
- name: {{ $objectData.shortName }}
{{- if or $medium $size }}
emptyDir:
{{- if $medium }}
medium: {{ $medium }}
{{- end -}}
{{- if $size }}
sizeLimit: {{ $size }}
{{- end -}}
{{- else }}
emptyDir: {}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,35 @@
{{/* Returns hostPath Volume */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.pod.volume.hostPath" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the volume.
*/}}
{{- define "tc.v1.common.lib.pod.volume.hostPath" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $hostPathType := "" -}}
{{- if $objectData.hostPathType -}}
{{- $hostPathType = tpl $objectData.hostPathType $rootCtx -}}
{{- end -}}
{{- if not $objectData.hostPath -}}
{{- fail "Persistence - Expected non-empty <hostPath> on <hostPath> type" -}}
{{- end -}}
{{- $hostPath := tpl $objectData.hostPath $rootCtx -}}
{{- if not (hasPrefix "/" $hostPath) -}}
{{- fail "Persistence - Expected <hostPath> to start with a forward slash [/] on <hostPath> type" -}}
{{- end -}}
{{- $types := (list "DirectoryOrCreate" "Directory" "FileOrCreate" "File" "Socket" "CharDevice" "BlockDevice") -}}
{{- if and $hostPathType (not (mustHas $hostPathType $types)) -}}
{{- fail (printf "Persistence - Expected <hostPathType> to be one of [%s], but got [%s]" (join ", " $types) $hostPathType) -}}
{{- end }}
- name: {{ $objectData.shortName }}
hostPath:
path: {{ $hostPath }}
{{- with $hostPathType }}
type: {{ $hostPathType }}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,56 @@
{{/* Returns ixVolume Volume */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.pod.volume.ixVolume" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the volume.
*/}}
{{- define "tc.v1.common.lib.pod.volume.ixVolume" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $hostPathType := "" -}}
{{- if $objectData.hostPathType -}}
{{- $hostPathType = tpl $objectData.hostPathType $rootCtx -}}
{{- end -}}
{{- if not $objectData.datasetName -}}
{{- fail "Persistence - Expected non-empty <datasetName> on <ixVolume> type" -}}
{{- end -}}
{{- $datasetName := tpl $objectData.datasetName $rootCtx -}}
{{- if not $rootCtx.Values.ixVolumes -}}
{{- fail "Persistence - Expected non-empty <ixVolumes> in values on <ixVolume> type" -}}
{{- end -}}
{{- $hostPath := "" -}}
{{- $found := false -}}
{{- range $idx, $normalizedHostPath := $rootCtx.Values.ixVolumes -}}
{{- if eq $datasetName (base $normalizedHostPath.hostPath) -}}
{{- $found = true -}}
{{- $hostPath = $normalizedHostPath.hostPath -}}
{{- end -}}
{{- end -}}
{{- if not $found -}} {{/* If we go over the ixVolumes and we dont find a match, fail */}}
{{- $datasets := list -}}
{{- range $rootCtx.Values.ixVolumes -}}
{{- $datasets = mustAppend $datasets (base .hostPath) -}}
{{- end -}}
{{- fail (printf "Persistence - Expected <datasetName> [%s] to exist on <ixVolumes> list, but list contained [%s] on <ixVolume> type" $datasetName (join ", " $datasets)) -}}
{{- end -}}
{{- if not (hasPrefix "/" $hostPath) -}}
{{- fail "Persistence - Expected normalized path from <ixVolumes> to start with a forward slash [/] on <ixVolume> type" -}}
{{- end -}}
{{- $types := (list "DirectoryOrCreate" "Directory" "FileOrCreate" "File" "Socket" "CharDevice" "BlockDevice") -}}
{{- if and $hostPathType (not (mustHas $hostPathType $types)) -}}
{{- fail (printf "Persistence - Expected <hostPathType> to be one of [%s], but got [%s]" (join ", " $types) $hostPathType) -}}
{{- end }}
- name: {{ $objectData.shortName }}
hostPath:
path: {{ $hostPath }}
{{- with $hostPathType }}
type: {{ $hostPathType }}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,27 @@
{{/* Returns NFS Volume */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.pod.volume.nfs" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the volume.
*/}}
{{- define "tc.v1.common.lib.pod.volume.nfs" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- if not $objectData.path -}}
{{- fail "Persistence - Expected non-empty <path> on <nfs> type" -}}
{{- end -}}
{{- $path := tpl $objectData.path $rootCtx -}}
{{- if not (hasPrefix "/" $path) -}}
{{- fail "Persistence - Expected <path> to start with a forward slash [/] on <nfs> type" -}}
{{- end -}}
{{- if not $objectData.server -}}
{{- fail "Persistence - Expected non-empty <server> on <nfs> type" -}}
{{- end }}
- name: {{ $objectData.shortName }}
nfs:
path: {{ $path }}
server: {{ tpl $objectData.server $rootCtx }}
{{- end -}}

View File

@@ -0,0 +1,18 @@
{{/* Returns PVC Volume */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.pod.volume.pvc" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the volume.
*/}}
{{- define "tc.v1.common.lib.pod.volume.pvc" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $pvcName := (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $objectData.shortName) -}}
{{- with $objectData.existingClaim -}}
{{- $pvcName = tpl . $rootCtx -}}
{{- end }}
- name: {{ $objectData.shortName }}
persistentVolumeClaim:
claimName: {{ $pvcName }}
{{- end -}}

View File

@@ -0,0 +1,71 @@
{{/* Returns Secret Volume */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.pod.volume.secret" (dict "rootCtx" $ "objectData" $objectData) }}
rootCtx: The root context of the chart.
objectData: The object data to be used to render the volume.
*/}}
{{- define "tc.v1.common.lib.pod.volume.secret" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- if not $objectData.objectName -}}
{{- fail "Persistence - Expected non-empty <objectName> on <secret> type" -}}
{{- end -}}
{{- $objectName := tpl $objectData.objectName $rootCtx -}}
{{- $expandName := true -}}
{{- if kindIs "bool" $objectData.expandObjectName -}}
{{- $expandName = $objectData.expandObjectName -}}
{{- end -}}
{{- if $expandName -}}
{{- $object := (get $rootCtx.Values.secret $objectName) -}}
{{- $certObject := (get $rootCtx.Values.scaleCertificate $objectName) -}}
{{- if and (not $object) (not $certObject) (not $objectData.optional) -}}
{{- fail (printf "Persistence - Expected secret [%s] defined in <objectName> to exist" $objectName) -}}
{{- end -}}
{{- $objectName = (printf "%s-%s" (include "tc.v1.common.lib.chart.names.fullname" $rootCtx) $objectName) -}}
{{- end -}}
{{- $optional := false -}}
{{- if hasKey $objectData "optional" -}}
{{- if not (kindIs "bool" $objectData.optional) -}}
{{- fail (printf "Persistence - Expected <optional> to be [bool], but got [%s]" (kindOf $objectData.optional)) -}}
{{- end -}}
{{- $optional = $objectData.optional -}}
{{- end -}}
{{- $defMode := "" -}}
{{- if (and $objectData.defaultMode (not (kindIs "string" $objectData.defaultMode))) -}}
{{- fail (printf "Persistence - Expected <defaultMode> to be [string], but got [%s]" (kindOf $objectData.defaultMode)) -}}
{{- end -}}
{{- with $objectData.defaultMode -}}
{{- $defMode = tpl $objectData.defaultMode $rootCtx -}}
{{- end -}}
{{- if and $defMode (not (mustRegexMatch "^[0-9]{4}$" $defMode)) -}}
{{- fail (printf "Persistence - Expected <defaultMode> to have be in format of [\"0777\"], but got [%q]" $defMode) -}}
{{- end }}
- name: {{ $objectData.shortName }}
secret:
secretName: {{ $objectName }}
{{- with $defMode }}
defaultMode: {{ . }}
{{- end }}
optional: {{ $optional }}
{{- with $objectData.items }}
items:
{{- range . -}}
{{- if not .key -}}
{{- fail "Persistence - Expected non-empty <items.key>" -}}
{{- end -}}
{{- if not .path -}}
{{- fail "Persistence - Expected non-empty <items.path>" -}}
{{- end }}
- key: {{ tpl .key $rootCtx }}
path: {{ tpl .path $rootCtx }}
{{- end -}}
{{- end -}}
{{- end -}}