From 253eb6db9f5ce44ff9dd79d31a134161c343ed8e Mon Sep 17 00:00:00 2001 From: Stavros kois Date: Tue, 31 Jan 2023 17:00:22 +0200 Subject: [PATCH] termperiodsec --- .../tests/pod/priority_class_name_test.yaml | 13 +--- .../tests/pod/restart_policy_test.yaml | 9 --- .../tests/pod/scheduler_name_test.yaml | 9 --- .../pod/termination_grace_period_test.yaml | 72 +++++++++++++++++++ library/common/1.0.0/docs/controllers.md | 38 +++++----- .../1.0.0/templates/lib/controller/_pod.tpl | 3 + .../pod/_terminationGracePeriodSeconds.tpl | 29 ++++++++ library/common/1.0.0/values.yaml | 2 +- 8 files changed, 127 insertions(+), 48 deletions(-) create mode 100644 library/common-test/tests/pod/termination_grace_period_test.yaml create mode 100644 library/common/1.0.0/templates/lib/pod/_terminationGracePeriodSeconds.tpl diff --git a/library/common-test/tests/pod/priority_class_name_test.yaml b/library/common-test/tests/pod/priority_class_name_test.yaml index 82796787b3..de777c1fbb 100644 --- a/library/common-test/tests/pod/priority_class_name_test.yaml +++ b/library/common-test/tests/pod/priority_class_name_test.yaml @@ -31,9 +31,6 @@ tests: type: Deployment podSpec: {} asserts: - - documentIndex: *deploymentDoc - isKind: - of: Deployment - documentIndex: *deploymentDoc equal: path: spec.template.spec.priorityClassName @@ -51,9 +48,6 @@ tests: podSpec: priorityClassName: some-other-priority-class asserts: - - documentIndex: *deploymentDoc - isKind: - of: Deployment - documentIndex: *deploymentDoc equal: path: spec.template.spec.priorityClassName @@ -61,7 +55,7 @@ tests: - it: should pass with priorityClassName from "pod" with tpl set: - priorityclass: some-other-priority-class + priorityClass: some-other-priority-class podOptions: priorityClassName: some-priority-class controllers: @@ -70,11 +64,8 @@ tests: primary: true type: Deployment podSpec: - priorityClassName: "{{ .Values.priorityclass }}" + priorityClassName: "{{ .Values.priorityClass }}" asserts: - - documentIndex: *deploymentDoc - isKind: - of: Deployment - documentIndex: *deploymentDoc equal: path: spec.template.spec.priorityClassName diff --git a/library/common-test/tests/pod/restart_policy_test.yaml b/library/common-test/tests/pod/restart_policy_test.yaml index f52754316c..408b33ab72 100644 --- a/library/common-test/tests/pod/restart_policy_test.yaml +++ b/library/common-test/tests/pod/restart_policy_test.yaml @@ -32,9 +32,6 @@ tests: type: Deployment podSpec: {} asserts: - - documentIndex: *deploymentDoc - isKind: - of: Deployment - documentIndex: *deploymentDoc equal: path: spec.template.spec.restartPolicy @@ -52,9 +49,6 @@ tests: podSpec: restartPolicy: Always asserts: - - documentIndex: *deploymentDoc - isKind: - of: Deployment - documentIndex: *deploymentDoc equal: path: spec.template.spec.restartPolicy @@ -93,9 +87,6 @@ tests: podSpec: restartPolicy: "{{ .Values.policy }}" asserts: - - documentIndex: *jobDoc - isKind: - of: Job - documentIndex: *jobDoc equal: path: spec.template.spec.restartPolicy diff --git a/library/common-test/tests/pod/scheduler_name_test.yaml b/library/common-test/tests/pod/scheduler_name_test.yaml index c76bd3f87a..4e3238b49f 100644 --- a/library/common-test/tests/pod/scheduler_name_test.yaml +++ b/library/common-test/tests/pod/scheduler_name_test.yaml @@ -31,9 +31,6 @@ tests: type: Deployment podSpec: {} asserts: - - documentIndex: *deploymentDoc - isKind: - of: Deployment - documentIndex: *deploymentDoc equal: path: spec.template.spec.schedulerName @@ -51,9 +48,6 @@ tests: podSpec: schedulerName: some-other-scheduler asserts: - - documentIndex: *deploymentDoc - isKind: - of: Deployment - documentIndex: *deploymentDoc equal: path: spec.template.spec.schedulerName @@ -72,9 +66,6 @@ tests: podSpec: schedulerName: "{{ .Values.scheduler }}" asserts: - - documentIndex: *deploymentDoc - isKind: - of: Deployment - documentIndex: *deploymentDoc equal: path: spec.template.spec.schedulerName diff --git a/library/common-test/tests/pod/termination_grace_period_test.yaml b/library/common-test/tests/pod/termination_grace_period_test.yaml new file mode 100644 index 0000000000..a3331dd237 --- /dev/null +++ b/library/common-test/tests/pod/termination_grace_period_test.yaml @@ -0,0 +1,72 @@ +suite: pod termination grace period test +templates: + - common.yaml +tests: + - it: should pass with empty terminationGracePeriodSeconds + set: + podOptions: + terminationGracePeriodSeconds: "" + controllers: + controller-name1: + enabled: true + primary: true + type: DaemonSet + podSpec: {} + asserts: + - documentIndex: &daemonSetDoc 0 + isKind: + of: DaemonSet + - documentIndex: *daemonSetDoc + isNull: + path: spec.template.spec.terminationGracePeriodSeconds + + - it: should pass with terminationGracePeriodSeconds from "global" + set: + podOptions: + terminationGracePeriodSeconds: 100 + controllers: + controller-name1: + enabled: true + primary: true + type: DaemonSet + podSpec: {} + asserts: + - documentIndex: *daemonSetDoc + equal: + path: spec.template.spec.terminationGracePeriodSeconds + value: 100 + + - it: should pass with terminationGracePeriodSeconds from "pod" + set: + podOptions: + terminationGracePeriodSeconds: 100 + controllers: + controller-name1: + enabled: true + primary: true + type: DaemonSet + podSpec: + terminationGracePeriodSeconds: 150 + asserts: + - documentIndex: *daemonSetDoc + equal: + path: spec.template.spec.terminationGracePeriodSeconds + value: 150 + + - it: should pass with terminationGracePeriodSeconds from "pod" with tpl + set: + period: 125 + podOptions: + terminationGracePeriodSeconds: 50 + controllers: + controller-name1: + enabled: true + primary: true + type: DaemonSet + podSpec: + terminationGracePeriodSeconds: "{{ .Values.period }}" + asserts: + - documentIndex: *daemonSetDoc + equal: + path: spec.template.spec.terminationGracePeriodSeconds + value: 125 diff --git a/library/common/1.0.0/docs/controllers.md b/library/common/1.0.0/docs/controllers.md index a255ffcb34..5048138f19 100644 --- a/library/common/1.0.0/docs/controllers.md +++ b/library/common/1.0.0/docs/controllers.md @@ -1,23 +1,24 @@ # Controllers -| Key | Type | Required | Helm Template | Default | Description | -| :------------------------------------------------------- | :-------: | :------: | :-----------: | :---------------------------------------------------: | :----------------------------------------------------------------------------------- | -| controllers | `dict` | ❌ | ❌ | `{}` | Define the controllers as dicts | -| controllers.[controller-name] | `dict` | ✅ | ❌ | `{}` | Holds controller definition | -| controllers.[controller-name].enabled | `boolean` | ✅ | ❌ | `false` | Enables or Disables the controller | -| controllers.[controller-name].primary | `boolean` | ✅ | ❌ | `false` | Sets the controller as primary | -| controllers.[controller-name].labels | `dict` | ❌ | ✅ | `{}` | Additional labels for controller | -| controllers.[controller-name].annotations | `dict` | ❌ | ✅ | `{}` | Additional annotations for controller | -| controllers.[controller-name].type | `string` | ✅ | ❌ | `""` | Define the kind of the controller (Deployment, DaemonSet, StatefulSet, CronJob, Job) | -| controllers.[controller-name].podSpec | `dict` | ✅ | ❌ | `{}` | Holds the pod definition | -| controllers.[controller-name].podSpec.labels | `dict` | ❌ | ✅ | `{}` | Pod Labels | -| controllers.[controller-name].podSpec.annotations | `dict` | ❌ | ✅ | `{}` | Pod Annotations | -| controllers.[controller-name].podSpec.hostNetwork | `boolean` | ❌ | ❌ | `{{ .Values.podOptions.hostNetwork }}` (false) | Pod's hostNetwork | -| 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 | -| controllers.[controller-name].podSpec.hostname | `string` | ❌ | ✅ | `""` | Pod's hostname | +| Key | Type | Required | Helm Template | Default | Description | +| :------------------------------------------------------------------ | :-------: | :------: | :-----------: | :------------------------------------------------------------: | :----------------------------------------------------------------------------------- | +| controllers | `dict` | ❌ | ❌ | `{}` | Define the controllers as dicts | +| controllers.[controller-name] | `dict` | ✅ | ❌ | `{}` | Holds controller definition | +| controllers.[controller-name].enabled | `boolean` | ✅ | ❌ | `false` | Enables or Disables the controller | +| controllers.[controller-name].primary | `boolean` | ✅ | ❌ | `false` | Sets the controller as primary | +| controllers.[controller-name].labels | `dict` | ❌ | ✅ | `{}` | Additional labels for controller | +| controllers.[controller-name].annotations | `dict` | ❌ | ✅ | `{}` | Additional annotations for controller | +| controllers.[controller-name].type | `string` | ✅ | ❌ | `""` | Define the kind of the controller (Deployment, DaemonSet, StatefulSet, CronJob, Job) | +| controllers.[controller-name].podSpec | `dict` | ✅ | ❌ | `{}` | Holds the pod definition | +| controllers.[controller-name].podSpec.labels | `dict` | ❌ | ✅ | `{}` | Pod Labels | +| controllers.[controller-name].podSpec.annotations | `dict` | ❌ | ✅ | `{}` | Pod Annotations | +| controllers.[controller-name].podSpec.hostNetwork | `boolean` | ❌ | ❌ | `{{ .Values.podOptions.hostNetwork }}` (false) | Pod's hostNetwork | +| 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 | +| controllers.[controller-name].podSpec.hostname | `string` | ❌ | ✅ | `""` | Pod's hostname | +| controllers.[controller-name].podSpec.terminationGracePeriodSeconds | `int` | ❌ | ✅ | `{{ .Values.podOptions.terminationGracePeriodSeconds }}` (120) | Pod's terminationGracePeriodSeconds | --- @@ -62,4 +63,5 @@ controllers: schedulerName: some-scheduler priorityClassName: some-priority-class-name hostname: some-hostname + terminationGracePeriodSeconds: 100 ``` 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 938b2ddde5..354e146685 100644 --- a/library/common/1.0.0/templates/lib/controller/_pod.tpl +++ b/library/common/1.0.0/templates/lib/controller/_pod.tpl @@ -24,4 +24,7 @@ priorityClassName: {{ . }} {{- with (include "ix.v1.common.lib.pod.hostname" (dict "rootCtx" $rootCtx "objectData" $objectData)) }} hostname: {{ . }} {{- end }} + {{- with (include "ix.v1.common.lib.pod.terminationGracePeriodSeconds" (dict "rootCtx" $rootCtx "objectData" $objectData)) }} +terminationGracePeriodSeconds: {{ . }} + {{- end }} {{- end -}} diff --git a/library/common/1.0.0/templates/lib/pod/_terminationGracePeriodSeconds.tpl b/library/common/1.0.0/templates/lib/pod/_terminationGracePeriodSeconds.tpl new file mode 100644 index 0000000000..a0066411b6 --- /dev/null +++ b/library/common/1.0.0/templates/lib/pod/_terminationGracePeriodSeconds.tpl @@ -0,0 +1,29 @@ +{{/* Returns Termination Grace Period Seconds */}} +{{/* Call this template: +{{ include "ix.v1.common.lib.pod.terminationGracePeriodSeconds" (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.terminationGracePeriodSeconds" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $gracePeriod := "" -}} + + {{/* Initialize from the "global" option */}} + {{- with $rootCtx.Values.podOptions.terminationGracePeriodSeconds -}} + {{- $gracePeriod = . -}} + {{- end -}} + + {{/* Override with pod's option */}} + {{- with $objectData.podSpec.terminationGracePeriodSeconds -}} + {{- $gracePeriod = . -}} + {{- end -}} + + {{/* Expand tpl */}} + {{- if (kindIs "string" $gracePeriod) -}} + {{- $gracePeriod = tpl $gracePeriod $rootCtx -}} + {{- end -}} + + {{- $gracePeriod -}} +{{- end -}} diff --git a/library/common/1.0.0/values.yaml b/library/common/1.0.0/values.yaml index 7964edf448..deb6a80fd0 100644 --- a/library/common/1.0.0/values.yaml +++ b/library/common/1.0.0/values.yaml @@ -119,7 +119,7 @@ podOptions: tolerations: [] schedulerName: "" priorityClassName: "" - terminationGracePeriodSeconds: 30 + terminationGracePeriodSeconds: 120 # TODO: Add affinity # TODO: Add topologySpreadConstraints