How do I add a default value to a key in etcd3 if one does not already exist?

280 Views Asked by At

In etcd2, I could populate a default value as follows:

curl -Ss -XPUT "${ETCDCTL_PEERS}/v2/keys/mykey?prevExist=false" -d value=defaultValue

How can I achieve the same logic with etcdv3?

1

There are 1 best solutions below

0
On

Something like this:

etcdctl txn <<<'mod("my_key_exists") > "0"

get next_ip_value

put my_key_exists 1
put my_key "defaultValue"

'