mirror of
https://github.com/truecharts/library-charts.git
synced 2026-07-03 11:14:25 -03:00
fix(common): correctly add persistenceList and misc fixes (#378)
**Description** <!-- Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change. --> ⚒️ Fixes # <!--(issue)--> Will also add persistence list later today **⚙️ Type of change** - [ ] ⚙️ Feature/App addition - [ ] 🪛 Bugfix - [ ] ⚠️ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] 🔃 Refactor of current code **🧪 How Has This Been Tested?** <!-- Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration --> **📃 Notes:** <!-- Please enter any other relevant information here --> **✔️ Checklist:** - [ ] ⚖️ My code follows the style guidelines of this project - [ ] 👀 I have performed a self-review of my own code - [ ] #️⃣ I have commented my code, particularly in hard-to-understand areas - [ ] 📄 I have made corresponding changes to the documentation - [ ] ⚠️ My changes generate no new warnings - [ ] 🧪 I have added tests to this description that prove my fix is effective or that my feature works - [ ] ⬆️ I increased versions for any altered app according to semantic versioning **➕ App addition** If this PR is an app addition please make sure you have done the following. - [ ] 🪞 I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] 🖼️ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._
This commit is contained in:
@@ -64,6 +64,7 @@ tests:
|
||||
VAR7:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
VAR8: ""
|
||||
asserts:
|
||||
- documentIndex: &deploymentDoc 2
|
||||
isKind:
|
||||
@@ -127,6 +128,12 @@ tests:
|
||||
valueFrom:
|
||||
fieldRef:
|
||||
fieldPath: metadata.name
|
||||
- documentIndex: *deploymentDoc
|
||||
contains:
|
||||
path: spec.template.spec.containers[0].env
|
||||
content:
|
||||
name: VAR8
|
||||
value: ""
|
||||
|
||||
# Failures
|
||||
- it: it should fail invalid ref
|
||||
|
||||
@@ -663,6 +663,149 @@ tests:
|
||||
isAPIVersion:
|
||||
of: apps/v1
|
||||
|
||||
- it: should pass with volume from persistenceList with selected pod and containers and specific values from tpl
|
||||
set:
|
||||
some_path: /some/other/path
|
||||
some_propagation: None
|
||||
some_sub_path: /some/sub/path
|
||||
image: *image
|
||||
workload:
|
||||
workload-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
containers:
|
||||
container-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
imageSelector: image
|
||||
probes: *probes
|
||||
container-name2:
|
||||
enabled: true
|
||||
primary: false
|
||||
imageSelector: image
|
||||
probes: *probes
|
||||
persistenceList:
|
||||
- enabled: true
|
||||
type: emptyDir
|
||||
mountPath: /some/path
|
||||
readOnly: true
|
||||
targetSelector:
|
||||
workload-name:
|
||||
container-name1:
|
||||
mountPath: "{{ .Values.some_path }}"
|
||||
readOnly: false
|
||||
mountPropagation: "{{ .Values.some_propagation }}"
|
||||
subPath: "{{ .Values.some_sub_path }}"
|
||||
container-name2: {}
|
||||
asserts:
|
||||
- documentIndex: &deploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDoc
|
||||
isAPIVersion:
|
||||
of: apps/v1
|
||||
- documentIndex: *deploymentDoc
|
||||
contains:
|
||||
path: spec.template.spec.containers[0].volumeMounts
|
||||
content:
|
||||
name: persist-list-0
|
||||
mountPath: /some/other/path
|
||||
readOnly: false
|
||||
mountPropagation: None
|
||||
subPath: /some/sub/path
|
||||
- documentIndex: *deploymentDoc
|
||||
contains:
|
||||
path: spec.template.spec.containers[1].volumeMounts
|
||||
content:
|
||||
name: persist-list-0
|
||||
mountPath: /some/path
|
||||
readOnly: true
|
||||
|
||||
- it: should pass with volume from persistenceList with name
|
||||
set:
|
||||
image: *image
|
||||
workload:
|
||||
workload-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
containers:
|
||||
container-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
imageSelector: image
|
||||
probes: *probes
|
||||
persistenceList:
|
||||
- name: some-vol
|
||||
enabled: true
|
||||
type: emptyDir
|
||||
mountPath: /some/path
|
||||
readOnly: true
|
||||
asserts:
|
||||
- documentIndex: &deploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDoc
|
||||
isAPIVersion:
|
||||
of: apps/v1
|
||||
- documentIndex: *deploymentDoc
|
||||
contains:
|
||||
path: spec.template.spec.containers[0].volumeMounts
|
||||
content:
|
||||
name: some-vol
|
||||
mountPath: /some/path
|
||||
readOnly: true
|
||||
|
||||
- it: should pass with volume from persistenceList and from persistence
|
||||
set:
|
||||
image: *image
|
||||
workload:
|
||||
workload-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
containers:
|
||||
container-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
imageSelector: image
|
||||
probes: *probes
|
||||
persistence:
|
||||
some-vol:
|
||||
enabled: true
|
||||
type: emptyDir
|
||||
mountPath: /some/path
|
||||
persistenceList:
|
||||
- name: some-other-vol
|
||||
enabled: true
|
||||
type: emptyDir
|
||||
mountPath: /some/other/path
|
||||
asserts:
|
||||
- documentIndex: &deploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDoc
|
||||
isAPIVersion:
|
||||
of: apps/v1
|
||||
- documentIndex: *deploymentDoc
|
||||
contains:
|
||||
path: spec.template.spec.containers[0].volumeMounts
|
||||
content:
|
||||
name: some-vol
|
||||
mountPath: /some/path
|
||||
readOnly: false
|
||||
- documentIndex: *deploymentDoc
|
||||
contains:
|
||||
path: spec.template.spec.containers[0].volumeMounts
|
||||
content:
|
||||
name: some-other-vol
|
||||
mountPath: /some/other/path
|
||||
readOnly: false
|
||||
|
||||
# Failures
|
||||
- it: should fail with invalid mountPropagation
|
||||
set:
|
||||
|
||||
@@ -121,3 +121,20 @@ tests:
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Persistence - Expected [medium] to be one of ["", Memory], but got [not-a-valid-medium] on <emptyDir> type
|
||||
|
||||
- it: should fail with invalid size format
|
||||
set:
|
||||
workload:
|
||||
some-workload:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
persistence:
|
||||
volume1:
|
||||
enabled: true
|
||||
type: emptyDir
|
||||
size: not-a-valid-size
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Persistence Expected <size> to have one of the following formats [(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)], but got [not-a-valid-size]
|
||||
|
||||
@@ -15,4 +15,4 @@ maintainers:
|
||||
name: common
|
||||
sources: null
|
||||
type: library
|
||||
version: 12.4.1
|
||||
version: 12.4.2
|
||||
|
||||
@@ -11,8 +11,12 @@ objectData: The object data to be used to render the container.
|
||||
{{- range $k, $v := $objectData.env -}}
|
||||
{{- include "tc.v1.common.helper.container.envDupeCheck" (dict "rootCtx" $rootCtx "objectData" $objectData "source" "env" "key" $k) }}
|
||||
- name: {{ $k | quote }}
|
||||
{{- if not (kindIs "map" $v) }}
|
||||
value: {{ tpl (toString $v) $rootCtx | quote }}
|
||||
{{- if not (kindIs "map" $v) -}}
|
||||
{{- $value := "" -}}
|
||||
{{- if $v -}} {{/* Only tpl non-empty values */}}
|
||||
{{- $value = tpl (toString $v) $rootCtx -}}
|
||||
{{- end }}
|
||||
value: {{ $value | quote }}
|
||||
{{- else if kindIs "map" $v }}
|
||||
valueFrom:
|
||||
{{- $refs := (list "configMapKeyRef" "secretKeyRef" "fieldRef") -}}
|
||||
|
||||
@@ -17,6 +17,14 @@ objectData: The object data to be used to render the volume.
|
||||
{{- $size = tpl . $rootCtx -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if $size -}}
|
||||
{{/* Size: https://regex101.com/r/NNPV2D/1 */}}
|
||||
{{- if not (mustRegexMatch "^[1-9][0-9]*([EPTGMK]i?|e[0-9]+)?$" (toString $size)) -}}
|
||||
{{- $formats := "(Suffixed with E/P/T/G/M/K - eg. 1G), (Suffixed with Ei/Pi/Ti/Gi/Mi/Ki - eg. 1Gi), (Plain Integer in bytes - eg. 1024), (Exponent - eg. 134e6)" -}}
|
||||
{{- fail (printf "Persistence Expected <size> to have one of the following formats [%s], but got [%s]" $formats $size) -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $medium (ne $medium "Memory") -}}
|
||||
{{- fail (printf "Persistence - Expected [medium] to be one of [\"\", Memory], but got [%s] on <emptyDir> type" $medium) -}}
|
||||
{{- end }}
|
||||
|
||||
@@ -4,6 +4,9 @@
|
||||
{{/* Merge chart values and the common chart defaults */}}
|
||||
{{- include "tc.v1.common.values.init" . -}}
|
||||
|
||||
{{/* Parse lists and append to values */}}
|
||||
{{- include "tc.v1.common.loader.lists" . -}}
|
||||
|
||||
{{/* Ensure TrueCharts chart context information is available */}}
|
||||
{{- include "tc.v1.common.lib.util.chartcontext" . -}}
|
||||
|
||||
|
||||
5
library/common/templates/loader/_lists.tpl
Normal file
5
library/common/templates/loader/_lists.tpl
Normal file
@@ -0,0 +1,5 @@
|
||||
{{- define "tc.v1.common.loader.lists" -}}
|
||||
|
||||
{{- include "tc.v1.common.values.persistenceList" . -}}
|
||||
|
||||
{{- end -}}
|
||||
18
library/common/templates/values/lists/_persistenceList.tpl
Normal file
18
library/common/templates/values/lists/_persistenceList.tpl
Normal file
@@ -0,0 +1,18 @@
|
||||
{{- define "tc.v1.common.values.persistenceList" -}}
|
||||
{{- $rootCtx := . -}}
|
||||
|
||||
{{- range $idx, $persistenceValues := $rootCtx.Values.persistenceList -}}
|
||||
{{- $name := (printf "persist-list-%s" (toString $idx)) -}}
|
||||
|
||||
{{- with $persistenceValues.name -}}
|
||||
{{- $name = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if not (hasKey $rootCtx.Values "persistence") -}}
|
||||
{{- $_ := set $rootCtx.Values "persistence" dict -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- $_ := set $rootCtx.Values.persistence $name $persistenceValues -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -207,7 +207,7 @@ persistence:
|
||||
mountPath: /dev/shm
|
||||
targetSelectAll: true
|
||||
|
||||
|
||||
persistenceList: []
|
||||
|
||||
# -- Injected from SCALE middleware
|
||||
# Only for reference here
|
||||
|
||||
Reference in New Issue
Block a user