Skip to content

Commit

Permalink
feat(common): Release common library 3.6.0 (#364)
Browse files Browse the repository at this point in the history
Signed-off-by: solidDoWant <fred.heinecke@yahoo.com>
Co-authored-by: solidDoWant <fred.heinecke@yahoo.com>
  • Loading branch information
bjw-s and solidDoWant authored Dec 26, 2024
1 parent 6d23aa6 commit e68b41e
Show file tree
Hide file tree
Showing 11 changed files with 240 additions and 9 deletions.
58 changes: 58 additions & 0 deletions charts/library/common-test/tests/pod/field_hostUsers_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# 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
capabilities:
majorVersion: 1
minorVersion: 29
tests:
- it: default should pass for kubernetes < 1.28
capabilities:
majorVersion: 1
minorVersion: 28
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
notExists:
path: spec.template.spec.hostUsers

- it: default should pass for kubernetes >= 1.29
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostUsers
value: true

- it: hostUsers disabled should pass
set:
defaultPodOptions:
hostUsers: false
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostUsers
value: false

- it: hostUsers enabled should pass
set:
defaultPodOptions:
hostUsers: true
asserts:
- documentIndex: 0
isKind:
of: Deployment
- documentIndex: 0
equal:
path: spec.template.spec.hostUsers
value: true
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: "pod metadata: annotations"
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default pod annotations
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- notExists:
path: spec.template.metadata.annotations

- it: pod annotations from defaultPodOptions should be included
set:
defaultPodOptions:
annotations:
defaultPodOptionsAnnotation: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.annotations
content:
defaultPodOptionsAnnotation: test

- it: pod annotations from pod options should be included
set:
controllers:
main:
pod:
annotations:
podOptionsAnnotation: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.annotations
content:
podOptionsAnnotation: test

- it: pod annotations from global annotations should not be included by default
set:
global:
annotations:
globalAnnotation: test
documentSelector: *DeploymentSelector
asserts:
- isNotSubset:
path: spec.template.metadata.annotations
content:
globalAnnotation: test

- it: pod annotations from global annotations should be included when requested
set:
global:
propagateGlobalMetadataToPods: true
annotations:
globalAnnotation: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.annotations
content:
globalAnnotation: test
70 changes: 70 additions & 0 deletions charts/library/common-test/tests/pod/metadata_labels_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: "pod metadata: labels"
templates:
- common.yaml
values:
- ../_values/controllers_main_default_container.yaml
tests:
- it: default pod labels
documentSelector: &DeploymentSelector
path: $[?(@.kind == "Deployment")].metadata.name
value: RELEASE-NAME
asserts:
- equal:
path: spec.template.metadata.labels
value:
app.kubernetes.io/component: main
app.kubernetes.io/instance: RELEASE-NAME
app.kubernetes.io/name: RELEASE-NAME

- it: pod labels from defaultPodOptions should be included
set:
defaultPodOptions:
labels:
defaultPodOptionsLabel: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.labels
content:
defaultPodOptionsLabel: test

- it: pod labels from pod options should be included
set:
controllers:
main:
pod:
labels:
podOptionsLabel: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.labels
content:
podOptionsLabel: test

- it: pod labels from global labels should not be included by default
set:
global:
labels:
globalLabel: test
documentSelector: *DeploymentSelector
asserts:
- isNotSubset:
path: spec.template.metadata.labels
content:
globalLabel: test

- it: pod labels from global labels should be included when requested
set:
global:
propagateGlobalMetadataToPods: true
labels:
globalLabel: test
documentSelector: *DeploymentSelector
asserts:
- isSubset:
path: spec.template.metadata.labels
content:
globalLabel: test
7 changes: 5 additions & 2 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.5.1
version: 3.6.0
kubeVersion: ">=1.22.0-0"
keywords:
- common
Expand All @@ -16,4 +16,7 @@ annotations:
artifacthub.io/changes: |-
- kind: added
description: |-
Add feature flag to override enforcing the creation of a default ServiceAccount
Add hostUsers field to pod spec for k8s clusters >= 1.29
- kind: added
description: |-
Allow propagating global labels and annotations to Pod metadata
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.5.1](https://img.shields.io/badge/Version-3.5.1-informational?style=flat-square) ![Type: library](https://img.shields.io/badge/Type-library-informational?style=flat-square)
![Version: 3.6.0](https://img.shields.io/badge/Version-3.6.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.5.1
version: 3.6.0
repository: https://bjw-s.github.io/helm-charts/
```
Expand Down
4 changes: 4 additions & 0 deletions charts/library/common/schemas/pod.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@
"type": "boolean",
"default": false
},
"hostUsers": {
"type": "boolean",
"default": false
},
"hostname": {
"type": "string"
},
Expand Down
3 changes: 3 additions & 0 deletions charts/library/common/templates/lib/pod/_spec.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ hostname: {{ . | trim }}
hostIPC: {{ include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "hostIPC" "default" false) }}
hostNetwork: {{ include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "hostNetwork" "default" false) }}
hostPID: {{ include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "hostPID" "default" false) }}
{{- if ge ($rootContext.Capabilities.KubeVersion.Minor | int) 29 }}
hostUsers: {{ include "bjw-s.common.lib.pod.getOption" (dict "ctx" $ctx "option" "hostUsers" "default" true) }}
{{- end }}
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")) }}
dnsConfig: {{ . | nindent 2 }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@ Returns the value for annotations
{{- $controllerObject := .controllerObject -}}

{{- /* Default annotations */ -}}
{{- $annotations := dict -}}
{{- $annotations := merge
(dict)
-}}

{{- /* Include global annotations if specified */ -}}
{{- if $rootContext.Values.global.propagateGlobalMetadataToPods -}}
{{- $annotations = merge
(include "bjw-s.common.lib.metadata.globalAnnotations" $rootContext | fromYaml)
$annotations
-}}
{{- end -}}

{{- /* Set to the default if it is set */ -}}
{{- $defaultOption := get (default dict $rootContext.Values.defaultPodOptions) "annotations" -}}
Expand Down
8 changes: 8 additions & 0 deletions charts/library/common/templates/lib/pod/metadata/_labels.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ Returns the value for labels
(dict "app.kubernetes.io/component" $controllerObject.identifier)
-}}

{{- /* Include global labels if specified */ -}}
{{- if $rootContext.Values.global.propagateGlobalMetadataToPods -}}
{{- $labels = merge
(include "bjw-s.common.lib.metadata.globalLabels" $rootContext | fromYaml)
$labels
-}}
{{- end -}}

{{- /* Fetch the Pod selectorLabels */ -}}
{{- $selectorLabels := include "bjw-s.common.lib.metadata.selectorLabels" $rootContext | fromYaml -}}
{{- if not (empty $selectorLabels) -}}
Expand Down
12 changes: 8 additions & 4 deletions charts/library/common/values.schema.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.5.1/charts/library/common/values.schema.json",
"$id": "https://raw.githubusercontent.com/bjw-s/helm-charts/common-3.6.0/charts/library/common/values.schema.json",
"type": "object",
"properties": {
"global": {
"type": "object",
"properties": {
"annotations": {
"$ref": "schemas/definitions.json#/annotations"
},
"nameOverride": {
"type": [
"string",
Expand All @@ -21,8 +18,15 @@
"null"
]
},
"propagateGlobalMetadataToPods": {
"type": "boolean",
"default": false
},
"labels": {
"$ref": "schemas/definitions.json#/labels"
},
"annotations": {
"$ref": "schemas/definitions.json#/annotations"
}
}
},
Expand Down
5 changes: 5 additions & 0 deletions charts/library/common/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ global:
nameOverride:
# -- Set the entire name definition
fullnameOverride:
# -- Propagate global metadata to Pod labels.
propagateGlobalMetadataToPods: false
# -- Set additional global labels. Helm templates can be used.
labels: {}
# -- Set additional global annotations. Helm templates can be used.
Expand Down Expand Up @@ -48,6 +50,9 @@ defaultPodOptions:
# -- Use the host's pid namespace
hostPID: false

# -- Use the host's user namespace (requires 1.29 or newer)
hostUsers: true

# -- Set image pull secrets
imagePullSecrets: []

Expand Down

0 comments on commit e68b41e

Please sign in to comment.