# CRD schemas

Charts that deploy custom resources, such as a `ServiceMonitor` or a `Certificate`, need schemas
that are not part of Kubernetes. `helm-schema` reads them from a CRD catalog,
[datreeio/CRDs-catalog](https://github.com/datreeio/CRDs-catalog), fetched when first needed and
cached on disk.

For a resource with an API group, the lookup goes, in order, to:

1. **your local overrides** in `--crd-override-dir`, which always win;
2. **the CRD catalog;**
3. **the Kubernetes schemas,** for built-in kinds.

## Strict and loose version lookup

```sh
helm-schema ./mychart --crd-version-lookup loose
```

- **`strict`**, the default: only the exact group, kind and version the chart uses are read. Another
  version is never used in its place: the schema of `v1alpha1` is not the schema of `v1`.
- **`loose`:** resolves the same way, and also looks through the local cache for other versions of
  the same group and kind. When the requested version is missing but others are cached, it reports
  [`CrdVersionAvailableAtOtherVersions`](https://romnn.github.io/helm-schema/docs/reference/diagnostics/), for
  information only.

`--strict-crd-version` is a short form of `--crd-version-lookup strict`.

## Mirrors and caching

`--crd-catalog-mirror` adds another source of CRD schemas. It repeats, and works in both lookup
modes:

```sh
helm-schema ./mychart --crd-catalog-mirror https://schemas.example.com/crds
```

Each mirror is cached in its own directory, so its files never take the place of the default
catalog's. Two more flags control the cache:

- **`--crd-catalog-cache-dir`:** the cache directory for CRD schemas, separate from the Kubernetes
  one; see [Caching](https://romnn.github.io/helm-schema/docs/reference/caching/).
- **`--crd-cache-record-source`:** writes a `<schema>.json.meta` file beside each cached schema
  with the address it came from and when, to find out which mirror answered.

## Local overrides

`--crd-override-dir` is a directory of schemas you keep yourself, read before the catalog and the
Kubernetes schemas:

```sh
helm-schema ./mychart --crd-override-dir ./schema-overrides
```

Each file is `<group>/<kind>_<version>.json`, such as
`monitoring.coreos.com/servicemonitor_v1.json`. Despite the `crd-` in its name, the directory takes
a schema for any resource with a group: a CRD you patched, or a built-in resource whose schema you
want to replace, to add constraints, keep an older schema, or work around an upstream bug.

- **It is never cleared.** Unlike the caches, it is your content, so point it only at a directory
  you control.
- **An unreadable file stops the lookup.** When an override exists but cannot be read,
  `helm-schema` reports `LocalOverrideUnreadable` and does not fall back to the catalog, since that
  would put a different schema in place of the one you chose.

> [!NOTE]
> `--crd-catalog-dir` was removed. Use `--crd-override-dir` for schemas you keep, and
> `--crd-catalog-cache-dir` for the cache. The old flag fails with a message that names both.
