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,40 @@
{{/* Service - MetalLB Annotations */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.metalLBAnnotations" (dict "rootCtx" $rootCtx "objectData" $objectData "annotations" $annotations) -}}
rootCtx: The root context of the chart.
objectData: The object data of the service
annotations: The annotations variable reference, to append the MetalLB annotations
*/}}
{{- define "tc.v1.common.lib.service.metalLBAnnotations" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $annotations := .annotations -}}
{{- $sharedKey := include "tc.v1.common.lib.chart.names.fullname" $rootCtx -}}
{{/* A custom shared key can be defined per service even between multiple charts */}}
{{- with $objectData.sharedKey -}}
{{- $sharedKey = tpl . $rootCtx -}}
{{- end -}}
{{- if $rootCtx.Values.global.addMetalLBAnnotations -}}
{{- $_ := set $annotations "metallb.universe.tf/allow-shared-ip" $sharedKey -}}
{{- end -}}
{{- end -}}
{{/* Service - Traefik Annotations */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.traefikAnnotations" (dict "rootCtx" $rootCtx "annotations" $annotations) -}}
rootCtx: The root context of the chart.
annotations: The annotations variable reference, to append the Traefik annotations
*/}}
{{- define "tc.v1.common.lib.service.traefikAnnotations" -}}
{{- $rootCtx := .rootCtx -}}
{{- $annotations := .annotations -}}
{{- if $rootCtx.Values.global.addTraefikAnnotations -}}
{{- $_ := set $annotations "traefik.ingress.kubernetes.io/service.serversscheme" "https" -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,63 @@
{{/* Service - Ports */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.ports" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The object data of the service
*/}}
{{- define "tc.v1.common.lib.service.ports" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $tcpProtocols := (list "tcp" "http" "https") -}}
{{- range $name, $portValues := $objectData.ports -}}
{{- if $portValues.enabled -}}
{{- $protocol := $rootCtx.Values.fallbackDefaults.serviceProtocol -}} {{/* Default to fallback protocol, if no protocol is defined */}}
{{- $port := $portValues.port -}}
{{- $targetPort := $portValues.targetPort -}}
{{- $nodePort := $portValues.nodePort -}}
{{/* Expand port */}}
{{- if (kindIs "string" $port) -}}
{{- $port = (tpl $port $rootCtx) -}}
{{- end -}}
{{- $port = int $port -}}
{{/* Expand targetPort */}}
{{- if (kindIs "string" $targetPort) -}}
{{- $targetPort = tpl $targetPort $rootCtx -}}
{{- end -}}
{{- $targetPort = int $targetPort -}}
{{/* Expand nodePort */}}
{{- if (kindIs "string" $nodePort) -}}
{{- $nodePort = tpl $nodePort $rootCtx -}}
{{- end -}}
{{- $nodePort = int $nodePort -}}
{{- with $portValues.protocol -}}
{{- $protocol = tpl . $rootCtx -}}
{{- if mustHas $protocol $tcpProtocols -}}
{{- $protocol = "tcp" -}}
{{- end -}}
{{- end }}
- name: {{ $name }}
port: {{ $port }}
protocol: {{ $protocol | upper }}
targetPort: {{ $targetPort | default $port }} {{/* If no targetPort, default to port */}}
{{- if (eq $objectData.type "NodePort") -}}
{{- if not $nodePort -}}
{{- fail "Service - Expected non-empty <nodePort> on NodePort service type" -}}
{{- end -}}
{{- $minNodePort := int $rootCtx.Values.global.minNodePort -}}
{{- if (lt $nodePort $minNodePort) -}}
{{- fail (printf "Service - Expected <nodePort> to be higher than [%v], but got [%v]" $minNodePort $nodePort) -}}
{{- end }}
nodePort: {{ $nodePort }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,133 @@
{{/* Service Validation */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.validation" (dict "objectData" $objectData) -}}
objectData:
rootCtx: The root context of the chart.
objectData: The service object.
*/}}
{{- define "tc.v1.common.lib.service.validation" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- if and $objectData.targetSelector (not (kindIs "string" $objectData.targetSelector)) -}}
{{- fail (printf "Service - Expected <targetSelector> to be [string], but got [%s]" (kindOf $objectData.targetSelector)) -}}
{{- end -}}
{{- $svcTypes := (list "ClusterIP" "LoadBalancer" "NodePort" "ExternalName" "ExternalIP") -}}
{{- if and $objectData.type (not (mustHas $objectData.type $svcTypes)) -}}
{{- fail (printf "Service - Expected <type> to be one of [%s] but got [%s]" (join ", " $svcTypes) $objectData.type) -}}
{{- end -}}
{{- $hasEnabledPort := false -}}
{{- if ne $objectData.type "ExternalName" -}}
{{- range $name, $port := $objectData.ports -}}
{{- if $port.enabled -}}
{{- $hasEnabledPort = true -}}
{{- if and $port.targetSelector (not (kindIs "string" $port.targetSelector)) -}}
{{- fail (printf "Service - Expected <port.targetSelector> to be [string], but got [%s]" (kindOf $port.targetSelector)) -}}
{{- end -}}
{{- if not $port.port -}}
{{- fail (printf "Service - Expected non-empty <port.port>") -}}
{{- end -}}
{{- $protocolTypes := (list "tcp" "udp" "http" "https") -}}
{{- if $port.protocol -}}
{{- if not (mustHas (tpl $port.protocol $rootCtx) $protocolTypes) -}}
{{- fail (printf "Service - Expected <port.protocol> to be one of [%s] but got [%s]" (join ", " $protocolTypes) $port.protocol) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- if not $hasEnabledPort -}}
{{- fail "Service - Expected enabled service to have at least one port" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* Service Primary Validation */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.primaryValidation" $ -}}
*/}}
{{- define "tc.v1.common.lib.service.primaryValidation" -}}
{{/* Initialize values */}}
{{- $hasPrimary := false -}}
{{- $hasEnabled := false -}}
{{- range $name, $service := .Values.service -}}
{{/* If service is enabled */}}
{{- if $service.enabled -}}
{{- $hasEnabled = true -}}
{{/* And service is primary */}}
{{- if and (hasKey $service "primary") ($service.primary) -}}
{{/* Fail if there is already a primary service */}}
{{- if $hasPrimary -}}
{{- fail "Service - Only one service can be primary" -}}
{{- end -}}
{{- $hasPrimary = true -}}
{{- include "tc.v1.common.lib.servicePort.primaryValidation" (dict "objectData" $service.ports) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* Require at least one primary service, if any enabled */}}
{{- if and $hasEnabled (not $hasPrimary) -}}
{{- fail "Service - At least one enabled service must be primary" -}}
{{- end -}}
{{- end -}}
{{/* Service Port Primary Validation */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.primaryValidation" (dict "objectData" $objectData -}}
objectData:
The ports of the service.
*/}}
{{- define "tc.v1.common.lib.servicePort.primaryValidation" -}}
{{- $objectData := .objectData -}}
{{/* Initialize values */}}
{{- $hasPrimary := false -}}
{{- $hasEnabled := false -}}
{{- range $name, $port := $objectData -}}
{{/* If service is enabled */}}
{{- if $port.enabled -}}
{{- $hasEnabled = true -}}
{{/* And service is primary */}}
{{- if and (hasKey $port "primary") ($port.primary) -}}
{{/* Fail if there is already a primary port */}}
{{- if $hasPrimary -}}
{{- fail "Service - Only one port per service can be primary" -}}
{{- end -}}
{{- $hasPrimary = true -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{/* Require at least one primary service, if any enabled */}}
{{- if and $hasEnabled (not $hasPrimary) -}}
{{- fail "Service - At least one enabled port in service must be primary" -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,16 @@
{{/* Service - clusterIP */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.clusterIP" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
{{- with $objectData.clusterIP }}
clusterIP: {{ tpl . $rootCtx }}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,17 @@
{{/* Service - externalIPs */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.externalIPs" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.externalIPs" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- with $objectData.externalIPs -}}
{{- range . }}
- {{ tpl . $rootCtx }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,22 @@
{{/* Service - externalTrafficPolicy */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.externalTrafficPolicy" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
{{- with $objectData.externalTrafficPolicy }}
{{- $policy := tpl . $rootCtx -}}
{{- $policies := (list "Cluster" "Local") -}}
{{- if not (mustHas $policy $policies) -}}
{{- fail (printf "Service - Expected <externalTrafficPolicy> to be one of [%s], but got [%s]" (join ", " $policies) $policy) -}}
{{- end }}
externalTrafficPolicy: {{ $policy }}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,38 @@
{{/* Service - ipFamily */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.ipFamily" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.ipFamily" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- with $objectData.ipFamilyPolicy -}}
{{- $famPolicy := tpl . $rootCtx -}}
{{- $stacks := (list "SingleStack" "PreferDualStack" "RequireDualStack") -}}
{{- if not (mustHas $famPolicy $stacks) -}}
{{- fail (printf "Service - Expected <ipFamilyPolicy> to be one of [%s], but got [%s]" (join ", " $stacks) $famPolicy) -}}
{{- end }}
ipFamilyPolicy: {{ $famPolicy }}
{{- end -}}
{{- if and $objectData.ipFamilies (not (kindIs "slice" $objectData.ipFamilies)) -}}
{{- fail (printf "Service - Expected <ipFamilies> to be a list, but got a [%s]" (kindOf $objectData.ipFamilies)) -}}
{{- end -}}
{{- with $objectData.ipFamilies }}
ipFamilies:
{{- range . }}
{{- $ipFam := tpl . $rootCtx -}}
{{- $stacks := (list "IPv4" "IPv6") -}}
{{- if not (mustHas $ipFam $stacks) -}}
{{- fail (printf "Service - Expected <ipFamilies> to be one of [%s], but got [%s]" (join ", " $stacks) $ipFam) -}}
{{- end }}
- {{ $ipFam }}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,19 @@
{{/* Service - publishNotReadyAddresses */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.publishNotReadyAddresses" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
{{- $publishAddr := false -}}
{{- if (kindIs "bool" $objectData.publishNotReadyAddresses) -}}
{{- $publishAddr = $objectData.publishNotReadyAddresses -}}
{{- end -}}
{{- $publishAddr -}}
{{- end -}}

View File

@@ -0,0 +1,42 @@
{{/* Service - Session Affinity */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.sessionAffinity" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.sessionAffinity" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- with $objectData.sessionAffinity -}}
{{- $affinity := tpl . $rootCtx -}}
{{- $affinities := (list "ClientIP" "None") -}}
{{- if not (mustHas $affinity $affinities) -}}
{{- fail (printf "Service - Expected <sessionAffinity> to be one of [%s], but got [%s]" (join ", " $affinities) $affinity) -}}
{{- end }}
sessionAffinity: {{ $affinity }}
{{- if eq $affinity "ClientIP" -}}
{{- with $objectData.sessionAffinityConfig -}}
{{- with .clientIP -}}
{{- $timeout := .timeoutSeconds -}}
{{- if kindIs "string" $timeout -}}
{{- $timeout = tpl $timeout $rootCtx -}}
{{- end -}}
{{- $timeout = int $timeout -}}
{{- if and $timeout (mustHas (kindOf $timeout) (list "float64" "int64" "int")) -}}
{{- if or (lt $timeout 0) (gt $timeout 86400) -}}
{{- fail (printf "Service - Expected <sessionAffinityConfig.clientIP.timeoutSeconds> to be between [0 - 86400], but got [%v]" $timeout) -}}
{{- end }}
sessionAffinityConfig:
clientIP:
timeoutSeconds: {{ $timeout }}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -0,0 +1,21 @@
{{/* Service - ClusterIP Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.spec.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.spec.clusterIP" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
type: ClusterIP
publishNotReadyAddresses: {{ include "tc.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim }}
{{- with (include "tc.v1.common.lib.service.externalIPs" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
externalIPs:
{{- . | nindent 2 }}
{{- end -}}
{{- include "tc.v1.common.lib.service.sessionAffinity" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.ipFamily" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- end -}}

View File

@@ -0,0 +1,19 @@
{{/* Service - ExternalIP Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.spec.externalIP" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.spec.externalIP" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
publishNotReadyAddresses: {{ include "tc.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim }}
{{- with (include "tc.v1.common.lib.service.externalIPs" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
externalIPs:
{{- . | nindent 2 }}
{{- end -}}
{{- include "tc.v1.common.lib.service.sessionAffinity" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- end -}}

View File

@@ -0,0 +1,26 @@
{{/* Service - ExternalName Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.spec.externalName" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.spec.externalName" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
{{- if not $objectData.externalName -}}
{{- fail "Service - Expected non-empty <externalName> on ExternalName service type." -}}
{{- end }}
type: ExternalName
externalName: {{ tpl $objectData.externalName $rootCtx }}
publishNotReadyAddresses: {{ include "tc.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim }}
{{- with (include "tc.v1.common.lib.service.externalIPs" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
externalIPs:
{{- . | nindent 2 }}
{{- end }}
{{- include "tc.v1.common.lib.service.sessionAffinity" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- end -}}

View File

@@ -0,0 +1,33 @@
{{/* Service - LoadBalancer Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.spec.loadBalancer" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.spec.loadBalancer" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
type: LoadBalancer
allocateLoadBalancerNodePorts: {{ $objectData.allocateLoadBalancerNodePorts | default false }}
publishNotReadyAddresses: {{ include "tc.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim }}
{{- with (include "tc.v1.common.lib.service.externalIPs" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
externalIPs:
{{- . | nindent 2 }}
{{- end -}}
{{- with $objectData.loadBalancerIP }}
loadBalancerIP: {{ tpl . $rootCtx }}
{{- end -}}
{{- with $objectData.loadBalancerSourceRanges }}
loadBalancerSourceRanges:
{{- range . }}
- {{ tpl . $rootCtx }}
{{- end -}}
{{- end -}}
{{- include "tc.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.ipFamily" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.sessionAffinity" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- end -}}

View File

@@ -0,0 +1,22 @@
{{/* Service - NodePort Spec */}}
{{/* Call this template:
{{ include "tc.v1.common.lib.service.spec.nodePort" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
rootCtx: The root context of the chart.
objectData: The service object data
*/}}
{{- define "tc.v1.common.lib.service.spec.nodePort" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData }}
type: NodePort
publishNotReadyAddresses: {{ include "tc.v1.common.lib.service.publishNotReadyAddresses" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim }}
{{- with (include "tc.v1.common.lib.service.externalIPs" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
externalIPs:
{{- . | nindent 2 }}
{{- end -}}
{{- include "tc.v1.common.lib.service.sessionAffinity" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.clusterIP" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.ipFamily" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- include "tc.v1.common.lib.service.externalTrafficPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim | nindent 0 }}
{{- end -}}