我的头盔图表中有一个PodSecurityPolicy
,并且想动态更改rule
上的runAsUser
。
启用{{- if .Values.global.psp.enabled }}
并且相应的values.yaml
包含以下内容:
runAsUnprivilegedUser: true
我希望模板能够像这样呈现:
runAsUser:
# Require the container to run without root privileges.
rule: 'MustRunAsNonRoot'
和另外为默认的非root用户提供UID
1000。
另一方面,如果将runAsUnprivilegedUser
设置为false
,我想拥有
runAsUser:
rule: 'RunAsAny'
受雇。
答案 0 :(得分:2)
我认为您可以使用条件语句来做到这一点
kind: PodSecurityPolicy
apiVersion: policy/v1beta1
metadata:
name: allow-flex-volumes
spec:
runAsUser:
# Require the container to run without root privileges.
{{- if and .Values.global.psp .Values.podSecurityContext}}
rule: 'MustRunAsNonRoot'
{{else }}
rule: 'RunAsAny'
{{end}}