feat(common): add hostPID support (#428)

**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?**
<!--
Please describe the tests that you ran to verify your changes. Provide
instructions so we can reproduce. Please also list any relevant details
for your test configuration
-->

**📃 Notes:**
<!-- Please enter any other relevant information here -->

**✔️ 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>
This commit is contained in:
Kjeld Schouten
2023-05-22 10:44:42 +02:00
committed by GitHub
parent 9c75239475
commit 1dcb382749
5 changed files with 102 additions and 1 deletions

View File

@@ -61,6 +61,7 @@ tests:
automountServiceAccountToken: false
runtimeClassName:
hostNetwork: false
hostPID: false
enableServiceLinks: false
restartPolicy: Always
dnsPolicy: ClusterFirst

View File

@@ -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

View File

@@ -15,4 +15,4 @@ maintainers:
name: common
sources: null
type: library
version: 12.9.1
version: 12.9.2

View File

@@ -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 -}}

View File

@@ -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)) }}