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

Before

Width:  |  Height:  |  Size: 26 KiB

After

Width:  |  Height:  |  Size: 26 KiB

Before After
Before After

View file

@ -1,2 +0,0 @@
test:
test: "{{ .Values.configMapsFromFolderBasePath }}"

View file

@ -0,0 +1,2 @@
test:
test: "{{ .Values.global.random.nonExistentKey }}"

View file

@ -15,7 +15,7 @@ tests:
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 2 count: 2
- documentIndex: &ConfigmapDocument 1 - documentIndex: &ConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *ConfigmapDocument - documentIndex: *ConfigmapDocument
@ -43,7 +43,7 @@ tests:
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 2 count: 2
- documentIndex: &ConfigmapDocument 1 - documentIndex: &ConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *ConfigmapDocument - documentIndex: *ConfigmapDocument
@ -79,7 +79,7 @@ tests:
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 2 count: 2
- documentIndex: &ConfigmapDocument 1 - documentIndex: &ConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *ConfigmapDocument - documentIndex: *ConfigmapDocument
@ -99,17 +99,39 @@ tests:
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
test_label: test test_label: test
- it: default configuration from folder with binary files should fail
set:
configMaps:
config:
data:
test: test
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
asserts:
- failedTemplate:
errorMessage: "There was an error loading ConfigMap: test_2. If it was automatically generated from a folder verify that files are properly flagged as `binary` or `escaped`"
- it: default metadata from folder should pass - it: default metadata from folder should pass
set: set:
configMaps: configMaps:
config: config:
data: data:
test: test test: test
configMapsFromFolderBasePath: ci/configMapsFolder configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_2:
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 4 count: 4
- documentIndex: &FirstConfigmapDocument 1 - documentIndex: &FirstConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *FirstConfigmapDocument - documentIndex: *FirstConfigmapDocument
@ -123,7 +145,7 @@ tests:
app.kubernetes.io/managed-by: Helm app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
- documentIndex: &SecondConfigmapDocument 2 - documentIndex: &SecondConfigmapDocument 1
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *SecondConfigmapDocument - documentIndex: *SecondConfigmapDocument
@ -137,7 +159,7 @@ tests:
app.kubernetes.io/managed-by: Helm app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
- documentIndex: &ThirdConfigmapDocument 3 - documentIndex: &ThirdConfigmapDocument 2
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *ThirdConfigmapDocument - documentIndex: *ThirdConfigmapDocument
@ -151,3 +173,66 @@ tests:
app.kubernetes.io/managed-by: Helm app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
- it: custom metadata from folder should pass
set:
configMaps:
config:
data:
test: test
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_2:
labels:
test: test_label
annotations:
test: test_annotation
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts:
- hasDocuments:
count: 4
- documentIndex: &FirstConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *FirstConfigmapDocument
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
- documentIndex: &SecondConfigmapDocument 1
isKind:
of: ConfigMap
- documentIndex: *SecondConfigmapDocument
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
- documentIndex: &ThirdConfigmapDocument 2
isKind:
of: ConfigMap
- documentIndex: *ThirdConfigmapDocument
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: test_label
- documentIndex: *ThirdConfigmapDocument
equal:
path: metadata.annotations
value:
test: test_annotation

View file

@ -42,13 +42,13 @@ tests:
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 3 count: 3
- documentIndex: &FirstConfigmapDocument 1 - documentIndex: &FirstConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *FirstConfigmapDocument - documentIndex: *FirstConfigmapDocument
isNotNullOrEmpty: isNotNullOrEmpty:
path: metadata.name path: metadata.name
- documentIndex: &SecondConfigmapDocument 2 - documentIndex: &SecondConfigmapDocument 1
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *SecondConfigmapDocument - documentIndex: *SecondConfigmapDocument
@ -64,7 +64,7 @@ tests:
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 2 count: 2
- documentIndex: &ConfigmapDocument 1 - documentIndex: &ConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *ConfigmapDocument - documentIndex: *ConfigmapDocument
@ -82,7 +82,7 @@ tests:
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 2 count: 2
- documentIndex: &ConfigmapDocument 1 - documentIndex: &ConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *ConfigmapDocument - documentIndex: *ConfigmapDocument
@ -100,7 +100,7 @@ tests:
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 2 count: 2
- documentIndex: &ConfigmapDocument 1 - documentIndex: &ConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *ConfigmapDocument - documentIndex: *ConfigmapDocument
@ -115,28 +115,82 @@ tests:
data: data:
test: test test: test
nameOverride: "{{ .Release.Name }}" nameOverride: "{{ .Release.Name }}"
configMapsFromFolderBasePath: ci/configMapsFolder configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_2:
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts: asserts:
- hasDocuments: - hasDocuments:
count: 4 count: 4
- documentIndex: &FirstConfigmapDocument 1 - documentIndex: &FirstConfigmapDocument 0
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *FirstConfigmapDocument - documentIndex: *FirstConfigmapDocument
equal: equal:
path: metadata.name path: metadata.name
value: RELEASE-NAME value: RELEASE-NAME
- documentIndex: &SecondConfigmapDocument 2 - documentIndex: &SecondConfigmapDocument 1
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *SecondConfigmapDocument - documentIndex: *SecondConfigmapDocument
equal: equal:
path: metadata.name path: metadata.name
value: RELEASE-NAME-test_1 value: RELEASE-NAME-test_1
- documentIndex: &ThirdConfigmapDocument 3 - documentIndex: &ThirdConfigmapDocument 2
isKind: isKind:
of: ConfigMap of: ConfigMap
- documentIndex: *ThirdConfigmapDocument - documentIndex: *ThirdConfigmapDocument
equal: equal:
path: metadata.name path: metadata.name
value: RELEASE-NAME-test_2 value: RELEASE-NAME-test_2
- it: with templated nameOverride and from folder with forceRename should pass
set:
configMaps:
config:
data:
test: test
nameOverride: "{{ .Release.Name }}"
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_1:
forceRename: &newName1 newName1
test_2:
forceRename: &newName2 newName2
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts:
- hasDocuments:
count: 4
- documentIndex: &FirstConfigmapDocument 0
isKind:
of: ConfigMap
- documentIndex: *FirstConfigmapDocument
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: &SecondConfigmapDocument 1
isKind:
of: ConfigMap
- documentIndex: *SecondConfigmapDocument
equal:
path: metadata.name
value: *newName1
- documentIndex: &ThirdConfigmapDocument 2
isKind:
of: ConfigMap
- documentIndex: *ThirdConfigmapDocument
equal:
path: metadata.name
value: *newName2

View file

@ -25,7 +25,7 @@ tests:
data: data:
test: value 1 test: value 1
asserts: asserts:
- documentIndex: &ControllerDoc 0 - documentIndex: &ControllerDoc 3
isKind: isKind:
of: Deployment of: Deployment
- documentIndex: *ControllerDoc - documentIndex: *ControllerDoc
@ -33,3 +33,41 @@ tests:
path: spec.template.metadata.annotations path: spec.template.metadata.annotations
value: value:
checksum/configMaps: 66d23d7a53c4e2a523ba85a969696b4ebb78ec5d79ab9c12c210c1569f48511b checksum/configMaps: 66d23d7a53c4e2a523ba85a969696b4ebb78ec5d79ab9c12c210c1569f48511b
- it: default metadata from folder should pass
set:
configMaps:
config:
enabled: true
data:
test: value 1
test_default_enabled:
data:
test: value 1
test_not_in_checksum:
includeInChecksum: false
data:
test: value 1
test_disabled:
enabled: false
data:
test: value 1
configMapsFromFolder:
enabled: true
basePath: ci/configMapsFolder
configMapsOverrides:
test_2:
fileAttributeOverrides:
helm.jpg:
binary: true
test_2.yaml:
escaped: true
asserts:
- documentIndex: &ControllerDoc 5
isKind:
of: Deployment
- documentIndex: *ControllerDoc
equal:
path: spec.template.metadata.annotations
value:
checksum/configMaps: e83a24569d0b4f2ccc44aec36d4e9a1c44a29bcc92eefdffe14fb1ce81dff054

View file

@ -108,7 +108,7 @@ tests:
data: data:
test: test test: test
asserts: asserts:
- documentIndex: &DeploymentDoc 0 - documentIndex: &DeploymentDoc 1
isKind: isKind:
of: Deployment of: Deployment
- documentIndex: *DeploymentDoc - documentIndex: *DeploymentDoc

View file

@ -5,119 +5,91 @@ templates:
- common.yaml - common.yaml
values: values:
- ../_values/controllers_main_default_container.yaml - ../_values/controllers_main_default_container.yaml
- ../_values/service_main_default.yaml
set: set:
controllers.main.containers.main.probes.liveness.enabled: true controllers.main.containers.main.probes.liveness.enabled: true
controllers.main.containers.main.probes.readiness.enabled: true controllers.main.containers.main.probes.readiness.enabled: true
controllers.main.containers.main.probes.startup.enabled: true controllers.main.containers.main.probes.startup.enabled: true
tests: tests:
- it: default should pass - it: default probes
set: documentSelector: &DeploymentSelector
service: path: $[?(@.kind == "Deployment")].metadata.name
main: value: RELEASE-NAME
controller: main
ports:
http:
enabled: true
port: &port 80
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].livenessProbe path: spec.template.spec.containers[0].livenessProbe
value: value:
failureThreshold: 3 failureThreshold: 3
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: 8081
timeoutSeconds: 1 timeoutSeconds: 1
- documentIndex: 0 - equal:
equal:
path: spec.template.spec.containers[0].readinessProbe path: spec.template.spec.containers[0].readinessProbe
value: value:
failureThreshold: 3 failureThreshold: 3
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: 8081
timeoutSeconds: 1 timeoutSeconds: 1
- documentIndex: 0 - equal:
equal:
path: spec.template.spec.containers[0].startupProbe path: spec.template.spec.containers[0].startupProbe
value: value:
failureThreshold: 3 failureThreshold: 3
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: 8081
timeoutSeconds: 1 timeoutSeconds: 1
- it: custom primary port should pass - it: custom primary port gets picked up by probes
set: set:
service: service.main.ports.test:
main: enabled: true
controller: main primary: true
ports: port: 8080
http: documentSelector: *DeploymentSelector
enabled: true
port: 80
test:
enabled: true
primary: true
port: &port 8080
asserts: asserts:
- documentIndex: 0 - documentIndex: 0
isKind: isKind:
of: Deployment of: Deployment
- documentIndex: 0 - equal:
equal:
path: spec.template.spec.containers[0].livenessProbe path: spec.template.spec.containers[0].livenessProbe
value: value:
failureThreshold: 3 failureThreshold: 3
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: 8080
timeoutSeconds: 1 timeoutSeconds: 1
- documentIndex: 0 - equal:
equal:
path: spec.template.spec.containers[0].readinessProbe path: spec.template.spec.containers[0].readinessProbe
value: value:
failureThreshold: 3 failureThreshold: 3
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: 8080
timeoutSeconds: 1 timeoutSeconds: 1
- documentIndex: 0 - equal:
equal:
path: spec.template.spec.containers[0].startupProbe path: spec.template.spec.containers[0].startupProbe
value: value:
failureThreshold: 3 failureThreshold: 3
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: 8080
timeoutSeconds: 1 timeoutSeconds: 1
- it: default with string Service port should pass - it: probes with string Service port
set: set:
service: service.main.ports.http.port: "80"
main: documentSelector: *DeploymentSelector
controller: main
ports:
http:
enabled: true
port: "80"
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].livenessProbe path: spec.template.spec.containers[0].livenessProbe
value: value:
failureThreshold: 3 failureThreshold: 3
@ -126,8 +98,7 @@ tests:
tcpSocket: tcpSocket:
port: 80 port: 80
timeoutSeconds: 1 timeoutSeconds: 1
- documentIndex: 0 - equal:
equal:
path: spec.template.spec.containers[0].readinessProbe path: spec.template.spec.containers[0].readinessProbe
value: value:
failureThreshold: 3 failureThreshold: 3
@ -136,8 +107,7 @@ tests:
tcpSocket: tcpSocket:
port: 80 port: 80
timeoutSeconds: 1 timeoutSeconds: 1
- documentIndex: 0 - equal:
equal:
path: spec.template.spec.containers[0].startupProbe path: spec.template.spec.containers[0].startupProbe
value: value:
failureThreshold: 3 failureThreshold: 3
@ -147,7 +117,7 @@ tests:
port: 80 port: 80
timeoutSeconds: 1 timeoutSeconds: 1
- it: multiple services should pass - it: multiple services are handled correctly
set: set:
controllers: controllers:
other: other:
@ -170,81 +140,69 @@ tests:
ports: ports:
http: http:
enabled: true enabled: true
port: &secondDeploymentPort 8080 port: 8080
main:
controller: main
ports:
http:
enabled: true
port: &firstDeploymentPort 80
asserts: asserts:
- documentIndex: &firstDeploymentDocument 0 - documentSelector:
isKind: path: $[?(@.kind == "Deployment")].metadata.name
of: Deployment value: RELEASE-NAME-main
- documentIndex: *firstDeploymentDocument
equal: equal:
path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port
value: *firstDeploymentPort value: 8081
- documentIndex: *firstDeploymentDocument - documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-main
equal: equal:
path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port
value: *firstDeploymentPort value: 8081
- documentIndex: *firstDeploymentDocument - documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-main
equal: equal:
path: spec.template.spec.containers[0].startupProbe.tcpSocket.port path: spec.template.spec.containers[0].startupProbe.tcpSocket.port
value: *firstDeploymentPort value: 8081
- documentIndex: &secondDeploymentDocument 1 - documentSelector:
isKind: path: $[?(@.kind == "Deployment")].metadata.name
of: Deployment value: RELEASE-NAME-other
- documentIndex: *secondDeploymentDocument
equal: equal:
path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port path: spec.template.spec.containers[0].livenessProbe.tcpSocket.port
value: *secondDeploymentPort value: 8080
- documentIndex: *secondDeploymentDocument - documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-other
equal: equal:
path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port path: spec.template.spec.containers[0].readinessProbe.tcpSocket.port
value: *secondDeploymentPort value: 8080
- documentIndex: *secondDeploymentDocument - documentSelector:
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME-other
equal: equal:
path: spec.template.spec.containers[0].startupProbe.tcpSocket.port path: spec.template.spec.containers[0].startupProbe.tcpSocket.port
value: *secondDeploymentPort value: 8080
- it: disabled service should pass - it: no probes are defined when services are disabled
set: set:
service: service:
main: main:
enabled: false enabled: false
controller: main controller: main
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - notExists:
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.containers[0].livenessProbe path: spec.template.spec.containers[0].livenessProbe
- documentIndex: 0 - notExists:
notExists:
path: spec.template.spec.containers[0].readinessProbe path: spec.template.spec.containers[0].readinessProbe
- documentIndex: 0 - notExists:
notExists:
path: spec.template.spec.containers[0].startupProbe path: spec.template.spec.containers[0].startupProbe
- it: AUTO type probe should pass - it: AUTO type probe can be configured
set: set:
service: service.main.ports.http.protocol: HTTP
main:
controller: main
ports:
http:
protocol: HTTP
port: &port 80
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
liveness: liveness:
enabled: true enabled: true
type: AUTO type: AUTO
path: /api/version path: /api/version
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - documentIndex: 0
isKind: isKind:
@ -255,86 +213,95 @@ tests:
value: value:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
scheme: HTTP scheme: HTTP
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
- it: HTTP type probe should pass - it: HTTP type probe can be configured
set: set:
service:
main:
controller: main
ports:
http:
port: &port 80
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
liveness: liveness:
enabled: true enabled: true
type: HTTP type: HTTP
path: /api/version path: /api/version
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].livenessProbe path: spec.template.spec.containers[0].livenessProbe
value: value:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
scheme: HTTP scheme: HTTP
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
- it: HTTPS type probe should pass - it: HTTPS type probe can be configured
set: set:
service:
main:
controller: main
ports:
http:
port: &port 80
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
liveness: liveness:
enabled: true enabled: true
type: HTTPS type: HTTPS
path: /api/version path: /api/version
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].livenessProbe path: spec.template.spec.containers[0].livenessProbe
value: value:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
scheme: HTTPS scheme: HTTPS
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
- it: custom liveness probe should pass - it: GRPC type probe can be configured without service
set: set:
service: controllers.main.containers.main.probes:
main: liveness:
controller: main enabled: true
ports: type: GRPC
http: documentSelector: *DeploymentSelector
port: &port 80 asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
grpc:
port: 8081
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: GRPC type probe can be configured with service
set:
controllers.main.containers.main.probes:
liveness:
enabled: true
type: GRPC
service: test
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.containers[0].livenessProbe
value:
grpc:
port: 8081
service: test
initialDelaySeconds: 0
periodSeconds: 10
timeoutSeconds: 1
failureThreshold: 3
- it: custom liveness probe can be configured
set:
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
liveness: liveness:
enabled: true enabled: true
@ -342,36 +309,26 @@ tests:
spec: spec:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].livenessProbe path: spec.template.spec.containers[0].livenessProbe
value: value:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
- it: custom readiness probe should pass - it: custom readiness probe can be configured
set: set:
service:
main:
controller: main
ports:
http:
port: &port 80
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
readiness: readiness:
enabled: true enabled: true
@ -379,36 +336,26 @@ tests:
spec: spec:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].readinessProbe path: spec.template.spec.containers[0].readinessProbe
value: value:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
- it: custom startup probe should pass - it: custom startup probe can be configured
set: set:
service:
main:
controller: main
ports:
http:
port: &port 80
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
startup: startup:
enabled: true enabled: true
@ -416,45 +363,32 @@ tests:
spec: spec:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].startupProbe path: spec.template.spec.containers[0].startupProbe
value: value:
httpGet: httpGet:
path: /api/version path: /api/version
port: *port port: 8081
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
timeoutSeconds: 1 timeoutSeconds: 1
failureThreshold: 3 failureThreshold: 3
- it: User-defined liveness probe port should pass - it: User-defined liveness probe port can be configured
set: set:
service:
main:
controller: main
ports:
http:
port: &port 80
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
liveness: liveness:
enabled: true enabled: true
port: &port http port: http
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0 - documentIndex: 0
equal: equal:
path: spec.template.spec.containers[0].livenessProbe path: spec.template.spec.containers[0].livenessProbe
@ -463,92 +397,41 @@ tests:
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: http
timeoutSeconds: 1 timeoutSeconds: 1
- it: User-defined liveness probe port should pass - it: User-defined readiness probe port can be configured
set: set:
service:
main:
controller: main
ports:
http:
port: &port 80
controllers.main.containers.main.probes:
liveness:
enabled: true
port: &port http
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].livenessProbe
value:
failureThreshold: 3
initialDelaySeconds: 0
periodSeconds: 10
tcpSocket:
port: *port
timeoutSeconds: 1
- it: User-defined readiness probe port should pass
set:
service:
main:
controller: main
ports:
http:
port: &port 80
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
readiness: readiness:
enabled: true enabled: true
port: &port http port: http
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].readinessProbe path: spec.template.spec.containers[0].readinessProbe
value: value:
failureThreshold: 3 failureThreshold: 3
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: http
timeoutSeconds: 1 timeoutSeconds: 1
- it: User-defined startup probe port should pass - it: User-defined startup probe port can be configured
set: set:
service:
main:
controller: main
ports:
http:
port: &port 80
controllers.main.containers.main.probes: controllers.main.containers.main.probes:
startup: startup:
enabled: true enabled: true
port: &port http port: http
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.containers[0].startupProbe path: spec.template.spec.containers[0].startupProbe
value: value:
failureThreshold: 3 failureThreshold: 3
initialDelaySeconds: 0 initialDelaySeconds: 0
periodSeconds: 10 periodSeconds: 10
tcpSocket: tcpSocket:
port: *port port: http
timeoutSeconds: 1 timeoutSeconds: 1

View file

@ -54,9 +54,12 @@ tests:
identifier: mySettings identifier: mySettings
asserts: asserts:
- documentIndex: 0 - documentIndex: 0
isKind:
of: ConfigMap
- documentIndex: 1
isKind: isKind:
of: Deployment of: Deployment
- documentIndex: 0 - documentIndex: 1
equal: equal:
path: spec.template.spec.volumes[0] path: spec.template.spec.volumes[0]
value: value:

View file

@ -6,16 +6,15 @@ templates:
values: values:
- ../_values/controllers_main_default_container.yaml - ../_values/controllers_main_default_container.yaml
tests: tests:
- it: default should pass - it: affinity is not present by default
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts: asserts:
- documentIndex: 0 - notExists:
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.affinity path: spec.template.spec.affinity
- it: defaultPodOption should pass - it: affinity can be set with defaultPodOption
set: set:
defaultPodOptions: defaultPodOptions:
affinity: affinity:
@ -28,12 +27,9 @@ tests:
values: values:
- antarctica-east1 - antarctica-east1
- antarctica-west1 - antarctica-west1
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.affinity path: spec.template.spec.affinity
value: value:
nodeAffinity: nodeAffinity:
@ -46,7 +42,7 @@ tests:
- antarctica-east1 - antarctica-east1
- antarctica-west1 - antarctica-west1
- it: defaultPodOption with pod override should pass - it: affinity can be set with defaultPodOption and overridden on pod level
set: set:
defaultPodOptions: defaultPodOptions:
affinity: affinity:
@ -72,12 +68,9 @@ tests:
values: values:
- asia-east1 - asia-east1
- asia-west1 - asia-west1
documentSelector: *DeploymentSelector
asserts: asserts:
- documentIndex: 0 - equal:
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.affinity path: spec.template.spec.affinity
value: value:
nodeAffinity: nodeAffinity:
@ -89,3 +82,33 @@ tests:
values: values:
- asia-east1 - asia-east1
- asia-west1 - asia-west1
- it: affinity can be configured with templated valued
set:
controllers:
main:
pod:
affinity:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- "{{ .Release.Name }}"
topologyKey: kubernetes.io/hostname
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.affinity
value:
podAntiAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
- labelSelector:
matchExpressions:
- key: app
operator: In
values:
- RELEASE-NAME
topologyKey: kubernetes.io/hostname

View file

@ -0,0 +1,35 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: pod security
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: shareProcessNamespace should not be present by default
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- notExists:
path: spec.template.spec.shareProcessNamespace
- it: shareProcessNamespace disabled should pass
set:
defaultPodOptions:
shareProcessNamespace: false
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.shareProcessNamespace
value: false
- it: shareProcessNamespace enabled should pass
set:
defaultPodOptions:
shareProcessNamespace: true
documentSelector: *DeploymentSelector
asserts:
- equal:
path: spec.template.spec.shareProcessNamespace
value: true

View file

@ -13,18 +13,14 @@ set:
spec: spec:
test: test test: test
tests: tests:
- it: default metadata should pass - it: default metadata should be present
documentSelector: &EndpointSelector
path: $[?(@.kind == "Endpoint")].metadata.name
value: RELEASE-NAME-config
asserts: asserts:
- hasDocuments: - notExists:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
notExists:
path: metadata.annotations path: metadata.annotations
- documentIndex: *rawResourceDocument - equal:
equal:
path: metadata.labels path: metadata.labels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
@ -32,7 +28,7 @@ tests:
app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass - it: custom metadata can be configured
set: set:
rawResources: rawResources:
config: config:
@ -40,19 +36,13 @@ tests:
test_annotation: test test_annotation: test
labels: labels:
test_label: test test_label: test
documentSelector: *EndpointSelector
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.annotations path: metadata.annotations
value: value:
test_annotation: test test_annotation: test
- documentIndex: *rawResourceDocument - equal:
equal:
path: metadata.labels path: metadata.labels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
@ -61,7 +51,7 @@ tests:
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
test_label: test test_label: test
- it: custom metadata with global metadata should pass - it: global metadata can be configured with local overrides
set: set:
global: global:
labels: labels:
@ -74,20 +64,14 @@ tests:
test_annotation: test test_annotation: test
labels: labels:
test_label: test test_label: test
documentSelector: *EndpointSelector
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.annotations path: metadata.annotations
value: value:
global_annotation: test global_annotation: test
test_annotation: test test_annotation: test
- documentIndex: *rawResourceDocument - equal:
equal:
path: metadata.labels path: metadata.labels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME

View file

@ -19,28 +19,24 @@ set:
port: 443 port: 443
protocol: TCP protocol: TCP
tests: tests:
- it: default should pass - it: raw resources can be configured
documentSelector: &EndpointSelector
path: $[?(@.kind == "Endpoint")].metadata.name
value: RELEASE-NAME-endpoint
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: subsets[0].addresses[0].ip path: subsets[0].addresses[0].ip
value: 127.0.0.1 value: 127.0.0.1
- it: nameOverride should pass - it: nameOverride can be configured
set: set:
rawResources.endpoint: rawResources.endpoint:
nameOverride: test nameOverride: test
documentSelector:
path: $[?(@.kind == "Endpoint")].metadata.name
value: RELEASE-NAME-test
asserts: asserts:
- documentIndex: &rawResourceDocument 1 - equal:
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.name path: metadata.name
value: RELEASE-NAME-test value: RELEASE-NAME-test
@ -48,16 +44,15 @@ tests:
set: set:
rawResources.endpoint: rawResources.endpoint:
nameOverride: "{{ .Release.Name }}" nameOverride: "{{ .Release.Name }}"
documentSelector:
path: $[?(@.kind == "Endpoint")].metadata.name
value: RELEASE-NAME
asserts: asserts:
- documentIndex: &rawResourceDocument 1 - equal:
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.name path: metadata.name
value: RELEASE-NAME value: RELEASE-NAME
- it: spec with template should pass - it: spec can render Helm template
set: set:
rawResources.endpoint: rawResources.endpoint:
spec: spec:
@ -68,11 +63,8 @@ tests:
- name: "{{ .Release.Name }}" - name: "{{ .Release.Name }}"
port: 443 port: 443
protocol: TCP protocol: TCP
documentSelector: *EndpointSelector
asserts: asserts:
- documentIndex: &rawResourceDocument 1 - equal:
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: subsets[0].ports[0].name path: subsets[0].ports[0].name
value: RELEASE-NAME value: RELEASE-NAME

View file

@ -6,18 +6,16 @@ templates:
values: values:
- ../_values/controllers_main_default_container.yaml - ../_values/controllers_main_default_container.yaml
tests: tests:
- it: default metadata should pass - it: default metadata
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
documentSelector: &ServiceSelector
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME
asserts: asserts:
- documentIndex: &ServiceDocument 1 - notExists:
isKind:
of: Service
- documentIndex: *ServiceDocument
notExists:
path: metadata.annotations path: metadata.annotations
- documentIndex: *ServiceDocument - equal:
equal:
path: metadata.labels path: metadata.labels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
@ -26,7 +24,7 @@ tests:
app.kubernetes.io/service: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
- it: custom metadata should pass - it: custom metadata
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
@ -36,17 +34,13 @@ tests:
test_annotation: test test_annotation: test
labels: labels:
test_label: test test_label: test
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: metadata.annotations path: metadata.annotations
value: value:
test_annotation: test test_annotation: test
- documentIndex: *ServiceDocument - equal:
equal:
path: metadata.labels path: metadata.labels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
@ -56,7 +50,7 @@ tests:
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
test_label: test test_label: test
- it: custom metadata with global metadata should pass - it: custom metadata with global metadata
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
@ -71,18 +65,14 @@ tests:
test_annotation: test test_annotation: test
labels: labels:
test_label: test test_label: test
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: metadata.annotations path: metadata.annotations
value: value:
global_annotation: test global_annotation: test
test_annotation: test test_annotation: test
- documentIndex: *ServiceDocument - equal:
equal:
path: metadata.labels path: metadata.labels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME

View file

@ -6,49 +6,42 @@ templates:
values: values:
- ../_values/controllers_main_default_container.yaml - ../_values/controllers_main_default_container.yaml
tests: tests:
- it: default should pass - it: default name
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &ServiceDocument 1
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: metadata.name path: metadata.name
value: RELEASE-NAME value: RELEASE-NAME
- it: custom name suffix should pass - it: custom name suffix
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
service.main.nameOverride: http service.main.nameOverride: http
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME-http
asserts: asserts:
- documentIndex: &ServiceDocument 1 - exists:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: metadata.name path: metadata.name
value: RELEASE-NAME-http
- it: custom name suffix with template should pass - it: custom name suffix with template
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
service.main.nameOverride: "{{ .Release.Name }}" service.main.nameOverride: "{{ .Chart.Name }}"
documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME-common-test
asserts: asserts:
- documentIndex: &ServiceDocument 1 - exists:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: metadata.name path: metadata.name
value: RELEASE-NAME
- it: multiple should pass - it: multiple services
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
@ -59,19 +52,13 @@ tests:
ui: ui:
port: 8082 port: 8082
asserts: asserts:
- hasDocuments: - documentSelector:
count: 3 path: $[?(@.kind == "Service")].metadata.name
- documentIndex: &ServiceDocumentFirst 1
isKind:
of: Service
- documentIndex: *ServiceDocumentFirst
equal:
path: metadata.name
value: RELEASE-NAME-main value: RELEASE-NAME-main
- documentIndex: &ServiceDocumentSecond 2 exists:
isKind:
of: Service
- documentIndex: *ServiceDocumentSecond
equal:
path: metadata.name path: metadata.name
- documentSelector:
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME-second value: RELEASE-NAME-second
exists:
path: metadata.name

View file

@ -6,89 +6,91 @@ templates:
values: values:
- ../_values/controllers_main_default_container.yaml - ../_values/controllers_main_default_container.yaml
tests: tests:
- it: default should pass - it: default should render
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
documentSelector: &ServiceSelector
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &ServiceDocument 1
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0].protocol path: spec.ports[0].protocol
value: TCP value: TCP
- it: explicit TCP should pass - it: explicit TCP should render
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
service.main.ports.http.protocol: TCP service.main.ports.http.protocol: TCP
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0].protocol path: spec.ports[0].protocol
value: TCP value: TCP
- it: explicit UDP should pass - it: explicit UDP should render
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
service.main.ports.http.protocol: UDP service.main.ports.http.protocol: UDP
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0].protocol path: spec.ports[0].protocol
value: UDP value: UDP
- it: explicit HTTP should pass - it: explicit HTTP should render
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
service.main.ports.http.protocol: HTTP service.main.ports.http.protocol: HTTP
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0].protocol path: spec.ports[0].protocol
value: TCP value: TCP
- documentIndex: *ServiceDocument - notExists:
notExists:
path: metadata.annotations path: metadata.annotations
- it: explicit HTTPS should pass - it: explicit HTTPS should render
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
service.main.ports.http.protocol: HTTPS service.main.ports.http.protocol: HTTPS
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0].protocol path: spec.ports[0].protocol
value: TCP value: TCP
- it: explicit appProtocol should pass - it: explicit appProtocol should render
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
service.main.ports.http.appProtocol: kubernetes.io/h2c service.main.ports.http.appProtocol: kubernetes.io/h2c
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0].appProtocol path: spec.ports[0].appProtocol
value: kubernetes.io/h2c value: kubernetes.io/h2c
- it: mixed protocols can be configured on the same port number
values:
- ../_values/service_main_default.yaml
set:
service.main.ports.udptest:
port: 8081
protocol: UDP
documentSelector: *ServiceSelector
asserts:
- equal:
path: spec.ports
value:
- name: http
port: 8081
protocol: TCP
targetPort: 8081
- name: udptest
port: 8081
protocol: UDP
targetPort: 8081

View file

@ -9,14 +9,11 @@ tests:
- it: default should pass - it: default should pass
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
documentSelector: &ServiceSelector
path: $[?(@.kind == "Service")].metadata.name
value: RELEASE-NAME
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &ServiceDocument 1
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0] path: spec.ports[0]
value: value:
name: http name: http
@ -36,12 +33,9 @@ tests:
server: server:
enabled: true enabled: true
port: 8080 port: 8080
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0] path: spec.ports[0]
value: value:
name: server name: server
@ -59,12 +53,9 @@ tests:
http: http:
enabled: true enabled: true
targetPort: 80 targetPort: 80
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.ports[0] path: spec.ports[0]
value: value:
name: http name: http

View file

@ -15,17 +15,16 @@ tests:
ports: ports:
first: first:
port: 80 port: 80
documentSelector: &ServiceSelector
path: kind
value: Service
asserts: asserts:
- hasDocuments: - containsDocument:
count: 2 kind: Service
- documentIndex: &FirstServiceDocument 1 apiVersion: v1
isKind: name: RELEASE-NAME
of: Service
- documentIndex: *FirstServiceDocument
notExists:
path: spec.allocateLoadBalancerNodePorts
- it: services can be disabled - it: service not present when disabled
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
@ -33,13 +32,13 @@ tests:
main: main:
enabled: false enabled: false
asserts: asserts:
- hasDocuments: - not: true
count: 1 containsDocument:
- documentIndex: &DeploymentDocument 0 kind: Service
isKind: apiVersion: v1
of: Deployment name: RELEASE-NAME
- it: externalTrafficPolicy should pass for NodePort service - it: externalTrafficPolicy can be configured for NodePort service
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
@ -47,32 +46,26 @@ tests:
main: main:
type: NodePort type: NodePort
externalTrafficPolicy: Local externalTrafficPolicy: Local
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.externalTrafficPolicy path: spec.externalTrafficPolicy
value: Local value: Local
- it: internalTrafficPolicy should pass - it: internalTrafficPolicy can be configured
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
service: service:
main: main:
internalTrafficPolicy: Local internalTrafficPolicy: Local
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.internalTrafficPolicy path: spec.internalTrafficPolicy
value: Local value: Local
- it: externalTrafficPolicy should pass for LoadBalancer service - it: externalTrafficPolicy can be configured for LoadBalancer service
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
@ -80,12 +73,9 @@ tests:
main: main:
type: LoadBalancer type: LoadBalancer
externalTrafficPolicy: Local externalTrafficPolicy: Local
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.externalTrafficPolicy path: spec.externalTrafficPolicy
value: Local value: Local
@ -97,12 +87,9 @@ tests:
main: main:
type: LoadBalancer type: LoadBalancer
allocateLoadBalancerNodePorts: true allocateLoadBalancerNodePorts: true
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.allocateLoadBalancerNodePorts path: spec.allocateLoadBalancerNodePorts
value: true value: true
@ -114,16 +101,13 @@ tests:
main: main:
type: LoadBalancer type: LoadBalancer
allocateLoadBalancerNodePorts: false allocateLoadBalancerNodePorts: false
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.allocateLoadBalancerNodePorts path: spec.allocateLoadBalancerNodePorts
value: false value: false
- it: externalName should pass for ExternalName service - it: externalName can be configured for ExternalName service
values: values:
- ../_values/service_main_default.yaml - ../_values/service_main_default.yaml
set: set:
@ -131,11 +115,8 @@ tests:
main: main:
type: ExternalName type: ExternalName
externalName: my.database.example.com externalName: my.database.example.com
documentSelector: *ServiceSelector
asserts: asserts:
- documentIndex: &ServiceDocument 1 - equal:
isKind:
of: Service
- documentIndex: *ServiceDocument
equal:
path: spec.externalName path: spec.externalName
value: my.database.example.com value: my.database.example.com

View file

@ -8,12 +8,11 @@ values:
tests: tests:
- it: a serviceMonitor is not created by default - it: a serviceMonitor is not created by default
asserts: asserts:
- hasDocuments: - not: true
count: 1 containsDocument:
- documentIndex: 0 kind: ServiceMonitor
not: true apiVersion: monitoring.coreos.com/v1
isKind: name: RELEASE-NAME
of: ServiceMonitor
- it: a serviceMonitor is not created when disabled - it: a serviceMonitor is not created when disabled
set: set:
@ -22,14 +21,13 @@ tests:
enabled: false enabled: false
serviceName: "{{ .Release.Name }}" serviceName: "{{ .Release.Name }}"
asserts: asserts:
- hasDocuments: - not: true
count: 1 containsDocument:
- documentIndex: 0 kind: ServiceMonitor
not: true apiVersion: monitoring.coreos.com/v1
isKind: name: RELEASE-NAME
of: ServiceMonitor
- it: a serviceMonitor is created - it: a serviceMonitor can be configured
set: set:
serviceMonitor: serviceMonitor:
main: main:
@ -42,35 +40,25 @@ tests:
path: /metrics path: /metrics
interval: 1m interval: 1m
scrapeTimeout: 10s scrapeTimeout: 10s
documentSelector: &ServiceMonitorSelector
path: $[?(@.kind == "ServiceMonitor")].metadata.name
value: RELEASE-NAME
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &ServiceMonitorDocument 1
isKind:
of: ServiceMonitor
- documentIndex: *ServiceMonitorDocument
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: *ServiceMonitorDocument
equal:
path: spec.namespaceSelector path: spec.namespaceSelector
value: value:
matchNames: matchNames:
- NAMESPACE - NAMESPACE
- documentIndex: *ServiceMonitorDocument - equal:
equal:
path: spec.jobLabel path: spec.jobLabel
value: RELEASE-NAME value: RELEASE-NAME
- documentIndex: *ServiceMonitorDocument - equal:
equal:
path: spec.selector.matchLabels path: spec.selector.matchLabels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME
app.kubernetes.io/service: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME
- documentIndex: *ServiceMonitorDocument - equal:
equal:
path: spec.endpoints path: spec.endpoints
value: value:
- port: http - port: http
@ -78,8 +66,7 @@ tests:
path: /metrics path: /metrics
interval: 1m interval: 1m
scrapeTimeout: 10s scrapeTimeout: 10s
- documentIndex: *ServiceMonitorDocument - equal:
equal:
path: metadata.labels path: metadata.labels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
@ -88,7 +75,7 @@ tests:
helm.sh/chart: common-test-1.0.0 helm.sh/chart: common-test-1.0.0
test.label: testvalue test.label: testvalue
- it: a serviceMonitor is created with nameOverride - it: a serviceMonitor can be created with a nameOverride
set: set:
serviceMonitor: serviceMonitor:
main: main:
@ -100,25 +87,18 @@ tests:
path: /metrics path: /metrics
interval: 1m interval: 1m
scrapeTimeout: 10s scrapeTimeout: 10s
documentSelector:
path: $[?(@.kind == "ServiceMonitor")].metadata.name
value: RELEASE-NAME-test
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &ServiceMonitorDocument 1
isKind:
of: ServiceMonitor
- documentIndex: *ServiceMonitorDocument
equal:
path: metadata.name
value: RELEASE-NAME-test
- documentIndex: *ServiceMonitorDocument
equal:
path: spec.selector.matchLabels path: spec.selector.matchLabels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME
app.kubernetes.io/service: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME
- it: a serviceMonitor is created with a templated service - it: a templated service can be configured
set: set:
serviceMonitor: serviceMonitor:
main: main:
@ -129,25 +109,16 @@ tests:
path: /metrics path: /metrics
interval: 1m interval: 1m
scrapeTimeout: 10s scrapeTimeout: 10s
documentSelector: *ServiceMonitorSelector
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &ServiceMonitorDocument 1
isKind:
of: ServiceMonitor
- documentIndex: *ServiceMonitorDocument
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: *ServiceMonitorDocument
equal:
path: spec.selector.matchLabels path: spec.selector.matchLabels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME
app.kubernetes.io/service: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME
- it: a serviceMonitor is created with a custom selector - it: a custom selector can be configured
set: set:
serviceMonitor: serviceMonitor:
main: main:
@ -160,25 +131,16 @@ tests:
path: /metrics path: /metrics
interval: 1m interval: 1m
scrapeTimeout: 10s scrapeTimeout: 10s
documentSelector: *ServiceMonitorSelector
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &ServiceMonitorDocument 1
isKind:
of: ServiceMonitor
- documentIndex: *ServiceMonitorDocument
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: *ServiceMonitorDocument
equal:
path: spec.selector path: spec.selector
value: value:
matchExpressions: matchExpressions:
- key: k8s-app - key: k8s-app
operator: Exists operator: Exists
- it: a serviceMonitor is created with targetLabels - it: targetLabels can be configured
set: set:
serviceMonitor: serviceMonitor:
main: main:
@ -193,25 +155,15 @@ tests:
targetLabels: targetLabels:
- testlabel1 - testlabel1
- testlabel2 - testlabel2
documentSelector: *ServiceMonitorSelector
asserts: asserts:
- hasDocuments: - equal:
count: 2
- documentIndex: &ServiceMonitorDocument 1
isKind:
of: ServiceMonitor
- documentIndex: *ServiceMonitorDocument
equal:
path: metadata.name
value: RELEASE-NAME
- documentIndex: *ServiceMonitorDocument
equal:
path: spec.selector.matchLabels path: spec.selector.matchLabels
value: value:
app.kubernetes.io/instance: RELEASE-NAME app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME app.kubernetes.io/name: RELEASE-NAME
app.kubernetes.io/service: RELEASE-NAME app.kubernetes.io/service: RELEASE-NAME
- documentIndex: *ServiceMonitorDocument - equal:
equal:
path: spec.endpoints path: spec.endpoints
value: value:
- port: http - port: http
@ -219,9 +171,48 @@ tests:
path: /metrics path: /metrics
interval: 1m interval: 1m
scrapeTimeout: 10s scrapeTimeout: 10s
- documentIndex: *ServiceMonitorDocument - equal:
equal:
path: spec.targetLabels path: spec.targetLabels
value: value:
- testlabel1 - testlabel1
- testlabel2 - testlabel2
- it: a serviceMonitor can be configured with templated endpoints
set:
serviceMonitor:
main:
labels:
test.label: testvalue
serviceName: "{{ .Release.Name }}"
endpoints:
- port: http
scheme: http
path: /metrics
interval: 1m
scrapeTimeout: 10s
basicAuth:
username:
name: "{{.Release.Name}}-secret"
key: USERNAME
password:
name: "{{.Release.Name}}-secret"
key: PASSWORD
documentSelector: &ServiceMonitorSelector
path: $[?(@.kind == "ServiceMonitor")].metadata.name
value: RELEASE-NAME
asserts:
- equal:
path: spec.endpoints
value:
- port: http
scheme: http
path: /metrics
interval: 1m
scrapeTimeout: 10s
basicAuth:
username:
name: RELEASE-NAME-secret
key: USERNAME
password:
name: RELEASE-NAME-secret
key: PASSWORD

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.6.1 version: 3.7.0
kubeVersion: ">=1.22.0-0" kubeVersion: ">=1.22.0-0"
keywords: keywords:
- common - common
@ -16,10 +16,22 @@ annotations:
artifacthub.io/changes: |- artifacthub.io/changes: |-
- kind: fixed - kind: fixed
description: |- description: |-
Only add hostUsers when explicitly configured Raw resources with `forceRename` fields are no longer flagged as invalid
- kind: fixed - kind: added
description: |- description: |-
`hosts` should be an optional field for Ingress resources Allow setting pullPolicy to Never
- kind: fixed - kind: added
description: |- 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 # 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 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.6.1 version: 3.7.0
repository: https://bjw-s.github.io/helm-charts/ repository: https://bjw-s.github.io/helm-charts/
``` ```

View file

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

View file

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

View file

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

View file

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

View file

@ -4,8 +4,28 @@ Validate configMap values
{{- define "bjw-s.common.lib.configMap.validate" -}} {{- define "bjw-s.common.lib.configMap.validate" -}}
{{- $rootContext := .rootContext -}} {{- $rootContext := .rootContext -}}
{{- $configMapValues := .object -}} {{- $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")) -}} {{- if and (empty (get $configMapValues "data")) (empty (get $configMapValues "binaryData")) -}}
{{- fail (printf "No data or binaryData specified for configMap. (configMap: %s)" $configMapValues.identifier) }} {{- fail (printf "No data or binaryData specified for configMap. (configMap: %s)" $configMapValues.identifier) }}
{{- end -}} {{- end -}}
{{- 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 "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" -}} {{- $probeHeader = "tcpSocket" -}}
{{- $_ := set $probeDefinition $probeHeader dict -}} {{- $_ := set $probeDefinition $probeHeader dict -}}
{{- end -}} {{- 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")) }} {{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "hostUsers")) }}
hostUsers: {{ . | trim }} hostUsers: {{ . | trim }}
{{- end -}} {{- end -}}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "shareProcessNamespace")) }}
shareProcessNamespace: {{ . | trim }}
{{- end -}}
{{- end }} {{- end }}
dnsPolicy: {{ include "bjw-s.common.lib.pod.field.dnsPolicy" (dict "ctx" $ctx) | trim }} 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")) }} {{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "dnsConfig")) }}
@ -52,7 +55,7 @@ restartPolicy: {{ . | trim }}
nodeSelector: {{ . | nindent 2 }} nodeSelector: {{ . | nindent 2 }}
{{- end -}} {{- end -}}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "affinity")) }} {{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "affinity")) }}
affinity: {{ . | nindent 2 }} affinity: {{- tpl . $rootContext | nindent 2 }}
{{- end -}} {{- end -}}
{{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "topologySpreadConstraints")) }} {{- with (include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "topologySpreadConstraints")) }}
topologySpreadConstraints: {{ . | nindent 2 }} topologySpreadConstraints: {{ . | nindent 2 }}

View file

@ -8,13 +8,13 @@ Secondary entrypoint and primary loader for the common chart
{{- /* 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 -}}
{{- 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.controllers" . | nindent 0 -}}
{{- include "bjw-s.common.render.services" . | nindent 0 -}} {{- include "bjw-s.common.render.services" . | nindent 0 -}}
{{- include "bjw-s.common.render.ingresses" . | nindent 0 -}} {{- include "bjw-s.common.render.ingresses" . | nindent 0 -}}
{{- include "bjw-s.common.render.serviceMonitors" . | nindent 0 -}} {{- include "bjw-s.common.render.serviceMonitors" . | nindent 0 -}}
{{- include "bjw-s.common.render.routes" . | 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.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 -}} {{- 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 */ -}} {{- /* Create object from the raw configMap values */ -}}
{{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $configMapValues)) | fromYaml -}} {{- $configMapObject := (include "bjw-s.common.lib.valuesToObject" (dict "rootContext" $rootContext "id" $key "values" $configMapValues)) | fromYaml -}}
{{- /* Perform validations on the configMap before rendering */ -}} {{- /* 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 the configMap class */}}
{{- include "bjw-s.common.class.configMap" (dict "rootContext" $ "object" $configMapObject) | nindent 0 -}} {{- 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. Renders configMap objects required by the chart from a folder in the repo's path.
*/}} */}}
{{- define "bjw-s.common.render.configMaps.fromFiles" -}} {{- define "bjw-s.common.render.configMaps.fromFolder" -}}
{{- $rootValues := .Values -}}
{{/* Generate a list of unique top level folders */}} {{- $valuesCopy := .Values -}}
{{ $topLevelFolders := dict}} {{- $configMapsFromFolder := .Values.configMapsFromFolder | default dict -}}
{{- range $path, $_ := .Files.Glob (printf "%s/*/*" .Values.configMapsFromFolderBasePath) -}} {{- $configMapsFromFolderEnabled := dig "enabled" false $configMapsFromFolder -}}
{{- $_ := set $topLevelFolders (dir $path) "" -}}
{{- end -}} {{- if $configMapsFromFolderEnabled -}}
{{- $top_level_folder_list := keys $topLevelFolders | sortAlpha -}} {{- /* Perform validations before rendering */ -}}
{{/* Iterate over the top level folders */}} {{- include "bjw-s.common.lib.configMap.fromFolder.validate" (dict "rootContext" $ "basePath" $configMapsFromFolder.basePath) -}}
{{ range $path := $top_level_folder_list }} {{- $basePath := $configMapsFromFolder.basePath -}}
{{- $filesContentNoFormat := ($.Files.Glob (printf "%s/*" $path)) -}} {{/* Generate a list of unique top level folders */}}
{{- $filesContent := dict -}} {{ $topLevelFolders := dict}}
{{- $binaryFilesContent := dict -}} {{- range $path, $_ := .Files.Glob (printf "%s/*/*" $basePath) -}}
{{- range $file_name, $content := $filesContentNoFormat -}} {{- $_ := set $topLevelFolders (dir $path) "" -}}
{{- $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 -}}
{{- end -}} {{- 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 -}} {{- $configMapAnnotations := dig "configMapsOverrides" $folder "annotations" dict $configMapsFromFolder -}}
{{- $existingConfigMaps := (get $rootValues "configMaps"| default dict) -}} {{- $configMapLabels := dig "configMapsOverrides" $folder "labels" dict $configMapsFromFolder -}}
{{- $mergedConfigMaps := deepCopy $existingConfigMaps | merge (dict (base $path) $configMapValues) -}} {{- $configMapForceRename := dig "configMapsOverrides" $folder "forceRename" nil $configMapsFromFolder -}}
{{- $rootValues := merge $rootValues (dict "configMaps" $mergedConfigMaps) -}} {{- 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 }}
{{ 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.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", "type": "object",
"properties": { "properties": {
"global": { "global": {

View file

@ -14,7 +14,7 @@ global:
# -- Set default options for all controllers / pods here # -- Set default options for all controllers / pods here
# Each of these options can be overridden on a Controller level # Each of these options can be overridden on a Controller level
defaultPodOptions: 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) # [[ref]](https://kubernetes.io/docs/concepts/scheduling-eviction/assign-pod-node/#affinity-and-anti-affinity)
affinity: {} affinity: {}
@ -79,6 +79,10 @@ defaultPodOptions:
# -- Configure the Security Context for the Pod # -- Configure the Security Context for the Pod
securityContext: {} 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 # -- Duration in seconds the pod needs to terminate gracefully
# -- [[ref](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#lifecycle)] # -- [[ref](https://kubernetes.io/docs/reference/kubernetes-api/workload-resources/pod-v1/#lifecycle)]
terminationGracePeriodSeconds: terminationGracePeriodSeconds:
@ -471,19 +475,43 @@ configMaps:
# data: # data:
# foo: bar # 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. # 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: # files:
# └── configmap1 # └── configmap1
# ├── file1 # ├── file1
# └── file2 # └── file2
# This will generate a ConfigMap named `configmap1` with keys `file1` and `file2`, values being the respective contents of those files. # This will generate a ConfigMap named `configmap1` with keys `file1` and `file2`.
# 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. configMapsFromFolder:
# For example, `file1.escape.yaml` will be converted to `file1.yaml` in the ConfigMap with the contents of the file not templated. enabled: false
# If your file is a binary file like an image, prefix the file extension with `.binary` # #-- The path in your parent's chart filesystem where you can add files to be converted into individual ConfigMaps.
# For example, `file1.binary.png` will be converted to `file1.png` in the ConfigMap under binaryData with the contents of the file base64 encoded. # basePath: "files/configMaps"
configMapsFromFolderBasePath: null # #-- 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. # -- Configure the services for the chart here.
# Additional services can be added by adding a dictionary key similar to the 'main' service. # 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. # # -- Configures the target Service for the serviceMonitor. Helm templates can be used.
# serviceName: '{{ include "bjw-s.common.lib.chart.names.fullname" $ }}' # 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 # # @default -- See values.yaml
# endpoints: # endpoints:
# - port: http # - port: http