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