mirror of
https://github.com/truenas/charts.git
synced 2024-04-21 15:21:45 +00:00
tolerations
This commit is contained in:
@@ -0,0 +1,201 @@
|
||||
suite: pod tolerations test
|
||||
templates:
|
||||
- common.yaml
|
||||
tests:
|
||||
- it: should pass with empty tolerations
|
||||
set:
|
||||
podOptions:
|
||||
tolerations: []
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
asserts:
|
||||
- documentIndex: &deploymentDoc 0
|
||||
isKind:
|
||||
of: Deployment
|
||||
- documentIndex: *deploymentDoc
|
||||
isNull:
|
||||
path: spec.template.spec.tolerations
|
||||
|
||||
- it: should pass with tolerations from "global"
|
||||
set:
|
||||
podOptions:
|
||||
tolerations:
|
||||
- operator: Exists
|
||||
effect: NoExecute
|
||||
tolerationSeconds: 3600
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec: {}
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: spec.template.spec.tolerations
|
||||
value:
|
||||
- operator: Exists
|
||||
effect: NoExecute
|
||||
tolerationSeconds: 3600
|
||||
|
||||
- it: should pass with tolerations from "pod"
|
||||
set:
|
||||
podOptions:
|
||||
tolerations:
|
||||
- operator: Exists
|
||||
effect: NoExecute
|
||||
tolerationSeconds: 3600
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
tolerations:
|
||||
- operator: Exists
|
||||
effect: NoSchedule
|
||||
tolerationSeconds: 1800
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: spec.template.spec.tolerations
|
||||
value:
|
||||
- operator: Exists
|
||||
effect: NoSchedule
|
||||
tolerationSeconds: 1800
|
||||
|
||||
- it: should pass with tolerations from "pod" with tpl
|
||||
set:
|
||||
op: Exists
|
||||
effect: NoSchedule
|
||||
op1: Equal
|
||||
effect1: PreferNoSchedule
|
||||
key: key
|
||||
value: value
|
||||
podOptions:
|
||||
tolerations:
|
||||
- operator: Exists
|
||||
effect: NoExecute
|
||||
tolerationSeconds: 3600
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
tolerations:
|
||||
- operator: "{{ .Values.op }}"
|
||||
effect: "{{ .Values.effect }}"
|
||||
tolerationSeconds: 1800
|
||||
- operator: "{{ .Values.op1 }}"
|
||||
effect: "{{ .Values.effect1 }}"
|
||||
tolerationSeconds: 1800
|
||||
key: "{{ .Values.key }}"
|
||||
value: "{{ .Values.value }}"
|
||||
asserts:
|
||||
- documentIndex: *deploymentDoc
|
||||
equal:
|
||||
path: spec.template.spec.tolerations
|
||||
value:
|
||||
- operator: Exists
|
||||
effect: NoSchedule
|
||||
tolerationSeconds: 1800
|
||||
- operator: Equal
|
||||
effect: PreferNoSchedule
|
||||
tolerationSeconds: 1800
|
||||
key: key
|
||||
value: value
|
||||
|
||||
# Failures
|
||||
- it: should fail with invalid operator
|
||||
set:
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
tolerations:
|
||||
- operator: Invalid
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Expected <tolerations.operator> to be one of [Exists, Equal] but got [Invalid]
|
||||
|
||||
- it: should fail with empty key and operator set to Equal
|
||||
set:
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
tolerations:
|
||||
- operator: Equal
|
||||
value: value
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Expected non-empty <tolerations.key> and <tolerations.value> with <tolerations.operator> set to [Equal]
|
||||
|
||||
- it: should fail with empty value and operator set to Equal
|
||||
set:
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
tolerations:
|
||||
- operator: Equal
|
||||
key: key
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Expected non-empty <tolerations.key> and <tolerations.value> with <tolerations.operator> set to [Equal]
|
||||
|
||||
- it: should fail with value set and operator set to Exists
|
||||
set:
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
tolerations:
|
||||
- operator: Exists
|
||||
value: value
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Expected empty <tolerations.value> with <tolerations.operator> set to [Exists], but got [value]
|
||||
|
||||
- it: should fail with effect set to Invalid
|
||||
set:
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
tolerations:
|
||||
- operator: Exists
|
||||
effect: Invalid
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Expected <tolerations.effect> to be one of [NoExecute, NoSchedule, PreferNoSchedule], but got [Invalid]
|
||||
|
||||
- it: should fail with tolerationSeconds not a number
|
||||
set:
|
||||
controllers:
|
||||
controller-name1:
|
||||
enabled: true
|
||||
primary: true
|
||||
type: Deployment
|
||||
podSpec:
|
||||
tolerations:
|
||||
- operator: Exists
|
||||
tolerationSeconds: not-a-number
|
||||
asserts:
|
||||
- failedTemplate:
|
||||
errorMessage: Expected <tolerations.tolerationSeconds> to be a number, but got [not-a-number]
|
||||
@@ -35,6 +35,12 @@
|
||||
| controllers.[controller-name].podSpec.hostAliases.hostnames | `list` | ❌ | ❌ | | Hostnames for the `ip` in hosts aliases |
|
||||
| controllers.[controller-name].podSpec.hostAliases.hostnames.[host-name] | `string` | ❌ | ✅ | | [Value] for `hostnames` for the `ip` in hosts aliases |
|
||||
| controllers.[controller-name].podSpec.dnsPolicy | `string` | ❌ | ✅ | `{{ .Values.podOptions.dnsPolicy }}` (ClusterFirst) | Pod's DNS Policy (ClusterFirst, ClusterFirstWithHostNet, Default, None). |
|
||||
| controllers.[controller-name].podSpec.tolerations | `list` | ❌ | ❌ | `{{ .Values.podOptions.tolerations }}` ([]) | Pod's Tolerations |
|
||||
| controllers.[controller-name].podSpec.tolerations.operator | `string` | ✅ | ✅ | | Toleration's `operator` (Equal, Exists) |
|
||||
| controllers.[controller-name].podSpec.tolerations.key | `string` | ❌/✅ | ✅ | | Toleration's `key`. Required only when `operator` = `Equal` |
|
||||
| controllers.[controller-name].podSpec.tolerations.value | `string` | ❌/✅ | ✅ | | Toleration's `value`. Required only when `operator` = `Equal` |
|
||||
| controllers.[controller-name].podSpec.tolerations.effect | `string` | ❌ | ✅ | | Toleration's `effect`.(NoExecute, NoSchedule, PreferNoSchedule) |
|
||||
| controllers.[controller-name].podSpec.tolerations.tolerationSeconds | `int` | ❌ | ❌ | | Toleration's `tolerationSeconds`. |
|
||||
|
||||
---
|
||||
|
||||
@@ -113,4 +119,8 @@ controllers:
|
||||
- name: ndots
|
||||
value: "2"
|
||||
- name: edns0
|
||||
tolerations:
|
||||
- operator: Exists
|
||||
effect: NoExecute
|
||||
tolerationSeconds: 3600
|
||||
```
|
||||
|
||||
@@ -20,7 +20,7 @@ schedulerName: {{ . }}
|
||||
{{- end -}}
|
||||
{{- with (include "ix.v1.common.lib.pod.priorityClassName" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}
|
||||
priorityClassName: {{ . }}
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
{{- with (include "ix.v1.common.lib.pod.nodeSelector" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
nodeSelector:
|
||||
{{- . | nindent 2 }}
|
||||
@@ -35,5 +35,9 @@ hostname: {{ . }}
|
||||
{{- include "ix.v1.common.lib.pod.dns" (dict "rootCtx" $rootCtx "objectData" $objectData) -}}
|
||||
{{- with (include "ix.v1.common.lib.pod.terminationGracePeriodSeconds" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}
|
||||
terminationGracePeriodSeconds: {{ . }}
|
||||
{{- end }}
|
||||
{{- end -}}
|
||||
{{- with (include "ix.v1.common.lib.pod.tolerations" (dict "rootCtx" $rootCtx "objectData" $objectData) | trim) }}
|
||||
tolerations:
|
||||
{{- . | nindent 2 }}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
{{/* Returns Tolerations */}}
|
||||
{{/* Call this template:
|
||||
{{ include "ix.v1.common.lib.pod.tolerations" (dict "rootCtx" $ "objectData" $objectData) }}
|
||||
rootCtx: The root context of the template. It is used to access the global context.
|
||||
objectData: The object data to be used to render the Pod.
|
||||
*/}}
|
||||
{{- define "ix.v1.common.lib.pod.tolerations" -}}
|
||||
{{- $rootCtx := .rootCtx -}}
|
||||
{{- $objectData := .objectData -}}
|
||||
|
||||
{{- $tolerations := list -}}
|
||||
|
||||
{{/* Initialize from the "global" option */}}
|
||||
{{- with $rootCtx.Values.podOptions.tolerations -}}
|
||||
{{- $tolerations = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{/* Override from the "pod" option */}}
|
||||
{{- with $objectData.podSpec.tolerations -}}
|
||||
{{- $tolerations = . -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- range $tolerations -}}
|
||||
{{/* Expand values */}}
|
||||
{{- $operator := (tpl (.operator | default "") $rootCtx) -}}
|
||||
{{- $key := (tpl (.key | default "") $rootCtx) -}}
|
||||
{{- $value := (tpl (.value | default "") $rootCtx) -}}
|
||||
{{- $effect := (tpl (.effect | default "") $rootCtx) -}}
|
||||
{{- $tolSeconds := .tolerationSeconds -}}
|
||||
|
||||
{{- if not (mustHas $operator (list "Exists" "Equal")) -}}
|
||||
{{- fail (printf "Expected <tolerations.operator> to be one of [Exists, Equal] but got [%s]" $operator) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and (eq $operator "Equal") (or (not $key) (not $value)) -}}
|
||||
{{- fail "Expected non-empty <tolerations.key> and <tolerations.value> with <tolerations.operator> set to [Equal]" -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and (eq $operator "Exists") $value -}}
|
||||
{{- fail (printf "Expected empty <tolerations.value> with <tolerations.operator> set to [Exists], but got [%s]" $value) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and $effect (not (mustHas $effect (list "NoExecute" "NoSchedule" "PreferNoSchedule"))) -}}
|
||||
{{- fail (printf "Expected <tolerations.effect> to be one of [NoExecute, NoSchedule, PreferNoSchedule], but got [%s]" $effect) -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- if and (not (kindIs "invalid" $tolSeconds)) (not (mustHas (kindOf $tolSeconds) (list "int" "float64"))) -}}
|
||||
{{- fail (printf "Expected <tolerations.tolerationSeconds> to be a number, but got [%s]" $tolSeconds) -}}
|
||||
{{- end }}
|
||||
- operator: {{ $operator }}
|
||||
{{- with $key }}
|
||||
key: {{ $key }}
|
||||
{{- end -}}
|
||||
{{- with $effect }}
|
||||
effect: {{ $effect }}
|
||||
{{- end -}}
|
||||
{{- with $value }}
|
||||
value: {{ . }}
|
||||
{{- end -}}
|
||||
{{- if (mustHas (kindOf $tolSeconds) (list "int" "float64")) }}
|
||||
tolerationSeconds: {{ $tolSeconds }}
|
||||
{{- end -}}
|
||||
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
Reference in New Issue
Block a user