# Component file format

> Write YAML with the shared envelope and component fields, and pin installation content with digests.

A component is installed once for the whole cluster and used by every project. A template, in contrast, is installed per project and can be installed many times.

Place each component in its own directory, `components/<id>/component.yaml`, with one directory for each upstream. The directory holds only `component.yaml` and the component's READMEs. The YAML file contains the shared envelope, installation content, and configuration. The directory name is the ID. For example, `components/traefik/component.yaml` has the ID `traefik`. An ID is lowercase letters, digits and single hyphens, and no template has the same ID.

## Shared envelope

Components and templates share an envelope of `apiVersion`, `kind`, `metadata`, and `requires`. `kind` distinguishes components from templates. Each entry of `requires` is `{capability: <capability>}` or `{component: <id>}`.

```yaml
apiVersion: catalog.zeabur.com/v1
kind: Component                   # or Template
metadata:
  name: Traefik Proxy
  license: MIT                    # SPDX
  homepage: https://traefik.io/traefik/
requires: [{capability: certificates}]   # or {component: <id>}
```

A component's `metadata` also has a `summary`: what it gives the cluster, in one plain sentence for people choosing components, with its translations in `locales`. A comment at the top of the file says why the catalog recommends the component. A `LicenseRef-` id in `license` needs the HTTPS URL of its text in `licenseUrls`, such as `licenseUrls: {LicenseRef-example: https://example.com/license}`, so that a reader can link it.

```yaml
metadata:
  summary: Routes traffic from your domains to your services.
  locales:
    zh-TW: {summary: 把網域的流量導向你的服務。}
    zh-CN: {summary: 把域名的流量转发到你的服务。}
```

The keys of `locales` are BCP 47 tags. `config/locales.yaml` lists the tags that every `locales` map in components and templates must have, and `zeabur-catalog check` checks them. A map may have other tags too.

## README

Each component has `README.md`, `README.zh-TW.md` and `README.zh-CN.md` in its directory for the administrator who decides whether to install it. They use only these level-2 headings, in this order: `## Introduction`, `## Before you install`, `## Use it`, `## Remove it` and `## Troubleshooting` (`簡介`, `安裝前準備`, `使用方式`, `移除`, `疑難排解` in zh-TW; `简介`, `安装前准备`, `使用方法`, `移除`, `故障排除` in zh-CN).

- **Introduction** (required) says what the component does, when a cluster needs it, and how far its rights reach.
- **Before you install** says what to prepare outside the cluster, such as a bucket and its keys. It is required when an input is `required` and has no `default` and no `generate`.
- **Use it** (required) links to the Zeabur OSS docs page where the component shows up, without repeating that page. A component without a Zeabur OSS screen gives its first step and links to the upstream docs.
- **Remove it** (required) says what removal deletes, what stays, and what to check first.
- **Troubleshooting** (optional) has one `###` per problem.

`zeabur-catalog check` checks the files and the headings.

## Component fields

The following example shows a minimal component. `defaults` specifies whether to enable the component for each profile (the `single-node` or `multi-node` configuration), and `recommended` means enabled by default (recommended). `releases` lists the content to install in order. Settings in `profiles` merge into the shared `values`.

```yaml
apiVersion: catalog.zeabur.com/v1
kind: Component
metadata:
  name: Traefik Proxy
  license: MIT                    # SPDX; OSI-approved, or opt-in only (see below)
  homepage: https://traefik.io/traefik/
provides: {capability: ingress}         # the capability it offers; see below for registry
defaults: {single-node: recommended, multi-node: recommended}
requires: [{capability: certificates}]  # installed first
distributions: [k3s, rke2, kubesolo]    # distributions it supports and e2e tests it on
kubeVersion: ">=1.30.0-0"               # Kubernetes versions it supports

releases:                         # installed in order
  - name: traefik
    type: helm                                  # helm, manifest or inline
    namespace: traefik
    chart: oci://ghcr.io/traefik/helm/traefik   # or repo: https://… plus chart: <name>
    version: 42.1.3                             # exact; Renovate bumps it
    chartDigest: sha256:…                       # required with chart; see Digests
    values: |                                   # shared by every profile
      gatewayClass:
        # Every value has a comment saying why; `zeabur-catalog check` enforces it.
        enabled: true
      image:
        # Every image is <tag>@sha256:<digest>; `zeabur-catalog render` enforces it.
        tag: v3.7.16@sha256:…
    profiles:                                   # merged over values like helm -f
      single-node: |
        deployment:
          # One node: a second replica gains nothing.
          replicas: 1
  - name: crds
    type: manifest
    namespace: kube-system
    urls: [https://github.com/…/releases/download/{version}/standard-install.yaml]
    version: v1.6.3
    urlDigests: [sha256:…]                      # one per URL, in order
  # or type: inline with manifests: |  objects applied as written

inputs: []        # values to ask for or generate; Secrets are created from them
resources: {...}  # memory it needs while working, on top of idle
internalCRDs: []  # CRDs of detection.crds whose objects it writes itself
networkPolicies: |  # traffic it needs where an installer isolates namespaces
contributes: []   # values added to another component's release (CrowdSec -> Traefik)
detection: {...}  # CRDs, API services, Helm charts, workloads, distribution add-ons
security: {...}   # RBAC summary, podSecurity
health: []        # read-only checks an installer runs on a cluster
smoke: []         # extra e2e checks
leftovers: []     # what the upstream keeps on uninstall (e.g. CRDs)
```

## What installers read

These fields tell an installer what a component offers, so the installer never needs to know a component by its ID.

`provides.capability` is the capability the component offers, such as `ingress` or `logs`. A `requires` entry `{capability: <capability>}` installs one of the components that offer it. A component that offers no capability leaves it out, and `requires` names it with `{component: <id>}`. A capability isn't the ID of a component that offers another capability, because an installer reads a name in `enable` and `disable` as a component ID first.

`provides.registry` is an OCI registry in the cluster: `host` is the `host:port` images name, and `ca` is the Secret key with the CA that signs its certificate. Zeabur and signed-in users read that Secret, so it holds the CA and no private key. Removing the component waits until no Pod outside its namespaces runs an image from the host.

An input with `generate: {type: clusterIP}` takes a fixed ClusterIP for a Service of the component. A node's container runtime cannot resolve the registry host, so Zeabur fills an empty input with a free address in the Service CIDR when it installs the component. The component then points each node there itself; Zeabur Builder does this with a DaemonSet. Without Zeabur, as in CI, the input stays empty, Kubernetes assigns an address and only Pods reach the registry.

```yaml
inputs:
  - name: clusterIp
    release: zot
    path: service.clusterIP
    generate: {type: clusterIP}
provides:
  capability: builds
  registry:
    host: zot.zot.svc:5000
    ca: {name: registry-ca, key: ca.crt, namespace: builder-system}
```

An input's `name` is camelCase. An input with `generate: {type: random, bytes: 64, encoding: hex}` takes `bytes` random bytes, from 12 to 64, in `encoding`: lowercase `hex` or `base64url` without padding. Both fields are required, so an installer never guesses a length. An installer doesn't fill in an input whose `generate.type` it doesn't know.

An input goes either to `path` in the values of a release, or to a key of the Secret in `secret`, which the installer creates before the install. `testValue` is the value CI installs with.

`detection.csiDrivers` lists the CSI drivers of the volumes the component provides. Removing the component waits until no PersistentVolume uses one of them. Find the StorageClass by its `provisioner`.

Removing a component also waits for the objects of its `detection.crds` outside its namespaces, except those in `internalCRDs`: CRDs whose objects the component writes itself, such as scan reports. Every entry of `internalCRDs` must be in `detection.crds`.

`resources.work` lists each kind of work the component does, such as a build. Each entry has a `name`, unique in the list, and one or more of these, each in Kubernetes quantities of `cpu` and `memory`:

- `requests` and `limits` are the resource requests and limits of each pod doing one unit of the work. Give them when a controller creates those pods and no render shows them, such as a build pod. Copy them from the chart's values, and change them when a chart upgrade changes those values.
- `use` is what the component uses on top of its idle use while doing one unit of the work. Its idle use is measured in e2e and published in the [API](https://oss.zeabur.com/docs/catalog/reference/releases#the-api).

```yaml
resources:
  work:
    - name: build
      requests: {cpu: 100m, memory: 256Mi}
      limits: {cpu: "1", memory: 1Gi}
      use: {memory: 500Mi}
```

The API publishes `resources.work` as written. An installer adds the memory of `requests` to the requests of the pods in the component's rendered objects, because the scheduler counts requests. `validate` fails on a resource other than `cpu` and `memory`, or on an amount that is not above zero. Profiles and inputs don't change the result.

`health` lists read-only checks that an installer runs on an installed cluster. Each check waits until the objects in `resource` reach `condition`, within `timeout`. A check of a `Deployment`, `DaemonSet` or `StatefulSet` has no `condition` and no `all`: those objects are ready when their rollout is complete. `resource` has a `kind`, a `namespace` when the kind has one, and exactly one of these: `name` for one object, `selector` for the objects with those labels, or `all: true` for every object of the kind. `validate` fails on a kind that isn't listed in [the schema](https://github.com/zeabur-oss/catalog/blob/v0.6.3/schema/v1/component.schema.json), and on a missing field. When a check fails, the installer shows the reason and message of the object, then its `advice`, which tells the reader in English what to do. A health check has no manifest and applies nothing. Put checks that create objects in `smoke`, which only e2e runs. e2e runs `health` after install and before `smoke`. Each `smoke` check lists `wait` entries. An entry names its objects as `resource: <kind>/<name>`, or as a kind with `selector` or `all: true`, with a `namespace` when the kind has one. It has a `condition`, either `condition=<name>` or `jsonpath=<path>=<value>`, unless the objects are a `Deployment`, `DaemonSet` or `StatefulSet`, which are ready when their rollout is complete.

A component that serves an admission webhook (a `ValidatingWebhookConfiguration` or `MutatingWebhookConfiguration`) needs at least one `health` check, so that the components that need it install only after the webhook answers. `zeabur-catalog render` fails otherwise.

```yaml
health:
  - name: nodes-ready
    resource: {kind: Node.longhorn.io, all: true, namespace: longhorn-system}
    condition: Ready
    timeout: 60s
    advice: "The message above names what the node lacks for Longhorn, such as open-iscsi, an NFS client or a kernel module. Install it on that node; the check passes once Longhorn finds it."
```

`distributions` names the distributions the component supports, and e2e tests it on each of them. Where that test passed is a different list: an installer works it out from the measurements in the API, as [How installers choose and install components](https://oss.zeabur.com/docs/catalog/reference/installers#tested-on) describes, and warns that a component is untested on a distribution and platform where it didn't pass.

`kubeVersion` is the range of Kubernetes versions the component supports, in the syntax of a Helm chart's `kubeVersion`. Give the strictest range of its charts, or `">=1.34.0-0"` when they give none. `zeabur-catalog check` fails when the range leaves out a Kubernetes version that the catalog tests. An installer doesn't offer the component on a cluster outside the range.

`persistsData: true` marks a component that keeps state in volumes, so removing it loses that data.

A release with `skipIfPresent` is skipped when every CRD it lists already exists, such as Gateway API CRDs that another installation put on the cluster. `releaseName` sets the Helm release name when it differs from `name`.

`contributes` adds values to a release of another component. `target` names the component and its release, and `values` holds the values. The component needs a `helm` release of its own: an installer finds the components it installed by their Helm releases, and adds their values again each time it writes the target.

```yaml
contributes:
  - target: {component: traefik, release: traefik}
    values: |
      ...
```

The other lists of `detection` find an existing installation of the upstream, so that an installer can reuse it: `crds` and `apiServices` by name, `ingressControllers` and `gatewayControllers` by the controller of an IngressClass or GatewayClass, `helmCharts` by the chart of a Helm release, and `workloads` by the `kind` and `labels` of a Deployment, StatefulSet or DaemonSet.

`detection.addons` lists the add-ons of a distribution that install the same upstream, such as `{distribution: k3s, name: traefik}` for the Traefik that k3s packages and `{distribution: rke2, name: rke2-traefik}` for RKE2's. The name is the add-on's HelmChart in `kube-system`. A reader ignores an entry of a distribution it doesn't know.

`security.podSecurity` is the Pod Security level that the component's own namespaces need: `restricted`, `baseline` or `privileged`. `zeabur-catalog render` checks every Pod of the render against it.

`networkPolicies` is for installers that block incoming traffic to each namespace by default. It holds standard NetworkPolicy objects in the component's own namespaces, which such an installer applies before the releases, for the traffic the component needs from elsewhere. Other installers can ignore it. `zeabur-catalog check` checks that each object is a NetworkPolicy in one of the component's namespaces.

## Pin content with digests

Every `releases` entry must pin its content with a digest. `zeabur-catalog render` stops if the chart or URL content doesn't match its digest, and an installer must stop too.

- For HTTP charts, `chartDigest` uses the `digest` from the corresponding entry in the repository's `index.yaml`, which is the sha256 of the `.tgz`.
- For OCI charts, `chartDigest` uses the manifest digest, which is the value that `helm push` outputs. `helm pull <chart>:<version>@sha256:…` checks this value.
- `urlDigests` uses the sha256 of each downloaded file, in the same order as the URLs.
- Images in `values` use `<tag>@sha256:<digest>`, including images that the chart passes to an operator as arguments. If a chart doesn't accept a digest, list the image in `unpinnedImages` and explain why in a comment. URL installation entries are exempt from this requirement.

Renovate updates image and chart versions together with their digests. It can't read digests for URLs: after Renovate updates their `version`, `zeabur-catalog render` fails and outputs the new digest for you to copy into the file.

Installation results must be consistent: charts must not generate keys or certificates. Put values that need generation in `inputs` and store them in Secrets; cert-manager supplies certificates. If two renders produce different results, `zeabur-catalog render` fails.

For the complete field definitions, see the [component JSON Schema](https://github.com/zeabur-oss/catalog/blob/v0.6.3/schema/v1/component.schema.json).
