feat(common): Release v3.3.0 (#335)

This commit is contained in:
Bernd Schorgers 2024-07-29 14:50:49 +02:00 committed by GitHub
parent 040eb7b9d2
commit 74f3170cec
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 386 additions and 10 deletions

View file

@ -95,3 +95,16 @@ persistence:
- path: /data/config.yaml - path: /data/config.yaml
readOnly: false readOnly: false
subPath: config.yaml subPath: config.yaml
rawResources:
unsupportedPDB:
enabled: true
nameOverride: pdb
apiVersion: policy/v1
kind: PodDisruptionBudget
spec:
spec:
minAvailable: 1
selector:
matchLabels:
app.kubernetes.io/instance: "{{ .Release.Name }}"

View file

@ -0,0 +1,98 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: rawResource metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
rawResources:
config:
apiVersion: v1
kind: Endpoint
spec:
test: test
tests:
- it: default metadata should pass
asserts:
- hasDocuments:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
notExists:
path: metadata.annotations
- documentIndex: *rawResourceDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass
set:
rawResources:
config:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *rawResourceDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test
- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
rawResources:
config:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *rawResourceDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test

View file

@ -0,0 +1,78 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: rawResource values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
rawResources:
endpoint:
apiVersion: v1
kind: Endpoint
spec:
subsets:
- addresses:
- ip: 127.0.0.1
ports:
- name: "{{ .Release.Name }}"
port: 443
protocol: TCP
tests:
- it: default should pass
asserts:
- hasDocuments:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: subsets[0].addresses[0].ip
value: 127.0.0.1
- it: nameOverride should pass
set:
rawResources.endpoint:
nameOverride: test
asserts:
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.name
value: RELEASE-NAME-test
- it: nameOverride with template should pass
set:
rawResources.endpoint:
nameOverride: "{{ .Release.Name }}"
asserts:
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.name
value: RELEASE-NAME
- it: spec with template should pass
set:
rawResources.endpoint:
spec:
subsets:
- addresses:
- ip: 127.0.0.1
ports:
- name: "{{ .Release.Name }}"
port: 443
protocol: TCP
asserts:
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: subsets[0].ports[0].name
value: RELEASE-NAME

View file

@ -3,7 +3,7 @@ apiVersion: v2
name: common name: common
description: Function library for Helm charts description: Function library for Helm charts
type: library type: library
version: 3.2.1 version: 3.3.0
kubeVersion: ">=1.22.0-0" kubeVersion: ">=1.22.0-0"
keywords: keywords:
- common - common
@ -16,16 +16,16 @@ annotations:
artifacthub.io/changes: |- artifacthub.io/changes: |-
- kind: added - kind: added
description: |- description: |-
Support templating in annotation and label values for all objects (fixed in v3.2.1) Added support for specifying unsupported raw resources.
- kind: added - kind: added
description: |- description: |-
Support activeDeadlineSeconds field on CronJobs and Jobs Added `stdin` and `tty` fields to container spec.
- kind: added - kind: added
description: |- description: |-
Support excluding secrets and configMaps from pod checksum annotation Added `persistentVolumeClaimRetentionPolicy` field to statefulset spec.
- kind: fixed - kind: fixed
description: |- description: |-
Fixed failing ServiceMonitor test Added `externalName` field to service schema.
- kind: fixed - kind: fixed
description: |- description: |-
Fixed networkPolicies not rendering correctly Always allow specifying `nodePort` field on service ports.

View file

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

View file

@ -149,6 +149,10 @@
"securityContext": { "securityContext": {
"$ref": "k8s-api.json#/core.v1.ContainerSecurityContext" "$ref": "k8s-api.json#/core.v1.ContainerSecurityContext"
}, },
"stdin": {
"type": "boolean",
"default": false
},
"terminationMessagePath": { "terminationMessagePath": {
"type": "string" "type": "string"
}, },
@ -156,6 +160,10 @@
"type": "string", "type": "string",
"enum": ["File", "FallbackToLogsOnError"] "enum": ["File", "FallbackToLogsOnError"]
}, },
"tty": {
"type": "boolean",
"default": false
},
"workingDir": { "workingDir": {
"type": "string" "type": "string"
} }

View file

@ -146,6 +146,22 @@
"podManagementPolicy": { "podManagementPolicy": {
"type": "string" "type": "string"
}, },
"persistentVolumeClaimRetentionPolicy": {
"type": "object",
"additionalProperties": false,
"properties": {
"whenDeleted": {
"type": "string",
"enum": ["Delete", "Retain"],
"default": "Retain"
},
"whenScaled": {
"type": "string",
"enum": ["Delete", "Retain"],
"default": "Retain"
}
}
},
"volumeClaimTemplates": { "volumeClaimTemplates": {
"type": "array", "type": "array",
"items": { "items": {

View file

@ -0,0 +1,29 @@
{
"instance": {
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"default": true
},
"apiVersion": {
"type": "string"
},
"kind": {
"type": "string"
},
"annotations": {
"$ref": "definitions.json#/annotations"
},
"labels": {
"$ref": "definitions.json#/labels"
},
"nameOverride": {
"type": "string"
},
"spec": {}
},
"required": ["apiVersion", "kind", "spec"]
}
}

View file

@ -22,6 +22,9 @@
"clusterIP": { "clusterIP": {
"type": "string" "type": "string"
}, },
"externalName": {
"type": "string"
},
"loadBalancerIP": { "loadBalancerIP": {
"type": "string" "type": "string"
}, },

View file

@ -0,0 +1,37 @@
{{/*
This template serves as a blueprint for all raw resource objects that are created
within the common library.
*/}}
{{- define "bjw-s.common.class.rawResource" -}}
{{- $rootContext := .rootContext -}}
{{- $resourceObject := .object -}}
{{- $labels := merge
($resourceObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
{{- $annotations := merge
($resourceObject.annotations | default dict)
(include "bjw-s.common.lib.metadata.globalAnnotations" $rootContext | fromYaml)
-}}
---
apiVersion: {{ $resourceObject.apiVersion }}
kind: {{ $resourceObject.kind }}
metadata:
name: {{ $resourceObject.name }}
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $resourceObject.spec }}
{{- tpl (toYaml .) $rootContext | nindent 0 }}
{{- end }}
{{- end -}}

View file

@ -93,7 +93,7 @@ spec:
protocol: TCP protocol: TCP
{{- end }} {{- end }}
name: {{ $name }} name: {{ $name }}
{{- if (and (eq $svcType "NodePort") (not (empty $port.nodePort))) }} {{- if (not (empty $port.nodePort)) }}
nodePort: {{ $port.nodePort }} nodePort: {{ $port.nodePort }}
{{ end }} {{ end }}
{{- if (not (empty $port.appProtocol)) }} {{- if (not (empty $port.appProtocol)) }}

View file

@ -47,6 +47,9 @@ spec:
app.kubernetes.io/component: {{ $statefulsetObject.identifier }} app.kubernetes.io/component: {{ $statefulsetObject.identifier }}
{{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }} {{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }}
serviceName: {{ include "bjw-s.common.lib.chart.names.fullname" $rootContext }} serviceName: {{ include "bjw-s.common.lib.chart.names.fullname" $rootContext }}
{{- with (dig "statefulset" "persistentVolumeClaimRetentionPolicy" nil $statefulsetObject) }}
persistentVolumeClaimRetentionPolicy: {{ . | toYaml | nindent 4 }}
{{- end }}
template: template:
metadata: metadata:
{{- with (include "bjw-s.common.lib.pod.metadata.annotations" (dict "rootContext" $rootContext "controllerObject" $statefulsetObject)) }} {{- with (include "bjw-s.common.lib.pod.metadata.annotations" (dict "rootContext" $rootContext "controllerObject" $statefulsetObject)) }}

View file

@ -50,6 +50,12 @@ resources: {{ toYaml . | trim | nindent 2 }}
{{- end -}} {{- end -}}
{{- with $containerObject.restartPolicy }} {{- with $containerObject.restartPolicy }}
restartPolicy: {{ . | trim }} restartPolicy: {{ . | trim }}
{{- end -}}
{{- with $containerObject.stdin }}
stdin: {{ . | trim }}
{{- end -}}
{{- with $containerObject.tty }}
tty: {{ . | trim }}
{{- end -}} {{- end -}}
{{- with (include "bjw-s.common.lib.container.field.volumeMounts" (dict "ctx" $ctx) | trim) }} {{- with (include "bjw-s.common.lib.container.field.volumeMounts" (dict "ctx" $ctx) | trim) }}
volumeMounts: {{ . | trim | nindent 2 }} volumeMounts: {{ . | trim | nindent 2 }}

View file

@ -0,0 +1,7 @@
{{/*
Validate raw resource values
*/}}
{{- define "bjw-s.common.lib.rawResource.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $resourceObject := .object -}}
{{- end -}}

View file

@ -0,0 +1,27 @@
{{/*
Convert raw resource values to an object
*/}}
{{- define "bjw-s.common.lib.rawResource.valuesToObject" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $objectValues := .values -}}
{{- /* Determine and inject the raw resource 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 -}}
{{- if not (eq $objectName $identifier) -}}
{{- $objectName = printf "%s-%s" $objectName $identifier -}}
{{- end -}}
{{- end -}}
{{- $_ := set $objectValues "name" $objectName -}}
{{- $_ := set $objectValues "identifier" $identifier -}}
{{- /* Return the raw resource object */ -}}
{{- $objectValues | toYaml -}}
{{- end -}}

View file

@ -16,4 +16,5 @@ Secondary entrypoint and primary loader for the common chart
{{- include "bjw-s.common.render.configMaps" . | nindent 0 -}} {{- include "bjw-s.common.render.configMaps" . | nindent 0 -}}
{{- include "bjw-s.common.render.secrets" . | nindent 0 -}} {{- include "bjw-s.common.render.secrets" . | nindent 0 -}}
{{- include "bjw-s.common.render.networkpolicies" . | nindent 0 -}} {{- include "bjw-s.common.render.networkpolicies" . | nindent 0 -}}
{{- include "bjw-s.common.render.rawResources" . | nindent 0 -}}
{{- end -}} {{- end -}}

View file

@ -0,0 +1,26 @@
{{/*
Renders other arbirtrary objects required by the chart.
*/}}
{{- define "bjw-s.common.render.rawResources" -}}
{{- /* Generate pvc as required */ -}}
{{- range $key, $resource := .Values.rawResources -}}
{{- /* Enable by default, but allow override */ -}}
{{- $resourceEnabled := true -}}
{{- if hasKey $resource "enabled" -}}
{{- $resourceEnabled = $resource.enabled -}}
{{- end -}}
{{- if $resourceEnabled -}}
{{- $resourceValues := (mustDeepCopy $resource) -}}
{{- /* Create object from the raw resource values */ -}}
{{- $resourceObject := (include "bjw-s.common.lib.rawResource.valuesToObject" (dict "rootContext" $ "id" $key "values" $resourceValues)) | fromYaml -}}
{{- /* Perform validations on the resource before rendering */ -}}
{{- include "bjw-s.common.lib.rawResource.validate" (dict "rootContext" $ "object" $resourceValues) -}}
{{- /* Include the raw resource class */ -}}
{{- include "bjw-s.common.class.rawResource" (dict "rootContext" $ "object" $resourceValues) | nindent 0 -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -1,6 +1,6 @@
{ {
"$schema": "http://json-schema.org/draft-07/schema", "$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.2.1/charts/library/common/values.schema.json", "$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.3.0/charts/library/common/values.schema.json",
"type": "object", "type": "object",
"properties": { "properties": {
@ -71,6 +71,11 @@
"additionalProperties": { "additionalProperties": {
"$ref": "schemas/persistence.json#/item" "$ref": "schemas/persistence.json#/item"
} }
},
"rawResources": {
"additionalProperties": {
"$ref": "schemas/rawResource.json#/instance"
}
} }
} }
} }

View file

@ -723,3 +723,22 @@ networkpolicies:
# # -- The egress rules for this networkPolicy. Allows all egress traffic by default. # # -- The egress rules for this networkPolicy. Allows all egress traffic by default.
# egress: # egress:
# - {} # - {}
# -- Configure any unsupported raw resources here.
# @default -- See below
rawResources: {}
# example:
# # -- Enables or disables the resource. Defaults to true
# enabled: false
# # -- Specify the apiVersion of the resource.
# apiVersion: v1
# # -- Specify the kind of the resource.
# kind: Endpoint
# # -- Override the name suffix that is used for this resource.
# nameOverride: ""
# # -- Provide additional annotations which may be required.
# annotations: {}
# # -- Provide additional labels which may be required.
# labels: {}
# # -- Configure the contents of the resource that is to be rendered.
# spec: