chore(rwo): show warning when deployment|sfs + rwo + replica >1 (#741)

This commit is contained in:
Stavros Kois
2024-03-10 03:55:48 +02:00
committed by GitHub
parent 953f0ebf54
commit 98ac79aa80
4 changed files with 59 additions and 15 deletions

View File

@@ -15,7 +15,7 @@ maintainers:
name: common
sources: null
type: library
version: 19.1.0
version: 19.1.1
annotations:
artifacthub.io/category: "integration-delivery"
artifacthub.io/license: "BUSL-1.1"

View File

@@ -6,6 +6,8 @@
{{- include "tc.v1.common.lib.chart.footer" . -}}
{{- include "tc.v1.common.lib.chart.warnings" . -}}
{{- end -}}
{{- define "tc.v1.common.lib.chart.header" -}}
@@ -19,3 +21,18 @@
{{- define "tc.v1.common.lib.chart.footer" -}}
{{- tpl $.Values.notes.footer $ | nindent 0 }}
{{- end -}}
{{- define "tc.v1.common.lib.chart.warnings" -}}
{{- range $w := $.Values.notes.warnings }}
{{- tpl $w $ | nindent 0 }}
{{- end }}
{{- end -}}
{{- define "add.warning" -}}
{{- $rootCtx := .rootCtx -}}
{{- $warn := .warn -}}
{{- $newWarns := $rootCtx.Values.notes.warnings -}}
{{- $newWarns = mustAppend $newWarns $warn -}}
{{- $_ := set $rootCtx.Values.notes "warnings" $newWarns -}}
{{- end -}}

View File

@@ -51,19 +51,10 @@ objectData: The object data to be used to render the Pod.
{{/* Define the volume based on type */}}
{{- $type := ($persistence.type | default $rootCtx.Values.fallbackDefaults.persistenceType) -}}
{{- if eq $objectData.type "DaemonSet" -}}
{{/* Only check accessModes if persistence is one of those types */}}
{{- $typesWithAccessMode := (list "pvc") -}}
{{- if (mustHas $type $typesWithAccessMode) -}}
{{- $modes := include "tc.v1.common.lib.pvc.accessModes" (dict "rootCtx" $rootCtx "objectData" $persistence "caller" "Volumes") | fromYamlArray -}}
{{- range $m := $modes -}}
{{- if eq $m "ReadWriteOnce" -}}
{{- fail "Expected [accessMode] to not be [ReadWriteOnce] when used on a [DaemonSet]" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- include "tc.v1.common.lib.pod.volumes.checkRWO" (dict
"rootCtx" $rootCtx "objectData" $objectData "persistence" $persistence
"type" $type "name" $name)
-}}
{{- if eq "pvc" $type -}}
{{- include "tc.v1.common.lib.pod.volume.pvc" (dict "rootCtx" $rootCtx "objectData" $persistence) | trim | nindent 0 -}}
@@ -90,3 +81,39 @@ objectData: The object data to be used to render the Pod.
{{- end -}}
{{- end -}}
{{- end -}}
{{- define "tc.v1.common.lib.pod.volumes.checkRWO" -}}
{{- $rootCtx := .rootCtx -}}
{{- $objectData := .objectData -}}
{{- $persistence := .persistence -}}
{{- $type := .type -}}
{{- $name := .name -}}
{{/* Only check accessModes if persistence is one of those types */}}
{{- $typesWithAccessMode := (list "pvc") -}}
{{- if (mustHas $type $typesWithAccessMode) -}}
{{- $modes := include "tc.v1.common.lib.pvc.accessModes" (dict "rootCtx" $rootCtx
"objectData" $persistence "caller" "Volumes") | fromYamlArray
-}}
{{- $hasRWO := false -}}
{{- range $m := $modes -}}
{{- if eq $m "ReadWriteOnce" -}}
{{- $hasRWO = true -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- if $hasRWO -}}
{{- if eq $objectData.type "DaemonSet" -}}
{{- fail "Expected [accessMode] to not be [ReadWriteOnce] when used on a [DaemonSet]" -}}
{{- else if and (mustHas $objectData.type (list "Deployment" "StatefulSet")) (gt (($objectData.replicas| default 1) | int) 1) -}}
{{- include "add.warning" (dict "rootCtx" $rootCtx
"warn" (printf "WARNING: The [accessModes] on volume [%s] is set to [ReadWriteOnce] when on a [Deployment] with more than 1 replica" $name))
-}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

View File

@@ -397,7 +397,6 @@ notes:
- {{ toYaml . }}
{{- end -}}
{{- end }}
## Sources for {{ .Chart.Name }}
{{- range .Chart.Sources }}
@@ -417,6 +416,7 @@ notes:
OpenSource can only exist with your help, please consider supporting TrueCharts:
https://truecharts.org/sponsor
warnings: []
# -- iXsystems prototype values.yaml based portals
iXPortals: []