k8s-controller-reconcile
Installation
SKILL.md
Kubernetes Controller Reconciliation
Core reconciliation patterns for building reliable Kubernetes controllers with controller-runtime. Draws from battle-tested patterns in Envoy Gateway and Envoy AI Gateway.
Level-Triggered Reconciliation
The golden rule: reconciliation must be idempotent and level-triggered, not edge-triggered. Your Reconcile() function should derive the desired state from the current world state, not from the event that triggered it.
func (r *MyReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
// 1. Fetch the current state of the object
var obj myv1.MyResource
if err := r.client.Get(ctx, req.NamespacedName, &obj); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
}
// 2. Compute desired state from CURRENT world state (not from the event)
desired := r.computeDesiredState(ctx, &obj)