fix(common): Release v3.0.3 (#291)

Co-authored-by: Gabe Cook <gabe565@gmail.com>
This commit is contained in:
Bernd Schorgers 2024-03-13 14:26:40 +01:00 committed by GitHub
parent a50630fa60
commit 425f4428ab
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 164 additions and 33 deletions

View file

@ -0,0 +1,22 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: Chart validations
templates:
- common.yaml
tests:
- it: advancedMounts invalid controller reference should fail
set:
persistence:
data:
type: configMap
name: myConfigMap
advancedMounts:
test:
main:
- path: /data/config.yaml
readOnly: false
mountPropagation: HostToContainer
subPath: config.yaml
asserts:
- failedTemplate:
errorMessage: "No enabled controller found with this identifier. (persistence item: 'data', controller: 'test')"

View file

@ -146,6 +146,68 @@ tests:
port: 80 port: 80
timeoutSeconds: 1 timeoutSeconds: 1
- it: multiple services should pass
set:
controllers:
other:
containers:
main:
image:
repository: ghcr.io/mendhak/http-https-echo
tag: 31
pullPolicy: IfNotPresent
probes:
liveness:
enabled: true
readiness:
enabled: true
startup:
enabled: true
service:
other:
controller: other
ports:
http:
enabled: true
port: &secondDeploymentPort 8080
main:
controller: main
ports:
http:
enabled: true
port: &firstDeploymentPort 80
asserts:
- documentIndex: &firstDeploymentDocument 0
isKind:
of: Deployment
- documentIndex: *firstDeploymentDocument
equal:
path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port
value: *firstDeploymentPort
- documentIndex: *firstDeploymentDocument
equal:
path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port
value: *firstDeploymentPort
- documentIndex: *firstDeploymentDocument
equal:
path: spec.template.spec.containers[0].startupProbe.tcpSocket.port
value: *firstDeploymentPort
- documentIndex: &secondDeploymentDocument 1
isKind:
of: Deployment
- documentIndex: *secondDeploymentDocument
equal:
path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port
value: *secondDeploymentPort
- documentIndex: *secondDeploymentDocument
equal:
path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port
value: *secondDeploymentPort
- documentIndex: *secondDeploymentDocument
equal:
path: spec.template.spec.containers[0].startupProbe.tcpSocket.port
value: *secondDeploymentPort
- it: disabled service should pass - it: disabled service should pass
set: set:
service: service:

View file

@ -0,0 +1,14 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: Service validations
templates:
- common.yaml
tests:
- it: invalid controller reference should fail
set:
service:
main:
controller: other
asserts:
- failedTemplate:
errorMessage: "No enabled controller found with this identifier. (service: 'main', controller: 'other')"

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.0.2 version: 3.0.3
kubeVersion: ">=1.22.0-0" kubeVersion: ">=1.22.0-0"
keywords: keywords:
- common - common
@ -16,25 +16,7 @@ annotations:
artifacthub.io/changes: |- artifacthub.io/changes: |-
- kind: fixed - kind: fixed
description: |- description: |-
Fixed nameOverride logic to prevent duplicated name Fixed probes intermittently choosing the wrong service
- kind: changed - kind: fixed
description: |- description: |-
BREAKING: Default objects (they used to be called main) have been commented out and will therefore no longer provide any (both expected and unexpected) default values. Prevent potential incorrect controller references
- kind: changed
description: |-
BREAKING: `enableServiceLinks` is now disabled by default
- kind: changed
description: |-
BREAKING: Referencing services under Ingress paths has been separated in explicit `name` and `identifier` keys.
- kind: added
description: |-
Added support for restartPolicy field on container level. This enables Kubernetes 1.29 sidecar containers
links:
- name: Reference documentation
url: https://kubernetes.io/docs/concepts/workloads/pods/sidecar-containers/
- kind: added
description: |-
Added json-schema validation to the chart
- kind: added
description: |-
Allow referencing secrets and configMaps by identifier in persistence section

View file

@ -1,6 +1,6 @@
# common # common
![Version: 3.0.2](https://img.shields.io/badge/Version-3.0.2-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square) ![Version: 3.0.3](https://img.shields.io/badge/Version-3.0.3-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.0.2 version: 3.0.3
repository: https://bjw-s.github.io/helm-charts/ repository: https://bjw-s.github.io/helm-charts/
``` ```

View file

@ -101,6 +101,9 @@
"targetPort": { "targetPort": {
"type": ["string", "integer"] "type": ["string", "integer"]
}, },
"nodePort": {
"type": ["string", "integer"]
},
"appProtocol": { "appProtocol": {
"type": "string" "type": "string"
} }

View file

@ -0,0 +1,17 @@
{{/*
Validate global chart values
*/}}
{{- define "bjw-s.common.lib.chart.validate" -}}
{{- $rootContext := . -}}
{{- /* Validate persistence values */ -}}
{{- range $persistenceKey, $persistenceValues := .Values.persistence }}
{{- /* Make sure that any advancedMounts controller references actually resolve */ -}}
{{- range $key, $advancedMount := $persistenceValues.advancedMounts -}}
{{- $mountController := include "bjw-s.common.lib.controller.getByIdentifier" (dict "rootContext" $rootContext "id" $key) -}}
{{- if empty $mountController -}}
{{- fail (printf "No enabled controller found with this identifier. (persistence item: '%s', controller: '%s')" $persistenceKey $key) -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View file

@ -0,0 +1,14 @@
{{/*
Return a controller by its identifier.
*/}}
{{- define "bjw-s.common.lib.controller.getByIdentifier" -}}
{{- $rootContext := .rootContext -}}
{{- $identifier := .id -}}
{{- $enabledControllers := include "bjw-s.common.lib.controller.enabledControllers" (dict "rootContext" $rootContext) | fromYaml -}}
{{- $controllerValues := get $enabledControllers $identifier -}}
{{- if not (empty $controllerValues) -}}
{{- include "bjw-s.common.lib.controller.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $controllerValues) -}}
{{- end -}}
{{- end -}}

View file

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

View file

@ -9,6 +9,11 @@ Validate Service values
{{- fail (printf "controller field is required for Service. (service: %s)" $serviceObject.identifier) -}} {{- fail (printf "controller field is required for Service. (service: %s)" $serviceObject.identifier) -}}
{{- end -}} {{- end -}}
{{- $serviceController := include "bjw-s.common.lib.controller.getByIdentifier" (dict "rootContext" $rootContext "id" $serviceObject.controller) -}}
{{- if empty $serviceController -}}
{{- fail (printf "No enabled controller found with this identifier. (service: '%s', controller: '%s')" $serviceObject.identifier $serviceObject.controller) -}}
{{- end -}}
{{- /* Validate Service type */ -}} {{- /* Validate Service type */ -}}
{{- $validServiceTypes := (list "ClusterIP" "LoadBalancer" "NodePort" "ExternalName" "ExternalIP") -}} {{- $validServiceTypes := (list "ClusterIP" "LoadBalancer" "NodePort" "ExternalName" "ExternalIP") -}}
{{- if and $serviceObject.type (not (mustHas $serviceObject.type $validServiceTypes)) -}} {{- if and $serviceObject.type (not (mustHas $serviceObject.type $validServiceTypes)) -}}

View file

@ -2,6 +2,9 @@
Secondary entrypoint and primary loader for the common chart Secondary entrypoint and primary loader for the common chart
*/}} */}}
{{- define "bjw-s.common.loader.generate" -}} {{- define "bjw-s.common.loader.generate" -}}
{{- /* Run global chart validations */ -}}
{{- include "bjw-s.common.lib.chart.validate" . -}}
{{- /* Build the templates */ -}} {{- /* Build the templates */ -}}
{{- include "bjw-s.common.render.pvcs" . | nindent 0 -}} {{- include "bjw-s.common.render.pvcs" . | nindent 0 -}}
{{- include "bjw-s.common.render.serviceAccount" . | nindent 0 -}} {{- include "bjw-s.common.render.serviceAccount" . | nindent 0 -}}

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.0.2/charts/library/common/values.schema.json", "$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.0.3/charts/library/common/values.schema.json",
"type": "object", "type": "object",
"properties": { "properties": {