- The Reconcile request provides
req.NamespacedName(namespace + name). You must call the API to obtain the live object so your controller works against the current desired state. - Fetching the object lets you inspect
webapp.Spec, detect deletions, and avoid reconciling against stale or deleted resources.
- Obtain a logger from the context and store it in a real variable.
- Create an empty
webappvariable of typewebappv1.WebAppwhich the client will populate. - Call the reconciler’s
Getwithreq.NamespacedNameand a pointer to that variable. - Treat “not found” as a normal condition (object deleted after the request was queued) using
client.IgnoreNotFound(err). Return real errors for other failure cases.
Register the controller with the manager
- The generated
SetupWithManagerwires the reconciler to watchwebappv1.WebAppobjects. This ensures your reconciler gets called whenever the API server reports changes to those CRs.
Use
client.IgnoreNotFound(err) to treat deleted objects as a normal condition. That prevents your controller from requeuing errors for resources that no longer exist.- Run the full project build to catch missing imports, typos, and invalid syntax before running the controller:
- Start the manager and apply a sample WebApp manifest. Verify the controller logs show the expected fields (for example,
imageandreplicas) — that indicates the initial reconcile step is functioning.
- controller-runtime Reconcile docs: https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.23.3/pkg/reconcile
- Kubebuilder docs: https://book.kubebuilder.io/
- controller-runtime client API: https://pkg.go.dev/sigs.k8s.io/controller-runtime@v0.23.3/pkg/client