From 1dcb382749fefe4ad7ed8b4c2bc713e39cdbc8c8 Mon Sep 17 00:00:00 2001 From: Kjeld Schouten Date: Mon, 22 May 2023 10:44:42 +0200 Subject: [PATCH] feat(common): add hostPID support (#428) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit **Description** It seems somehow this option was forgoten to be included. **โš™๏ธ Type of change** - [x] โš™๏ธ Feature/App addition - [ ] ๐Ÿช› Bugfix - [ ] โš ๏ธ Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] ๐Ÿ”ƒ Refactor of current code **๐Ÿงช How Has This Been Tested?** **๐Ÿ“ƒ Notes:** **โœ”๏ธ Checklist:** - [ ] โš–๏ธ My code follows the style guidelines of this project - [ ] ๐Ÿ‘€ I have performed a self-review of my own code - [ ] #๏ธโƒฃ I have commented my code, particularly in hard-to-understand areas - [ ] ๐Ÿ“„ I have made corresponding changes to the documentation - [ ] โš ๏ธ My changes generate no new warnings - [ ] ๐Ÿงช I have added tests to this description that prove my fix is effective or that my feature works - [ ] โฌ†๏ธ I increased versions for any altered app according to semantic versioning **โž• App addition** If this PR is an app addition please make sure you have done the following. - [ ] ๐Ÿชž I have opened a PR on [truecharts/containers](https://github.com/truecharts/containers) adding the container to TrueCharts mirror repo. - [ ] ๐Ÿ–ผ๏ธ I have added an icon in the Chart's root directory called `icon.png` --- _Please don't blindly check all the boxes. Read them and only check those that apply. Those checkboxes are there for the reviewer to see what is this all about and the status of this PR with a quick glance._ --------- Co-authored-by: Stavros Kois <47820033+stavros-k@users.noreply.github.com> --- .../tests/defaults/defaults-test.yaml | 1 + .../common-test/tests/pod/host_pid_test.yaml | 75 +++++++++++++++++++ library/common/Chart.yaml | 2 +- library/common/templates/lib/pod/_hostPID.tpl | 24 ++++++ .../common/templates/lib/workload/_pod.tpl | 1 + 5 files changed, 102 insertions(+), 1 deletion(-) create mode 100644 library/common-test/tests/pod/host_pid_test.yaml create mode 100644 library/common/templates/lib/pod/_hostPID.tpl diff --git a/library/common-test/tests/defaults/defaults-test.yaml b/library/common-test/tests/defaults/defaults-test.yaml index e082cf6e..b84bf963 100644 --- a/library/common-test/tests/defaults/defaults-test.yaml +++ b/library/common-test/tests/defaults/defaults-test.yaml @@ -61,6 +61,7 @@ tests: automountServiceAccountToken: false runtimeClassName: hostNetwork: false + hostPID: false enableServiceLinks: false restartPolicy: Always dnsPolicy: ClusterFirst diff --git a/library/common-test/tests/pod/host_pid_test.yaml b/library/common-test/tests/pod/host_pid_test.yaml new file mode 100644 index 00000000..a1fd850b --- /dev/null +++ b/library/common-test/tests/pod/host_pid_test.yaml @@ -0,0 +1,75 @@ +suite: pod hostpid test +templates: + - common.yaml +tests: + - it: should pass with hostpid disabled from "global" + set: + podOptions: + hostPID: false + workload: + workload-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: &deploymentDoc 0 + isKind: + of: Deployment + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.hostPID + value: false + + - it: should pass with hostpid enabled from "global" + set: + podOptions: + hostPID: true + workload: + workload-name1: + enabled: true + primary: true + type: Deployment + podSpec: {} + asserts: + - documentIndex: *deploymentDoc + isKind: + of: Deployment + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.hostPID + value: true + + - it: should pass with disabled hostpid from pod + set: + podOptions: + hostPID: true + workload: + workload-name1: + enabled: true + primary: true + type: Deployment + podSpec: + hostPID: false + asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.hostPID + value: false + + - it: should pass with enabled hostpid from pod + set: + podOptions: + hostPID: false + workload: + workload-name1: + enabled: true + primary: true + type: Deployment + podSpec: + hostPID: true + asserts: + - documentIndex: *deploymentDoc + equal: + path: spec.template.spec.hostPID + value: true diff --git a/library/common/Chart.yaml b/library/common/Chart.yaml index 7d39b5c1..62eb655a 100644 --- a/library/common/Chart.yaml +++ b/library/common/Chart.yaml @@ -15,4 +15,4 @@ maintainers: name: common sources: null type: library -version: 12.9.1 +version: 12.9.2 diff --git a/library/common/templates/lib/pod/_hostPID.tpl b/library/common/templates/lib/pod/_hostPID.tpl new file mode 100644 index 00000000..5859ec2a --- /dev/null +++ b/library/common/templates/lib/pod/_hostPID.tpl @@ -0,0 +1,24 @@ +{{/* Returns Host PID */}} +{{/* Call this template: +{{ include "tc.v1.common.lib.pod.hostPID" (dict "rootCtx" $ "objectData" $objectData) }} +rootCtx: The root context of the chart. +objectData: The object data to be used to render the Pod. +*/}} +{{- define "tc.v1.common.lib.pod.hostPID" -}} + {{- $rootCtx := .rootCtx -}} + {{- $objectData := .objectData -}} + + {{- $hostPID := false -}} + + {{/* Initialize from the "global" option */}} + {{- if (kindIs "bool" $rootCtx.Values.podOptions.hostPID) -}} + {{- $hostPID = $rootCtx.Values.podOptions.hostPID -}} + {{- end -}} + + {{/* Override with pods option */}} + {{- if (kindIs "bool" $objectData.podSpec.hostPID) -}} + {{- $hostPID = $objectData.podSpec.hostPID -}} + {{- end -}} + + {{- $hostPID -}} +{{- end -}} diff --git a/library/common/templates/lib/workload/_pod.tpl b/library/common/templates/lib/workload/_pod.tpl index 173b6149..722012d4 100644 --- a/library/common/templates/lib/workload/_pod.tpl +++ b/library/common/templates/lib/workload/_pod.tpl @@ -15,6 +15,7 @@ imagePullSecrets: {{- . | nindent 2 }} {{- end }} hostNetwork: {{ include "tc.v1.common.lib.pod.hostNetwork" (dict "rootCtx" $rootCtx "objectData" $objectData) }} +hostPID: {{ include "tc.v1.common.lib.pod.hostPID" (dict "rootCtx" $rootCtx "objectData" $objectData) }} enableServiceLinks: {{ include "tc.v1.common.lib.pod.enableServiceLinks" (dict "rootCtx" $rootCtx "objectData" $objectData) }} restartPolicy: {{ include "tc.v1.common.lib.pod.restartPolicy" (dict "rootCtx" $rootCtx "objectData" $objectData) }} {{- with (include "tc.v1.common.lib.pod.schedulerName" (dict "rootCtx" $rootCtx "objectData" $objectData)) }}