Skip to content

Commit

Permalink
feat(common): Release v3.3.0 (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
bjw-s authored Jul 29, 2024
1 parent 040eb7b commit 74f3170
Show file tree
Hide file tree
Showing 19 changed files with 386 additions and 10 deletions.
13 changes: 13 additions & 0 deletions charts/library/common-test/ci/advanced-values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,16 @@ persistence:
- path: /data/config.yaml
readOnly: false
subPath: config.yaml

rawResources:
unsupportedPDB:
enabled: true
nameOverride: pdb
apiVersion: policy/v1
kind: PodDisruptionBudget
spec:
spec:
minAvailable: 1
selector:
matchLabels:
app.kubernetes.io/instance: "{{ .Release.Name }}"
98 changes: 98 additions & 0 deletions charts/library/common-test/tests/rawResource/metadata_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: rawResource metadata
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
rawResources:
config:
apiVersion: v1
kind: Endpoint
spec:
test: test
tests:
- it: default metadata should pass
asserts:
- hasDocuments:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
notExists:
path: metadata.annotations
- documentIndex: *rawResourceDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0

- it: custom metadata should pass
set:
rawResources:
config:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.annotations
value:
test_annotation: test
- documentIndex: *rawResourceDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
helm.sh/chart: common-test-1.0.0
test_label: test

- it: custom metadata with global metadata should pass
set:
global:
labels:
global_label: test
annotations:
global_annotation: test
rawResources:
config:
annotations:
test_annotation: test
labels:
test_label: test
asserts:
- hasDocuments:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.annotations
value:
global_annotation: test
test_annotation: test
- documentIndex: *rawResourceDocument
equal:
path: metadata.labels
value:
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/name: RELEASE-NAME
global_label: test
helm.sh/chart: common-test-1.0.0
test_label: test
78 changes: 78 additions & 0 deletions charts/library/common-test/tests/rawResource/values_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: rawResource values
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
set:
rawResources:
endpoint:
apiVersion: v1
kind: Endpoint
spec:
subsets:
- addresses:
- ip: 127.0.0.1
ports:
- name: "{{ .Release.Name }}"
port: 443
protocol: TCP
tests:
- it: default should pass
asserts:
- hasDocuments:
count: 2
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: subsets[0].addresses[0].ip
value: 127.0.0.1

- it: nameOverride should pass
set:
rawResources.endpoint:
nameOverride: test
asserts:
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.name
value: RELEASE-NAME-test

- it: nameOverride with template should pass
set:
rawResources.endpoint:
nameOverride: "{{ .Release.Name }}"
asserts:
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: metadata.name
value: RELEASE-NAME

- it: spec with template should pass
set:
rawResources.endpoint:
spec:
subsets:
- addresses:
- ip: 127.0.0.1
ports:
- name: "{{ .Release.Name }}"
port: 443
protocol: TCP
asserts:
- documentIndex: &rawResourceDocument 1
isKind:
of: Endpoint
- documentIndex: *rawResourceDocument
equal:
path: subsets[0].ports[0].name
value: RELEASE-NAME
12 changes: 6 additions & 6 deletions charts/library/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ apiVersion: v2
name: common
description: Function library for Helm charts
type: library
version: 3.2.1
version: 3.3.0
kubeVersion: ">=1.22.0-0"
keywords:
- common
Expand All @@ -16,16 +16,16 @@ annotations:
artifacthub.io/changes: |-
- kind: added
description: |-
Support templating in annotation and label values for all objects (fixed in v3.2.1)
Added support for specifying unsupported raw resources.
- kind: added
description: |-
Support activeDeadlineSeconds field on CronJobs and Jobs
Added `stdin` and `tty` fields to container spec.
- kind: added
description: |-
Support excluding secrets and configMaps from pod checksum annotation
Added `persistentVolumeClaimRetentionPolicy` field to statefulset spec.
- kind: fixed
description: |-
Fixed failing ServiceMonitor test
Added `externalName` field to service schema.
- kind: fixed
description: |-
Fixed networkPolicies not rendering correctly
Always allow specifying `nodePort` field on service ports.
4 changes: 2 additions & 2 deletions charts/library/common/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# common

![Version: 3.2.1](https://img.shields.io/badge/Version-3.2.1-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square)
![Version: 3.3.0](https://img.shields.io/badge/Version-3.3.0-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square)

Function library for Helm charts

Expand All @@ -27,7 +27,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
# Chart.yaml
dependencies:
- name: common
version: 3.2.1
version: 3.3.0
repository: https://bjw-s.github.io/helm-charts/
```
Expand Down
8 changes: 8 additions & 0 deletions charts/library/common/schemas/containers.json
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,21 @@
"securityContext": {
"$ref": "k8s-api.json#/core.v1.ContainerSecurityContext"
},
"stdin": {
"type": "boolean",
"default": false
},
"terminationMessagePath": {
"type": "string"
},
"terminationMessagePolicy": {
"type": "string",
"enum": ["File", "FallbackToLogsOnError"]
},
"tty": {
"type": "boolean",
"default": false
},
"workingDir": {
"type": "string"
}
Expand Down
16 changes: 16 additions & 0 deletions charts/library/common/schemas/controllers.json
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@
"podManagementPolicy": {
"type": "string"
},
"persistentVolumeClaimRetentionPolicy": {
"type": "object",
"additionalProperties": false,
"properties": {
"whenDeleted": {
"type": "string",
"enum": ["Delete", "Retain"],
"default": "Retain"
},
"whenScaled": {
"type": "string",
"enum": ["Delete", "Retain"],
"default": "Retain"
}
}
},
"volumeClaimTemplates": {
"type": "array",
"items": {
Expand Down
29 changes: 29 additions & 0 deletions charts/library/common/schemas/rawResource.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"instance": {
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"type": "boolean",
"default": true
},
"apiVersion": {
"type": "string"
},
"kind": {
"type": "string"
},
"annotations": {
"$ref": "definitions.json#/annotations"
},
"labels": {
"$ref": "definitions.json#/labels"
},
"nameOverride": {
"type": "string"
},
"spec": {}
},
"required": ["apiVersion", "kind", "spec"]
}
}
3 changes: 3 additions & 0 deletions charts/library/common/schemas/service.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
"clusterIP": {
"type": "string"
},
"externalName": {
"type": "string"
},
"loadBalancerIP": {
"type": "string"
},
Expand Down
37 changes: 37 additions & 0 deletions charts/library/common/templates/classes/_rawResource.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{{/*
This template serves as a blueprint for all raw resource objects that are created
within the common library.
*/}}
{{- define "bjw-s.common.class.rawResource" -}}
{{- $rootContext := .rootContext -}}
{{- $resourceObject := .object -}}

{{- $labels := merge
($resourceObject.labels | default dict)
(include "bjw-s.common.lib.metadata.allLabels" $rootContext | fromYaml)
-}}
{{- $annotations := merge
($resourceObject.annotations | default dict)
(include "bjw-s.common.lib.metadata.globalAnnotations" $rootContext | fromYaml)
-}}
---
apiVersion: {{ $resourceObject.apiVersion }}
kind: {{ $resourceObject.kind }}
metadata:
name: {{ $resourceObject.name }}
{{- with $labels }}
labels:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $annotations }}
annotations:
{{- range $key, $value := . }}
{{- printf "%s: %s" $key (tpl $value $rootContext | toYaml ) | nindent 4 }}
{{- end }}
{{- end }}
{{- with $resourceObject.spec }}
{{- tpl (toYaml .) $rootContext | nindent 0 }}
{{- end }}
{{- end -}}
2 changes: 1 addition & 1 deletion charts/library/common/templates/classes/_service.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ spec:
protocol: TCP
{{- end }}
name: {{ $name }}
{{- if (and (eq $svcType "NodePort") (not (empty $port.nodePort))) }}
{{- if (not (empty $port.nodePort)) }}
nodePort: {{ $port.nodePort }}
{{ end }}
{{- if (not (empty $port.appProtocol)) }}
Expand Down
3 changes: 3 additions & 0 deletions charts/library/common/templates/classes/_statefulset.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ spec:
app.kubernetes.io/component: {{ $statefulsetObject.identifier }}
{{- include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | nindent 6 }}
serviceName: {{ include "bjw-s.common.lib.chart.names.fullname" $rootContext }}
{{- with (dig "statefulset" "persistentVolumeClaimRetentionPolicy" nil $statefulsetObject) }}
persistentVolumeClaimRetentionPolicy: {{ . | toYaml | nindent 4 }}
{{- end }}
template:
metadata:
{{- with (include "bjw-s.common.lib.pod.metadata.annotations" (dict "rootContext" $rootContext "controllerObject" $statefulsetObject)) }}
Expand Down
6 changes: 6 additions & 0 deletions charts/library/common/templates/lib/container/_spec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ resources: {{ toYaml . | trim | nindent 2 }}
{{- end -}}
{{- with $containerObject.restartPolicy }}
restartPolicy: {{ . | trim }}
{{- end -}}
{{- with $containerObject.stdin }}
stdin: {{ . | trim }}
{{- end -}}
{{- with $containerObject.tty }}
tty: {{ . | trim }}
{{- end -}}
{{- with (include "bjw-s.common.lib.container.field.volumeMounts" (dict "ctx" $ctx) | trim) }}
volumeMounts: {{ . | trim | nindent 2 }}
Expand Down
Loading

0 comments on commit 74f3170

Please sign in to comment.