## What this PR does This PR adds installation defaults for applications: administrator sets `applicationDefaults` in the platform values, and every application created after that starts from them. Design is in [the proposal in cozystack/community](https://github.com/cozystack/community/pull/116), related to [the worker defaults issue](https://github.com/cozystack/cozystack/issues/3950). The value is keyed by ApplicationDefinition plural (for example `postgreses`) and the platform chart renders it into the `cozystack-application-defaults` ConfigMap in `cozy-system`. The aggregated API merges the entry for the kind under the submitted spec on create, apply-create and dry-run create, and saves the result in HelmRelease values. The order is user values, installation defaults, then developer defaults from the chart schema. Update never applies defaults, so changing the value leaves existing applications alone. The merge goes into objects that declare `properties` and replaces everything else whole: arrays, dictionaries with `additionalProperties`, free-form objects, objects that also take arbitrary keys and objects marked `x-kubernetes-map-type: atomic`. So a node pool that sets its own `registryMirrors` gets no platform mirror entries. Explicit empty values from the user (`{}`, `[]`, `false`, `0`, `""`) win over the installation value. An entry is checked against the application's OpenAPI schema before it is merged. An object that the merge completes is checked as a partial one, so `required` and `minProperties` are not enforced on it and its `oneOf` is not evaluated (CEL rules are not evaluated at all). Whatever is stored whole is checked whole: array rows, dictionary values, free-form and atomic objects. Without that, an entry like a RabbitMQ vhost without `roles` was accepted and stored, and the chart refused to render it. A missing ConfigMap means no defaults and gives no warning. An unreadable ConfigMap, invalid JSON, a bad entry or an unreadable schema does not block the create: defaults are skipped and the response carries a Warning (dry-run too). The generic checks cover the whole map, so one entry that is not an object, or a reserved top-level field in any entry, turns defaults off for every application until it is fixed, while a bad entry of one application only affects that application. The ConfigMap is read through a cache limited to that one object, startup waits up to 30 s for it to sync and a create waits up to 5 s for the read, then both go on without defaults. Some objects take exactly one of their children and the chart refuses two: the worker image of a node pool (`osImage.builtin` or `osImage.factory`), a vm-disk `source`, the `oidc.customConfig` of a kubernetes cluster and of a monitoring stack (`config` or `secretRef`). A default for one child merged into an application that chose another built that spec. These carry the atomic marker now, so the merge replaces them whole, and `values.yaml` tells catalog authors to do the same in their own schemas. The chart guide (`docs/agents/overview.md`) says when the marker fits and when it does not. The `osImage` change is the same hunk as in #5192. The dashboard order page sends one dry-run create when it opens and starts the form and YAML from the returned spec, so the browser reads no ConfigMap and merges nothing. If the preview fails, or gets no answer in 8 s, the form opens with a notice and Retry, and Deploy still works. After a failed preview a dropdown stays empty instead of selecting the cluster default option, so the API applies the platform default to the omitted field. A cleared text field leaves its key out, a dropdown None and a sensitive field are written as `""`. While the server owns defaults the form does not fill schema defaults on its own. Not in this PR: defaults on update, re-rendering existing applications when the value changes, defaults for HelmReleases that controllers create directly, validation when the ConfigMap is saved, previews on every edit in the dashboard. ### Merge order #5190 and #5191 are merged and this branch is rebased on main. #5192 is open and has the same `osImage` marker hunk, so whichever of the two lands second needs one more `make generate` after a rebase. ### Known limits - The dashboard does not show the API Warning. - `null` for a field that has a developer default is saved as `null` through kubectl or Terraform, but the dashboard form shows the developer default. - A number in an integer-or-string field is rejected by the form (same on main), so quantities in an entry have to be quoted, `cpu: "2"`. `values.yaml` says so. - After a failed preview the form still requires a field that has no schema default, even if an entry would supply it. Typing the value or switching to YAML gets around it. - The marker only fits a choice between alternatives that each stand complete. I went through the application charts and rendered every refusal I found that involves two or more fields, and most are not that. A pair that has to be set together (`resources.cpu` with `resources.memory`, `tls.enabled` with `tls.disableNonTLSListeners` in rabbitmq) is completed field by field today, and an atomic object would drop the default half. An object that also holds independent fields an admin would default (`backup` in clickhouse, mariadb, mongodb and postgres, `volume` in seaweedfs) would lose them. Relations between two objects or two top-level fields (`cloudflareProxy` with `proxyProtocol` in the ingress, most of postgres, the kubernetes addons) cannot carry a marker. In all of these a default for one field plus the user's value for another can make the chart refuse the render after the create went through. Catching that needs the relations declared as rules in the schema and the merged spec checked against them, and the API does not evaluate such rules on a user spec yet (#2657), so it is a separate change. A few relations depend on a lookup into the cluster and I could not render them offline. - Clearing an optional text or number field in the order form leaves its key out, so the default comes back. A dropdown set to None, a sensitive field and a dictionary value send an empty string and win. The form keeps its old meaning of clearing a field, same as on main. To override a default with an empty value, set it in the YAML tab (`""`, `0`). Switching from the YAML tab back to the form fills an empty dropdown with its default option again, a None included, so such a value has to be deployed from the YAML tab (https://github.com/cozystack/cozystack/issues/5473). - An entry that cannot be parsed (invalid JSON, a reserved `_` key) turns defaults off for every kind, not only its own, and the Warning on each create names the problem. I did not split it per entry: the failure is loud, the fix is in one place, and splitting touches the parse and cache path for a case only a typo causes. - An atomic object also drops a default for a field nested inside an alternative when the user sets another field of that alternative. A default for `osImage.factory.imageFactoryURL` does not survive a pool that sets `osImage.factory.version`, and the boot disk then comes from the public factory. `talos.imageFactoryURL` is the knob the chart falls back to, it is not atomic, and defaults for it keep working. - A schema that declares a typed property only inside an `allOf` or `anyOf` branch, under a root that takes arbitrary keys, is checked as partial. No schema in the tree looks like that. - An object inside an `allOf`, `anyOf` or `oneOf` branch is closed to unknown keys even when the property it constrains is declared as a dictionary, so a valid entry for such a schema is refused and the create goes on with a Warning (https://github.com/cozystack/cozystack/issues/5474). No schema in the tree looks like that either. - The preview uses the placeholder name `preview`, so it fails when the tenant already has an application of that kind with this name, and the form opens with the notice. - The cache wiring in `pkg/apiserver/apiserver.go` has no unit test, the cache itself has. ### Verification - `make unit-tests` on this head with `LC_ALL=C`, exit code 0 (a kafka bats test on main depends on the locale). - `tsc` and `eslint` in the console are clean. - For the checks below I broke the code on purpose and saw the matching test fail, except the `arrayMinItems` flag of the server form, I could not make it matter. - A run on a test cluster with v1.7.0 is in the comment below. It was on an earlier revision, the stored-whole checks, the extra markers and the cleared-field change came after and are covered by unit tests only. - Not run: `make test-controllers`. - The merge cases asked in review are fixtures of `TestInstallationDefaultsMergeContract` now: a field set inside the alternative a user chose of an atomic object, the same object without the marker, an atomic object nested in one that merges, and an explicit `null` over an installation object. The whole table is in the proposal addendum, https://github.com/cozystack/community/pull/146. Checked cases: - user values `{}`, `[]`, `false`, `0`, `""` are kept, and a node pool with its own `registryMirrors` gets none from the platform - an object with both `properties` and a dictionary, or with preserved unknown fields, is replaced whole - empty and `null` `spec` on create - update after create, apply-update and a field removed on update keep stored values - a broken entry for another application, or an application with no entry and no readable schema, does not touch this create - missing ConfigMap gives no defaults and no warning, invalid JSON, unreadable ConfigMap and a cache that did not sync give a Warning and the create goes on - partial entry: `required`, `minProperties` and object `oneOf` are skipped on an object the merge completes, while unknown fields, wrong types, scalar `oneOf` and array items are still checked - array rows, dictionary values, free-form and atomic objects are checked whole, also when the constraint sits in an `allOf` or `anyOf` branch next to the property, and in these shapes an accepted entry merges into a spec that the application's own schema accepts - every ApplicationDefinition in the tree accepts an entry built from its own developer defaults - an object that lists properties without `type: object` is checked as an object, so an unknown field in it is refused - a pool with `osImage.factory`, a disk with another `source`, a cluster with `oidc.customConfig.secretRef` and a monitoring stack with `oidc.customConfig.config` do not get the other child from the platform, on their real schemas - a node pool that sets `resources.cpu` still gets `resources.memory` from an entry, so the marker does not take away the field-by-field completion of pairs - dashboard: a user with no tenant does not wait on the spinner, switching tenant keeps what was typed, a preview answer that arrives after the tenant changed is dropped, a non-object answer counts as a failed preview, Retry sends the current draft - dashboard: after a failed preview dropdowns in a field, an array row and a dictionary value stay empty, and edits made in YAML come back into the form - `required` inside array rows and dictionary values stays in force when the server owns defaults, and an emptied sensitive field stays `""` ### Screenshots Not captured yet. ### Downstream repositories This PR changes `packages/core/platform/values.yaml`. The docs for the new key are in https://github.com/cozystack/website/pull/828, and the proposal addendum with the merge cases and two decision records is in https://github.com/cozystack/community/pull/146. The Terraform provider may be reached too: it has its own defaults for some sizing fields (storage class, disk size), so installation defaults would not apply to those, while the Talos block fields are left out when unset and do get them. I read the schema, not the expand code. - [ ] No downstream repository is affected by this change - [x] [cozystack/website](https://github.com/cozystack/website) - follow-up: https://github.com/cozystack/website/pull/828 - [ ] [cozystack/terraform-provider-cozystack](https://github.com/cozystack/terraform-provider-cozystack) - follow-up: to check, provider defaults vs installation defaults - [ ] [cozystack/ansible-cozystack](https://github.com/cozystack/ansible-cozystack) - follow-up: - [ ] [cozystack/ccp](https://github.com/cozystack/ccp) - follow-up: - [ ] [cozystack/talm](https://github.com/cozystack/talm) - follow-up: - [ ] [cozystack/cozyhr](https://github.com/cozystack/cozyhr) - follow-up: - [ ] [cozystack/cozy-proxy](https://github.com/cozystack/cozy-proxy) - follow-up: - [ ] [cozystack/cozystack-telemetry-server](https://github.com/cozystack/cozystack-telemetry-server) - follow-up: - [ ] [cozystack/external-apps-example](https://github.com/cozystack/external-apps-example) - follow-up: - [ ] [cozystack/examples](https://github.com/cozystack/examples) - follow-up: - [x] [cozystack/community](https://github.com/cozystack/community) - follow-up: https://github.com/cozystack/community/pull/146 ### Release note ```release-note feat(api): add the `applicationDefaults` platform value, installation defaults are applied to new applications under user values, existing applications keep their saved settings, and the dashboard order form starts from the same defaults. ```
26 KiB
Cozystack Project Overview
This document provides detailed information about Cozystack project structure and conventions for AI agents.
About Cozystack
Cozystack is an open-source Kubernetes-based platform and framework for building cloud infrastructure. It provides:
- Managed Services: Databases, VMs, Kubernetes clusters, object storage, and more
- Multi-tenancy: Full isolation and self-service for tenants
- GitOps-driven: FluxCD-based continuous delivery
- Modular Architecture: Extensible with custom packages and services
- Developer Experience: Simplified local development with cozyhr tool
The platform exposes infrastructure services via the Kubernetes API with ready-made configs, built-in monitoring, and alerts.
Code Layout
.
├── packages/ # Main directory for cozystack packages
│ ├── core/ # Core platform logic charts (installer, platform)
│ ├── system/ # System charts (CSI, CNI, operators, etc.)
│ ├── apps/ # User-facing charts shown in dashboard catalog
│ └── extra/ # Tenant-specific modules, singleton charts which are used as dependencies
├── dashboards/ # Grafana dashboards for monitoring
├── hack/ # Helper scripts for local development
│ └── e2e-chainsaw/ # End-to-end application tests (Kyverno Chainsaw)
├── scripts/ # Scripts used by cozystack container
│ └── migrations/ # Version migration scripts
├── docs/ # Documentation
│ ├── agents/ # AI agent instructions
│ └── changelogs/ # Release changelogs
├── cmd/ # Go command entry points
│ ├── cozystack-api/
│ ├── cozystack-controller/
│ └── cozystack-assets-server/
├── internal/ # Internal Go packages
│ ├── controller/ # Controller implementations
│ └── lineagecontrollerwebhook/
├── pkg/ # Public Go packages
│ ├── apis/
│ ├── apiserver/
│ └── registry/
└── api/ # Kubernetes API definitions (CRDs)
└── v1alpha1/
Package Structure
Every package is a Helm chart following the umbrella chart pattern:
packages/<category>/<package-name>/
├── Chart.yaml # Chart definition and parameter docs
├── Makefile # Development workflow targets
├── charts/ # Vendored upstream charts
├── images/ # Dockerfiles and image build context
├── patches/ # Optional upstream chart patches
├── templates/ # Additional manifests
├── values.yaml # Override values for upstream
└── values.schema.json # JSON schema for validation and UI
Build and Development Commands
Root targets (run from the repo root):
make build # Build all Docker images (needs: docker, skopeo, jq, gh, helm, yq, GNU tar/sed/awk)
make unit-tests # Run unit tests (requires bats-core >= 1.5; GNU parallel is optional)
make test-controllers # Run the Go tests under ./internal/... (controllers, contract tests)
make generate # Code generation (hack/update-codegen.sh) — CRDs, DeepCopy, clients, RBAC
make manifests # Generate CRD manifests and operator YAML variants
make cozypkg # Build the cozypkg CLI
make test # Full E2E tests (requires a cluster)
make prepare-env # Prepare the E2E test environment (apply + prepare-cluster)
Per-package targets (run inside packages/{apps,system,extra,core}/<name>/):
make image # Build the package image
make show # Render the Helm template
make apply # Apply the Helm release to a cluster (needs NAME, NAMESPACE)
make diff # Diff the template against the cluster
make test # Package-specific tests
make generate # Regenerate values.schema.json + README.md from values.yaml
Build environment variables:
REGISTRY— Docker registry (defaultghcr.io/cozystack/cozystack).PUSH=1/LOAD=0— control buildx push/load behaviour.LOAD=1 PUSH=0— load images locally instead of pushing. Builds for the host architecture only, because the classic docker image store cannot load a multi-platform index.PLATFORM— the buildx platforms. Defaults tolinux/amd64,linux/arm64for anything butLOAD=1, so a push from either architecture publishes an index both can run. Needs adocker-containerbuilder (BUILDER) or a docker daemon on the containerd image store, with QEMU registered for the non-native half. Compiling builder stages run natively on$BUILDPLATFORMand cross-compile for the target, but everyRUNstep of a stage that runs on the target platform (package installs,setcap, install scripts, patch steps) still runs emulated.packages/core/testingpinslinux/amd64, because it carries an x86 KVM sandbox.packages/core/talosbuilds the Talos installer and release assets for the arches inPLATFORMwith the upstream imager, which needs no QEMU for either; its matchbox image carries the amd64 and arm64 kernel and initramfs whateverPLATFORMsays, because it network-boots machines of either arch.PUSHED_TAGS_LOG— a file theimage-tagsmacro appends every pushed<repo>:<tag>to, one per line. Unset by default; the release build sets it sohack/stitch-multiarch.shcan move every tag it pushed, versioned ones included, onto the multi-arch index. The append happens at recipe expansion, somake -nwrites it too.CACHE_TAG— the tag of the mode=max build cache each image reads (and writes underWRITE_CACHE=1). Defaults tobuildcache. Apart from the Talos installer and matchbox in the release job, CI builds one architecture per job, and builds arm64 images only for pre-release tags and in a nightly build of main: the images are built again on native arm64 runners under<tag>-arm64withCACHE_TAG=buildcache-arm64, which only the nightly writes. The talos and testing packages get no arm64 leg: the release job builds the Talos installer and matchbox for both arches itself, and testing is amd64 only. For a pre-release,hack/stitch-multiarch.shthen joins each pair into one index,hack/verify-multiarch.shfails the rc on any pinned image that is not an amd64+arm64 index, and the packages artifact is republished pinned on the index digests; seedocs/release/ci-pipeline.md. The stitch skips any image whose digest is also pinned in a file it does not rewrite, which then fails that gate; the kamaji control-plane provider's gzipped manifest is the one such copy it does rewrite (seedocs/agents/image-refs.md).
Values schema generation
Package values.yaml files carry annotations (@param, @typedef, @field, @enum, @section) that cozyvalues-gen turns into values.schema.json and README.md. Run make generate in the package after editing annotations. A pre-commit hook runs make generate across packages/apps/* and packages/extra/* on every commit to keep these in sync — see contributing.md for the regenerate-before-commit rule.
A chart also declares the limits on its own resource name there, with ## @name {string} - <why> followed by the constraint tags (@maxLength, @minLength, @pattern) it needs. cozyvalues-gen publishes the declaration at the root of values.schema.json as x-cozystack-name, from where hack/update-crd.sh carries it into the ApplicationDefinition, and the aggregated API server enforces it on metadata.name for whatever kind the definition describes. The description is the message a rejected name is answered with, so write it as the explanation of the limit. A @pattern is unanchored, as JSON Schema specifies, so one meant for the whole name is written ^...$. A declaration the server cannot enforce as written — a constraint keyword it does not implement, a wrong type, a null, lengths no name satisfies, a pattern that is not RE2 — refuses every create of that kind with a configuration error rather than being dropped. A pattern is checked only to compile, not to match anything, so one that matches no name ($^) rejects every name with the pattern as the reason. Annotation keywords such as title or examples, and x- extensions, are ignored. A cap only ever tightens: prefix + name must still fit the 53-character Helm release name limit, and a declaration looser than that budget does not widen it. The limits belong in the chart because that is where the facts behind them are — which sub-resources it renders and what release names they take — and a chart that needs nothing beyond the platform-wide limits declares nothing.
An object that is one choice is marked with ## @x-kubernetes-map-type atomic on the line after the @field or @param it marks. The marker reaches values.schema.json and the ApplicationDefinition, and so the OpenAPI the API serves like any schema keyword, and the only code in this repository that acts on it is the installation defaults merge (pkg/registry/apps/application/installation_defaults.go, the cozystack-application-defaults ConfigMap): an atomic object comes whole from the user's spec when the user sets it and whole from the default otherwise, and the two never mix, where every other object merges field by field. Helm's own value merging is not affected, and arrays, maps and free-form objects are already taken whole, so they need no marker. The case it exists for is an object whose children are alternatives that each stand complete on their own, so that a default for one plus a user value for another would merge into an object the chart refuses, although the default alone and the user's spec alone both render: osImage (builtin or factory), vm-disk source, and the oidc.customConfig of kubernetes and of monitoring (config or secretRef) are the marked ones. The create succeeds and the release then fails, so the marker has to be there when the object is written. It also drops defaults for fields nested inside an alternative, so a default for such a field belongs on a knob that is not atomic, as talos.imageFactoryURL is for osImage.factory.imageFactoryURL. Marking an object means adding a case to a test that runs the merge on its real schema: TestInstallationDefaultsExclusiveChoicesAreAtomic, or a test of its own like the one for osImage.
The test for a marker is whether every sub-object a user can write is a complete choice by itself, and most refusals in the charts fail it. Leave the marker off an object whose fields must be set together or one needs the other (resources.cpu with resources.memory, enabled with what it enables): a user who sets one half loses the default's other half, and the chart refuses an object that merging field by field would have completed. Leave it off an object that also holds fields an admin would default and that are independent of the exclusive pair (a backup's schedule, retention, endpoint or CA, a Secret reference), because the marker drops them as soon as the user sets any one field. It cannot help a relation between two objects or between fields at the spec root (cloudflareProxy and proxyProtocol), because it marks one object. A relation inside one object can be stated with ## @x-kubernetes-validations [json] on the line after that object's @field or @param, as the mongodb backup object does. cozyvalues-gen has no placement for the spec root, so for fields there say in each field description which combinations the chart refuses. Adding a rule to an existing kind is a breaking change for the API review gate and needs an approval from the API owners. The API server does not evaluate these rules on a user's spec yet (#2657), so a spec that breaks one still fails at render.
Testing
- Helm and BATS unit tests:
make helm-unit-testsrunshack/helm-unit-tests.shover every package that defines atesttarget. Atesttarget is expected to run helm-unittest: the sweep fails a package whose run reports no suite, because exiting 0 having asserted nothing is indistinguishable from passing. A target that drives something else belongs under another name, aspackages/core/testingalready does with its sandbox flow.make bats-unit-testsrequires bats-core 1.5 or newer; GNU parallel is optional and the target runs serially without it. Run the complete local BATS and POSIX-compatibility pass withpre-commit run bats-unit-tests --hook-stage manual --all-files; pull-request CI runs both lanes for code changes and the BATS contracts for docs-only changes. On a host whose/bin/shdiffers from CI,make BATS_POSIX_SHELL=dash bats-posix-compat-testsselects the same interpreter explicitly.make unit-testsruns the full unit suite — Helm, BATS, the targeted POSIX-shell compatibility pass, Go, and the preset/readiness checks. It does not include the controller tests under./internal/...; runmake test-controllersas well. CI invokes both targets together. The backport-batch tests are not part of it: runmake test-backport-batchafter changing anything listed incmd/backport-batch/test-inputs.txt, which is also what CI keys them on. - E2E tests: Kyverno Chainsaw suites in
hack/e2e-chainsaw/(one directory per app), run withchainsaw test. Cluster bootstrap (hack/e2e-install-cozystack.bats) and the OpenAPI checks (hack/e2e-test-openapi.bats) remain BATS. Conventions for writing and stabilising them — and the CI that runs them — live ine2e-testing.md. - Go tests: standard
go test, with Ginkgo/Gomega for controllers.
Test first, failure path first
These rules apply to changes with testable behavior. Documentation-only edits and unmodified upstream updates need the relevant checks, not an artificial failing test. First-party adaptations made during a dependency bump remain covered by these rules.
- Write the test before changing the implementation and watch it fail for the intended reason, not on a typo or a missing fixture. Then make it green, then refactor under it.
- Cover relevant failure paths before the happy path: empty or null values, invalid input, a number where a string is expected, a missing resource, a timeout or an API error. Assert the resulting message, exit status and post-failure state required by the operation's contract.
- Fix regressions in the implementation. Do not skip, weaken or delete a test, or silence a linter, merely to get a green run. When the intended contract changes, update or replace the obsolete assertions and retain coverage of applicable failure cases.
- A stub needs a failing test for the intended behavior during development. Finish that behavior and make the test pass before merge; do not make the test accept an unintended not-implemented result just to get green CI.
- A bug found along the way that is out of the PR's scope gets an issue and a test pinning the current broken behaviour, marked
FIXME(#N). The PR that fixes the bug flips the test to pin the fixed behaviour.
Do not negate a BATS assertion with !: it can silently pass. Bats catches a failing negation only when it is the last command in the test body; hack/cozytest.sh appends a successful return and misses it there too. See §11 of e2e-testing.md.
Linters
Fix every linter finding before pushing, the cosmetic ones included. When a rule genuinely conflicts with the project, change the linter configuration and state the reason there, instead of suppressing the finding inline.
Markdown follows these markdownlint rules: every code fence names a language (text when nothing else fits), table separators have spaces around the pipes (| --- |), and there is a blank line before and after every list and after every heading. Line length (MD013) is the exception: prose stays one line per paragraph, as Prose Formatting explains.
Conventions
Helm Charts
- Follow umbrella chart pattern for system components
- Include upstream charts in
charts/directory (vendored, not referenced) - Override configuration in root
values.yaml - Use
values.schema.jsonfor input validation and dashboard UI rendering - An unquoted numeric value (
name: 123) reaches a template as a number:lenon it aborts the render withlen of type float64(int64for a value given with--set) before anyfailmessage is reached, andif not $vtreats0as unset. For fields validated as text that permit numeric inputs, reject missing or null values withkindIs "invalid", then coerce withprintf "%v"and check emptiness witheq $v "". Coercing null first produces the non-empty string<nil>. - For integer fields, keep string inputs on their lexical validation path. Validate numeric inputs for type, integrality and bounds before conversion, then format the validated integer in decimal. Generic
printf "%v"can emit exponent notation for a float (4200000000becomes4.2e+09), so it is not integer normalization. - For nested values, validate or normalize each parent map before reading its children; checking only the leaf cannot prevent a nil-pointer error from a missing or null parent.
No lookup that copies another object into the render. A lookup reads cluster state at render time, and nothing re-renders the HelmRelease when that state changes, so whatever it copied into the output (a bucket name, an endpoint, a CA, a list of StorageClasses) stays stale until something unrelated upgrades the release. Lookups of this kind already in the charts have caused failures, and several have since been moved to values, so they are not precedent: do not add one of this kind unless a maintainer has authorized that specific one.
A lookup is fine when a repeated render gives the same output and carries nothing from another object into it: checking that an object exists, keeping a generated Secret's value, keeping an immutable field of the chart's own live object, or a guard that fails on an unsafe change. Keep its empty branch rendering, because offline helm template and helm-unittest without a kubernetesProvider mock see only that branch; test the other branch with such a mock.
To use a fact about the cluster instead, read it from values: _cluster and _namespace in the cozystack-values Secret, or valuesFrom on a specific Secret, whose content change is a values change and so upgrades the release. Ask whether an API is served with .Capabilities.APIVersions.Has, since a lookup on an unserved group aborts the whole render. Otherwise check at run time in a hook or Job, or let a controller own the object.
Container images
For a new container image built from source maintained in this repository, name the build definition Containerfile and pass it to docker buildx build with --file in the package Makefile. Keep existing Dockerfiles and vendored build definitions unchanged.
Examples and fixtures
Illustrative addresses and names in docs, examples and test fixtures come from the reserved documentation ranges, never from a routable value that merely looks realistic: IPv4 from RFC 5737 (192.0.2.0/24, 198.51.100.0/24, 203.0.113.0/24), IPv6 from RFC 3849 (2001:db8::/32), domains from RFC 2606 and RFC 6761 (example.com, .example, .test, .invalid), ASNs from RFC 5398 (64496–64511, 65536–65551), MAC addresses from RFC 7042 (00:00:5E:00:53:00–00:00:5E:00:53:FF). Where no reserved range exists, use an obviously synthetic placeholder such as <NODE_IP>.
When a test depends on a protocol-defined address's behavior, use that value, such as 127.0.0.1 or localhost for a local test server. Keep network tests isolated; this exception does not permit arbitrary live endpoints.
Go Code
- Follow standard Go conventions and idioms
- Use controller-runtime patterns for Kubernetes controllers
- Prefer kubebuilder for API definitions and controllers
- Add proper error handling and structured logging
Git Commits
Conventional Commits (type(scope): description) with --signoff, kept atomic and focused. Full format, scopes, AI-attribution trailer, and PR workflow are in contributing.md — the source of truth; do not duplicate them here.
PackageSource CRD upgrade policy
Each component in a PackageSource may set install.upgradeCRDs to control how CRDs from the chart's crds/ directory are handled on HelmRelease upgrades. Allowed values: Skip (default — helm-controller does not touch CRDs on upgrade), Create (create new CRDs only), CreateReplace (create new and overwrite existing).
Set upgradeCRDs: CreateReplace for operators whose upstream regularly adds new CRDs between versions (etcd-operator, cnpg, kubevirt, kamaji). Without it, new CRDs from a chart bump do not land on existing clusters — only fresh installs get them.
Do not set CreateReplace blindly: it overwrites every CRD in crds/ and can cause silent data loss if upstream drops a field from a CRD that has live objects. Only enable it for operators whose schema evolution is additive-only. When in doubt, leave it unset and apply new CRDs manually.
Documentation — where a new document goes
Product documentation lives in cozystack/website, not here. This repository holds only documentation that something in the repository references by path, or that describes the repository's own machinery. Pick the destination before writing, because moving a document later means chasing every @param, template comment and test comment that points at it.
| Destination | What belongs there |
|---|---|
packages/<group>/<name>/README.md |
Anything scoped to a single package. Prose goes above ## Parameters; that section is cozyvalues-gen output and is never hand-edited. The website's make update-apps / update-vms / update-networking / update-k8s / update-services targets append the whole README onto a published page, but only for the packages named in the APPS, VMS, NETWORKING, K8S and SERVICES lists of the website Makefile, and only from packages/apps/ and packages/extra/: nothing under packages/system/ is ever imported, and neither is a package that is not on those lists. The sync runs when a release is promoted or tagged, or by hand in the website repository, not when a pull request merges here. Use this route only for a package that is on the lists; for any other the prose reaches no reader, so put it on the website instead. |
cozystack/website, under content/en/docs/ |
Operator- and tenant-facing content that spans packages or is task-shaped: guides, how-tos, troubleshooting runbooks, reference tables. Which version directory a page goes into is set by the website's own CONTRIBUTING.md; follow that file rather than a copy of its rules here. |
docs/ |
Documentation that a chart template, migration, script or workflow references by repo-relative path, plus this repository's own process docs (docs/agents/, docs/changelogs/, docs/release.md and the pages under docs/release/). |
api/<group>/<version>/DESIGN.md, pkg/apis/<group>/DESIGN.md |
Design of an API group, beside the types it describes. |
cozystack/community |
Design proposals and RFCs. Not this repository. |
When a document could go in either docs/ or the website, the test is whether a non-documentation file has to link to it by path. docs/operations/seaweedfs-431-rename-recovery.md stays because packages/*/seaweedfs/templates/_naming.tpl and a platform migration point at it. A guide referenced only from a values.yaml @param does not qualify — put it on the website and link the URL.
Documenting a feature's current limitations is useful and belongs with the feature. Documenting the development process around it does not: no "What is NOT in Phase N", no "out of scope for this PR", no "this PR" phrasing, no action plans or review negotiation. A merged document describes what the code does now, and states a limitation as a limitation rather than as a roadmap position. Scope, phasing and follow-ups belong in the pull request description or an issue.
An app's README and the field descriptions in its values.yaml describe what the app does now, for the person using it: no history ("moves from", "previously", "used to", rollout phase names) and no account of how another chart behaved before. A change users must act on is announced by a ! in the pull request title and described on the website's per-version upgrade page (content/en/docs/next/operations/cluster/upgrade-to-vX.Y.md), so an app README carries no history or breaking-changes section. A description says what the field does, what it accepts and what it refuses, not what it replaced, and does not tell the reader to keep it in sync with another chart; when two charts have to agree, a test says so. A change that touches a README or a description fixes what is wrong in that place while it is there.
A document that names an unmerged pull request or an unreleased dependency needs a tracking issue, because nothing re-checks that claim later and it silently becomes false once the thing ships.
Domain references for specific tasks
Before working on these areas, read the relevant doc first:
- Backup subsystem design:
api/backups/v1alpha1/DESIGN.md - A new app package: copy the structure of an existing one (e.g.
packages/apps/postgres/)
Things Agents Should Not Do
Never Edit These
- Do not modify files in
/vendor/(Go dependencies) - Do not edit generated files:
zz_generated.*.go - Do not change
go.mod/go.summanually (usego get) - Do not edit upstream charts in
packages/*/charts/directly (use patches) - Do not modify image digests in
values.yaml(generated by build)
Version Control
- Do not commit built artifacts from
_out - Do not commit test artifacts or temporary files
Git Operations
- Do not force push to main/master
- Do not update git config
- Do not perform destructive operations without explicit request
Core Components
- Do not modify
packages/core/platform/without understanding migration impact