<p>I'm just getting started with kubebuilder and Golang to extend our Kubernetes-cluster with a custom resource. I would love to do different things in the reconciler-function based on the event, that actually called it.</p>
<p>Was the resource created? Was it updated? Was it deleted?</p>
<p>Each of those events triggers the controller, however, I can't seem to find a possibility to see, which of those events actually happened. I can work around this issue by writing a reconciler like this:</p>
<pre class="lang-golang prettyprint-override"><code>func (r *ServiceDescriptorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
    service := &amp;batchv1.ServiceDescriptor{}
    if err := r.Get(context.TODO(), req.NamespacedName, service); err != nil &amp;&amp; errors.IsNotFound(err) {
        fmt.Println(&quot;Resource was not found -&gt; must have been deleted&quot;)
    else {
        fmt.Println(&quot;No errors found -&gt; Resource must have been created or updated&quot;)
    }
}
</code></pre>
<p>However, this feels oddly implicit and kinda hacky.</p>
<p>Is there a clean (possibly native) way of getting the event-type of the reconciler-call?</p>

Tim Hilt
<p>You won't be able to to that because this system was designed as level-based and it's not being triggered by individual events changes but rather by the actual cluster state that is being fetch from the apiserver.</p>
<p>Looking at <code>reconcile.go</code> you will notice in line <a href="https://github.com/kubernetes-sigs/controller-runtime/blob/b704f447ea7c8f7059c6665143a4aa1f6da28328/pkg/reconcile/reconcile.go#L84-L87" rel="noreferrer">#84</a> has this comment about it:</p>
<blockquote>
<p>Reconciliation is level-based, meaning action <strong>isn't driven off changes
in individual Events</strong>, but instead is driven by actual cluster state
read from the apiserver or a local cache. For example if responding to
a Pod Delete Event, the Request won't contain that a Pod was
deleted,instead the reconcile function observes this when reading the
cluster state and seeing the Pod as missing.</p>
</blockquote>
<p>And in line <a href="https://github.com/kubernetes-sigs/controller-runtime/blob/master/pkg/reconcile/reconcile.go#L44-L46" rel="noreferrer">#44</a>:</p>
<blockquote>
<p>Request contains the information necessary to reconcile a
Kubernetes object. This includes the information to uniquely
identify the object - its Name and Namespace. <strong>It does NOT contain
information about any specific Event or the object contents itself</strong>.</p>
</blockquote>
