<p>I'm looking to create a custom Kubernetes controller; I do mean <strong>controller</strong> in this case because I'm not looking to create a CRD, and thus, not an operator. Basically, it would be similar to the <a href="https://github.com/kubernetes-incubator/external-dns" rel="nofollow noreferrer">External DNS</a> project in that it watches annotations, and takes actions based on the presence / absence of that annotation.</p>

<p>Is there a a simple example of something like this? Most of the resources I find are for operators and creating CRDs, but my use case just involves looking at an annotation only.</p>

<p>I know this is an old question, but for anyone interested, here's a simple operator without CRD: <a href="https://github.com/busser/label-operator" rel="nofollow noreferrer">https://github.com/busser/label-operator</a></p>
<p>This operator uses only the Pod kind:</p>
<pre><code>// SetupWithManager sets up the controller with the Manager.
func (r *PodReconciler) SetupWithManager(mgr ctrl.Manager) error {
    return ctrl.NewControllerManagedBy(mgr).
        For(&amp;corev1.Pod{}). // &lt;&lt;&lt; here
        Complete(r)
}
</code></pre>
<p>Checks if there is a label on the pod and changes it if necessary:</p>
<pre><code>labelShouldBePresent := pod.Annotations[addPodNameLabelAnnotation] == &quot;true&quot;
labelIsPresent := pod.Labels[podNameLabel] == pod.Name

if labelShouldBePresent == labelIsPresent {
    // The desired state and actual state of the Pod are the same.
    // No further action is required by the operator at this moment.
    log.Info(&quot;no update required&quot;)
    return ctrl.Result{}, nil
}

if labelShouldBePresent {
    // If the label should be set but is not, set it.
    if pod.Labels == nil {
        pod.Labels = make(map[string]string)
    }
    pod.Labels[podNameLabel] = pod.Name
    log.Info(&quot;adding label&quot;)
} else {
    // If the label should not be set but is, remove it.
    delete(pod.Labels, podNameLabel)
    log.Info(&quot;removing label&quot;)
}
</code></pre>
<p>I hope I have helped in some way.</p>
