Writing a control loop
With a strategy for the in-memory representation of resource manifests in place, it is now much easier to begin writing the Operator's control loop. As described in previous chapters, this control loop comprises a core state reconciliation function call that is triggered by certain relevant cluster events. This function does not run continuously on a loop, but rather the main thread of the Operator will be continuously observing the cluster for those events to kick off a call to the state reconciliation function.
The empty Reconcile()
function has been scaffolded already by the Operator SDK in controllers/nginxoperator_controller.go
:
func (r *NginxOperatorReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Result, error) {
_ = log.FromContext(ctx)
// your logic here
return ctrl.Result{}, nil ...