mirror of
https://github.com/truenas/charts.git
synced 2024-04-21 15:21:45 +00:00
finish up configmap
This commit is contained in:
@@ -0,0 +1 @@
|
||||
{{- include "ix.v1.common.loader.all" . -}}
|
||||
|
||||
@@ -0,0 +1,75 @@
|
||||
suite: configmap data test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should pass with key-value data
|
||||
set:
|
||||
configmaps:
|
||||
my-configmap1:
|
||||
enabled: true
|
||||
data:
|
||||
foo: bar
|
||||
asserts:
|
||||
- documentIndex: &configmapDoc 0
|
||||
isKind:
|
||||
of: ConfigMap
|
||||
- documentIndex: *configmapDoc
|
||||
equal:
|
||||
path: data
|
||||
value:
|
||||
foo: bar
|
||||
|
||||
- it: should pass with key-value data from tpl
|
||||
set:
|
||||
data: bar
|
||||
configmaps:
|
||||
my-configmap1:
|
||||
enabled: true
|
||||
data:
|
||||
foo: "{{ .Values.data }}"
|
||||
asserts:
|
||||
- documentIndex: *configmapDoc
|
||||
equal:
|
||||
path: data
|
||||
value:
|
||||
foo: bar
|
||||
|
||||
- it: should pass with scalar data
|
||||
set:
|
||||
configmaps:
|
||||
my-configmap1:
|
||||
enabled: true
|
||||
data:
|
||||
foo: |
|
||||
some multi line
|
||||
string text
|
||||
asserts:
|
||||
- documentIndex: &configmapDoc 0
|
||||
isKind:
|
||||
of: ConfigMap
|
||||
- documentIndex: *configmapDoc
|
||||
equal:
|
||||
path: data
|
||||
value:
|
||||
foo: |-
|
||||
some multi line
|
||||
string text
|
||||
|
||||
- it: should pass with scalar data with tpl
|
||||
set:
|
||||
data: some_text
|
||||
configmaps:
|
||||
my-configmap1:
|
||||
enabled: true
|
||||
data:
|
||||
foo: |
|
||||
Some other text
|
||||
{{ .Values.data }}
|
||||
asserts:
|
||||
- documentIndex: *configmapDoc
|
||||
equal:
|
||||
path: data
|
||||
value:
|
||||
foo: |-
|
||||
Some other text
|
||||
some_text
|
||||
@@ -0,0 +1,54 @@
|
||||
suite: configmap test
|
||||
templates:
|
||||
- common.yaml
|
||||
chart:
|
||||
appVersion: &appVer v9.9.9
|
||||
tests:
|
||||
- it: should pass with configmap created with labels and annotations
|
||||
documentIndex: &configMapDoc 0
|
||||
set:
|
||||
label1: label1
|
||||
label2: global_label2
|
||||
annotation1: annotation1
|
||||
annotation2: global_annotation2
|
||||
global:
|
||||
labels:
|
||||
g_label1: global_label1
|
||||
g_label2: "{{ .Values.label2 }}"
|
||||
annotations:
|
||||
g_annotation1: global_annotation1
|
||||
g_annotation2: "{{ .Values.annotation2 }}"
|
||||
configmaps:
|
||||
my-configmap1:
|
||||
enabled: true
|
||||
labels:
|
||||
label1: "{{ .Values.label1 }}"
|
||||
label2: label2
|
||||
annotations:
|
||||
annotation1: "{{ .Values.annotation1 }}"
|
||||
annotation2: annotation2
|
||||
data:
|
||||
foo: bar
|
||||
asserts:
|
||||
- isKind:
|
||||
of: ConfigMap
|
||||
- equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
annotation1: annotation1
|
||||
annotation2: annotation2
|
||||
g_annotation1: global_annotation1
|
||||
g_annotation2: global_annotation2
|
||||
- equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app: common-test-1.0.0
|
||||
release: release-name
|
||||
helm-revision: 0
|
||||
helm.sh/chart: common-test-1.0.0
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/version: v9.9.9
|
||||
g_label1: global_label1
|
||||
g_label2: global_label2
|
||||
label1: label1
|
||||
label2: label2
|
||||
@@ -0,0 +1,36 @@
|
||||
suite: configmap name test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should generate correct name
|
||||
set:
|
||||
configmaps:
|
||||
my-configmap1:
|
||||
enabled: true
|
||||
data:
|
||||
foo: bar
|
||||
my-configmap2:
|
||||
enabled: true
|
||||
data:
|
||||
foo: bar
|
||||
asserts:
|
||||
- documentIndex: &configmapDoc 0
|
||||
isKind:
|
||||
of: ConfigMap
|
||||
- documentIndex: *configmapDoc
|
||||
isAPIVersion:
|
||||
of: v1
|
||||
- documentIndex: *configmapDoc
|
||||
equal:
|
||||
path: metadata.name
|
||||
value: release-name-common-test-my-configmap1
|
||||
- documentIndex: &configmapDoc2 1
|
||||
isKind:
|
||||
of: ConfigMap
|
||||
- documentIndex: *configmapDoc2
|
||||
isAPIVersion:
|
||||
of: v1
|
||||
- documentIndex: *configmapDoc2
|
||||
equal:
|
||||
path: metadata.name
|
||||
value: release-name-common-test-my-configmap2
|
||||
@@ -0,0 +1,69 @@
|
||||
suite: configmap validation test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should fail with name longer than 63 characters
|
||||
set:
|
||||
configmaps:
|
||||
my-configmap-super-long-name-that-is-longer-than-63-characters:
|
||||
enabled: true
|
||||
data:
|
||||
foo: bar
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Name [release-name-common-test-my-configmap-super-long-name-that-is-longer-than-63-characters] is not valid. Must start and end with an alphanumeric character. It can contain '-'. And must be at most 63 characters.
|
||||
|
||||
- it: should fail with name starting with underscore
|
||||
set:
|
||||
configmaps:
|
||||
_my-configmap:
|
||||
enabled: true
|
||||
data:
|
||||
foo: bar
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Name [release-name-common-test-_my-configmap] is not valid. Must start and end with an alphanumeric character. It can contain '-'. And must be at most 63 characters.
|
||||
|
||||
- it: should fail with labels not a dict
|
||||
set:
|
||||
configmaps:
|
||||
my-configmap:
|
||||
enabled: true
|
||||
labels: "not a dict"
|
||||
data:
|
||||
foo: bar
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Configmap - Expected <labels> to be a dictionary, but got [string]
|
||||
|
||||
- it: should fail with annotations not a dict
|
||||
set:
|
||||
configmaps:
|
||||
my-configmap:
|
||||
enabled: true
|
||||
annotations: "not a dict"
|
||||
data:
|
||||
foo: bar
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Configmap - Expected <annotations> to be a dictionary, but got [string]
|
||||
|
||||
- it: should fail with data not a dict
|
||||
set:
|
||||
configmaps:
|
||||
my-configmap:
|
||||
enabled: true
|
||||
data: "not a dict"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Configmap - Expected <data> to be a dictionary, but got [string]
|
||||
|
||||
- it: should fail with empty data
|
||||
set:
|
||||
configmaps:
|
||||
my-configmap:
|
||||
enabled: true
|
||||
data: {}
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Configmap - Expected non-empty <data>
|
||||
@@ -19,7 +19,7 @@ Appears in:
|
||||
|
||||
Naming scheme:
|
||||
|
||||
- `$FullName-$ConfigmapName`
|
||||
- `$FullName-$ConfigmapName` (release-name-chart-name-configmapName)
|
||||
|
||||
---
|
||||
|
||||
@@ -43,7 +43,6 @@ configmaps:
|
||||
enabled: true
|
||||
data:
|
||||
key: |
|
||||
multi line
|
||||
text value
|
||||
|
||||
|
||||
```
|
||||
|
||||
@@ -1,6 +1,34 @@
|
||||
{{/* Configmap Class */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.class.configmap" (dict "objectData" $objectData "rootCtx" $) }}
|
||||
|
||||
rootCtx: The root context of the template. It is used to access the global context.
|
||||
objectData:
|
||||
name: The name of the configmap.
|
||||
labels: The labels of the configmap.
|
||||
annotations: The annotations of the configmap.
|
||||
data: The data of the configmap.
|
||||
*/}}
|
||||
|
||||
{{- define "ix.v1.common.class.configmap" -}}
|
||||
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData }}
|
||||
---
|
||||
apiVersion: v1
|
||||
kind: ConfigMap
|
||||
metadata:
|
||||
name: {{ $objectData.name }}
|
||||
{{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
|
||||
{{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
|
||||
labels:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
{{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
|
||||
{{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
|
||||
annotations:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
data:
|
||||
{{- tpl (toYaml $objectData.data) $rootCtx | nindent 2 }}
|
||||
{{- end -}}
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
{{/* Returns the name of the Chart */}}
|
||||
{{- define "ix.common.lib.chart.names.name" -}}
|
||||
|
||||
{{- .Chart.Name | trunc 63 | trimSuffix "-" -}}
|
||||
{{- .Chart.Name | lower | trunc 63 | trimSuffix "-" -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
@@ -12,12 +12,30 @@
|
||||
|
||||
{{- $name := include "ix.common.lib.chart.names.name" . -}}
|
||||
|
||||
{{- if contains $name .Release.name -}}
|
||||
{{- if contains $name .Release.Name -}}
|
||||
{{- $name = .Release.Name -}}
|
||||
{{- else -}}
|
||||
{{- $name = printf "%s-%s" .Release.Name $name -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $name | trunc 63 | trimSuffix "-" -}}
|
||||
{{- $name | lower | trunc 63 | trimSuffix "-" -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{/* Validates names */}}
|
||||
{{- define "ix.v1.common.lib.chart.names.validation" -}}
|
||||
|
||||
{{- $name := .name -}}
|
||||
|
||||
{{- if not (mustRegexMatch "^[a-z0-9]([a-z0-9-]){1,61}[a-z0-9]$" $name) -}}
|
||||
{{- fail (printf "Name [%s] is not valid. Must start and end with an alphanumeric character. It can contain '-'. And must be at most 63 characters." $name) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{/* Create chart name and version as used by the chart label */}}
|
||||
{{- define "ix.v1.common.lib.chart.names.chart" -}}
|
||||
|
||||
{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
@@ -9,11 +9,11 @@
|
||||
{{- end -}}
|
||||
|
||||
{{- define "ix.v1.common.lib.chart.header" -}}
|
||||
{{- tpl $.Values.common.notes.header $ | nindent 0 }}
|
||||
{{- tpl $.Values.notes.header $ | nindent 0 }}
|
||||
{{- end -}}
|
||||
{{- define "ix.v1.common.lib.chart.custom" -}}
|
||||
{{- tpl $.Values.common.notes.header $ | nindent 0 }}
|
||||
{{- tpl $.Values.notes.header $ | nindent 0 }}
|
||||
{{- end -}}
|
||||
{{- define "ix.v1.common.lib.chart.footer" -}}
|
||||
{{- tpl $.Values.common.notes.header $ | nindent 0 }}
|
||||
{{- tpl $.Values.notes.header $ | nindent 0 }}
|
||||
{{- end -}}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
{{/* Configmap Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.configmap.validation" (dict "objectData" $objectData) -}}
|
||||
objectData:
|
||||
name: The name of the configmap.
|
||||
labels: The labels of the configmap.
|
||||
annotations: The annotations of the configmap.
|
||||
data: The data of the configmap.
|
||||
*/}}
|
||||
|
||||
{{- define "ix.v1.common.lib.configmap.validation" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if not $objectData.data -}}
|
||||
{{- fail "Configmap - Expected non-empty <data>" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not (kindIs "map" $objectData.data) -}}
|
||||
{{- fail (printf "Configmap - Expected <data> to be a dictionary, but got [%v]" (kindOf $objectData.data)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $objectData.labels (not (kindIs "map" $objectData.labels)) -}}
|
||||
{{- fail (printf "Configmap - Expected <labels> to be a dictionary, but got [%v]" (kindOf $objectData.labels)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $objectData.annotations (not (kindIs "map" $objectData.annotations)) -}}
|
||||
{{- fail (printf "Configmap - Expected <annotations> to be a dictionary, but got [%v]" (kindOf $objectData.annotations)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,9 @@
|
||||
{{/* Annotations that are added to all objects */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.metadata.allAnnotations" . }}
|
||||
*/}}
|
||||
{{- define "ix.v1.common.lib.metadata.allAnnotations" -}}
|
||||
{{/* Currently empty but can add later, if needed */}}
|
||||
{{- include "ix.v1.common.lib.metadata.globalAnnotations" . }}
|
||||
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,13 @@
|
||||
{{/* Labels that are added to all objects */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.metadata.allLabels" . }}
|
||||
*/}}
|
||||
{{- define "ix.v1.common.lib.metadata.allLabels" -}}
|
||||
helm.sh/chart: {{ include "ix.v1.common.lib.chart.names.chart" . }}
|
||||
helm-revision: {{ .Release.Revision | quote }}
|
||||
app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}
|
||||
app.kubernetes.io/managed-by: {{ .Release.Service }}
|
||||
app: {{ include "ix.v1.common.lib.chart.names.chart" . }}
|
||||
release: {{ .Release.Name | lower }}
|
||||
{{- include "ix.v1.common.lib.metadata.globalLabels" . }}
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,6 @@
|
||||
{{/* Returns the global annotations */}}
|
||||
{{- define "ix.v1.common.lib.metadata.globalAnnotations" -}}
|
||||
|
||||
{{- include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $ "annotations" .Values.global.annotations) -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,6 @@
|
||||
{{/* Returns the global labels */}}
|
||||
{{- define "ix.v1.common.lib.metadata.globalLabels" -}}
|
||||
|
||||
{{- include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $ "labels" .Values.global.labels) -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -0,0 +1,28 @@
|
||||
{{/* Renders a dict of labels */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $ "labels" $labels) }}
|
||||
{{ include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $ "annotations" $annotations) }}
|
||||
*/}}
|
||||
|
||||
{{- define "ix.v1.common.lib.metadata.render" -}}
|
||||
{{- $labels := .labels -}}
|
||||
{{- $annotations := .annotations -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
|
||||
{{- with $labels -}}
|
||||
{{- range $k, $v := . -}}
|
||||
{{- if and $k $v }}
|
||||
{{ $k }}: {{ tpl $v $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- with $annotations -}}
|
||||
{{- range $k, $v := . -}}
|
||||
{{- if and $k $v }}
|
||||
{{ $k }}: {{ tpl $v $rootCtx }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
@@ -12,8 +12,13 @@
|
||||
{{/* Create a copy of the configmap */}}
|
||||
{{- $objectData := (mustDeepCopy $configmap) -}}
|
||||
|
||||
{{- $objectName := (printf "%s-%s" (include "ix.common.lib.chart.names.fullname" $) $name) -}}
|
||||
{{/* Perform validations */}}
|
||||
{{- include "ix.v1.common.lib.chart.names.validation" (dict "name" $objectName) -}}
|
||||
{{- include "ix.v1.common.lib.configmap.validation" (dict "objectData" $objectData) -}}
|
||||
|
||||
{{/* Set the name of the configmap */}}
|
||||
{{- $_ := set $objectData "name" (printf "%s-%s" (include "ix.common.lib.chart.names.fullname" $) $name) -}}
|
||||
{{- $_ := set $objectData "name" $objectName -}}
|
||||
{{/* Call class to create the object */}}
|
||||
{{- include "ix.v1.common.class.configmap" (dict "objectData" $objectData "rootCtx" $) -}}
|
||||
|
||||
|
||||
@@ -36,19 +36,17 @@ image:
|
||||
pullPolicy: IfNotPresent
|
||||
|
||||
# -- ConfigMaps
|
||||
configmaps:
|
||||
# -- ConfigMap name
|
||||
conf-name:
|
||||
# -- Enables the ConfigMap
|
||||
enabled: false
|
||||
# -- ConfigMap labels
|
||||
labels: {}
|
||||
# -- ConfigMap annotations
|
||||
annotations: {}
|
||||
# -- ConfigMap data
|
||||
data:
|
||||
# -- ConfigMap data
|
||||
key: value
|
||||
configmaps: {}
|
||||
# # -- ConfigMap name
|
||||
# conf-name:
|
||||
# # -- Enables the ConfigMap
|
||||
# enabled: false
|
||||
# # -- ConfigMap labels
|
||||
# labels: {}
|
||||
# # -- ConfigMap annotations
|
||||
# annotations: {}
|
||||
# # -- ConfigMap data
|
||||
# data: {}
|
||||
|
||||
# -- Secrets
|
||||
secrets:
|
||||
|
||||
Reference in New Issue
Block a user