kbridge

kbridge is a single, generic Kubernetes controller that manages objects in external HTTP APIs from custom resources. A YAML descriptor describes each resource kind: the CRD schema, the HTTP calls that read, create, update and delete the external object, and the projection of the API response back into the spec shape. Adding a provider or a resource kind needs no Go code.

kbridge detects drift: on every sync it compares the external object with the spec, then reapplies the spec, raises an alert, or ignores the difference, as the resource’s drift policy says.

Status: early development. The shipped descriptors (AWS S3 bucket, Cloudflare R2 bucket, Proxmox VE storage) pass the integration tests against API fakes; they have not run against the real APIs yet.

How it works

  1. kbridge gen turns the descriptors into CRDs and RBAC.
  2. kbridge run starts one controller per enabled resource kind.
  3. For each custom resource, the controller resolves its ProviderConfig and credentials, reads the external object, creates it when absent, compares it with spec.forProvider, and calls the update operation for the fields that differ.
  4. The result goes to status: conditions Ready and Synced, and the observed state in status.atProvider. Drift also produces Kubernetes events, log lines and Prometheus metrics.

Quick start

Build and validate the shipped descriptors:

make build
./bin/kbridge validate --descriptors providers

Output:

aws/s3-bucket         Bucket.s3.aws.kbridge.io/v1alpha1
cloudflare/r2-bucket  Bucket.r2.cloudflare.kbridge.io/v1alpha1
proxmox/storage       Storage.storage.proxmox.kbridge.io/v1alpha1
3 resource(s) valid

Build and push the image, which embeds the providers/ directory:

docker build -t <registry>/kbridge:0.1.0 .
docker push <registry>/kbridge:0.1.0

Set newName: <registry>/kbridge and newTag: 0.1.0 under images in deploy/kustomization.yaml, then install the namespace, CRDs, RBAC and controller:

kubectl apply -k deploy

Store the AWS credentials in the controller namespace, without putting them on the command line:

kubectl -n kbridge create secret generic aws-credentials \
  --from-file=accessKeyId=./access-key-id \
  --from-file=secretAccessKey=./secret-access-key

Create a ProviderConfig and a bucket:

kubectl apply -f docs/examples/providerconfig-aws.yaml
kubectl apply -f docs/examples/s3-bucket.yaml
kubectl -n web get buckets.s3.aws.kbridge.io

docs/examples/ also holds an IRSA ProviderConfig and the Cloudflare R2 and Proxmox VE equivalents. Proxmox VE is self-hosted: see Self-hosted APIs first. The test suite validates every example against the generated CRDs.

Commands

Exit codes: 0 on success, 1 for invalid descriptors, flags or runtime errors, 2 for a missing or unknown command.

kbridge validate

Loads and validates the descriptors, then lists the enabled resources.

FlagRequiredDefaultDescription
--descriptorsyesDirectory holding Provider and Resource descriptors. It is searched recursively. Hidden entries and testdata directories are skipped.
--resourcesnoallComma-separated provider/resource list to enable.

kbridge gen

Prints the CRDs, ClusterRole, Role and bindings the enabled resources need, as YAML documents on stdout. make manifests writes the output for the shipped providers to deploy/generated.yaml; a test fails when that file is stale.

FlagRequiredDefaultDescription
--descriptorsyesAs for validate.
--resourcesnoallAs for validate.
--namespacenokbridgeNamespace the controller runs in. The Role (Secrets, leases, events) is created there.
--service-accountnokbridgeService account the controller runs as.
./bin/kbridge gen --descriptors providers --resources aws/s3-bucket > s3.yaml

kbridge run

Runs the controllers until it receives SIGINT or SIGTERM. At startup it checks that the CRD of every enabled resource is installed and serves the expected version.

FlagRequiredDefaultDescription
--descriptorsyesAs for validate. The image ships the descriptors in /providers.
--resourcesnoallAs for validate.
--namespaceyesNamespace of the credential Secrets and the leader election lease. The deployment passes the pod namespace.
--kubeconfignoin-clusterKubeconfig file. Without it, kbridge uses the pod service account and never reads ~/.kube/config.
--metrics-addrno:8080Prometheus metrics address; 0 disables it.
--health-addrno:8081Address of /healthz and /readyz; 0 disables it.
--leader-electnotrueElect a leader so that only one replica reconciles.
--workersno4Concurrent reconciles per resource kind.
--log-levelnoinfodebug, info, warn or error. Logs are JSON on stderr; debug adds one line per API request.

Documentation

  • Operating kbridge: ProviderConfig, credentials, managed resource fields, status, drift, adoption, deletion, metrics.
  • Descriptor reference: every field of Provider and Resource descriptors, and the expression variables.
  • Writing a provider: how to describe a new API, with the pitfalls to avoid.

Development

Requirements: Go 1.26 (the go command downloads it when GOTOOLCHAIN=auto). Lint and envtest tools run through go run at pinned versions.

make check   # fmt, vet, lint, tests with the race detector, coverage >= 85 %

make test downloads the Kubernetes API server binaries for envtest and fails if it cannot. The integration tests run the shipped descriptors against fake S3, R2 and Proxmox VE APIs, and against a fake API that assigns identifiers on create. They need no cloud account and touch no cluster.

Edit this page