<p>I'm checking if key resources.limits is provided in deployment kubernetes using OPA rego code. Below is the code, I'm trying to fetch the resources.limits key and it is always returning TRUE. Regardless of resources provided or not.</p>
<pre><code>    package resourcelimits

    violation[{&quot;msg&quot;: msg}] {
    some container; input.request.object.spec.template.spec.containers[container]
    not container.resources.limits.memory
    msg := &quot;Resources for the pod needs to be provided&quot;
</code></pre>

3br10ee032
<p>You can try something like this:</p>
<pre><code>import future.keywords.in

violation[{&quot;msg&quot;: msg}] {
    input.request.kind.kind == &quot;Deployment&quot;

    some container in input.request.object.spec.template.spec.containers
    not container.resources.limits.memory
    msg := sprintf(&quot;Container '%v/%v' does not have memory limits&quot;, [input.request.object.metadata.name, container.name])
}
</code></pre>
