feat: Bump common library to v3.4.0 (#349)

This commit is contained in:
Bernd Schorgers 2024-08-27 14:16:37 +02:00
parent a78c21ab00
commit 86062681a9
No known key found for this signature in database
GPG key ID: BC5E2BD907F9A8EC
45 changed files with 1023 additions and 149 deletions

View file

@ -3,7 +3,7 @@ apiVersion: v2
name: common
description: Function library for Helm charts
type: library
version: 3.3.2
version: 3.4.0
kubeVersion: ">=1.22.0-0"
keywords:
- common
@ -16,16 +16,16 @@ annotations:
artifacthub.io/changes: |-
- kind: added
description: |-
Added support for specifying unsupported raw resources.
Add configMapsFromFolderBasePath to create ConfigMaps from a folder
- kind: added
description: |-
Added `stdin` and `tty` fields to container spec. (fixed in v3.3.2)
Added support for setting `defaultContainerOptions`.
links:
- name: Documentation
url: https://bjw-s.github.io/helm-charts/docs/common-library/howto/default-container-options
- kind: added
description: |-
Added `persistentVolumeClaimRetentionPolicy` field to statefulset spec.
Added support for `loadBalancerClass`.
- kind: fixed
description: |-
Added `externalName` field to service schema. (fixed in v3.3.1)
- kind: fixed
description: |-
Always allow specifying `nodePort` field on service ports.
Fixed volume name reference when persistence key matches release name.

View file

@ -1,6 +1,6 @@
# common
![Version: 3.3.2](https://img.shields.io/badge/Version-3.3.2-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square)
![Version: 3.4.0](https://img.shields.io/badge/Version-3.4.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.3.2
version: 3.4.0
repository: https://bjw-s.github.io/helm-charts/
```
@ -50,4 +50,4 @@ These values will be validated by a JSON schema which can be found [here](https:
- Join the home-operations [Discord](https://discord.gg/home-operations) community
----------------------------------------------
Autogenerated from chart metadata using [helm-docs v1.13.1](https://github.com/norwoodj/helm-docs/releases/v1.13.1)
Autogenerated from chart metadata using [helm-docs v1.14.2](https://github.com/norwoodj/helm-docs/releases/v1.14.2)

View file

@ -9,22 +9,10 @@
"default": true
},
"args": {
"oneOf": [
{
"type": "array",
"items": {"type": "string"}
},
{"type": "string"}
]
"$ref": "#/args"
},
"command": {
"oneOf": [
{
"type": "array",
"items": {"type": "string"}
},
{"type": "string"}
]
"$ref": "#/command"
},
"dependsOn": {
"oneOf": [
@ -36,82 +24,13 @@
]
},
"env": {
"oneOf": [
{
"type": "array",
"items": {
"anyOf": [
{"$ref": "envVars.json#/envVarListItem"},
{"$ref": "envVars.json#/valueFromListItem"}
]
}
},
{
"type": "object",
"additionalProperties": {
"anyOf": [
{"$ref": "envVars.json#/envVarValue"},
{"$ref": "envVars.json#/envVarItem"},
{"$ref": "envVars.json#/valueFromItem"}
]
}
}
]
"$ref": "#/env"
},
"envFrom": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"configMap": {
"type": "string"
},
"configMapRef": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {"type": "string"},
"identifier": {"type": "string"},
"optional": {"type": "boolean"}
},
"oneOf": [{"required": ["name"]}, {"required": ["identifier"]}]
},
"prefix": {
"type": ["string", "null"]
},
"secret": {
"type": "string"
},
"secretRef": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {"type": "string"},
"identifier": {"type": "string"},
"optional": {"type": "boolean"}
},
"oneOf": [{"required": ["name"]}, {"required": ["identifier"]}]
}
}
}
"$ref": "#/envFrom"
},
"image": {
"type": "object",
"additionalProperties": false,
"properties": {
"pullPolicy": {
"type": "string",
"enum": ["Always", "IfNotPresent"]
},
"repository": {
"type": "string"
},
"tag": {
"type": ["string", "number"]
}
},
"required": ["repository", "tag"]
"$ref": "#/image"
},
"lifecycle": {
"$ref": "k8s-api.json#/core.v1.Lifecycle"
@ -170,6 +89,106 @@
}
},
"args": {
"oneOf": [
{
"type": "array",
"items": {"type": "string"}
},
{"type": "string"}
]
},
"command": {
"oneOf": [
{
"type": "array",
"items": {"type": "string"}
},
{"type": "string"}
]
},
"env": {
"oneOf": [
{
"type": "array",
"items": {
"anyOf": [
{"$ref": "envVars.json#/envVarListItem"},
{"$ref": "envVars.json#/valueFromListItem"}
]
}
},
{
"type": "object",
"additionalProperties": {
"anyOf": [
{"$ref": "envVars.json#/envVarValue"},
{"$ref": "envVars.json#/envVarItem"},
{"$ref": "envVars.json#/valueFromItem"}
]
}
}
]
},
"envFrom": {
"type": "array",
"items": {
"type": "object",
"additionalProperties": false,
"properties": {
"configMap": {
"type": "string"
},
"configMapRef": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {"type": "string"},
"identifier": {"type": "string"},
"optional": {"type": "boolean"}
},
"oneOf": [{"required": ["name"]}, {"required": ["identifier"]}]
},
"prefix": {
"type": ["string", "null"]
},
"secret": {
"type": "string"
},
"secretRef": {
"type": "object",
"additionalProperties": false,
"properties": {
"name": {"type": "string"},
"identifier": {"type": "string"},
"optional": {"type": "boolean"}
},
"oneOf": [{"required": ["name"]}, {"required": ["identifier"]}]
}
}
}
},
"image": {
"type": "object",
"additionalProperties": false,
"properties": {
"pullPolicy": {
"type": "string",
"enum": ["Always", "IfNotPresent"]
},
"repository": {
"type": "string"
},
"tag": {
"type": ["string", "number"]
}
}
},
"probe": {
"additionalProperties": false,
"properties": {

View file

@ -47,6 +47,42 @@
"statefulset": {
"$ref": "#/statefulset"
},
"applyDefaultContainerOptionsToInitContainers": {
"type": "boolean",
"default": true
},
"defaultContainerOptionsStrategy": {
"type": "string",
"default": "overwrite",
"enum": ["overwrite", "merge"]
},
"defaultContainerOptions": {
"type": "object",
"additionalProperties": false,
"properties": {
"args": {
"$ref": "containers.json#/args"
},
"command": {
"$ref": "containers.json#/command"
},
"env": {
"$ref": "containers.json#/env"
},
"envFrom": {
"$ref": "containers.json#/envFrom"
},
"image": {
"$ref": "containers.json#/image"
},
"resources": {
"$ref": "k8s-api.json#/core.v1.ResourceRequirements"
},
"securityContext": {
"$ref": "k8s-api.json#/core.v1.ContainerSecurityContext"
}
}
},
"initContainers": {
"type": "object",
"additionalProperties": {

View file

@ -32,6 +32,9 @@
"type": "array",
"items": {"type": "string"}
},
"loadBalancerClass": {
"type": "string"
},
"externalTrafficPolicy": {
"type": "string",
"enum": ["Cluster", "Local"]

View file

@ -49,6 +49,9 @@ spec:
loadBalancerSourceRanges:
{{ toYaml $serviceObject.loadBalancerSourceRanges | nindent 4 }}
{{- end -}}
{{- if $serviceObject.loadBalancerClass }}
loadBalancerClass: {{ $serviceObject.loadBalancerClass }}
{{- end -}}
{{- else if eq $svcType "ExternalName" }}
type: {{ $svcType }}
{{- if $serviceObject.externalName }}

View file

@ -3,11 +3,39 @@ Convert container values to an object
*/}}
{{- define "bjw-s.common.lib.container.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $controllerObject := mustDeepCopy .controllerObject -}}
{{- $containerType := .containerType -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- $objectValues := mustDeepCopy .values -}}
{{- $defaultContainerOptionsStrategy := dig "defaultContainerOptionsStrategy" "overwrite" $controllerObject -}}
{{- $mergeDefaultContainerOptions := true -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Allow disabling default options for initContainers */ -}}
{{- if (eq "init" $containerType) -}}
{{- $applyDefaultContainerOptionsToInitContainers := dig "applyDefaultContainerOptionsToInitContainers" true $controllerObject -}}
{{- if (not (eq $applyDefaultContainerOptionsToInitContainers true)) -}}
{{- $mergeDefaultContainerOptions = false -}}
{{- end -}}
{{- end -}}
{{- /* Merge default container options if required */ -}}
{{- if (eq true $mergeDefaultContainerOptions) -}}
{{- if eq "overwrite" $defaultContainerOptionsStrategy -}}
{{- range $key, $defaultValue := (dig "defaultContainerOptions" dict $controllerObject) }}
{{- $specificValue := dig $key nil $objectValues -}}
{{- if not (empty $specificValue) -}}
{{- $_ := set $objectValues $key $specificValue -}}
{{- else -}}
{{- $_ := set $objectValues $key $defaultValue -}}
{{- end -}}
{{- end -}}
{{- else if eq "merge" $defaultContainerOptionsStrategy -}}
{{- $objectValues = merge $objectValues (dig "defaultContainerOptions" dict $controllerObject) -}}
{{- end -}}
{{- end -}}
{{- /* Process image tags */ -}}
{{- if kindIs "map" $objectValues.image -}}
{{- $imageTag := dig "image" "tag" "" $objectValues -}}

View file

@ -4,19 +4,17 @@ Args used by the container.
{{- define "bjw-s.common.lib.container.field.args" -}}
{{- $ctx := .ctx -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $argValues := get $containerObject "args" -}}
{{- /* Default to empty list */ -}}
{{- $args := list -}}
{{- /* See if an override is desired */ -}}
{{- if not (empty (get $containerObject "args")) -}}
{{- $option := get $containerObject "args" -}}
{{- if not (empty $option) -}}
{{- if kindIs "string" $option -}}
{{- $args = append $args $option -}}
{{- else -}}
{{- $args = $option -}}
{{- end -}}
{{- if not (empty $argValues) -}}
{{- if kindIs "string" $argValues -}}
{{- $args = append $args $argValues -}}
{{- else -}}
{{- $args = $argValues -}}
{{- end -}}
{{- end -}}

View file

@ -4,19 +4,17 @@ Command used by the container.
{{- define "bjw-s.common.lib.container.field.command" -}}
{{- $ctx := .ctx -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $commandValues := get $containerObject "command" -}}
{{- /* Default to empty list */ -}}
{{- $command := list -}}
{{- /* See if an override is desired */ -}}
{{- if not (empty (get $containerObject "command")) -}}
{{- $option := get $containerObject "command" -}}
{{- if not (empty $option) -}}
{{- if kindIs "string" $option -}}
{{- $command = append $command $option -}}
{{- else -}}
{{- $command = $option -}}
{{- end -}}
{{- if not (empty $commandValues) -}}
{{- if kindIs "string" $commandValues -}}
{{- $command = append $command $commandValues -}}
{{- else -}}
{{- $command = $commandValues -}}
{{- end -}}
{{- end -}}

View file

@ -5,25 +5,26 @@ Env field used by the container.
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $envValues := get $containerObject "env" -}}
{{- /* Default to empty list */ -}}
{{- $envList := list -}}
{{- /* See if an override is desired */ -}}
{{- if not (empty (get $containerObject "env")) -}}
{{- if kindIs "slice" $containerObject.env -}}
{{- if not (empty $envValues) -}}
{{- if kindIs "slice" $envValues -}}
{{- /* Env is a list so we assume the order is already as desired */ -}}
{{- range $name, $var := $containerObject.env -}}
{{- range $name, $var := $envValues -}}
{{- if kindIs "int" $name -}}
{{- $name = required "environment variables as a list of maps require a name field" $var.name -}}
{{- end -}}
{{- end -}}
{{- $envList = $containerObject.env -}}
{{- $envList = $envValues -}}
{{- else -}}
{{- /* Env is a map so we must check if ordering is desired */ -}}
{{- $graph := dict -}}
{{- range $name, $var := $containerObject.env -}}
{{- range $name, $var := $envValues -}}
{{- if kindIs "map" $var -}}
{{- /* Value is a map so ordering can be specified */ -}}
{{- if empty (dig "dependsOn" nil $var) -}}
@ -44,7 +45,7 @@ Env field used by the container.
{{- range $name := $args.out -}}
{{- $envItem := dict "name" $name -}}
{{- $envValue := get $containerObject.env $name -}}
{{- $envValue := get $envValues $name -}}
{{- if kindIs "map" $envValue -}}
{{- $envItem := merge $envItem (omit $envValue "dependsOn") -}}

View file

@ -1,14 +1,15 @@
{{/*
Env field used by the container.
envFrom field used by the container.
*/}}
{{- define "bjw-s.common.lib.container.field.envFrom" -}}
{{- $ctx := .ctx -}}
{{- $rootContext := $ctx.rootContext -}}
{{- $containerObject := $ctx.containerObject -}}
{{- $envFromValues := get $containerObject "envFrom" -}}
{{- if not (empty (get $containerObject "envFrom")) -}}
{{- if not (empty $envFromValues) -}}
{{- $envFrom := list -}}
{{- range $containerObject.envFrom -}}
{{- range $envFromValues -}}
{{- $item := dict -}}
{{- if hasKey . "configMap" -}}

View file

@ -15,7 +15,7 @@ Returns the value for containers
{{- range $key, $containerValues := $enabledContainers -}}
{{- /* Create object from the container values */ -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $containerValues)) | fromYaml -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerType" "default" "id" $key "values" $containerValues)) | fromYaml -}}
{{- /* Perform validations on the Container before rendering */ -}}
{{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "controllerObject" $controllerObject "containerObject" $containerObject) -}}

View file

@ -21,7 +21,7 @@ Returns the value for initContainers
{{- if $containerEnabled -}}
{{- /* Create object from the container values */ -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $containerValues)) | fromYaml -}}
{{- $containerObject := (include "bjw-s.common.lib.container.valuesToObject" (dict "rootContext" $rootContext "controllerObject" $controllerObject "containerType" "init" "id" $key "values" $containerValues)) | fromYaml -}}
{{- /* Perform validations on the Container before rendering */ -}}
{{- include "bjw-s.common.lib.container.validate" (dict "rootContext" $ "controllerObject" $controllerObject "containerObject" $containerObject) -}}

View file

@ -51,7 +51,9 @@ Returns the value for volumes
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $persistenceValues.nameOverride) -}}
{{- end -}}
{{- else -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $identifier) -}}
{{- if not (eq $pvcName $identifier) -}}
{{- $pvcName = (printf "%s-%s" (include "bjw-s.common.lib.chart.names.fullname" $rootContext) $identifier) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- $_ := set $volume "persistentVolumeClaim" (dict "claimName" $pvcName) -}}

View file

@ -13,6 +13,7 @@ Secondary entrypoint and primary loader for the common chart
{{- 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 -}}

View file

@ -24,3 +24,36 @@ Renders the configMap objects required by the chart.
{{- end -}}
{{- end -}}
{{- end -}}
{{/*
Renders configMap objects required by the chart from a folder in the repo's path.
*/}}
{{- define "bjw-s.common.render.configMaps.fromFiles" -}}
{{- $rootValues := .Values -}}
{{/* 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 -}}
{{- 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 -}}
{{- $filesContent = merge $filesContent (dict $key ($.Files.Get $file_name)) -}}
{{- end -}}
{{- end -}}
{{- $configMapValues := dict "enabled" true "labels" dict "annotations" dict "data" $filesContent -}}
{{- $existingConfigMaps := (get $rootValues "configMaps"| default dict) -}}
{{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict (base $path) $configMapValues) -}}
{{- $rootValues := merge $rootValues (dict "configMaps" $mergedConfigMaps) -}}
{{ 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.3.2/charts/library/common/values.schema.json",
"$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.4.0/charts/library/common/values.schema.json",
"type": "object",
"properties": {

View file

@ -194,6 +194,36 @@ controllers: {}
# # Controller-specific overrides for `defaultPodOptions` keys
# pod: {}
# # -- Whether to apply defaultContainerOptions to initContainers
# applyDefaultContainerOptionsToInitContainers: true
# # -- Set the strategy for the default container options. Defaults to
# # overwrite: If container-level options are set, use those instead of the defaults.
# # merge: If container-level options are set, merge them with the defaults
# # @default -- overwrite
# defaultContainerOptionsStrategy: overwrite
# # -- Set default options for all (init)Containers here
# # Each of these options can be overridden on a container level
# defaultContainerOptions:
# image:
# # -- Override the image repository for the containers
# repository:
# # -- Override the image tag for the containers
# tag:
# # -- Override the image pull policy for the containers
# pullPolicy:
# # -- Override the command(s) for the containers
# command:
# # -- Override the args for the containers
# args:
# # -- Environment variables.
# env:
# # -- Secrets and/or ConfigMaps that will be loaded as environment variables.
# envFrom: {}
# # -- Set the resource requests / limits for the container.
# resources:
# # -- Configure the Security Context for the container
# securityContext: {}
# containers:
# main:
# # -- Override the container name
@ -211,11 +241,11 @@ controllers: {}
# # -- image pull policy
# pullPolicy:
# # -- Override the command(s) for the default container
# # -- Override the command(s) for the container
# command: []
# # -- Override the args for the default container
# # -- Override the args for the container
# args: []
# # -- Override the working directory for the default container
# # -- Override the working directory for the container
# workingDir:
# # -- Environment variables. Template enabled.
@ -410,6 +440,18 @@ configMaps:
# data:
# foo: bar
# -- A path in your parent's chart filesystem where you can add files to be converted into individual ConfigMaps.
# 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
# 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.
configMapsFromFolderBasePath: null
# -- Configure the services for the chart here.
# Additional services can be added by adding a dictionary key similar to the 'main' service.
# @default -- See below