Skip to content

Commit

Permalink
chore(rwo): show warning when deployment|sfs + rwo + replica >1 (#741)
Browse files Browse the repository at this point in the history
  • Loading branch information
stavros-k authored Mar 10, 2024
1 parent 953f0eb commit 98ac79a
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 15 deletions.
2 changes: 1 addition & 1 deletion library/common/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
17 changes: 17 additions & 0 deletions library/common/templates/lib/chart/_notes.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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" -}}
Expand All @@ -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 -}}
53 changes: 40 additions & 13 deletions library/common/templates/lib/pod/_volumes.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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 -}}
Expand All @@ -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 -}}
2 changes: 1 addition & 1 deletion library/common/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,6 @@ notes:
- {{ toYaml . }}
{{- end -}}
{{- end }}
## Sources for {{ .Chart.Name }}
{{- range .Chart.Sources }}
Expand All @@ -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: []
Expand Down

0 comments on commit 98ac79a

Please sign in to comment.