Project topology (.genop.yaml)#
Every repository managed by genop keeps a .genop.yaml at the root that
describes the full structure of the project: which operators exist, where
they live on disk, which controllers they expose, and which resources and
reconcilers each controller manages.
Why it exists#
Kubernetes operator projects tend to grow in the same predictable pattern —
API types, webhooks, metrics, a controller entry point, a Helm chart.
genop apply and genop create scaffold all of that for you, and
.genop.yaml is the machine-readable record of what was generated and how
it was configured. It serves three purposes:
- Ergonomics — once the file exists you no longer need to pass
--api-group-suffix,--controller, or--projecton every command; genop resolves them from the topology automatically. - Non-default paths — the logical project name (
project) and the filesystem location (path) can differ. This lets genop coexist in repositories that also contain non-operator code (e.g. CLIs, shared libraries) without forcing the operator into a directory named after it. - Rebuild — if generated files are lost or need to be re-created,
genop applyreplays the topology and regenerates any missing scaffolding.
Format#
apiVersion: genop.kornercloud.dev/v1
kind: ProjectTopology
spec:
module: gitlab.com/acme.io/test-operator
license:
path: LICENSE # path to the LICENSE file, relative to .genop.yaml
# disabled: true # set this instead to opt out of license headers
operators:
- project: postgresql
apiGroup: postgresql.acme.io
path: operators/postgresql # optional — defaults to the project name
controllers:
- name: database
resources:
- version: v1alpha1
kind: Database
preReconcileHooks:
- name: AddFinalizers # func run before the apply/delete steps
cleanupHooks:
- name: RemoveFinalizers # func run only on delete, before finalizer removal
apply:
- name: ProvisionDatabase
conditionType: DatabaseProvisioned
- version: v1alpha1
kind: Snapshot
scope: Cluster # cluster-scoped kind (default: Namespaced); read only when the resource is first scaffolded
metrics: false # do not record resource metrics
webhook:
validating: false # do not serve a validating admission webhook
mutating: false # do not serve a mutating admission webhookEvery field of
.genop.yaml— its type, whether it is required, its default and its meaning — is listed in the.genop.yamlreference, generated from the topology structs.docs/genop.schema.jsonis a JSON Schema for editor autocomplete and validation.
Per-resource switches#
| Field | Default | Effect when false |
|---|---|---|
scope | Namespaced | Not a switch: Cluster makes the kind cluster-scoped. It is fixed at creation and only read when genop first scaffolds the resource. |
metrics | true | The resource metrics recorder is not started. |
webhook.validating | true | No validating admission webhook is registered, and the resource is dropped from ValidatingWebhookConfiguration. |
webhook.mutating | true | No mutating admission webhook is registered, and the resource is dropped from MutatingWebhookConfiguration. |
The vocabulary is validating / mutating throughout — topology keys, env
var names and Helm values all use it. A switch that is left enabled is
simply absent from the file: only disabling is ever written, so the
defaults stay implicit. Writing webhook: false as a scalar is rejected;
disable both halves explicitly.
Switches roll up. When no resource under a controller registers a webhook,
that controller gets no webhook service and no certificate DNS entry. When
no resource in the whole operator does, the operator gets no Issuer and
no Certificate at all — the cert-manager dependency disappears with
them.
When license.path is set, every generated Go file is prefixed with the
contents of that file wrapped in a /* ... */ block comment. genop apply reads the same path on every run, so updating your LICENSE file and
re-applying propagates the change to any newly created files. Set
license.disabled: true to explicitly opt out of license headers (both
fields are mutually exclusive).
The file is created and updated automatically by every genop command.
You can edit it by hand to reflect intentional structural changes. It is
not a lock file: genop tracks what the topology adds, not what a hand
edit removes, so removing an entry leaves the generated code on disk.
Every apply and create command ends with a drift check that warns
about that orphaned code — see below.
Drift policy#
Generated files fall into two categories.
Yours to edit. Go source, values-local.yaml, README.md and
DEVELOPMENT.md are scaffolded once and never overwritten. genop apply
recreates them only when they are missing; to regenerate one, delete it
and re-run apply.
Generated and managed. Everything under config/kustomize/base and
config/helm — including values.yaml and the chart templates, but not
values-local.yaml — is regenerated in full from the topology on every
genop apply. Each such file carries a header saying so:
# GENERATED and MANAGED by genop — do not edit.
# Override with your own values file (helm -f) or a kustomize overlay.Hand edits to those files are lost on the next sync. Manifests the topology no longer calls for are deleted, not merely left unreferenced: turning both webhooks off removes the webhook configurations, the certificate, the issuer and the per-controller webhook service from disk. That is what lets a toggle take effect in both directions.
To customise managed output, layer on top of it rather than editing it:
pass your own values file to Helm (helm -f my-values.yaml), or add a
kustomize overlay that patches the base.
Orphaned code#
genop apply only ever creates Go code — it never deletes it. Removing a
project, controller, resource or step from .genop.yaml therefore leaves
its generated files on disk, still compiling and still wired into the
manager.
Every mutating command finishes with a drift check that walks each
operator’s directory and warns about anything present on disk but absent
from .genop.yaml:
drift: kind "gadget" exists on disk but is absent from .genop.yaml path=infra/api/v1/gadget_types.goIt reports five levels — project, controller, API version, kind,
reconciliation step. It is warning only: nothing is deleted and the
exit code is always zero. Run it on demand with genop drift, or suppress
the automatic check with --no-drift-check (env: GENOP_NO_DRIFT_CHECK).
Removing the orphaned code is opt-in. genop apply --prune deletes
everything the drift check would have warned about instead of just
reporting it, and genop delete project|controller|api|step removes an
entry from .genop.yaml and prunes its generated files in one step — the
equivalent of a hand edit followed by apply --prune. See
genop delete.
Upgrading a repository scaffolded before apply --prune#
Pruning requires every per-kind region in main.go and
test/e2e/suite_test.go to be fully re-rendered from the topology on each
apply, not just appended to. That needed begin/end marker pairs
(// +genop:scaffold:cmd:vars:begin / :end, and the same for
cmd:flags, cmd:controllers, cmd:imports:* and e2e:imports /
e2e:init-suite / e2e:scheme) in place of the single-line markers older
versions of genop scaffolded. Both files are created once and never
regenerated, so genop apply on an existing repository will fail with
marker "..." not found until it is migrated: either replace each old
single-line marker with a :begin/:end pair around its existing
generated content by hand, or delete the file and let the next genop apply (or genop create api) recreate it from a controller with no
resources yet, then re-add each resource with genop create api.