feat(common): Release library 3.7.0 (#377)

Signed-off-by: solidDoWant <fred.heinecke@yahoo.com>
Co-authored-by: Patrick Collins <Patricol@users.noreply.github.com>
Co-authored-by: Patrick Collins <patrick.collins@gainbridge.io>
Co-authored-by: Lawrence Gil <larrywtf609@gmail.com>
Co-authored-by: solidDoWant <fred.heinecke@yahoo.com>
This commit is contained in:
Bernd Schorgers 2025-02-07 20:03:04 +01:00 committed by GitHub
parent aee0d999ba
commit 8b33237e27
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 793 additions and 655 deletions

View file

@ -3,7 +3,7 @@ apiVersion: v2
name: common
description: Function library for Helm charts
type: library
version: 3.6.1
version: 3.7.0
kubeVersion: ">=1.22.0-0"
keywords:
- common
@ -16,10 +16,22 @@ annotations:
artifacthub.io/changes: |-
- kind: fixed
description: |-
Only add hostUsers when explicitly configured
- kind: fixed
Raw resources with `forceRename` fields are no longer flagged as invalid
- kind: added
description: |-
`hosts` should be an optional field for Ingress resources
- kind: fixed
Allow setting pullPolicy to Never
- kind: added
description: |-
`defaultBackend` should be an object for Ingress resources
Revamped configMap.fromFiles into configMap.fromFolder
- kind: added
description: |-
Add support for setting shareProcessNamespace on Pods
- kind: added
description: |-
Add support for templating ServiceMonitor endpoints
- kind: added
description: |-
Add support for templating Pod affinity
- kind: added
description: |-
Add support for configuring gRPC probes

View file

@ -1,6 +1,6 @@
# common
![Version: 3.6.1](https://img.shields.io/badge/Version-3.6.1-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square)
![Version: 3.7.0](https://img.shields.io/badge/Version-3.7.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square)
Function library for Helm charts
@ -27,7 +27,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
# Chart.yaml
dependencies:
- name: common
version: 3.6.1
version: 3.7.0
repository: https://bjw-s.github.io/helm-charts/
```

View file

@ -178,7 +178,7 @@
"properties": {
"pullPolicy": {
"type": "string",
"enum": ["Always", "IfNotPresent"]
"enum": ["Always", "IfNotPresent", "Never"]
},
"repository": {
"type": "string"
@ -206,12 +206,15 @@
"port": {
"type": ["number", "string"]
},
"service": {
"type": "string"
},
"spec": {
"$ref": "k8s-api.json#/core.v1.Probe"
},
"type": {
"type": "string",
"enum": ["TCP", "HTTP", "HTTPS", "AUTO"]
"enum": ["TCP", "HTTP", "HTTPS", "GRPC", "AUTO"]
}
}
}

View file

@ -79,6 +79,10 @@
"securityContext": {
"$ref": "k8s-api.json#/core.v1.PodSecurityContext"
},
"shareProcessNamespace": {
"type": ["boolean", "null"],
"default": false
},
"terminationGracePeriodSeconds": {
"type": ["integer", "null"]
},

View file

@ -22,6 +22,9 @@
"nameOverride": {
"type": "string"
},
"forceRename": {
"type": "string"
},
"spec": {}
},
"required": ["apiVersion", "kind", "spec"]

View file

@ -39,7 +39,7 @@ spec:
app.kubernetes.io/service: {{ tpl $serviceMonitorObject.serviceName $rootContext }}
{{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }}
{{- end }}
endpoints: {{- toYaml $serviceMonitorObject.endpoints | nindent 4 }}
endpoints: {{- tpl (toYaml $serviceMonitorObject.endpoints) $rootContext | nindent 4 }}
{{- if not (empty $serviceMonitorObject.targetLabels )}}
targetLabels:
{{- toYaml $serviceMonitorObject.targetLabels | nindent 4 }}

View file

@ -4,8 +4,28 @@ Validate configMap values
{{- define "bjw-s.common.lib.configMap.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $configMapValues := .object -}}
{{- $identifier := .id -}}
{{- if empty $configMapValues -}}
{{- fail (printf "There was an error loading ConfigMap: %s. If it was automatically generated from a folder verify that files are properly flagged as `binary` or `escaped`" $identifier) -}}
{{- end -}}
{{- if and (empty (get $configMapValues "data")) (empty (get $configMapValues "binaryData")) -}}
{{- fail (printf "No data or binaryData specified for configMap. (configMap: %s)" $configMapValues.identifier) }}
{{- end -}}
{{- end -}}
{{/*
Validate configMap from folder values
*/}}
{{- define "bjw-s.common.lib.configMap.fromFolder.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $basePath := required "If you're using `configMapsFromFolder` you need to specify a `basePath` key" .basePath -}}
{{ $topLevelFolders := dict}}
{{- range $path, $_ := $rootContext.Files.Glob (printf "%s/*/*" $basePath) -}}
{{- $_ := set $topLevelFolders (dir $path) "" -}}
{{- end -}}
{{- $topLevelFoldersList := keys $topLevelFolders | sortAlpha -}}
{{- if empty $topLevelFoldersList -}}
{{- fail (printf "No configMaps found in the folder %s" $basePath) }}
{{- end -}}
{{- end -}}

View file

@ -54,7 +54,13 @@ Probes used by the container.
"scheme" $probeType
)
-}}
{{- else }}
{{- else if (eq $probeType "GRPC") -}}
{{- $probeHeader = "grpc" -}}
{{- $_ := set $probeDefinition $probeHeader dict -}}
{{- if $probeValues.service -}}
{{- $_ := set (index $probeDefinition $probeHeader) "service" $probeValues.service -}}
{{- end -}}
{{- else -}}
{{- $probeHeader = "tcpSocket" -}}
{{- $_ := set $probeDefinition $probeHeader dict -}}
{{- end -}}

View file

@ -31,6 +31,9 @@ hostPID: {{ include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "hostUsers")) }}
hostUsers: {{ . | trim }}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "shareProcessNamespace")) }}
shareProcessNamespace: {{ . | trim }}
{{- end -}}
{{- end }}
dnsPolicy: {{ include "bjw-s.common.lib.pod.field.dnsPolicy" (dict "ctx" $ctx) | trim }}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "dnsConfig")) }}
@ -52,7 +55,7 @@ restartPolicy: {{ . | trim }}
nodeSelector: {{ . | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "affinity")) }}
affinity: {{ . | nindent 2 }}
affinity: {{- tpl . $rootContext | nindent 2 }}
{{- end -}}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "topologySpreadConstraints")) }}
topologySpreadConstraints: {{ . | nindent 2 }}

View file

@ -8,13 +8,13 @@ Secondary entrypoint and primary loader for the common chart
{{- /* Build the templates */ -}}
{{- include "bjw-s.common.render.pvcs" . | nindent 0 -}}
{{- include "bjw-s.common.render.serviceAccount" . | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps.fromFolder" . | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps" . | nindent 0 -}}
{{- include "bjw-s.common.render.controllers" . | nindent 0 -}}
{{- include "bjw-s.common.render.services" . | nindent 0 -}}
{{- include "bjw-s.common.render.ingresses" . | nindent 0 -}}
{{- include "bjw-s.common.render.serviceMonitors" . | nindent 0 -}}
{{- include "bjw-s.common.render.routes" . | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps.fromFiles" . | nindent 0 -}}
{{- include "bjw-s.common.render.configMaps" . | nindent 0 -}}
{{- include "bjw-s.common.render.secrets" . | nindent 0 -}}
{{- include "bjw-s.common.render.networkpolicies" . | nindent 0 -}}
{{- include "bjw-s.common.render.rawResources" . | nindent 0 -}}

View file

@ -17,9 +17,8 @@ Renders the configMap objects required by the chart.
{{- /* Create object from the raw configMap values */ -}}
{{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $configMapValues)) | fromYaml -}}
{{- /* Perform validations on the configMap before rendering */ -}}
{{- include "bjw-s.common.lib.configMap.validate" (dict "rootContext" $ "object" $configMapObject) -}}
{{- include "bjw-s.common.lib.configMap.validate" (dict "rootContext" $ "object" $configMapObject "id" $key) -}}
{{/* Include the configMap class */}}
{{- include "bjw-s.common.class.configMap" (dict "rootContext" $ "object" $configMapObject) | nindent 0 -}}
@ -30,36 +29,57 @@ Renders the configMap objects required by the chart.
{{/*
Renders configMap objects required by the chart from a folder in the repo's path.
*/}}
{{- define "bjw-s.common.render.configMaps.fromFiles" -}}
{{- $rootValues := .Values -}}
{{- define "bjw-s.common.render.configMaps.fromFolder" -}}
{{/* Generate a list of unique top level folders */}}
{{ $topLevelFolders := dict}}
{{- range $path, $_ := .Files.Glob (printf "%s/*/*" .Values.configMapsFromFolderBasePath) -}}
{{- $_ := set $topLevelFolders (dir $path) "" -}}
{{- end -}}
{{- $top_level_folder_list := keys $topLevelFolders | sortAlpha -}}
{{/* Iterate over the top level folders */}}
{{ range $path := $top_level_folder_list }}
{{- $filesContentNoFormat := ($.Files.Glob (printf "%s/*" $path)) -}}
{{- $filesContent := dict -}}
{{- $binaryFilesContent := dict -}}
{{- range $file_name, $content := $filesContentNoFormat -}}
{{- $key := base $file_name -}}
{{- if contains ".escape" $key -}}
{{- $key := $key | replace ".escape" "" -}}
{{- $filesContent = merge $filesContent (dict $key (($.Files.Get $file_name) | replace "{{" "{{ `{{` }}")) -}}
{{- else if contains ".binary" $key -}}
{{- $key := $key | replace ".binary" "" -}}
{{- $binaryFilesContent = merge $binaryFilesContent (dict $key ($.Files.Get $file_name | b64enc )) -}}
{{- else -}}
{{- $filesContent = merge $filesContent (dict $key ($.Files.Get $file_name)) -}}
{{- end -}}
{{- $valuesCopy := .Values -}}
{{- $configMapsFromFolder := .Values.configMapsFromFolder | default dict -}}
{{- $configMapsFromFolderEnabled := dig "enabled" false $configMapsFromFolder -}}
{{- if $configMapsFromFolderEnabled -}}
{{- /* Perform validations before rendering */ -}}
{{- include "bjw-s.common.lib.configMap.fromFolder.validate" (dict "rootContext" $ "basePath" $configMapsFromFolder.basePath) -}}
{{- $basePath := $configMapsFromFolder.basePath -}}
{{/* Generate a list of unique top level folders */}}
{{ $topLevelFolders := dict}}
{{- range $path, $_ := .Files.Glob (printf "%s/*/*" $basePath) -}}
{{- $_ := set $topLevelFolders (dir $path) "" -}}
{{- end -}}
{{- $top_level_folder_list := keys $topLevelFolders | sortAlpha -}}
{{/* Iterate over the top level folders */}}
{{ range $path := $top_level_folder_list }}
{{- $folder := base $path -}}
{{- $configMapData := dict -}}
{{- $configMapBinaryData := dict -}}
{{- $allFilesContent := ($.Files.Glob (printf "%s/*" $path)) -}}
{{- $configMapValues := dict "enabled" true "labels" dict "annotations" dict "data" $filesContent "binaryData" $binaryFilesContent -}}
{{- $existingConfigMaps := (get $rootValues "configMaps"| default dict) -}}
{{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict (base $path) $configMapValues) -}}
{{- $rootValues := merge $rootValues (dict "configMaps" $mergedConfigMaps) -}}
{{- $configMapAnnotations := dig "configMapsOverrides" $folder "annotations" dict $configMapsFromFolder -}}
{{- $configMapLabels := dig "configMapsOverrides" $folder "labels" dict $configMapsFromFolder -}}
{{- $configMapForceRename := dig "configMapsOverrides" $folder "forceRename" nil $configMapsFromFolder -}}
{{- range $file_name, $content := $allFilesContent -}}
{{- $file := base $file_name -}}
{{- $fileOverride := dig "configMapsOverrides" $folder "fileAttributeOverrides" $file nil $configMapsFromFolder -}}
{{- $fileContent := $.Files.Get $file_name -}}
{{- if not $fileOverride.exclude -}}
{{- if $fileOverride.binary -}}
{{- $fileContent = $fileContent | b64enc -}}
{{- $configMapBinaryData = merge $configMapBinaryData (dict $file $fileContent) -}}
{{- else if $fileOverride.escaped -}}
{{- $fileContent = $fileContent | replace "{{" "{{ `{{` }}" -}}
{{- $configMapData = merge $configMapData (dict $file $fileContent) -}}
{{- else -}}
{{- $configMapData = merge $configMapData (dict $file $fileContent) -}}
{{- end -}}
{{- end -}}
{{ end }}
{{- $configMapValues := dict "enabled" true "forceRename" $configMapForceRename "labels" $configMapLabels "annotations" $configMapAnnotations "data" $configMapData "binaryData" $configMapBinaryData -}}
{{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $ "id" $folder "values" $configMapValues)) | fromYaml -}}
{{/* Append it to .Values.configMaps so it can be created by "bjw-s.common.render.configMaps" and fetched by identifier */}}
{{- $existingConfigMaps := (get $valuesCopy "configMaps"| default dict) -}}
{{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict (base $path) $configMapValues) -}}
{{- $valuesCopy := merge $valuesCopy (dict "configMaps" $mergedConfigMaps) -}}
{{ end }}
{{ end }}
{{ end }}

View file

@ -1,6 +1,6 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.6.1/charts/library/common/values.schema.json",
"$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.7.0/charts/library/common/values.schema.json",
"type": "object",
"properties": {
"global": {

View file

@ -14,7 +14,7 @@ global:
# -- Set default options for all controllers / pods here
# Each of these options can be overridden on a Controller level
defaultPodOptions:
# -- Defines affinity constraint rules.
# -- Defines affinity constraint rules. Helm templates can be used.
# [[ref]](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity)
affinity: {}
@ -79,6 +79,10 @@ defaultPodOptions:
# -- Configure the Security Context for the Pod
securityContext: {}
# -- Allows sharing process namespace between containers in a Pod
# -- [[ref](https://kubernetes.io/docs/tasks/configure-pod-container/share-process-namespace/)]
shareProcessNamespace:
# -- Duration in seconds the pod needs to terminate gracefully
# -- [[ref](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#lifecycle)]
terminationGracePeriodSeconds:
@ -471,19 +475,43 @@ configMaps:
# data:
# foo: bar
# -- A path in your parent's chart filesystem where you can add files to be converted into individual ConfigMaps.
# -- Generate ConfigMaps from a folder in the Helm chart's filesystem
# Your files will need to be two levels deep from the base path.
# For example, if you set this to `files/`, and you have this file tree
# For example, if you set this to `files/`, you should have this file tree
# files:
# └── configmap1
# ├── file1
# └── file2
# This will generate a ConfigMap named `configmap1` with keys `file1` and `file2`, values being the respective contents of those files.
# If your file contains `gotpl` syntax that you don't want templated by Helm, prefix the file extension with `.escape` and it will be treated as a regular string.
# For example, `file1.escape.yaml` will be converted to `file1.yaml` in the ConfigMap with the contents of the file not templated.
# If your file is a binary file like an image, prefix the file extension with `.binary`
# For example, `file1.binary.png` will be converted to `file1.png` in the ConfigMap under binaryData with the contents of the file base64 encoded.
configMapsFromFolderBasePath: null
# This will generate a ConfigMap named `configmap1` with keys `file1` and `file2`.
configMapsFromFolder:
enabled: false
# #-- The path in your parent's chart filesystem where you can add files to be converted into individual ConfigMaps.
# basePath: "files/configMaps"
# #-- Define overrides for the generated ConfigMaps, each key is the name of a folder in `basePath`
# configMapsOverrides:
# test:
# # All ConfigMaps support a `forceRename` field, which allows you to rename the ConfigMap
# forceRename: null
# annotations:
# test: test
# labels:
# test: test
# # Configure how the individual files are added to the ConfigMap
# fileAttributeOverrides:
# # The key is the name of the file inside the ConfigMap's folder
# test.tpl:
# # If true the file won't be added to the ConfigMap
# exclude: false
# # If your file is a binary file like an image, set this to true. Takes precedence over `escaped`
# binary: false
# # If your file contains `gotpl` syntax that you don't want templated by Helm, set this to true
# escaped: true
# test.txt:
# exclude: true
# test2:
# fileAttributeOverrides:
# image.png:
# binary: true
# -- Configure the services for the chart here.
# Additional services can be added by adding a dictionary key similar to the 'main' service.
@ -637,7 +665,7 @@ serviceMonitor:
# # -- Configures the target Service for the serviceMonitor. Helm templates can be used.
# serviceName: '{{ include "bjw-s.common.lib.chart.names.fullname" $ }}'
# # -- Configures the endpoints for the serviceMonitor.
# # -- Configures the endpoints for the serviceMonitor. Helm templates can be used.
# # @default -- See values.yaml
# endpoints:
# - port: http