Adding a reconciler#
Steps#
genop create step ProvisionDatabase \
--project postgresql \
--controller database \
--api-version v1alpha1 \
--kind DatabasePass --delete to add the step to the delete list instead of the apply
list. --condition-type is derived from the step name when omitted —
ProvisionDatabase becomes DatabaseProvisioned. A step name whose verb
genop does not recognise is rejected: pass --condition-type explicitly.
This generates the reconciler file in the apply/ or delete/
subdirectory and wires it into main.go. Steps live in phase
subdirectories under the kind directory, each forming its own Go package:
internal/controllers/v1alpha1/database/
├── controller.go # package database
├── metrics.go
├── webhook.go
├── suite_test.go
├── apply/
│ ├── suite_test.go # package apply
│ └── provisiondatabase.go
└── delete/
├── suite_test.go # package delete
└── deprovisiondatabase.goDeclarative equivalent. Add the step to the resource’s
apply:(ordelete:) list in.genop.yaml, then rungenop apply. List order is execution order. Unlike the CLI, the file does not derive the condition type for you, soconditionTypemust be written out:resources: - version: v1alpha1 kind: Database apply: - name: ProvisionDatabase conditionType: DatabaseProvisioned delete: - name: DeprovisionDatabase conditionType: DatabaseDeprovisioned
genop applycreates the step files that are missing and re-wiresmain.go; existing step files are never overwritten. Removing an entry is reported as drift and only deleted withgenop apply --prune.
Hooks#
A hook is a plain
func(ctx context.Context, logger logr.Logger, resource *<Kind>) error —
it has no conditionType and reports no status condition of its own.
Pre-reconcile hooks run at the top of every reconcile loop, before the
apply/delete steps; cleanup hooks run only when the resource is being
deleted, after the deletion steps, regardless of deletion policy (Retain
included).
genop create hook AddFinalizers \
--project postgresql --controller database --api-version v1alpha1 \
--kind Database --pre-reconcile
genop create hook ReleaseConnectionPool \
--project postgresql --controller database --api-version v1alpha1 \
--kind Database --cleanupExactly one of --pre-reconcile / --cleanup is required per invocation;
the same name may be added to both phases (one file, wired twice). List
order in .genop.yaml is execution order.
Declarative equivalent. List the hook under
preReconcileHooks:orcleanupHooks:on the resource in.genop.yamland rungenop apply:preReconcileHooks: - name: AddFinalizers cleanupHooks: - name: ReleaseConnectionPool
Full flag tables: see the
genop create step
and
genop create hook
reference.