etcd v3 API types and gRPC service definitions in pure OCaml
README.md

etcd #

etcd v3 API types, an Eio client and a single-node server, in pure OCaml.

Overview #

etcd is the replicated key-value store behind Kubernetes, and its v3 API is gRPC over HTTP/2. Talking to it from OCaml has meant generating code from the protobuf files or shelling out to etcdctl. The etcd library maps the v3 messages (etcdserverpb and mvccpb) to OCaml records with nox-protobuf codecs and names each RPC as an nox-grpc method, with no I/O. The same definitions serve the client, the server and the tests.

The message types cover the KV, Lease, Watch, Auth, Cluster and Maintenance services, and the server answers all six, as a single-member cluster that does not enforce authentication. The client covers the KV service only (Range, Put and DeleteRange).

Packages #

  • etcd: the I/O-free message types and gRPC method definitions, and Etcd.Store, the storage interface a server dispatches to, with an in-memory implementation that follows etcd's revision and version rules. The whole store has one revision counter, raised by every transaction that changes anything; each key records the revision that created it, the revision of its last change and its version, the number of changes since its creation, reset to zero when the key is deleted. A read can ask for the store as it was at an older revision, and a watch resumes from one.
  • etcd-client: an Eio client for the etcdserverpb.KV service, with range, get, put and delete over one multiplexed connection.
  • etcd-server: an Eio gRPC server over any Etcd.Store.S, with key-value transactions, watches and leases; Etcd_server.Make (Etcd.Store.Memory) is a single-node in-memory etcd for tests.
  • etco: a command-line tool with get, put and del against a running etcd, serve for the in-memory server, and proxy, which serves the KV API by forwarding to a real etcd.

Installation #

$ opam install etcd-client

If opam cannot find the package, it may not yet be released in the public opam-repository. Add the overlay repository, then install it:

$ opam repo add samoht https://tangled.org/gazagnaire.org/opam-overlay.git
$ opam update
$ opam install etcd-client

API #

The interfaces are documented in the .mli files: one per service under lib/ (kv.mli, lease.mli, watch.mli, auth.mli, cluster.mli, maintenance.mli) plus store.mli, and the client and server under lib/client/ and lib/server/.

Licence #

ISC. See LICENSE.md.