<p>I'm using the kubebuilder framework in my controller and I want to completely ignore events from a list of given system namespaces. I think predicates must be the best option for this, hence I have the following code</p>
<pre><code>...

WithEventFilter(predicate.Funcs{
            GenericFunc: func(e event.GenericEvent) bool {
                namespace := e.Object.GetNamespace()
                if _, ok := systemNs[namespace]; ok {
                    // ignore events from system namespaces
                    return false
                }

                return true
            },
}).
</code></pre>
<p>However I still receive events from all namespaces instead of just the ones which I allow.
Is this a correct and valid use case of predicates?</p>

<p>According to <a href="https://github.com/kubernetes-sigs/controller-runtime/blob/1e4d87c9f9e15e4a58bb81909dd787f30ede7693/pkg/handler/eventhandler.go#L52" rel="nofollow noreferrer">controller-runtime</a></p>
<blockquote>
<p>Generic is called in response to an event of an unknown type or a synthetic event triggered as a cron or external trigger request - e.g. reconcile Autoscaling, or a Webhook.</p>
</blockquote>
<p>Most of the time reconciliation gets triggered on <code>Create</code>, <code>Update</code>, or <code>Delete</code> so you need to filter on these events.</p>
<pre class="lang-golang prettyprint-override"><code>WithEventFilter(predicate.Funcs{
    CreateFunc: func(e event.CreateEvent) bool {
        namespace := e.Object.GetNamespace()
        if _, ok := systemNs[namespace]; ok {
            // ignore events from system namespaces
            return false
        }
        return true
    },
    UpdateFunc: func(e event.UpdateEvent) bool {
        namespace := e.ObjectNew.GetNamespace()
        if _, ok := systemNs[namespace]; ok {
            // ignore events from system namespaces
            return false
        }
        return true
    },
    DeleteFunc: func(e event.DeleteEvent) bool {
        namespace := e.Object.GetNamespace()
        if _, ok := systemNs[namespace]; ok {
            // ignore events from system namespaces
            return false
        }
        return true
    },
}).
</code></pre>
