# Tests and CI

> Learn when each CI tier runs, what it checks, and how to configure template test inputs.

`check` runs on every pull request, and `smoke` runs in the merge queue, on the commit about to land. `full` runs on what is stale, after a push to `main` that changes a component or template and every Saturday. Check that nothing is stale before tagging a commit. Each tier covers different checks, and later tiers run checks that earlier tiers don't cover. You can also run the same tests as CI with `catalog e2e -tier check|smoke|full`.

## Before you start

- `check` doesn't require Docker.
- `smoke` and `full` create kind clusters and require Linux and Docker. Add `-cluster current` to use the cluster specified by `KUBECONFIG` instead.
- Tests on k3s, RKE2 and KubeSolo install the distribution on the host itself. They need root on a disposable Linux host without Docker. Before and after each test, they remove the distribution and clean up the mounts, network links, routes and firewall rules that its pods left on the host.

Standard tests use the `single-node` or `multi-node` profile, each with its own set of settings.

## `check`: Check every pull request

`ci.yml` runs the following checks. Each job runs `nix develop -c scripts/ci/<job>.sh`; run one locally the same way.

### Run Go tests and lint

Run the Go tests, `gofmt`, ShellCheck and actionlint.

### Validate files and template requirements

Validate all files against their schemas, and confirm that each template's `requires` resolves in both profiles.

### Check component licenses

Reject component licenses that aren't OSI-approved. Exceptions must meet both conditions:

- The license appears in `optInOnly` in [`config/licenses.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/licenses.yaml).
- No profile enables the component by default (recommended).

### Check profile rendering

Render each profile twice. Both outputs must match exactly.

Then validate the output with kubeconform for every Kubernetes version listed in [`config/kubernetes.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/kubernetes.yaml). Validate custom resources against the CRDs from the same rendering.

Then dry-run upgrades and profile switches. For each component, apply one render to the API server and send another over it with `--dry-run=server`: each profile's render over the other's, and, for each profile, the render of the pull request's base over this one's. The base is the merge-base with `main`, rendered with its own tools. When a release's CRDs differ, the check installs the base's CRDs first, applies the base's objects, then installs the new CRDs before the dry run, as an upgrade does. An object of the base that does not apply against the base's own CRDs fails the check. Namespaces, webhook configurations and Helm hooks are left out of the comparison, and so are the CRDs themselves. The check fails when the API server refuses an update, and names the component and the object. A StatefulSet whose `volumeClaimTemplates` change is one such case, because Kubernetes can't change that field in place.

When the check fails, look first for a change that updates in place, such as keeping the field's value. If there is none, mark the change file in `.changeset/` as `major` and write the migration steps in it. The check then accepts that upgrade refusal and logs it as an intended break. It never accepts a profile switch, so set the field to the same value in both profiles.

### Check template rendering

Render each template with test inputs, then check security rules, upstream Pod Security rules, and kubeconform validation results.

### Validate with the API server

Start etcd and kube-apiserver from [`flake.nix`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/flake.nix), use the Kubernetes version that matches the RKE2 release in [`config/kubernetes.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/kubernetes.yaml), and load only the rendered CRDs.

Then use `kubectl apply --dry-run=server` to send the rendered output for all components in both profiles and all templates to the API server. The API server checks fields, defaults, CEL rules, and Pod Security without running workloads.

Each template's Namespace generates warnings at its own enforce level. Any warning fails that template's test.

### Build the release

Build `bundle.tar.gz` with `nix build .#release` and the static API with `zeabur-catalog api`. A change to `go.sum` fails here until `flake.nix` has the new `vendorHash`. `zeabur-catalog compat` then checks every new API file against the schemas of the latest published release, which accept new fields and values, and fails when a change inside `v1` removes a field, changes a type or makes a field required.

## `smoke`: Install what a change affects

In the merge queue, `ci.yml` installs the following items in a single-node amd64 kind cluster, then runs smoke checks:

- Changed components and templates.
- Components and templates that a changed item needs.
- Components and templates that install a changed component.

A queued pull request tests what differs from the queue's base commit. A pull request itself doesn't start `smoke`. When the change touches no component or template there is nothing to test, so GitHub skips the `smoke` job. Require the `smoke-ok` check, which passes when the job is skipped and fails when a `smoke` job fails.

Tests that share dependencies share a cluster. Each dependency is installed only once per cluster. After a component passes its smoke check, the test uninstalls it unless a later test in the same cluster still needs it.

If a change affects `config/kubernetes.yaml`, `smoke` tests everything. If it affects `tools/`, `go.mod`, `go.sum`, the flake, another file in `config/`, or a workflow, `smoke` tests the `smokeRepresentative` list in [`config/e2e.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/e2e.yaml) instead.

## `full`: Test resource usage and cleanup

`weekly.yml` calls `e2e.yml` to run `full` on what is stale, and on what installs it. It runs after a push to `main` that changes `components/` or `templates/`, every Saturday, and when you run it by hand. A manual run can test only some IDs instead (`components`).

Each run records its inputs: the `sourceDigest` of the component or template, the `sourceDigest` of each component installed before it (`dependencies`), the release of each add-on that a host profile installs (`addOns`), and the release that [`config/kubernetes.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/kubernetes.yaml) pins, the kind node's `kubernetesVersion` or the host distribution's `distributionVersion`. A component or template is stale on a profile and architecture when it has no run there, its run there failed, or the inputs of that run differ from the current ones. `catalog list -tier full` prints what a run would test, and `catalog e2e -tier full` without IDs tests it.

The inputs don't cover everything that can change a result. After one of these changes, run `weekly.yml` by hand with the IDs it affects in `components`:

- An image tag or chart version that upstream points to new content.
- The test itself, in `tools/`, or its settings in `config/e2e.yaml`.
- The GitHub runner image.

Before tagging a release, merge the open measurements pull request, then check that `catalog list -tier full` on the commit to tag prints an empty `include`. Otherwise run `weekly.yml` on `main`, merge its pull request and check again.

`full` creates a fresh kind cluster for each component and profile on amd64 and arm64. `single-node` uses one node, and `multi-node` uses three nodes.

### Install dependencies

Install dependencies first, then the component under test.

### Measure idle resource usage

Sample the idle memory and CPU usage of each pod every 10 seconds until the totals of five consecutive samples are stable, for up to 3 minutes. Each workload (a Deployment, StatefulSet, or DaemonSet, the controller of a Job, or a bare Pod) is recorded once, as the median usage of one of its pods. Totals, replica counts and requests are not stored. A reader takes replicas and requests from the rendered objects.

### Run health and smoke checks, then uninstall

Run the component's health checks and smoke checks, then uninstall the component. Any leftover resources fail the test.

### Components that require additional credentials

The `unready` list in [`config/e2e.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/e2e.yaml) identifies components that require credentials CI doesn't have.

`full` installs these components without waiting for readiness, then runs smoke checks and uninstalls them.

### Templates and resource budgets

`full` installs each template and its required components in a single-node amd64 cluster, runs smoke checks, then uses the same sampling method to measure idle memory and CPU usage for Pods in the template's Namespace.

Component measurements are stored in `measurements/components/<id>.json`, and template measurements in `measurements/templates/<id>.json`. `environments` has one entry for each environment. `distribution`, `profile`, `platform`, `kubernetesVersion` and `distributionVersion` name the environment. `distribution` is `kind`, `k3s`, `rke2` or `kubesolo`, and `distributionVersion` is the release of a distribution on the host. kind has none. `result` is `passed` or `failed`, and a reader treats any other value as not passed. `versions` lists the version of each release for a component, and the tag and digest of each image for a template.

```json
{
  "component": "traefik",
  "environments": [
    {
      "distribution": "k3s",
      "profile": "single-node",
      "platform": {"os": "linux", "architecture": "arm64"},
      "kubernetesVersion": "v1.37.2",
      "distributionVersion": "v1.37.2+k3s1",
      "result": "passed",
      "pods": [{"workload": "traefik", "kind": "Deployment", "memory": "22Mi", "cpu": "3m"}],
      "versions": [{"release": "traefik", "version": "41.7.1"}],
      "measuredAt": "2026-11-03"
    }
  ]
}
```

`full` also checks the total usage of components enabled by default in the `single-node` profile on amd64 against the budget in [`config/budget.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/budget.yaml).

`weekly.yml` opens or updates one pull request to update `measurements/`. A run keeps the results already in that pull request, then drops each run whose inputs differ from those of the commit it tested, so a result of older files never stays. A run that tests nothing leaves the pull request as it is. One run goes at a time. A newer run replaces a waiting one and loses nothing, because it finds what is stale again. Renovate opens a pull request for each new upstream version and image digest.

### Tests on k3s, RKE2 and KubeSolo

With `-profile k3s`, `-profile rke2` or `-profile kubesolo`, the tests install that distribution on the Linux host, at the version pinned in [`config/kubernetes.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/kubernetes.yaml), and verify the checksum of every download. They change these defaults:

- k3s runs without its own Traefik and metrics-server.
- RKE2 runs without its ingress controller and metrics-server, and gets local-path-provisioner as its default StorageClass.
- KubeSolo gets the standalone helm-controller. KubeSolo has no release for the newest Kubernetes minor yet, so it runs one minor below the others.

The tests then run `full` with the `single-node` settings for every component that `single-node` supports. A component whose `distributions` leaves out the distribution isn't tested on it. Templates aren't tested on these distributions.

Measurements are stored alongside the kind results, with `profile: single-node`, the distribution in `distribution` and its release in `distributionVersion`, for example `v1.37.2+k3s1`. A failed run sets `result: failed` on its environment instead. When the cluster never answered, the entry has no `kubernetesVersion`.

Each measured environment carries `sourceDigest`, a digest of the component file, or of `template.yaml` and `manifests.yaml` for a template, that the run installed, and `dependencies`, the `sourceDigest` of each component that the run installed before it. The API publishes each component's `sourceDigest` next to its measurements. An installer counts a component as [tested on](https://oss.zeabur.com/docs/catalog/reference/installers#tested-on) a distribution and platform only while a passing run there has the component's current digest. Changing the file, including a release version in it, makes the component untested until a run of the new file passes. A failed run makes the platform untested too, and the next passing run on it makes it tested again.

## Configure template test inputs

Template tests get their input values from [`config/e2e.yaml`](https://github.com/zeabur-oss/catalog/blob/v0.6.3/config/e2e.yaml) and don't require repository secrets.

### Configure shared and per-template inputs

Configure the following in `config/e2e.yaml`:

- `templateInputs`: Values for all templates that declare the input.
- `templates.<id>`: Input values for a single template, objects to apply to `templates-e2e-<id>` before testing, and smoke checks to skip with reasons. The objects applied before testing can include Secrets specified by the input values.

All values are disposable test data.

### Configure object storage test data

Whenever an input value uses `.S3`, the tests start SeaweedFS (`seaweedfs-operator`) in `templates-e2e-s3` with a test CA and HTTPS on TCP 443. Backups and object storage data go to this service.

The `e2e-s3` Secret in the template's Namespace stores access credentials and a CA certificate named `ca.crt`.

Templates receive the CA through optional inputs such as `backupCASecret`. For templates that can't use a custom CA, the tests skip only the corresponding smoke checks.

To use a different storage service, change the template's input values in `config/e2e.yaml`.

## Check results

`check` starts its own API server. `smoke` and `full` create their own kind clusters, each with a separate kubeconfig.

After testing, each tier deletes the test environment it created. Add `-keep` to retain the environment.

## Troubleshooting

| Symptom or result | Next step |
| - | - |
| `check` fails because of Pod Security warnings for a template's Namespace | Fix the template according to the warnings. Warnings fail the template test. |
| A component appears in `unready` and has no resource measurements | Check `config/e2e.yaml`. These components require credentials CI doesn't have, so the tests don't measure their resource usage. |
| k3s, RKE2 or KubeSolo doesn't test a component | Check whether the component's `distributions` includes that distribution. |
| Nodes need to pull images from registry mirrors | Set `ZEABUR_REGISTRY_MIRRORS` with a value in the format `docker.io=http://mirror:5001,ghcr.io=...`. |
