Search code examples
goetcd

The Go client and 'etcdctl' cli utility tool seem to be working on different workspaces even though they are connected to the same hosts


I wrote a little Go program that connects to etcd hosts http://192.168.0.210:2379 and http://192.168.0.211:2379, sets a key /foo to bar and then reads it and prints the result. That part is working fine:

bar &{get {Key: /foo, CreatedIndex: 6, ModifiedIndex: 6, TTL: 0} <nil> 6 67b31bc85ffd6d2b} <nil>

the key can also be read using a HTTP GET request

{
    "action": "get",
    "node": {
        "key": "/foo",
        "value": "bar",
        "modifiedIndex": 6,
        "createdIndex": 6
    }
}

but when I use ectdctl it returns nothing as if the key didn't exist

./etcdctl --endpoints=192.168.0.210:2379,192.168.0.211:2379 get /foo

if I instead set /foo using etcdctl, then it works and reads the key correctly. It looks like etcdctl is working on a workspace of its own. Any ideas why this is happening?


Solution

  • The issue was I was using API v2 for the client and v3 for the etcdctl. Different API versions have different key namespaces. To use client v3 in Go import go.etcd.io/etcd/clientv3