kubernetes-operator-conventions
Skill7 starsChanged 3 days agoMITView on GitHub
Kubernetes operator/controller reconcile loops, any framework. TRIGGER when: editing reconcile handlers or controllers (`kopf`, `controller-runtime`, `operator-sdk`, `Reconcile()`); handling errors, retries, events or finalizers in a controller; generating CRD manifests; setting a field manager; documenting an operator's README; user asks about requeue, CRDs or status conditions. SKIP when: not operator code.
1 other project uses a version of this.
Adopted by
Most recently taken up by
- leroyguillaume/skillsword for word, first seen Nov 22, 2026
Other versions1 project uses a version of this.
Word for word · 1
- leroyguillaume/skills★ 7100% same
Edited · 0
None found.
Wrote their own version · 0
None found.
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository54 other files it gives its agents.
- adr-conventionsSkill
- api-conventionsSkill
- architecture-conventionsSkill
- argocd-conventionsSkill
- ci-conventionsSkill
- config-conventionsSkill
- contributing-conventionsSkill
- councilSkill
- cryptography-conventionsSkill
- dependency-update-conventionsSkill
- diagram-conventionsSkill
- docker-conventionsSkill
- documentation-conventionsSkill
- frontend-conventionsSkill
- github-actions-conventionsSkill
- github-issue-conventionsSkill
- github-pr-conventionsSkill
- github-repo-settingsSkill
- gitlab-ci-conventionsSkill
- helm-conventionsSkill
- herdr-core-delegationSkill
- herdr-delegationSkill
- herdr-tui-delegationSkill
- kopf-conventionsSkill
- logging-conventionsSkill
- logo-conventionsSkill
- mise-conventionsSkill
- ollama-conventionsSkill
- openssf-conventionsSkill
- pr-conventionsSkill
- pre-commit-conventionsSkill
- project-metadata-conventionsSkill
- python-async-conventionsSkill
- python-conventionsSkill
- readme-conventionsSkill
- release-script-conventionsSkill
- release-supply-chain-conventionsSkill
- renovate-ci-conventionsSkill
- rest-conventionsSkill
- rust-build-conventionsSkill
- rust-conventionsSkill
- rust-http-conventionsSkill
- security-policy-conventionsSkill
- signal-handling-conventionsSkill
- sql-conventionsSkill
- starlight-conventionsSkill
- systemd-conventionsSkill
- system-user-conventionsSkill
- task-conventionsSkill
- terraform-conventionsSkill
- topic-splittingSkill
- ui-copy-conventionsSkill
- web-layout-conventionsSkill
- yaml-conventionsSkill
The file
We split this skill into the rules it gives an agent
9 rules. About 0 are common, 4 are distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 25
A resource is never dropped into a permanently-failed state: Every failure must requeue the object so it recovers on its own once the cause …
- Distinctive: line 54
The requeue logic converges on one chokepoint: when the third handler repeats the extract-cause, log, requeue sequence, extract it into one …
- Very specific: line 72
Treat already-exists (409) on create and not-found (404) on delete as success, not failure — log and continue.
- Distinctive: line 74
Prefer create-or-skip / select-then-insert over blind inserts so a retry after a partial run never duplicates or errors.
- Very specific: line 82
Use a finalizer only for teardown Kubernetes can't do itself: external, non-Kubernetes resources (SaaS workspaces, DB rows, cloud objects).
- Very specific: line 88
When generating CRD YAML (e.g.
- Very specific: line 106
Default the command with no output dir to a multi-document YAML stream on stdout (all kinds, ----separated).
- Very specific: line 127
Every write to the API (server-side apply, JSON/merge/strategic-merge patch, create, update) must set an explicit, stable field_manager …
- Distinctive: line 171
Document failure/retry semantics in the project README.md (a *Troubleshooting* section): where to look (events + logs), and that every …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Kubernetes operator conventions
These rules govern any reconcile path: the handler itself and everything it
calls (clients, token providers, DB access), whatever the framework. The kopf
wiring is kopf-conventions; in controller-runtime and Operator SDK, requeue
with return ctrl.Result{}, err (the Result is ignored when err is
non-nil), or ctrl.Result{RequeueAfter: d}, nil for a chosen delay.
Error handling — always requeue, never abandon
This is the non-negotiable core rule.
- A resource is never dropped into a permanently-failed state. Every failure must requeue the object so it recovers on its own once the cause is fixed (an admin grants RBAC, a CRD gets installed, a dependency comes back, the user corrects the spec).
- Never take the framework's give-up path — kopf's
PermanentError, for one: it stops the retries, which violates this rule. Every failure must do three things, uniformly:
- Log at error level with the underlying cause as a structured field
— the API
reason/ responsemessage, not just an HTTP status code, and never the raw stack trace as the only signal. - Emit a Kubernetes Warning event on the object so it shows up in
kubectl describe. Post it explicitly (e.g. aReconcileFailedWarning from a reconcile wrapper) — do not assume the framework turns a raised error into an event; kopf, for one, does not by default. Thekopf-conventionsskill has the posting mechanics. - Requeue with a sensible delay.
A periodic status rollup — a kopf timer, a
RequeueAfterhealth check — reports a failure it keeps seeing through a status condition, not an event on every tick: the same Warning repeated each interval buries the others.- Log at error level with the underlying cause as a structured field
— the API
- Tune the requeue delay by error class, but always requeue:
- Transient (
5xx,429, network/timeout): retry quickly (e.g. 30s). - Client / input errors (
4xxsuch as422invalid manifest,403RBAC; or a failed spec validation): retry slowly (e.g. 300s) to avoid a hot loop, since they need an external change — but still retry. - This is the deliberate opposite of an HTTP client, which stops on a
422(rest-conventions): a reconciler's desired state persists in the object, and the fix lands outside it, so stopping would leave it broken after the fix.
- Transient (
- The requeue logic converges on one chokepoint: when the third handler repeats the extract-cause, log, requeue sequence, extract it into one module with a single requeue entry point and per-client cause extractors, and route every reconcile-path failure through it instead of scattering bare status checks and re-raises. Not before the third copy.
- Validate the spec first and requeue on invalid input the same way — a malformed spec is a slow-retry client error, not a silent no-op and not a crash.
Anti-patterns to fix on sight: raise kopf.PermanentError; re-raising a raw
client exception (the Kubernetes client's ApiException, an HTTP client's
status error) out of a handler; logging only status without the reason;
swallowing an error and returning so the resource silently stops
reconciling.
Idempotency
- Reconcile handlers run repeatedly; every side effect must be safe to repeat.
- Treat already-exists (
409) on create and not-found (404) on delete as success, not failure — log and continue. - Prefer create-or-skip / select-then-insert over blind inserts so a retry after a partial run never duplicates or errors.
Ownership, finalizers, garbage collection
- Set an ownerReference on every in-cluster child object so Kubernetes garbage-collects it when the parent is deleted — don't delete children by hand in the delete handler.
- Use a finalizer only for teardown Kubernetes can't do itself: external,
non-Kubernetes resources (SaaS workspaces, DB rows, cloud objects). Make that
teardown idempotent too (a
404/already-gone is success).
CRD manifests — one file per kind, kebab-case filename
When generating CRD YAML (e.g. a crd CLI subcommand driven by the typed spec
models), emit one file per kind into an output directory, not a
single --kind selector or one concatenated file. The generator owns the
filename↔manifest mapping in a single place (e.g. an all_crds() registry next
to the builders) so the CLI stays a thin caller and the pre-commit hook is one
entry, not one-per-kind.
Name each file after the kind in kebab-case, acronym-aware — never glue the words together:
Widget→widget.yamlWidgetAPIServer→widget-api-server.yaml(notwidgetapiserver.yaml)
Kebab conversion needs two passes: split lower/digit→upper boundaries
((?<=[a-z0-9])(?=[A-Z])), then acronym→word boundaries
((?<=[A-Z])(?=[A-Z][a-z]), the I→Server split in APIServer), then
lowercase. A naive .lower() of the PascalCase kind glues acronyms and is wrong.
Default the command with no output dir to a multi-document YAML stream on
stdout (all kinds, ----separated). A single pre-commit hook regenerates the
whole crds/ directory and the files: regex covers the spec modules plus
crds/.*\.yaml, so the committed CRDs can never drift from the models.
Optional spec fields — nullable, never type: "null"
A Kubernetes structural schema rejects both type: "null" and an anyOf
node that lacks its own type. Schema generators commonly emit an optional
field as anyOf: [{type: T}, {type: "null"}] (Pydantic does for T | None),
which the apiserver refuses on kubectl
apply of the CRD. When converting a spec model's JSON Schema to the CRD's
OpenAPI v3 subset, collapse <type> | null unions into the single branch with
nullable: true (carrying over sibling keywords like description). The same
converter must strip additionalProperties: false wherever it sits next to
properties (a model that forbids extra fields leaks it, and structural
schemas forbid the pair). Add a test that walks the generated CRD asserting no node has
type: "null" nor additionalProperties: false beside properties.
Field manager — always identify yourself on writes
Every write to the API (server-side apply, JSON/merge/strategic-merge patch,
create, update) must set an explicit, stable field_manager equal to the
operator's name (e.g. widget-operator). Never let the client default it:
the apiserver will then attribute the fields to a generic or empty manager,
which is invisible to downstream tooling.
This is non-negotiable because anything that reads .metadata.managedFields
relies on the manager name being recognisable:
- GitOps drift suppression. ArgoCD's
managedFieldsManagers(and Flux's equivalent) tells the GitOps engine "this manager owns these fields, don't flag them as drift". The lookup is by exact manager name. If the operator's writes don't carry a recognisable manager, the GitOps engine cannot defer ownership and the resource stays permanentlyOutOfSync. - SSA conflict resolution. Without a stable manager, two controllers
fighting over the same field can't be diagnosed (
kubectl get ... -o yamlshows nameless entries) andforce_conflictsdecisions become guesswork. - Auditability.
kubectl get ... --show-managed-fieldsbecomes the canonical answer to "who last wrote this field?". A blank or generic manager defeats the audit.
Apply this uniformly: the SSA call, every patch helper (json-patch+json,
merge-patch+json, strategic-merge-patch+json), and any direct
create/update. Centralise the constant (FIELD_MANAGER = "<operator>")
in one module so every I/O call site uses the same string. A patch helper
that silently omits field_manager is a bug to fix on sight — even if the
write succeeds, it breaks the contract with GitOps and audit tooling
downstream.
The manager appears in managedFields only after a successful write to
the resource — creation by another controller is not enough. When debugging
"my manager doesn't show up", it takes one reconcile that actually writes
before re-checking: on a live cluster, ask the user to trigger it, or for the
go-ahead to.
Observability
- Logs follow
logging-conventions. - Surface user-facing state through events and status conditions, not
just logs — the spec author sees
kubectl describe, not the operator's pod logs.
Documentation
- Document failure/retry semantics in the project
README.md(a Troubleshooting section): where to look (events + logs), and that every failure requeues — transient errors quickly, client errors slowly. Point at the module that holds the delays rather than copying their values, which would drift.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

