deploymentForconstructs the desired Deployment for a givenWebApp.configMapForconstructs the desired ConfigMap for a givenWebApp.
Setup the controller
Ensure
SetupWithManager still registers the WebApp type:
Reconcile to build the desired ConfigMap, set the owner reference, and create it if it’s missing. The pattern:
- Fetch the
WebAppinstance. - Build the desired child:
desiredCM := configMapFor(&webapp). - Set the controller reference so garbage collection and ownership work.
- Attempt to
Getthe existing ConfigMap. - If
IsNotFound,Createthe ConfigMap. - Return real errors for other failures (so controller-runtime retries).
Always set the controller reference (owner reference) on child objects. Without it, the garbage collector won’t remove children when the parent is deleted, and the relationship won’t be visible to controller-runtime’s owner-based watches.
- If
controllerutil.SetControllerReferencefails, return the error to requeue reconciliation. - If
GetreturnsIsNotFound, create the resource; if theCreatecall fails, return the error so the reconcile is retried. - For any other
Geterror (API server unavailable, permission issues, etc.), return that error so controller-runtime retries. - This initial implementation implements a create-if-missing pattern. You can extend it later to add update-and-repair behavior for existing children (compare desired vs found and patch/update as needed).
ConfigMaps are namespaced. Always set the child’s
Namespace to the parent’s namespace and set the controller reference so garbage collection and ownership are handled correctly.