Skip to content

Commit

Permalink
Documentation, op-guide, clientv3: add documentation for namespacing
Browse files Browse the repository at this point in the history
  • Loading branch information
Anthony Romano committed Mar 21, 2017
1 parent b8de1d0 commit 324383e
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
5 changes: 4 additions & 1 deletion Documentation/docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ The easiest way to get started using etcd as a distributed key-value store is to
- [gRPC API references][api_ref]
- [HTTP JSON API through the gRPC gateway][api_grpc_gateway]
- [gRPC naming and discovery][grpc_naming]
- [Client][namespace_client] and [proxy][namespace_proxy] namespacing
- [Embedding etcd][embed_etcd]
- [Experimental features and APIs][experimental]
- [System limits][system-limit]
Expand All @@ -25,7 +26,7 @@ Administrators who need to create reliable and scalable key-value stores for the

- [Setting up etcd clusters][clustering]
- [Setting up etcd gateways][gateway]
- [Setting up etcd gRPC proxy (pre-alpha)][grpc_proxy]
- [Setting up etcd gRPC proxy][grpc_proxy]
- [Run etcd clusters inside containers][container]
- [Hardware recommendations][hardware]
- [Configuration][conf]
Expand Down Expand Up @@ -90,3 +91,5 @@ Answers to [common questions] about etcd.
[experimental]: dev-guide/experimental_apis.md
[v3_upgrade]: upgrades/upgrade_3_0.md
[v31_upgrade]: upgrades/upgrade_3_1.md
[namespace_client]: https://godoc.org/github.com/coreos/etcd/clientv3/namespace
[namespace_proxy]: op-guide/grpc_proxy.md#namespacing
25 changes: 25 additions & 0 deletions Documentation/op-guide/grpc_proxy.md
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,28 @@ ETCDCTL_API=3 ./bin/etcdctl --endpoints=http://localhost:23792 member list --wri
| 0 | started | Gyu-Hos-MBP.sfo.coreos.systems | | 127.0.0.1:23792 |
+----+---------+--------------------------------+------------+-----------------+
```

## Namespacing

Suppose an application expects full control over the entire key space, but the etcd cluster is shared with other applications. To let all appications run without interfering with each other, the proxy can partition the etcd keyspace so clients appear to have access to the complete keyspace. When the proxy is given the flag `--namespace`, all client requests going into the proxy are translated to have a user-defined prefix on the keys. Accesses to the etcd cluster will be under the prefix and responses from the proxy will strip away the prefix; to the client, it appears as if there is no prefix at all.

To namespace a proxy, start it with `--namespace`:

```bash
$ etcd grpc-proxy start --endpoints=localhost:2379 \
--listen-addr=127.0.0.1:23790 \
--namespace=my-prefix/
```

Accesses to the proxy are now transparently prefixed on the etcd cluster:

```bash
$ ETCDCTL_API=3 ./bin/etcdctl --endpoints=localhost:23790 put my-key abc
# OK
$ ETCDCTL_API=3 ./bin/etcdctl --endpoints=localhost:23790 get my-key
# my-key
# abc
$ ETCDCTL_API=3 ./bin/etcdctl --endpoints=localhost:2379 get my-prefix/my-key
# my-prefix/my-key
# abc
```
4 changes: 4 additions & 0 deletions clientv3/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ if err != nil {

The etcd client optionally exposes RPC metrics through [go-grpc-prometheus](https://github.com/grpc-ecosystem/go-grpc-prometheus). See the [examples](https://github.com/coreos/etcd/blob/master/clientv3/example_metrics_test.go).

## Namespacing

The [namespace][https://godoc.org/github.com/coreos/etcd/clientv3/namespace] package provides `clientv3` interface wrappers to transparently isolate client requests to a user-defined prefix.

## Examples

More code examples can be found at [GoDoc](https://godoc.org/github.com/coreos/etcd/clientv3).
2 changes: 1 addition & 1 deletion clientv3/integration/namespace_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ func TestNamespacePutGet(t *testing.T) {
if string(resp.Kvs[0].Value) != "bar" {
t.Errorf("expected value=%q, got value=%q", "bar", resp.Kvs[0].Value)
}

}

func TestNamespaceWatch(t *testing.T) {
defer testutil.AfterTest(t)

Expand Down

0 comments on commit 324383e

Please sign in to comment.