Skip to main content
This guide shows how to make a parent custom resource (WebApp) report the ready replica count of its child Deployment by copying the child’s ReadyReplicas into the parent status. This is a common pattern for Kubernetes operators built with controller-runtime. Summary of the change
  • Read the live child Deployment from the API server.
  • Copy dep.Status.ReadyReplicas into webapp.Status.ReadyReplicas.
  • Persist that observation with r.Status().Update(ctx, &webapp).
Why this matters
  • The status subresource represents the controller’s observed state. By updating status with the child’s observed values, users can inspect the parent resource alone to determine runtime health without inspecting children directly.
  • Use the status client (r.Status()) rather than r.Update to avoid unintentionally changing spec fields.
Compact, correct Reconcile implementation
Key flow and error handling details
  • The controller first reads the parent WebApp instance. If it no longer exists, reconciliation ends.
  • It then ensures the desired child Deployment and Service exist, creating them if necessary and setting owner references so garbage collection and controller-runtime can manage lifecycle.
  • The live child Deployment is read from the API server and acts as the source of truth for ReadyReplicas.
  • If reading the Deployment fails, the Reconcile returns the error, causing controller-runtime to retry. The controller cannot truthfully report readiness without reading the child.
  • Status updates must use the status client: r.Status().Update(...). The status subresource is for the controller’s observed state and is distinct from spec fields that users edit.
Always use r.Status().Update (the status client) to change .status fields. Using r.Update modifies the whole object and is intended for spec changes.
Quick reference: API methods used Run and validate locally
  1. Build and run your manager locally to validate compilation and behavior.
  2. Sample manager logs (trimmed):
  1. In another terminal, apply the sample WebApp and wait for the child Deployment to become available:
Expected result
  • The Deployment controller reports ReadyReplicas first. The WebApp controller reads that observed value and publishes it onto the parent WebApp status.
  • After reconciliation, webapp.status.readyReplicas should match the Deployment’s ready replica count (for example, 2), allowing users to inspect the parent resource alone for availability information.
Additional references Helper reminder

Watch Video

Practice Lab