mirror of
https://github.com/truenas/charts.git
synced 2024-04-21 15:21:45 +00:00
statefulset spec
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
suite: statefulset metadata test
|
||||
templates:
|
||||
- common.yaml
|
||||
chart:
|
||||
appVersion: &appVer v9.9.9
|
||||
tests:
|
||||
- it: should pass with statefulset created with labels and annotations
|
||||
set:
|
||||
label1: label1
|
||||
label2: global_label2
|
||||
annotation1: annotation1
|
||||
annotation2: global_annotation2
|
||||
global:
|
||||
labels:
|
||||
g_label1: global_label1
|
||||
g_label2: "{{ .Values.label2 }}"
|
||||
annotations:
|
||||
g_annotation1: global_annotation1
|
||||
g_annotation2: "{{ .Values.annotation2 }}"
|
||||
controllers:
|
||||
controller-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: StatefulSet
|
||||
labels:
|
||||
label1: "{{ .Values.label1 }}"
|
||||
label2: label2
|
||||
annotations:
|
||||
annotation1: "{{ .Values.annotation1 }}"
|
||||
annotation2: annotation2
|
||||
asserts:
|
||||
- documentIndex: &statefulSetDoc 0
|
||||
isKind:
|
||||
of: StatefulSet
|
||||
- documentIndex: *statefulSetDoc
|
||||
equal:
|
||||
path: metadata.annotations
|
||||
value:
|
||||
annotation1: annotation1
|
||||
annotation2: annotation2
|
||||
g_annotation1: global_annotation1
|
||||
g_annotation2: global_annotation2
|
||||
- documentIndex: *statefulSetDoc
|
||||
equal:
|
||||
path: metadata.labels
|
||||
value:
|
||||
app: common-test-1.0.0
|
||||
release: release-name
|
||||
helm-revision: 0
|
||||
helm.sh/chart: common-test-1.0.0
|
||||
app.kubernetes.io/managed-by: Helm
|
||||
app.kubernetes.io/version: v9.9.9
|
||||
g_label1: global_label1
|
||||
g_label2: global_label2
|
||||
label1: label1
|
||||
label2: label2
|
||||
@@ -0,0 +1,49 @@
|
||||
suite: statefulset spec test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should pass with controller enabled
|
||||
set:
|
||||
controllers:
|
||||
controller-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: StatefulSet
|
||||
asserts:
|
||||
- documentIndex: &statefulSetDoc 0
|
||||
isKind:
|
||||
of: StatefulSet
|
||||
- documentIndex: *statefulSetDoc
|
||||
isAPIVersion:
|
||||
of: apps/v1
|
||||
- documentIndex: *statefulSetDoc
|
||||
isSubset:
|
||||
path: spec
|
||||
content:
|
||||
revisionHistoryLimit: 3
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
|
||||
- it: should apply spec correctly
|
||||
set:
|
||||
controllers:
|
||||
controller-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: StatefulSet
|
||||
revisionHistoryLimit: 4
|
||||
strategy: RollingUpdate
|
||||
rollingUpdate:
|
||||
partition: 5
|
||||
maxUnavailable: 5
|
||||
asserts:
|
||||
- documentIndex: *statefulSetDoc
|
||||
isSubset:
|
||||
path: spec
|
||||
content:
|
||||
revisionHistoryLimit: 4
|
||||
updateStrategy:
|
||||
type: RollingUpdate
|
||||
rollingUpdate:
|
||||
partition: 5
|
||||
maxUnavailable: 5
|
||||
@@ -0,0 +1,28 @@
|
||||
suite: statefulset validation test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should fail with invalid strategy
|
||||
set:
|
||||
controllers:
|
||||
controller-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: StatefulSet
|
||||
strategy: not-a-strategy
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: StatefulSet - Expected <strategy> to be one of [OnDelete, RollingUpdate], but got [not-a-strategy]
|
||||
|
||||
- it: should fail with rollingUpdate not a dict
|
||||
set:
|
||||
controllers:
|
||||
controller-name:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: StatefulSet
|
||||
strategy: RollingUpdate
|
||||
rollingUpdate: "not a dict"
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: StatefulSet - Expected <rollingUpdate> to be a dictionary, but got [string]
|
||||
@@ -0,0 +1,38 @@
|
||||
{{/* StatefulSet Class */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.class.deployment" (dict "objectData" $objectData "rootCtx" $) }}
|
||||
|
||||
rootCtx: The root context of the template. It is used to access the global context.
|
||||
objectData:
|
||||
name: The name of the configmap.
|
||||
labels: The labels of the configmap.
|
||||
annotations: The annotations of the configmap.
|
||||
replicas: The number of replicas.
|
||||
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
|
||||
strategy: The deployment strategy.
|
||||
*/}}
|
||||
|
||||
{{- define "ix.v1.common.class.statefulset" -}}
|
||||
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
{{- include "ix.v1.common.lib.controller.statefulsetValidation" (dict "objectData" $objectData) }}
|
||||
---
|
||||
apiVersion: apps/v1
|
||||
kind: StatefulSet
|
||||
metadata:
|
||||
name: {{ $objectData.name }}
|
||||
{{- $labels := (mustMerge ($objectData.labels | default dict) (include "ix.v1.common.lib.metadata.allLabels" $rootCtx | fromYaml)) -}}
|
||||
{{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "labels" $labels) | trim) }}
|
||||
labels:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end -}}
|
||||
{{- $annotations := (mustMerge ($objectData.annotations | default dict) (include "ix.v1.common.lib.metadata.allAnnotations" $rootCtx | fromYaml)) -}}
|
||||
{{- with (include "ix.v1.common.lib.metadata.render" (dict "rootCtx" $rootCtx "annotations" $annotations) | trim) }}
|
||||
annotations:
|
||||
{{- . | nindent 4 }}
|
||||
{{- end }}
|
||||
spec:
|
||||
{{- include "ix.v1.common.lib.controller.statefulsetSpec" (dict "rootCtx" $rootCtx "objectData" $objectData) | nindent 2 }}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
@@ -13,7 +13,10 @@ objectData:
|
||||
revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }}
|
||||
updateStrategy:
|
||||
type: {{ $objectData.strategy | default "RollingUpdate" }}
|
||||
{{- if and (eq $objectData.strategy "RollingUpdate") $objectData.rollingUpdate }}
|
||||
{{- if and
|
||||
(eq $objectData.strategy "RollingUpdate")
|
||||
$objectData.rollingUpdate
|
||||
(or $objectData.rollingUpdate.maxUnavailable $objectData.rollingUpdate.maxSurge) }}
|
||||
rollingUpdate:
|
||||
{{- with $objectData.rollingUpdate.maxUnavailable }}
|
||||
maxUnavailable: {{ .}}
|
||||
|
||||
@@ -14,7 +14,10 @@ replicas: {{ $objectData.replicas | default 1 }}
|
||||
revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }}
|
||||
strategy:
|
||||
type: {{ $objectData.strategy | default "Recreate" }}
|
||||
{{- if and (eq $objectData.strategy "RollingUpdate") $objectData.rollingUpdate }}
|
||||
{{- if and
|
||||
(eq $objectData.strategy "RollingUpdate")
|
||||
$objectData.rollingUpdate
|
||||
(or $objectData.rollingUpdate.maxUnavailable $objectData.rollingUpdate.maxSurge) }}
|
||||
rollingUpdate:
|
||||
{{- with $objectData.rollingUpdate.maxUnavailable }}
|
||||
maxUnavailable: {{ .}}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
{{/* StatefulSet Spec */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.controller.statefulsetSpec" (dict "objectData" $objectData "rootCtx" $rootCtx) -}}
|
||||
rootCtx: The root context of the template. It is used to access the global context.
|
||||
objectData:
|
||||
replicas: The number of replicas.
|
||||
revisionHistoryLimit: The number of old ReplicaSets to retain to allow rollback.
|
||||
strategy: The statefulset strategy to use to replace existing pods with new ones.
|
||||
*/}}
|
||||
{{- define "ix.v1.common.lib.controller.statefulsetSpec" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
replicas: {{ $objectData.replicas | default 1 }}
|
||||
revisionHistoryLimit: {{ $objectData.revisionHistoryLimit | default 3 }}
|
||||
serviceName: {{ $objectData.name }}
|
||||
updateStrategy:
|
||||
type: {{ $objectData.strategy | default "RollingUpdate" }}
|
||||
{{- if and
|
||||
(eq $objectData.strategy "RollingUpdate")
|
||||
$objectData.rollingUpdate
|
||||
(or $objectData.rollingUpdate.maxUnavailable $objectData.rollingUpdate.partition) }}
|
||||
rollingUpdate:
|
||||
{{- with $objectData.rollingUpdate.maxUnavailable }}
|
||||
maxUnavailable: {{ .}}
|
||||
{{- end -}}
|
||||
{{- with $objectData.rollingUpdate.partition }}
|
||||
partition: {{ . }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
@@ -121,3 +121,33 @@ objectData:
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* StatefulSet Validation */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.controller.statefulsetValidation" (dict "objectData" $objectData) -}}
|
||||
rootCtx: The root context of the template. It is used to access the global context.
|
||||
objectData:
|
||||
strategy: The strategy of the object.
|
||||
rollingUpdate: The rollingUpdate of the object.
|
||||
*/}}
|
||||
{{- define "ix.v1.common.lib.controller.statefulsetValidation" -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- if $objectData.strategy -}}
|
||||
{{- $strategy := $objectData.strategy -}}
|
||||
|
||||
{{- if not (mustHas $strategy (list "OnDelete" "RollingUpdate")) -}}
|
||||
{{- fail (printf "StatefulSet - Expected <strategy> to be one of [OnDelete, RollingUpdate], but got [%v]" $strategy) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
|
||||
{{- if $objectData.rollingUpdate -}}
|
||||
{{- $rollUp := $objectData.rollingUpdate -}}
|
||||
|
||||
{{- if and $rollUp (not (kindIs "map" $rollUp)) -}}
|
||||
{{- fail (printf "StatefulSet - Expected <rollingUpdate> to be a dictionary, but got [%v]" (kindOf $rollUp)) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -32,6 +32,7 @@
|
||||
{{- if eq $objectData.type "Deployment" -}}
|
||||
{{- include "ix.v1.common.class.deployment" (dict "objectData" $objectData "rootCtx" $) -}}
|
||||
{{- else if eq $objectData.type "StatefulSet" -}}
|
||||
{{- include "ix.v1.common.class.statefulset" (dict "objectData" $objectData "rootCtx" $) -}}
|
||||
{{- else if eq $objectData.type "DaemonSet" -}}
|
||||
{{- include "ix.v1.common.class.daemonset" (dict "objectData" $objectData "rootCtx" $) -}}
|
||||
{{- else if eq $objectData.type "Job" -}}
|
||||
|
||||
Reference in New Issue
Block a user