<p>I'm having a <code>PodSecurityPolicy</code> in my Helm Charts and would like to dynamically change the <code>rule</code> on <code>runAsUser</code>.  </p>

<p>When  <code>{{- if .Values.global.psp.enabled }}</code> is enabled and the respectrive <code>values.yaml</code> contains something like: </p>

<pre><code>runAsUnprivilegedUser: true 
</code></pre>

<p>I'm expecting the templates to be rendered like that: </p>

<pre><code>runAsUser:
    # Require the container to run without root privileges.
    rule: 'MustRunAsNonRoot'
</code></pre>

<p>and <strong>additionally</strong> providing a default non-root user with say <code>UID</code> 1000. </p>

<p>If, on the other hand, <code>runAsUnprivilegedUser</code> is set to <code>false</code>, I'd like to have </p>

<pre><code>runAsUser:
    rule: 'RunAsAny'
</code></pre>

<p>employed. </p>

brandshaide
<p>I think you can do that with conditional statement</p>

<pre><code>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}}
</code></pre>
