Skip to content
CLI Reference

CLI Reference

All commands read .genop.yaml from the current directory (or the nearest parent that contains one). genop apply is the sole generator: every genop create command validates its arguments, updates .genop.yaml, and finishes by running apply itself — there is no separate step where you write the topology and remember to apply it, so the file and the generated code never drift apart because a step was skipped.

genop apply — Regenerate scaffolding from .genop.yaml

Reads the topology and brings the repository back in line with it. This is the command every genop create subcommand runs internally, and the one to reach for directly when you have hand-edited .genop.yaml or lost a generated file.

Scaffolded source files that already exist are never overwritten — delete one first if you want it regenerated. Packaging is different: everything under config/kustomize/base and config/helm is rewritten from the topology on every run, and manifests the topology no longer calls for are deleted. See Drift policy.

For each operator, apply runs ProjectBuilder → ApiBuilder → StepBuilder, then finishes with the packaging pass that regenerates the manifests. That last pass is shared with every genop create command, so a project assembled one resource at a time and one rebuilt by a single apply end up byte-identical.

genop apply
FlagShortDescription
--pruneDelete scaffolding the topology no longer declares, instead of just reporting it (mutually exclusive with --no-drift-check)
--no-drift-checkSkip the post-apply drift check (env: GENOP_NO_DRIFT_CHECK)
--verbose-vEnable verbose logging

--prune is the batch equivalent of genop delete: useful after hand-editing .genop.yaml to remove several entries at once. See genop delete for removing one entry at a time.

--genop-version / --genop-testing-version are accepted here but inert: plain apply never rewrites an existing go.mod, so they only have an effect under --init-repo (or if go.mod is missing and apply recreates it).

Typical use cases:

  • You cloned a repository and want to regenerate the scaffolding from the topology.
  • You deleted a generated file by mistake and want it back without bootstrapping again.
  • You added an entry to .genop.yaml by hand and want the corresponding files created.

genop apply --init-repo — Bootstrap a new repository

Creates the full repository structure: repo-level scaffolding (go.mod, Makefile, .gitignore, .golangci.yml), .genop.yaml, then runs apply — which, with no operator declared yet, produces an empty but buildable repository. Add the first project with genop create project.

Fails immediately if .genop.yaml already exists — use plain genop apply to rebuild, or genop create project to add a project to a repository that already has one.

genop apply --init-repo --module gitlab.com/acme.io/my-operators --genop-version v0.1.0 --disable-license
FlagShortDescription
--moduleGo module path, e.g. gitlab.com/acme.io/my-operators (required)
--licensePath to a LICENSE file; its contents are prepended to every generated Go file as a /* ... */ block comment
--disable-licenseOpt out of license headers (mutually exclusive with --license)
--genop-versiongenop-runtime version written into go.mod (required with --init-repo)
--genop-testing-versiongenop-testing version written into go.mod (defaults to a pinned release)
--verbose-vEnable verbose logging

genop create project — Add a project to an existing repository

Registers a new project in the topology, then applies: scaffolds its Helm chart, README.md, DEVELOPMENT.md, e2e suite and Makefile targets. Requires .genop.yaml to exist — bootstrap with genop apply --init-repo first if this is a brand-new repository.

The project starts with no controller and no resource. Add them with genop create api.

genop create project mongodb --api-group mongodb.acme.io

# With an explicit path (when the directory name differs from the project name)
genop create project mongodb --path operators/mongodb --api-group mongodb.acme.io --helm
FlagShortRequiredDescription
--api-group-g✓The API group, e.g. {project}.acme.io
--pathFilesystem path relative to the repo root (defaults to the project name)
--kustomizeEnable kustomize packaging (default true)
--helmEnable helm packaging (default false)
--no-drift-checkSkip the post-apply drift check (env: GENOP_NO_DRIFT_CHECK)
--verbose-vEnable verbose logging

At least one of --kustomize / --helm must stay enabled.

genop create api — Add a resource to a controller

Creates the API types, webhook stubs, metrics service and controller for a new resource kind, then applies: wires everything into the controller’s main.go and the packaging. Updates .genop.yaml.

The controller is created when it does not exist yet — there is no separate command to create one.

genop create api Extension \
  --project postgresql \
  --controller database \
  --api-version v1alpha1

# A configuration CRD that needs neither webhooks nor metrics
genop create api WorkspaceProfile \
  --project postgresql \
  --controller database \
  --api-version v1alpha1 \
  --no-webhook --no-metrics

The resource starts with no reconciliation step — that is simply what create api produces, not an opt-in. It gets API types and CRD, webhook stubs, metrics service, controller, e2e test, and the usual main.go wiring, with empty apply and deletion step lists. Such a resource reconciles to Ready immediately and is re-checked at the success interval.

This is the right shape for a pure configuration CRD that nothing reconciles, or for a kind whose reconciliation you have not written yet. Add steps later with genop create step — the scaffold markers are already in place. The same applies to a resource declared in .genop.yaml with no apply: or delete: key: genop apply scaffolds it like any other.

FlagShortRequiredDescription
--project-p✓The project that owns the resource
--controller-c✓The controller that manages the resource (created when absent)
--api-version-a✓The resource API version, e.g. v1alpha1
--scopeResource scope: Namespaced (default) or Cluster, fixed at creation (env: API_SCOPE)
--no-metricsDo not record resource metrics for this resource
--no-validating-webhookDo not register a validating admission webhook
--no-mutating-webhookDo not register a mutating admission webhook
--no-webhookDo not register any admission webhook (mutually exclusive with the two flags above)
--retry-policyOperator retry policy: resumeAtFailure (default) or restartAll
--success-statusTerminal success phase: Running (default) or Succeeded
--deletion-policyDeletion-policy provider: default or fromAncestor
--backoff-base-delayBackoff base delay, Go duration (default 5s)
--backoff-max-delayBackoff max delay, Go duration (default 1h)
--backoff-factorBackoff growth factor, float > 1.0 (default 2.0)
--backoff-jitter-ratioBackoff jitter percentage, 1–100 (default 25; 0 keeps the default)
--pending-check-intervalPending re-check interval, Go duration (default 10s)
--success-check-intervalSuccess drift-check interval for this resource, Go duration. Overrides the controller-level SUCCESS_CHECK_INTERVAL (default 12h)
--no-drift-checkSkip the post-apply drift check (env: GENOP_NO_DRIFT_CHECK)
--verbose-vEnable verbose logging

The four opt-outs write straight into .genop.yaml, so the packaging generated by the same command already reflects them. The eight operator: flags populate the resource’s operator: block, adjustable later with genop set operator — see Operator configuration below.

genop create step — Add a reconciler to an existing resource

Generates a reconciler implementation and its test file, then applies: wires it into the controller’s main.go. Updates .genop.yaml. The generated reconciler file also includes a New<Step>(k8sClient client.Client, dynamicClient dynamic.Interface) *<Step> constructor — see the New<Step> escape hatch below.

The step is placed in an apply/ or delete/ subdirectory under the kind directory, each forming its own Go package (package apply / package delete). A suite_test.go is created automatically in the subdirectory the first time a step is added to a phase.

Requires the resource (--project + --controller + --api-version + --kind) to already exist in the topology. Fails if the step already exists.

genop create step BackupVolume \
  --project postgresql \
  --controller database \
  --api-version v1alpha1 \
  --kind Database

# Add the step to the delete list instead
genop create step BackupVolume \
  --project postgresql \
  --controller database \
  --api-version v1alpha1 \
  --kind Database \
  --delete
FlagShortRequiredDescription
--project-p✓The project that owns the resource
--controller-c✓The controller that manages the resource
--api-version-a✓The resource API version
--kind-k✓The resource kind
--condition-type-tThe condition type reported by the step (derived from the step name when omitted)
--deleteAdd the step to the delete list instead of the apply list
--no-drift-checkSkip the post-apply drift check (env: GENOP_NO_DRIFT_CHECK)
--verbose-vEnable verbose logging

--condition-type is derived from the step name when omitted: MountVolume becomes VolumeMounted, BackupVolume becomes VolumeBackedUp. Derivation is a best effort over the step name’s leading verb — a verb genop does not recognise is rejected outright rather than guessed at, so pass --condition-type explicitly for those.

genop create hook — Add a hook to a resource

Generates a hook function and its test file into the resource’s hooks/ package (package hooks, alongside apply/ and delete/), wires it into the controller’s main.go via WithPreReconcileHooks / WithCleanupHooks, and updates .genop.yaml. A shared suite_test.go is created the first time a hook is added to the resource.

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. When a hook returns an error the runtime records it as a PreReconcileHookExecuted / CleanupHookExecuted condition and fails the reconcile. 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 and before genop removes its own finalizer, regardless of the deletion policy (Retain included). List order in .genop.yaml is execution order.

Requires the resource (--project + --controller + --api-version + --kind) to already exist. Exactly one of --pre-reconcile / --cleanup is required. Fails if the hook already exists in the target phase — but the same name may be added to both phases (one file, wired twice).

genop create hook AddFinalizers \
  --project postgresql \
  --controller database \
  --api-version v1alpha1 \
  --kind Database \
  --pre-reconcile

# Same function, run again to release the dependency on delete
genop create hook RemoveFinalizers \
  --project postgresql \
  --controller database \
  --api-version v1alpha1 \
  --kind Database \
  --cleanup
FlagShortRequiredDescription
--project-p✓The project that owns the resource
--controller-c✓The controller that manages the resource
--api-version-a✓The resource API version
--kind-k✓The resource kind
--pre-reconcile✓ (or --cleanup)Add the hook to the preReconcileHooks list
--cleanup✓ (or --pre-reconcile)Add the hook to the cleanupHooks list
--no-drift-checkSkip the post-apply drift check (env: GENOP_NO_DRIFT_CHECK)
--verbose-vEnable verbose logging

Hooks participate in drift detection, apply --prune and genop delete exactly as reconciliation steps do.

Operator configuration

Every resource’s operator is built from an optional operator: block in .genop.yaml (all fields optional — an omitted field keeps the genop-runtime default) plus a generated Configure<Kind>Operator function for anything the block can’t express.

resources:
  - version: v1alpha1
    kind: VPC
    operator:
      retryPolicy: restartAll        # resumeAtFailure (default) | restartAll
      successStatus: Succeeded       # Running (default) | Succeeded
      deletionPolicy: fromAncestor   # default | fromAncestor
      backoff:
        baseDelay: 5s                # default 5s
        maxDelay: 1h                 # default 1h
        factor: 2.0                  # default 2.0
        jitterRatio: 25              # 1–100; default 25 (percent). 0 keeps the default
      pendingCheckInterval: 10s      # default 10s
      successCheckInterval: 6h       # default: controller-level SUCCESS_CHECK_INTERVAL (12h)

Every field, its type and its default are in the .genop.yaml reference under TopologyOperatorConfig. The genop-runtime defaults are: retry policy resumeAtFailure, success status Running, backoff 5s / 1h / 2.0 / 25, pending re-check 10s. successCheckInterval has no runtime default of its own: when unset, the resource uses the controller-level SUCCESS_CHECK_INTERVAL (12h); when set, it overrides that value for this resource only.

jitterRatio accepts 1–100. A 0 is not “no jitter”: it clears the field and keeps the runtime default of 25. Disabling jitter entirely is only reachable through Configure<Kind>Operator.

Set it from the CLI — at create time, or later with genop set operator:

genop create api VPC -p infra -c net -a v1alpha1 \
  --retry-policy restartAll --deletion-policy fromAncestor

genop set operator -p infra -c net -a v1alpha1 -k VPC \
  --backoff-base-delay 10s          # merge — only this field changes

genop set operator -p infra -c net -a v1alpha1 -k VPC \
  --retry-policy ""                 # clear one field; an empty block is removed

deletionPolicy: fromAncestor selects operators.NewDeletionFromAncestorPolicy, which walks ownerReferences and applies the policy of the top parent being deleted. It issues dynamic GETs against the parent kinds, so the controller needs get RBAC on those kinds: add the matching +kubebuilder:rbac markers to internal/controllers/<version>/<kindLower>/controller.go (where the resource’s other RBAC markers already live) and run make generate-manifests. A missing GET permission surfaces as a clear RBAC error in the operator logs on delete — not a silent failure — but deletion hangs until it is granted.

genop apply regenerates the operator wiring on every run (see below), so this reminder lives right above WithDeletionPolicyProvider in the generated main.go, not in a file that could go stale: it appears whenever deletionPolicy is fromAncestor — set at genop create api time or later with genop set operator — and disappears again if the policy reverts to default.

The Configure<Kind>Operator escape hatch

genop apply regenerates the operator wiring in main.go on every run, so hand edits there are lost. Anything the operator: block can’t express goes in internal/controllers/<version>/<kindLower>/operator_config.go instead (the generated directory lowercases the kind, e.g. .../v1alpha1/vpc/) — generated once, never rewritten:

func ConfigureVPCOperator(
    b *operators.OperatorBuilder[*infrav1alpha1.VPCStatus, *infrav1alpha1.VPC],
) *operators.OperatorBuilder[*infrav1alpha1.VPCStatus, *infrav1alpha1.VPC] {
    return b.WithDeletionPolicyProvider(myCustomPolicy(b.GetClient().Scheme()))
}

The generated wiring always chains it in via WithConfigOverride — the last call before Build(), after every other With* option from the operator: block — so it can add options genop doesn’t surface or override ones it does. b.GetClient() exposes Scheme(), RESTMapper() and the usual CRUD methods; b.GetDynamicClient() is the same dynamic client the generated wiring uses — so Configure<Kind>Operator needs no mgr/dynamicClient parameters of its own.

The New<Step> escape hatch

Each generated apply/delete step file also gets a constructor alongside the struct, generated once and never rewritten:

// apply/mountvolume.go
type MountVolume struct {
    K8sClient client.Client
}

func NewMountVolume(k8sClient client.Client, dynamicClient dynamic.Interface) *MountVolume {
    return &MountVolume{K8sClient: k8sClient}
}

The regenerated WithApplySteps/WithDeletionSteps wiring in main.go calls New<Step>(mgr.GetClient(), dynamicClient) instead of a bare &<Step>{} struct literal — so adding a field and wiring it in the constructor is a single, permanent hand-edit to one file, never touched again by genop apply.

genop set operator — Merge operator options into a resource

Updates the resource’s operator: block in .genop.yaml, then applies. Only the flags you pass change; passing an empty string (--retry-policy "") or a zero number clears that field, and when every field ends up unset the block is dropped from .genop.yaml entirely.

Requires the resource (--project + --controller + --api-version + --kind) to already exist in the topology.

genop set operator \
  --project infra \
  --controller net \
  --api-version v1alpha1 \
  --kind VPC \
  --backoff-max-delay 30m --backoff-factor 1.5
FlagShortRequiredDescription
--project-p✓The project that owns the resource
--controller-c✓The controller that manages the resource
--api-version-a✓The resource API version
--kind-k✓The resource kind
--retry-policyOperator retry policy: resumeAtFailure (default) or restartAll (empty string clears it)
--success-statusTerminal success phase: Running (default) or Succeeded
--deletion-policyDeletion-policy provider: default or fromAncestor
--backoff-base-delayBackoff base delay, Go duration (default 5s)
--backoff-max-delayBackoff max delay, Go duration (default 1h)
--backoff-factorBackoff growth factor, float > 1.0 (default 2.0)
--backoff-jitter-ratioBackoff jitter percentage, 1–100 (default 25; 0 keeps the default)
--pending-check-intervalPending re-check interval, Go duration (default 10s)
--success-check-intervalSuccess drift-check interval for this resource, Go duration. Overrides the controller-level SUCCESS_CHECK_INTERVAL (default 12h)
--no-drift-checkSkip the post-apply drift check (env: GENOP_NO_DRIFT_CHECK)
--verbose-vEnable verbose logging

genop drift — Report orphaned scaffolding

Walks each operator’s directory and lists artifacts that exist on disk but are no longer declared in .genop.yaml — a project, controller, API version, kind, reconciliation step or reconcile hook left behind by an entry removed from the topology.

This is the same check every genop apply / genop create runs at the end; the standalone command is for inspecting a repository without regenerating anything.

genop drift
FlagShortRequiredDescription
--verbose-vEnable verbose logging

Reporting only: genop drift never deletes anything and always exits 0. Remove the orphaned code by hand, or delete its entry from .genop.yaml and the files it leaves behind — or use genop delete / apply --prune below to do both at once.

genop delete — Remove an entry and prune its generated code

Five subcommands — project, controller, api, step, hook — each remove one entry from .genop.yaml, apply (so any code the removal exposes elsewhere, such as a shared main.go import, still self-heals correctly), then prune every file the removed entry leaves orphaned. Unlike apply --prune, pruning is not optional here: there is no --no-drift-check or --prune flag on any genop delete subcommand, and no undo beyond version control.

# Remove one reconciliation step
genop delete step BackupVolume --project postgresql --controller database --api-version v1alpha1 --kind Database

# Remove one reconcile hook from a single phase
genop delete hook AddFinalizers --project postgresql --controller database --api-version v1alpha1 --kind Database --pre-reconcile

# Remove a resource and every step it owned
genop delete api Extension --project postgresql --controller database --api-version v1alpha1

# Remove a controller and every resource under it
genop delete controller database --project postgresql

# Remove an entire project
genop delete project postgresql
SubcommandRequired flagsDescription
genop delete project <name>Remove the project and every file under its directory
genop delete controller <name>-p/--projectRemove the controller and every resource and step it owned
genop delete api <Kind>-p/--project, -c/--controller, -a/--api-versionRemove the resource and every reconciliation step it owned
genop delete step <Name>-p/--project, -c/--controller, -a/--api-version, -k/--kindRemove one reconciliation step (from the apply list unless --delete is passed)
genop delete hook <Name>-p/--project, -c/--controller, -a/--api-version, -k/--kind, --pre-reconcile or --cleanupRemove one hook from the named phase (a hook in both phases survives until removed from each)

Every subcommand also accepts --verbose/-v.