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]
FieldRequiredDescription
metadata.nameyesProvider name, referenced by resources and ProviderConfigs. Lowercase DNS label.
spec.endpointnoBase URL used by resources without their own endpoint. HTTPS, no query, no fragment, no trailing slash. May hold {param} placeholders.
spec.allowedHostsyesRegular expressions anchored with ^ and $. A request whose host, with its port if any, matches none of them fails before it is sent.
spec.encodingyesjson or xml: the format of request and response bodies.
spec.auth.typeyesbearer, header, basic or awsSigV4. See Operating kbridge for the matching Secret keys.
spec.auth.headerwith headerName of the header that carries the Secret’s value.
spec.rateLimit.rps, burstyesRequest rate per ProviderConfig; rps > 0, burst >= 1.
spec.timeoutyesTimeout of one request, at most 5m.
spec.retryablenoHTTP statuses retried with backoff. Any other error status is final until the next sync.
spec.contentMD5noSend a Content-MD5 header with each body. S3 requires it for some calls.
spec.errorMessagenoString expression that builds the error message from response. Without it, or when it returns "", the message is HTTP <status>.

Resource

FieldRequiredDescription
metadata.nameyesResource name; provider/name selects it in --resources.
spec.provideryesName of a Provider descriptor.
spec.crd.groupyesAPI group of the generated CRD. Must contain a dot.
spec.crd.versionyesv1, v1beta1, v1alpha1 style.
spec.crd.kindyesUpperCamelCase kind. The plural is derived from it.
spec.crd.immutablenoTop-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.schemayesOpenAPI v3 schema of spec.forProvider: an object with properties.
spec.endpointnoOverrides the provider endpoint, for example https://{bucket}.s3.{region}.amazonaws.com.
spec.paramsnoMap of placeholder name to expression. Names are identifiers other than id.
spec.headersnoMap of header name to string expression, sent with every request of the resource.
spec.authParamswith awsSigV4service and region expressions for request signing.
spec.drift.intervalnoTime between syncs, at least 30s. Default 10m.
spec.drift.policynoDefault drift policy of the kind: Reapply, Alert or Ignore. Default Reapply. A resource can override it.
spec.operations.readyessteps and observe.
spec.operations.createyessteps and id.
spec.operations.updatewhen a property is mutablesteps.
spec.operations.deleteyessteps.

Operations

Each operation runs its steps in order and stops at the first failure.

  • read.observe is an expression that projects the step results into the shape of forProvider. It returns a map, or null when the object does not exist. kbridge compares the keys it returns with forProvider and stores the map in status.atProvider.
  • create.id is a string expression that returns the external identifier. kbridge stores it in the kbridge.io/external-name annotation and exposes it as id. Derive it from spec when the API allows it: kbridge can then recover the identifier after an interrupted create.
  • update runs with changed, the list of mutable top-level fields that differ, and observed, the observed state. Use when to send only the calls that changed needs.
  • delete runs with id set.

Step

- name: get
  method: GET
  path: /accounts/{account}/r2/buckets/{bucket}
  absentOn: [404]
FieldRequiredDescription
namenoIdentifier. Named steps store their result in steps.<name> for later steps and for observe or id.
whennoBoolean expression. The step is skipped when it returns false.
methodyesGET, HEAD, POST, PUT, PATCH or DELETE.
pathyesStarts with /. {param} placeholders are allowed before the query only; the query is literal, as in /?versioning. {id} is the external identifier, unavailable in create.
headersnoMap of header name to string expression, merged over the resource headers. An empty string removes the header. Authorization, Host and Content-Length are reserved.
bodynoExpression encoded with the provider encoding. null sends no body. Not allowed with GET or HEAD.
acceptnoError statuses handled as success, for example 404 in a delete. The step result carries the status.
absentOnnoRead steps only. These statuses mean the object does not exist: the read stops and reports it absent.

A step result is a map:

KeyTypeDescription
statusintHTTP status.
headersmap(string, string)Response headers, lowercase names.
bodydynDecoded 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.

VariableTypeAvailableContent
specmapeverywherespec.forProvider of the resource.
metamapeverywherename, namespace, uid, generation, labels, annotations of the resource.
configmapeverywherespec.values of the ProviderConfig.
idstringeverywhereExternal identifier; empty before it is known.
stepsmapsteps, observe, idResults of the named steps already run in the current operation.
changedlist(string)updateMutable fields to converge.
observedmapupdateObserved state before the update.
responsemapprovider errorMessageFailed 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().

Edit this page