Descriptor reference
Descriptors are YAML files with apiVersion: kbridge.io/v1alpha1 and one document per file. A Provider describes how to reach an API. A Resource maps one custom resource kind to the API calls that manage its external object. Unknown fields are errors. kbridge validates every descriptor and compiles every expression at startup and in kbridge validate, so a broken descriptor never reaches a running controller.
Working examples: providers/aws/ (XML, SigV4, several calls per operation) providers/cloudflare/ (JSON, bearer token) and providers/proxmox/ (JSON, token header, existence read from a list).
Provider
apiVersion: kbridge.io/v1alpha1
kind: Provider
metadata:
name: cloudflare
spec:
endpoint: https://api.cloudflare.com/client/v4
allowedHosts: ['^api\.cloudflare\.com$']
encoding: json
auth:
type: bearer
rateLimit:
rps: 4
burst: 8
timeout: 10s
retryable: [429, 500, 502, 503, 504]
| Field | Required | Description |
|---|---|---|
metadata.name | yes | Provider name, referenced by resources and ProviderConfigs. Lowercase DNS label. |
spec.endpoint | no | Base URL used by resources without their own endpoint. HTTPS, no query, no fragment, no trailing slash. May hold {param} placeholders. |
spec.allowedHosts | yes | Regular expressions anchored with ^ and $. A request whose host, with its port if any, matches none of them fails before it is sent. |
spec.encoding | yes | json or xml: the format of request and response bodies. |
spec.auth.type | yes | bearer, header, basic or awsSigV4. See Operating kbridge for the matching Secret keys. |
spec.auth.header | with header | Name of the header that carries the Secret’s value. |
spec.rateLimit.rps, burst | yes | Request rate per ProviderConfig; rps > 0, burst >= 1. |
spec.timeout | yes | Timeout of one request, at most 5m. |
spec.retryable | no | HTTP statuses retried with backoff. Any other error status is final until the next sync. |
spec.contentMD5 | no | Send a Content-MD5 header with each body. S3 requires it for some calls. |
spec.errorMessage | no | String expression that builds the error message from response. Without it, or when it returns "", the message is HTTP <status>. |
Resource
| Field | Required | Description |
|---|---|---|
metadata.name | yes | Resource name; provider/name selects it in --resources. |
spec.provider | yes | Name of a Provider descriptor. |
spec.crd.group | yes | API group of the generated CRD. Must contain a dot. |
spec.crd.version | yes | v1, v1beta1, v1alpha1 style. |
spec.crd.kind | yes | UpperCamelCase kind. The plural is derived from it. |
spec.crd.immutable | no | Top-level forProvider properties that cannot change after creation. The CRD enforces it with a validation rule, and kbridge never sends updates for them. |
spec.crd.schema | yes | OpenAPI v3 schema of spec.forProvider: an object with properties. |
spec.endpoint | no | Overrides the provider endpoint, for example https://{bucket}.s3.{region}.amazonaws.com. |
spec.params | no | Map of placeholder name to expression. Names are identifiers other than id. |
spec.headers | no | Map of header name to string expression, sent with every request of the resource. |
spec.authParams | with awsSigV4 | service and region expressions for request signing. |
spec.drift.interval | no | Time between syncs, at least 30s. Default 10m. |
spec.drift.policy | no | Default drift policy of the kind: Reapply, Alert or Ignore. Default Reapply. A resource can override it. |
spec.operations.read | yes | steps and observe. |
spec.operations.create | yes | steps and id. |
spec.operations.update | when a property is mutable | steps. |
spec.operations.delete | yes | steps. |
Operations
Each operation runs its steps in order and stops at the first failure.
read.observeis an expression that projects the step results into the shape offorProvider. It returns a map, ornullwhen the object does not exist. kbridge compares the keys it returns withforProviderand stores the map instatus.atProvider.create.idis a string expression that returns the external identifier. kbridge stores it in thekbridge.io/external-nameannotation and exposes it asid. Derive it fromspecwhen the API allows it: kbridge can then recover the identifier after an interrupted create.updateruns withchanged, the list of mutable top-level fields that differ, andobserved, the observed state. Usewhento send only the calls thatchangedneeds.deleteruns withidset.
Step
- name: get
method: GET
path: /accounts/{account}/r2/buckets/{bucket}
absentOn: [404]
| Field | Required | Description |
|---|---|---|
name | no | Identifier. Named steps store their result in steps.<name> for later steps and for observe or id. |
when | no | Boolean expression. The step is skipped when it returns false. |
method | yes | GET, HEAD, POST, PUT, PATCH or DELETE. |
path | yes | Starts with /. {param} placeholders are allowed before the query only; the query is literal, as in /?versioning. {id} is the external identifier, unavailable in create. |
headers | no | Map of header name to string expression, merged over the resource headers. An empty string removes the header. Authorization, Host and Content-Length are reserved. |
body | no | Expression encoded with the provider encoding. null sends no body. Not allowed with GET or HEAD. |
accept | no | Error statuses handled as success, for example 404 in a delete. The step result carries the status. |
absentOn | no | Read steps only. These statuses mean the object does not exist: the read stops and reports it absent. |
A step result is a map:
| Key | Type | Description |
|---|---|---|
status | int | HTTP status. |
headers | map(string, string) | Response headers, lowercase names. |
body | dyn | Decoded body, null when empty. |
Placeholders
Endpoint and path placeholders take their value from params, or from id in paths. kbridge checks every value before it builds the URL:
- endpoint values must be lowercase DNS labels, so that a spec value cannot redirect requests to another host;
- path values are percent-encoded, and empty,
.and..values are rejected.
Expressions
Expressions use CEL. They are type-checked at load time, and their evaluation cost is bounded.
| Variable | Type | Available | Content |
|---|---|---|---|
spec | map | everywhere | spec.forProvider of the resource. |
meta | map | everywhere | name, namespace, uid, generation, labels, annotations of the resource. |
config | map | everywhere | spec.values of the ProviderConfig. |
id | string | everywhere | External identifier; empty before it is known. |
steps | map | steps, observe, id | Results of the named steps already run in the current operation. |
changed | list(string) | update | Mutable fields to converge. |
observed | map | update | Observed state before the update. |
response | map | provider errorMessage | Failed response: status, headers, body. |
Extensions: optional values (spec.?field.orValue(x), ?"key": spec.?field in map literals), the string and list libraries, two-variable comprehensions (transformList, transformMap, transformMapEntry), and toList(x). toList returns lists unchanged, [] for null, and wraps any other value in a list.
Codecs
JSON numbers without a fraction decode as integers. XML bodies encode from a map with a single root key. Lists become repeated elements and map keys are written in sorted order. XML decoding gives:
- text elements as strings;
- empty elements as
{}; - repeated elements as lists, but a single occurrence as a plain value. Wrap such elements with
toList().