mirror of
https://github.com/bjw-s-labs/helm-charts.git
synced 2025-07-04 00:47:04 +02:00
fix(common): Release 2.0.2 (#196)
This commit is contained in:
parent
d86b0de790
commit
f729651dbe
16 changed files with 260 additions and 41 deletions
|
@ -6,13 +6,88 @@ templates:
|
|||
tests:
|
||||
- it: default should pass
|
||||
asserts:
|
||||
- documentIndex: &ControllerDoc 0
|
||||
- documentIndex: &deploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *ControllerDoc
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: metadata.name
|
||||
value: RELEASE-NAME
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: metadata.labels['app.kubernetes.io/component']
|
||||
value: main
|
||||
|
||||
- it: additional controllers should pass
|
||||
set:
|
||||
controllers:
|
||||
second:
|
||||
containers:
|
||||
main:
|
||||
image:
|
||||
repository: ghcr.io/mendhak/http-https-echo
|
||||
tag: 30
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 3
|
||||
- documentIndex: &firstDeploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *firstDeploymentDoc
|
||||
equal:
|
||||
path: metadata.name
|
||||
value: RELEASE-NAME
|
||||
- documentIndex: *firstDeploymentDoc
|
||||
equal:
|
||||
path: metadata.labels['app.kubernetes.io/component']
|
||||
value: main
|
||||
- documentIndex: &secondDeploymentDoc 1
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *secondDeploymentDoc
|
||||
equal:
|
||||
path: metadata.name
|
||||
value: RELEASE-NAME-second
|
||||
- documentIndex: *secondDeploymentDoc
|
||||
equal:
|
||||
path: metadata.labels['app.kubernetes.io/component']
|
||||
value: second
|
||||
|
||||
- it: additional controllers with nameOverride should pass
|
||||
set:
|
||||
controllers:
|
||||
second:
|
||||
nameOverride: testOverride
|
||||
containers:
|
||||
main:
|
||||
image:
|
||||
repository: ghcr.io/mendhak/http-https-echo
|
||||
tag: 30
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 3
|
||||
- documentIndex: &firstDeploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *firstDeploymentDoc
|
||||
equal:
|
||||
path: metadata.name
|
||||
value: RELEASE-NAME
|
||||
- documentIndex: *firstDeploymentDoc
|
||||
equal:
|
||||
path: metadata.labels['app.kubernetes.io/component']
|
||||
value: main
|
||||
- documentIndex: &secondDeploymentDoc 1
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *secondDeploymentDoc
|
||||
equal:
|
||||
path: metadata.name
|
||||
value: RELEASE-NAME-testOverride
|
||||
- documentIndex: *secondDeploymentDoc
|
||||
equal:
|
||||
path: metadata.labels['app.kubernetes.io/component']
|
||||
value: second
|
||||
|
||||
- it: daemonset should pass
|
||||
set:
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
---
|
||||
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
|
||||
suite: pod serviceAccount
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: default should pass
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 2
|
||||
- documentIndex: &deploymentDocument 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDocument
|
||||
equal:
|
||||
path: spec.template.spec.serviceAccountName
|
||||
value: default
|
||||
|
||||
- it: with create, without name should pass
|
||||
set:
|
||||
serviceAccount:
|
||||
create: true
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 4
|
||||
- documentIndex: &serviceAccountDocument 0
|
||||
isKind:
|
||||
of: ServiceAccount
|
||||
- documentIndex: &deploymentDocument 1
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDocument
|
||||
equal:
|
||||
path: spec.template.spec.serviceAccountName
|
||||
value: RELEASE-NAME
|
||||
|
||||
- it: with create, with name should pass
|
||||
set:
|
||||
serviceAccount:
|
||||
create: true
|
||||
name: mySA
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 4
|
||||
- documentIndex: &serviceAccountDocument 0
|
||||
isKind:
|
||||
of: ServiceAccount
|
||||
- documentIndex: &deploymentDocument 1
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDocument
|
||||
equal:
|
||||
path: spec.template.spec.serviceAccountName
|
||||
value: mySA
|
||||
|
||||
- it: without create, with name should pass
|
||||
set:
|
||||
serviceAccount:
|
||||
create: false
|
||||
name: mySA
|
||||
asserts:
|
||||
- hasDocuments:
|
||||
count: 2
|
||||
- documentIndex: &deploymentDocument 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDocument
|
||||
equal:
|
||||
path: spec.template.spec.serviceAccountName
|
||||
value: mySA
|
|
@ -3,7 +3,7 @@ apiVersion: v2
|
|||
name: common
|
||||
description: Function library for Helm charts
|
||||
type: library
|
||||
version: 2.0.1
|
||||
version: 2.0.2
|
||||
kubeVersion: ">=1.22.0-0"
|
||||
keywords:
|
||||
- common
|
||||
|
@ -16,10 +16,7 @@ annotations:
|
|||
artifacthub.io/changes: |-
|
||||
- kind: fixed
|
||||
description: |-
|
||||
Mounting of volumeClaimTemplates was not implemented properly.
|
||||
ServiceAccount could not be referenced without creating
|
||||
- kind: fixed
|
||||
description: |-
|
||||
Using advancedMounts for initContainers resulted in an error.
|
||||
- kind: fixed
|
||||
description: |-
|
||||
Validations for container images have been improved.
|
||||
Controllers without a type did not default to Deployment
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
# common
|
||||
|
||||
 
|
||||
 
|
||||
|
||||
Function library for Helm charts
|
||||
|
||||
|
@ -27,7 +27,7 @@ Include this chart as a dependency in your `Chart.yaml` e.g.
|
|||
# Chart.yaml
|
||||
dependencies:
|
||||
- name: common
|
||||
version: 2.0.1
|
||||
version: 2.0.2
|
||||
repository: https://bjw-s.github.io/helm-charts/
|
||||
```
|
||||
|
||||
|
|
|
@ -6,6 +6,11 @@ Convert controller values to an object
|
|||
{{- $identifier := .id -}}
|
||||
{{- $objectValues := .values -}}
|
||||
|
||||
{{- /* Default the controller type to Deployment */ -}}
|
||||
{{- if eq (dig "type" "" $objectValues) "" -}}
|
||||
{{- $_ := set $objectValues "type" "deployment" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Determine and inject the controller name */ -}}
|
||||
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
|
||||
|
||||
|
|
|
@ -4,15 +4,8 @@ Returns the value for serviceAccountName
|
|||
{{- define "bjw-s.common.lib.pod.field.serviceAccountName" -}}
|
||||
{{- $rootContext := .ctx.rootContext -}}
|
||||
|
||||
{{- /* Default to "default" */ -}}
|
||||
{{- $name := "default" -}}
|
||||
{{- $serviceAccountValues := (mustDeepCopy $rootContext.Values.serviceAccount) -}}
|
||||
{{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" "default" "values" $serviceAccountValues)) | fromYaml -}}
|
||||
{{- $serviceAccountObject.name -}}
|
||||
|
||||
{{- /* See if an override is needed */ -}}
|
||||
{{- if $rootContext.Values.serviceAccount.create -}}
|
||||
{{- $serviceAccountValues := (mustDeepCopy $rootContext.Values.serviceAccount) -}}
|
||||
{{- $serviceAccountObject := (include "bjw-s.common.lib.serviceAccount.valuesToObject" (dict "rootContext" $rootContext "id" "default" "values" $serviceAccountValues)) | fromYaml -}}
|
||||
{{- $name = $serviceAccountObject.name -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $name -}}
|
||||
{{- end -}}
|
||||
|
|
|
@ -6,7 +6,7 @@ Validate Service values
|
|||
{{- $serviceObject := .object -}}
|
||||
|
||||
{{- if empty (get $serviceObject "controller") -}}
|
||||
{{- fail (printf "controller is required for Service. (service: %s)" $serviceObject.identifier) -}}
|
||||
{{- fail (printf "controller field is required for Service. (service: %s)" $serviceObject.identifier) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- /* Validate Service type */ -}}
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
{{/*
|
||||
Convert Secret values to an object
|
||||
Convert ServiceAccount values to an object
|
||||
*/}}
|
||||
{{- define "bjw-s.common.lib.serviceAccount.valuesToObject" -}}
|
||||
{{- $rootContext := .rootContext -}}
|
||||
|
@ -7,12 +7,15 @@ Convert Secret values to an object
|
|||
{{- $objectValues := .values -}}
|
||||
|
||||
{{- /* Determine and inject the serviceAccount name */ -}}
|
||||
{{- $objectName := (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
|
||||
|
||||
{{- if $objectValues.name -}}
|
||||
{{- $objectName = $objectValues.name -}}
|
||||
{{- $serviceAccountName := "" -}}
|
||||
{{- $defaultServiceAccountName := "default" -}}
|
||||
{{- if $objectValues.create -}}
|
||||
{{- $defaultServiceAccountName = (include "bjw-s.common.lib.chart.names.fullname" $rootContext) -}}
|
||||
{{- end -}}
|
||||
{{- $_ := set $objectValues "name" $objectName -}}
|
||||
|
||||
{{- $serviceAccountName = default $defaultServiceAccountName $objectValues.name -}}
|
||||
|
||||
{{- $_ := set $objectValues "name" $serviceAccountName -}}
|
||||
{{- $_ := set $objectValues "identifier" $identifier -}}
|
||||
|
||||
{{- /* Return the serviceAccount object */ -}}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue