Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions base/schema/chartDefaults.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
"persistentVolumeClaim": {
"$ref": "resources/persistentVolumeClaims.json#/instance"
},
"persistentVolume": {
"$ref": "resources/persistentVolumes.json#/instance"
},
"networkPolicy": {
"$ref": "resources/networkPolicies.json#/instance"
},
Expand Down
12 changes: 12 additions & 0 deletions base/schema/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -303,6 +303,18 @@
"$ref": "resources/requestAuthentications.json#/instance"
}
}
},
"persistentVolumes": {
"title": "Render some persistentVolumes, indexed by an identifier",
"type": "object",
"minProperties": 1,
"additionalProperties": false,
"patternProperties": {
"^[0-9a-z-]*$": {
"title": "Identifier of the persistent volume",
"$ref": "resources/persistentVolumes.json#/instance"
}
}
}
}
}
47 changes: 47 additions & 0 deletions base/schema/resources/persistentVolumes.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"instance": {
"type": "object",
"additionalProperties": false,
"properties": {
"enabled": {
"$ref": "../lib/utils.json#/enabled"
},
"annotations": {
"$ref": "../lib/k8s.json#/Annotations"
},
"labels": {
"$ref": "../lib/k8s.json#/Labels"
},
"nameOverride": {
"$ref": "../lib/utils.json#/nameOverride"
},
"accessModes": {
"type": "array",
"items": {
"type": "string",
"enum": ["ReadWriteOnce", "ReadOnlyMany", "ReadWriteMany", "ReadWriteOncePod"]
}
},
"nodeAffinity": {
"additionalProperties": false,
"properties": {
"required": {
"$ref": "../lib/k8s.json#/NodeSelector"
}
}
},
"size": {
"$ref": "../lib/k8s.json#/Quantity"
},
"storageClassName": {
"type": "string"
},
"csi": {
"type": "object",
"additionalProperties": {
"type": "string"
}
}
}
}
}
4 changes: 4 additions & 0 deletions base/templates/features/_chartDefaultsResources.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@
{{- include "base.lib.utils.mergeInValuesNonOverwrite" (dict "rootContext" $ "obj" (dict "resources" (dict "persistentVolumeClaims" (dict $identifier $.Values.chartDefaults.resources.persistentVolumeClaim)))) }}
{{- end -}}

{{- range $identifier, $persistentVolume := .Values.resources.persistentVolumes -}}
{{- include "base.lib.utils.mergeInValuesNonOverwrite" (dict "rootContext" $ "obj" (dict "resources" (dict "persistentVolumes" (dict $identifier $.Values.chartDefaults.resources.persistentVolume)))) }}
{{- end -}}

{{- range $identifier, $sidecar := .Values.resources.sidecars -}}
{{- include "base.lib.utils.mergeInValuesNonOverwrite" (dict "rootContext" $ "obj" (dict "resources" (dict "sidecars" (dict $identifier $.Values.chartDefaults.resources.sidecar)))) }}
{{- end -}}
Expand Down
1 change: 1 addition & 0 deletions base/templates/loader/_generate.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -53,4 +53,5 @@ Secondary entrypoint and primary loader for the common chart
{{- include "base.lib.resource.renderResources" (dict "rootContext" $ "class" "envoyFilters") | nindent 0 -}}
{{- include "base.lib.resource.renderResources" (dict "rootContext" $ "class" "datadogMetrics") | nindent 0 -}}
{{- include "base.lib.resource.renderResources" (dict "rootContext" $ "class" "requestAuthentications") | nindent 0 -}}
{{- include "base.lib.resource.renderResources" (dict "rootContext" $ "class" "persistentVolumes") | nindent 0 -}}
{{- end -}}
56 changes: 56 additions & 0 deletions base/templates/resources/persistentVolumes/_class.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{{- define "base.resources.persistentVolumes.class" -}}
{{- $rootContext := .rootContext -}}
{{- $object := .object -}}

{{- $labels := merge
($object.labels | default dict)
(include "base.lib.metadata.allLabels" (dict "rootContext" $rootContext "identifier" $object.identifier ) | fromYaml)
-}}
{{- $annotations := merge
($object.annotations | default dict)
(include "base.lib.metadata.globalAnnotations" $rootContext | fromYaml)
-}}
{{- if $object.retain }}
{{- $annotations = merge
(dict "helm.sh/resource-policy" "keep")
$annotations
-}}
{{- end -}}

---
kind: PersistentVolume
apiVersion: v1
metadata:
name: {{ $object.name }}
{{- with $labels }}
labels: {{- toYaml . | nindent 4 -}}
{{- end }}
{{- with $annotations }}
annotations: {{- toYaml . | nindent 4 -}}
{{- end }}
spec:
accessModes:
{{- if $object.accessModes }}
{{- $object.accessModes | toYaml | nindent 4 }}
{{- end }}
capacity:
storage: {{ $object.size }}
{{- if $object.storageClassName }}
storageClassName: {{ if (eq "-" $object.storageClassName) }}""{{- else }}{{ $object.storageClassName | quote }}{{- end }}
{{- end }}
{{- if $object.persistentVolumeReclaimPolicy }}
persistentVolumeReclaimPolicy: {{ $object.persistentVolumeReclaimPolicy }}
{{- end }}
{{- if $object.volumeMode }}
volumeMode: {{ $object.volumeMode }}
{{- end }}
{{- if $object.nodeAffinity }}
nodeAffinity:
{{- $object.nodeAffinity | toYaml | nindent 4 }}
{{- end }}
{{- if $object.csi }}
csi:
{{- $object.csi | toYaml | nindent 4 }}
{{- end }}

{{- end -}}
21 changes: 21 additions & 0 deletions base/templates/resources/persistentVolumes/_validate.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{{- define "base.resources.persistentVolumes.validate" -}}
{{- $rootContext := .rootContext -}}
{{- $object := .object -}}

{{- if not $object.accessModes }}
{{- fail (printf "accessModes is required (persistentVolume %s)" $object.identifier) }}
{{- end }}

{{- if not $object.size }}
{{- fail (printf "size is required (persistentVolume %s)" $object.identifier) }}
{{- end }}

{{- if and $object.csi (not $object.csi.driver) }}
{{- fail (printf "csi.driver is required (persistentVolume %s)" $object.identifier) }}
{{- end }}

{{- if and $object.csi (not $object.csi.volumeHandle) }}
{{- fail (printf "csi.volumeHandle is required (persistentVolume %s)" $object.identifier) }}
{{- end }}

{{- end -}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{- define "base.resources.persistentVolumes.valuesToObject" -}}
{{- include "base.lib.resource.defaultValuesToObject" . -}}
{{- .values | toYaml -}}
{{- end -}}
58 changes: 58 additions & 0 deletions base/templates/resources/persistentVolumes/configuration_test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
---
# yaml-language-server: $schema=https://raw.githubusercontent.com/helm-unittest/helm-unittest/main/schema/helm-testsuite.json
suite: persistentVolume configuration
templates:
- base.yaml
values:
- ../../../tests/overallValues.yaml
tests:
- it: persistentVolume enabled
set:
resources.persistentVolumes.main:
accessModes:
- ReadWriteOnce
csi:
driver: driver.longhorn.io
volumeHandle: toto42
storageClassName: toto
persistentVolumeReclaimPolicy: Reclaim
volumeMode: Filesystem
nodeAffinity:
required:
nodeSelectorTerms:
- matchExpressions:
- key: XXX
operator: Exists
documentSelector:
path: kind
value: PersistentVolume
asserts:
- equal:
path: metadata.name
value: RELEASE-NAME
- equal:
path: spec.accessModes
value:
- ReadWriteOnce
- equal:
path: spec.csi
value:
driver: driver.longhorn.io
volumeHandle: toto42
- equal:
path: spec.storageClassName
value: toto
- equal:
path: spec.persistentVolumeReclaimPolicy
value: Reclaim
- equal:
path: spec.volumeMode
value: Filesystem
- equal:
path: spec.nodeAffinity
value:
required:
nodeSelectorTerms:
- matchExpressions:
- key: XXX
operator: Exists
5 changes: 5 additions & 0 deletions base/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,11 @@ chartDefaults:
imageRepository:
interval: 1m0s

persistentVolume:
accessModes:
- ReadWriteOnce
size: 1Gi

persistentVolumeClaim:
accessMode: ReadWriteOnce
size: 1Gi
Expand Down