mirror of
https://github.com/bjw-s-labs/helm-charts.git
synced 2025-07-03 16:37:04 +02:00
fix(common): Release v3.0.3 (#291)
Co-authored-by: Gabe Cook <gabe565@gmail.com>
This commit is contained in:
parent
a50630fa60
commit
425f4428ab
12 changed files with 164 additions and 33 deletions
22
charts/library/common-test/tests/chart/validations_test.yaml
Normal file
22
charts/library/common-test/tests/chart/validations_test.yaml
Normal 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')"
|
|
@ -146,6 +146,68 @@ tests:
|
|||
port: 80
|
||||
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
|
||||
set:
|
||||
service:
|
||||
|
|
|
@ -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')"
|
|
@ -3,7 +3,7 @@ apiVersion: v2
|
|||
name: common
|
||||
description: Function library for Helm charts
|
||||
type: library
|
||||
version: 3.0.2
|
||||
version: 3.0.3
|
||||
kubeVersion: ">=1.22.0-0"
|
||||
keywords:
|
||||
- common
|
||||
|
@ -16,25 +16,7 @@ annotations:
|
|||
artifacthub.io/changes: |-
|
||||
- kind: fixed
|
||||
description: |-
|
||||
Fixed nameOverride logic to prevent duplicated name
|
||||
- kind: changed
|
||||
Fixed probes intermittently choosing the wrong service
|
||||
- kind: fixed
|
||||
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.
|
||||
- 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
|
||||
Prevent potential incorrect controller references
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# common
|
||||
|
||||
 
|
||||
 
|
||||
|
||||
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.0.2
|
||||
version: 3.0.3
|
||||
repository: https://bjw-s.github.io/helm-charts/
|
||||
```
|
||||
|
||||
|
|
|
@ -101,6 +101,9 @@
|
|||
"targetPort": {
|
||||
"type": ["string", "integer"]
|
||||
},
|
||||
"nodePort": {
|
||||
"type": ["string", "integer"]
|
||||
},
|
||||
"appProtocol": {
|
||||
"type": "string"
|
||||
}
|
||||
|
|
17
charts/library/common/templates/lib/chart/_validate.tpl
Normal file
17
charts/library/common/templates/lib/chart/_validate.tpl
Normal 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 -}}
|
|
@ -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 -}}
|
|
@ -11,18 +11,27 @@ Return the primary service object for a controller
|
|||
{{- /* Loop over all enabled services */ -}}
|
||||
{{- $enabledServices := (include "bjw-s.common.lib.service.enabledServices" (dict "rootContext" $rootContext) | fromYaml ) }}
|
||||
{{- 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 -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $name, $service := $enabledServicesForController -}}
|
||||
{{- /* Determine the Service that has been marked as primary */ -}}
|
||||
{{- if and (hasKey $service "primary") $service.primary -}}
|
||||
{{- if $service.primary -}}
|
||||
{{- $identifier = $name -}}
|
||||
{{- $result = $service -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Return the first Service if none has been explicitly marked as primary */ -}}
|
||||
{{- if not $result -}}
|
||||
{{- $identifier = keys $enabledServices | first -}}
|
||||
{{- $result = get $enabledServices $identifier -}}
|
||||
{{- $firstServiceKey := keys $enabledServicesForController | first -}}
|
||||
{{- $result = get $enabledServicesForController $firstServiceKey -}}
|
||||
{{- $identifier = $result.identifier -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- include "bjw-s.common.lib.service.valuesToObject" (dict "rootContext" $rootContext "id" $identifier "values" $result) -}}
|
||||
|
|
|
@ -9,6 +9,11 @@ Validate Service values
|
|||
{{- fail (printf "controller field is required for Service. (service: %s)" $serviceObject.identifier) -}}
|
||||
{{- 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 */ -}}
|
||||
{{- $validServiceTypes := (list "ClusterIP" "LoadBalancer" "NodePort" "ExternalName" "ExternalIP") -}}
|
||||
{{- if and $serviceObject.type (not (mustHas $serviceObject.type $validServiceTypes)) -}}
|
||||
|
|
|
@ -2,6 +2,9 @@
|
|||
Secondary entrypoint and primary loader for the common chart
|
||||
*/}}
|
||||
{{- define "bjw-s.common.loader.generate" -}}
|
||||
{{- /* Run global chart validations */ -}}
|
||||
{{- include "bjw-s.common.lib.chart.validate" . -}}
|
||||
|
||||
{{- /* Build the templates */ -}}
|
||||
{{- include "bjw-s.common.render.pvcs" . | nindent 0 -}}
|
||||
{{- include "bjw-s.common.render.serviceAccount" . | nindent 0 -}}
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"$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",
|
||||
"properties": {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue