<p>In kuberntes OPA gatekeeper, I need to determine if there is <code>volumeName</code> defined in PVC object, like below code:</p>
<pre class="lang-json prettyprint-override"><code>{
    &quot;apiVersion&quot;: &quot;v1&quot;,
    &quot;kind&quot;: &quot;PersistentVolumeClaim&quot;,
    &quot;metadata&quot;: {
        &quot;annotations&quot;: {},
        &quot;name&quot;: &quot;pvc-test-mxh&quot;,
        &quot;namespace&quot;: &quot;default&quot;
    },
    &quot;spec&quot;: {
        &quot;accessModes&quot;: [
            &quot;ReadWriteOnce&quot;
        ],
        &quot;resources&quot;: {
            &quot;requests&quot;: {
                &quot;storage&quot;: &quot;5Gi&quot;
            }
        },
        &quot;storageClassName&quot;: &quot;csi-disk&quot;,
        &quot;volumeName&quot;: &quot;mxh-test&quot;
    }
}
</code></pre>
<p>here, the <code>volumeName</code> is defined and belongs to normal behavior that it's allowed in the gatekeeper policy; while <code>volumeName</code> is missing here it would match to the violation. But how to write this policy, I tried <code>input.review.object.spec.volumeName == &quot;&quot;</code> or <code>count(input.review.object.spec.volumeName) &lt;= 0</code>, seems like it didn't work, anyone could help?</p>

Marco Mei
<p>You'd normally use the <code>not</code> keyword for that purpose:</p>
<pre><code>not input.review.object.spec.volumeName
</code></pre>
<p><code>not</code> will evaluate to true if <code>input.review.object.spec.volumeName</code> is undefined, and correspondingly to undefined if <code>input.review.object.spec.volumeName</code> is set.</p>
