<p>While deploying a Kubernetes application, I want to check if a particular PodSecurityPolicy exists, and if it does then skip installing it again.
I came across the <a href="https://helm.sh/docs/chart_template_guide/functions_and_pipelines/#using-the-lookup-function" rel="noreferrer">helm lookup function</a>, which allows us to check the existing K8 resources.
While I understand how to use this function to get all the resources of same kind, how do I use this function to check if a PodSecurityPolicy named &quot;myPodSecurityPolicy&quot; exists.</p>
<p>I tried something like this:</p>
<pre><code>{{- if ne (lookup &quot;v1&quot; &quot;PodSecurityPolicy&quot; &quot;&quot; &quot;&quot;) &quot;myPodSecurityPolicy&quot;}}
&lt;do my stuff&gt;

{{- end }}
</code></pre>
<p>But it doesn't look like I can compare it this way, seeing an error -</p>
<pre><code>error calling ne: invalid type for comparison
</code></pre>
<p>Any inputs? Thanks in advance.</p>

user4202236
<p>Please check your API version and PSP name. Lookup is returning a <code>map</code> or <code>nil</code> not a string and that's why you are getting that error. The following is working for me. For negative expression, just add <code>not</code> after <code>if</code>.</p>
<pre><code>{{- if (lookup &quot;policy/v1beta1&quot; &quot;PodSecurityPolicy&quot; &quot;&quot; &quot;example&quot;) }}
&lt;found: do your stuff&gt;

{{- end }}
</code></pre>
<p>HTH</p>
