diff --git a/library/common-test/tests/pod/priority_class_name_test.yaml b/library/common-test/tests/pod/priority_class_name_test.yaml new file mode 100644 index 0000000000..bb69913178 --- /dev/null +++ b/library/common-test/tests/pod/priority_class_name_test.yaml @@ -0,0 +1,81 @@ +suite: pod priority class name test +templates: + - common.yaml +tests: + - it: should pass with empty priorityClassName + set: + podOptions: + priorityClassName: "" + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + isNull: + path: spec.template.spec.priorityClassName + + - it: should pass with priorityClassName from "global" + set: + podOptions: + priorityClassName: some-priority-class + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.priorityClassName + value: some-priority-class + + - it: should pass with priorityClassName from "pod" + set: + podOptions: + priorityClassName: some-priority-class + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + priorityClassName: some-other-priority-class + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.priorityClassName + value: some-other-priority-class + + - it: should pass with priorityClassName from "pod" with tpl + set: + priorityclass: some-other-priority-class + podOptions: + priorityClassName: some-priority-class + controllers: + controller-name1: + enabled: true + primary: true + type: Deployment + podSpec: + priorityClassName: "{{ .Values.priorityclass }}" + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.priorityClassName + value: some-other-priority-class diff --git a/library/common/1.0.0/docs/controllers.md b/library/common/1.0.0/docs/controllers.md index 795a2db88f..49c26bf402 100644 --- a/library/common/1.0.0/docs/controllers.md +++ b/library/common/1.0.0/docs/controllers.md @@ -16,6 +16,7 @@ | controllers.[controller-name].podSpec.enableServiceLinks | `boolean` | ❌ | ❌ | `{{ .Values.podOptions.enableServiceLinks }}` (false) | Pod's enableServiceLinks | | controllers.[controller-name].podSpec.restartPolicy | `string` | ❌ | ✅ | `{{ .Values.podOptions.restartPolicy }}` (Always) | Pod's restartPolicy. (Always, Never, OnFailure) | | controllers.[controller-name].podSpec.schedulerName | `string` | ❌ | ✅ | `{{ .Values.podOptions.schedulerName }}` ("") | Pod's schedulerName | +| controllers.[controller-name].podSpec.priorityClassName | `string` | ❌ | ✅ | `{{ .Values.podOptions.priorityClassName }}` ("") | Pod's priorityClassName | --- @@ -58,4 +59,5 @@ controllers: hostNetwork: false enableServiceLinks: false schedulerName: some-scheduler + priorityClassName: some-priority-class-name ``` diff --git a/library/common/1.0.0/templates/lib/controller/_pod.tpl b/library/common/1.0.0/templates/lib/controller/_pod.tpl index e06ce86339..b40458f46a 100644 --- a/library/common/1.0.0/templates/lib/controller/_pod.tpl +++ b/library/common/1.0.0/templates/lib/controller/_pod.tpl @@ -14,7 +14,10 @@ imagePullSecrets: hostNetwork: {{ include "ix.v1.common.lib.pod.hostNetwork" (dict "rootCtx" $rootCtx "objectData" $objectData) }} enableServiceLinks: {{ include "ix.v1.common.lib.pod.enableServiceLinks" (dict "rootCtx" $rootCtx "objectData" $objectData) }} restartPolicy: {{ include "ix.v1.common.lib.pod.restartPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) }} - {{- with include "ix.v1.common.lib.pod.schedulerName" (dict "rootCtx" $rootCtx "objectData" $objectData) }} + {{- with (include "ix.v1.common.lib.pod.schedulerName" (dict "rootCtx" $rootCtx "objectData" $objectData)) }} schedulerName: {{ . }} + {{- end -}} + {{- with (include "ix.v1.common.lib.pod.priorityClassName" (dict "rootCtx" $rootCtx "objectData" $objectData)) }} +priorityClassName: {{ . }} {{- end }} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/pod/_priorityClassName.tpl b/library/common/1.0.0/templates/lib/pod/_priorityClassName.tpl new file mode 100644 index 0000000000..2de9c542f3 --- /dev/null +++ b/library/common/1.0.0/templates/lib/pod/_priorityClassName.tpl @@ -0,0 +1,24 @@ +{{/* Returns Priority Class Name */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.pod.priorityClassName" (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.priorityClassName" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $className := "" -}} + + {{/* Initialize from the "global" option */}} + {{- with $rootCtx.Values.podOptions.priorityClassName -}} + {{- $className = tpl . $rootCtx -}} + {{- end -}} + + {{/* Override with pod's option */}} + {{- with $objectData.podSpec.priorityClassName -}} + {{- $className = tpl . $rootCtx -}} + {{- end -}} + + {{- $className -}} +{{- end -}}