From 98ac79aa80e3157a4a183ec6c3cbe1ca5e8dfda7 Mon Sep 17 00:00:00 2001 From: Stavros Kois <47820033+stavros-k@users.noreply.github.com> Date: Sun, 10 Mar 2024 03:55:48 +0200 Subject: [PATCH] chore(rwo): show warning when deployment|sfs + rwo + replica >1 (#741) --- library/common/Chart.yaml | 2 +- library/common/templates/lib/chart/_notes.tpl | 17 ++++++ library/common/templates/lib/pod/_volumes.tpl | 53 ++++++++++++++----- library/common/values.yaml | 2 +- 4 files changed, 59 insertions(+), 15 deletions(-) diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index cbb519db..478e71b0 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -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" diff --git a/library/common/templates/lib/chart/_notes.tpl b/library/common/templates/lib/chart/_notes.tpl index b6924de5..0d4445a7 100644 --- a/library/common/templates/lib/chart/_notes.tpl +++ b/library/common/templates/lib/chart/_notes.tpl @@ -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 -}} diff --git a/library/common/templates/lib/pod/_volumes.tpl b/library/common/templates/lib/pod/_volumes.tpl index b3500082..9e372421 100644 --- a/library/common/templates/lib/pod/_volumes.tpl +++ b/library/common/templates/lib/pod/_volumes.tpl @@ -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 -}} diff --git a/library/common/values.yaml b/library/common/values.yaml index 768b494b..772a58c7 100644 --- a/library/common/values.yaml +++ b/library/common/values.yaml @@ -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: []