feat(common): Release common 4.0.0 (#398)

Co-authored-by: lab-assistant[bot] <180935599+lab-assistant[bot]@users.noreply.github.com>
This commit is contained in:
Bernd Schorgers 2025-05-16 08:40:39 +02:00
parent 1e210f43e3
commit a01a89cb13
No known key found for this signature in database
327 changed files with 11181 additions and 7330 deletions

View file

@ -14,6 +14,8 @@ Return the enabled services.
{{- end -}}
{{- if $serviceEnabled -}}
{{- $_ := set $enabledServices $name . -}}
{{- end -}}
{{- end -}}

View file

@ -4,10 +4,19 @@ Return a service Object by its Identifier.
{{- define "bjw-s.common.lib.service.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{- range $name, $serviceValues := $rootContext.Values.service -}}
{{- if eq $name $identifier -}}
{{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $serviceValues) -}}
{{- if (hasKey $enabledServices $identifier) -}}
{{- $objectValues := get $enabledServices $identifier -}}
{{- $object := include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $objectValues "itemCount" (len $enabledServices)) | fromYaml -}}
{{- if eq 1 (len $enabledControllers) -}}
{{- if (empty (dig "controller" nil $object)) -}}
{{- $_ := set $object "controller" ($enabledControllers | keys | first) -}}
{{- end -}}
{{- end -}}
{{- $object | toYaml -}}
{{- end -}}
{{- end -}}

View file

@ -5,7 +5,7 @@ Return the primary service object for a controller
{{- $rootContext := .rootContext -}}
{{- $controllerIdentifier := .controllerIdentifier -}}
{{- $identifier := "" -}}
{{- $serviceIdentifier := "" -}}
{{- $result := dict -}}
{{- /* Loop over all enabled services */ -}}
@ -13,27 +13,29 @@ Return the primary service object for a controller
{{- if $enabledServices -}}
{{- /* We are only interested in services for the specified controller */ -}}
{{- $enabledServicesForController := dict -}}
{{- range $name, $service := $enabledServices -}}
{{- if eq $service.controller $controllerIdentifier -}}
{{- $_ := set $enabledServicesForController $name $service -}}
{{- range $identifier, $serviceObject := $enabledServices -}}
{{- if eq $serviceObject.controller $controllerIdentifier -}}
{{- $_ := set $enabledServicesForController $identifier $serviceObject -}}
{{- end -}}
{{- end -}}
{{- range $name, $service := $enabledServicesForController -}}
{{- range $identifier, $serviceObject := $enabledServicesForController -}}
{{- /* Determine the Service that has been marked as primary */ -}}
{{- if $service.primary -}}
{{- $identifier = $name -}}
{{- $result = $service -}}
{{- if $serviceObject.primary -}}
{{- $serviceIdentifier = $identifier -}}
{{- $result = $serviceObject -}}
{{- end -}}
{{- /* Return the first Service (alphabetically) if none has been explicitly marked as primary */ -}}
{{- if not $result -}}
{{- $firstServiceKey := keys $enabledServicesForController | sortAlpha | first -}}
{{- $result = get $enabledServicesForController $firstServiceKey -}}
{{- $identifier = $result.identifier -}}
{{- $serviceIdentifier = $identifier -}}
{{- end -}}
{{- end -}}
{{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $result) -}}
{{- if not (empty $serviceIdentifier) -}}
{{- include "bjw-s.common.lib.service.getByIdentifier" (dict "rootContext" $rootContext "id" $serviceIdentifier) -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -5,6 +5,15 @@ Validate Service values
{{- $rootContext := .rootContext -}}
{{- $serviceObject := .object -}}
{{- $enabledControllers := (include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml ) -}}
{{/* Verify automatic controller detection */}}
{{- if not (eq 1 (len $enabledControllers)) -}}
{{- if or (not (has "controller" (keys $serviceObject))) (empty (get $serviceObject "controller")) -}}
{{- fail (printf "controller field is required because automatic controller detection is not possible. (service: %s)" $serviceObject.identifier ) -}}
{{- end -}}
{{- end -}}
{{- if empty (get $serviceObject "controller") -}}
{{- fail (printf "controller field is required for Service. (service: %s)" $serviceObject.identifier) -}}
{{- end -}}
@ -29,13 +38,13 @@ Validate Service values
{{- $enabledPorts := include "bjw-s.common.lib.service.enabledPorts" (dict "rootContext" $rootContext "serviceObject" $serviceObject) | fromYaml }}
{{- /* Validate at least one port is enabled */ -}}
{{- if not $enabledPorts -}}
{{- fail (printf "no ports are enabled for Service with key \"%s\"" $serviceObject.identifier) -}}
{{- fail (printf "No ports are enabled for Service with this identifier. (service: '%s')" $serviceObject.identifier) -}}
{{- end -}}
{{- range $name, $port := $enabledPorts -}}
{{- /* Validate a port number is configured */ -}}
{{- if not $port.port -}}
{{- fail (printf "no port number is configured for port \"%s\" under Service with key \"%s\"" $name $serviceObject.identifier) -}}
{{- fail (printf "No port number is configured for this port. (port: '%s', service: '%s')" $name $serviceObject.identifier) -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -1,30 +0,0 @@
{{/*
Convert Service values to an object
*/}}
{{- define "bjw-s.common.lib.service.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the Service name */ -}}
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
{{- if $objectValues.nameOverride -}}
{{- $override := tpl $objectValues.nameOverride $rootContext -}}
{{- if not (eq $objectName $override) -}}
{{- $objectName = printf "%s-%s" $objectName $override -}}
{{- end -}}
{{- else -}}
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }}
{{- if and (not $objectValues.primary) (gt (len $enabledServices) 1) -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the Service object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}