feat(common): Release 2.0.0 (#189)

This commit is contained in:
Bᴇʀɴᴅ Sᴄʜᴏʀɢᴇʀs 2023-10-02 13:21:17 +02:00 committed by GitHub
parent 8a42d212af
commit 98677d85b2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
56 changed files with 1192 additions and 1804 deletions

View file

@ -54,13 +54,28 @@ spec:
backend:
service:
{{ $service := include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" .service.name) | fromYaml -}}
{{ $servicePrimaryPort := dict -}}
{{ if $service -}}
{{ $servicePrimaryPort = include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $service) | fromYaml -}}
{{ $servicePort := 0 -}}
{{ if eq (dig "port" nil .service) nil -}}
{{/* Default to the Service primary port if no port has been specified */ -}}
{{ if $service -}}
{{ $defaultServicePort := include "bjw-s.common.lib.service.primaryPort" (dict "rootContext" $rootContext "serviceObject" $service) | fromYaml -}}
{{ if $defaultServicePort -}}
{{ $servicePort = $defaultServicePort.port -}}
{{ end -}}
{{ end -}}
{{ else -}}
{{/* If a port number is given, use that */ -}}
{{ if kindIs "float64" .service.port -}}
{{ $servicePort = .service.port -}}
{{ else if kindIs "string" .service.port -}}
{{/* If a port name is given, try to resolve to a number */ -}}
{{ $servicePort = include "bjw-s.common.lib.service.getPortNumberByName" (dict "rootContext" $rootContext "serviceID" .service.name "portName" .service.port) -}}
{{ end -}}
{{ end -}}
name: {{ default .service.name $service.name }}
port:
number: {{ default .service.port $servicePrimaryPort.port }}
number: {{ $servicePort }}
{{- end }}
{{- end }}
{{- end }}

View file

@ -7,6 +7,10 @@ within the common library.
{{- $routeObject := .object -}}
{{- $routeKind := $routeObject.kind | default "HTTPRoute" -}}
{{- $apiVersion := "gateway.networking.k8s.io/v1alpha2" -}}
{{- if $rootContext.Capabilities.APIVersions.Has (printf "gateway.networking.k8s.io/v1beta1/%s" $routeKind) }}
{{- $apiVersion = "gateway.networking.k8s.io/v1beta1" -}}
{{- end -}}
{{- $labels := merge
($routeObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
@ -16,7 +20,7 @@ within the common library.
(include "bjw-s.common.lib.metadata.globalAnnotations" $rootContext | fromYaml)
-}}
---
apiVersion: gateway.networking.k8s.io/v1alpha2
apiVersion: {{ $apiVersion }}
{{- if and (ne $routeKind "GRPCRoute") (ne $routeKind "HTTPRoute") (ne $routeKind "TCPRoute") (ne $routeKind "TLSRoute") (ne $routeKind "UDPRoute") }}
{{- fail (printf "Not a valid route kind (%s)" $routeKind) }}
{{- end }}

View file

@ -93,7 +93,7 @@ Returns the value for volumes
{{- $_ := set $volume.hostPath "type" . -}}
{{- end -}}
{{- /* hostPath persistence type */ -}}
{{- /* nfs persistence type */ -}}
{{- else if eq $persistenceValues.type "nfs" -}}
{{- $_ := set $volume "nfs" dict -}}
{{- $_ := set $volume.nfs "server" (required "server not set" $persistenceValues.server) -}}

View file

@ -0,0 +1,17 @@
{{/*
Return a service port number by name for a Service object
*/}}
{{- define "bjw-s.common.lib.service.getPortNumberByName" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .serviceID -}}
{{- $portName := .portName -}}
{{- $service := include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" $identifier) | fromYaml -}}
{{- if $service -}}
{{ $servicePort := dig "ports" $portName "port" nil $service -}}
{{- if not (eq $servicePort nil) -}}
{{- $servicePort -}}
{{- end -}}
{{- end -}}
{{- end -}}