I cannot seem to find a way to initialize etcd using a json file. A two-level file is what I need (directory from each top level, than its children as key-value pairs), but even a flat file would be good at this point. It any other way...
@ehudkaldor We currently support YAML format https://github.com/coreos/etcd/blob/master/embed/config.go#L199.
Example config can be found here https://github.com/coreos/etcd/blob/master/etcd.conf.yml.sample
not what I meant. this is how how to use a conf file for etcd itself. What I am looking for is a way to input (set/mk/whatever) the values I need served by etcd, after it starts.
It would be nice if, as part of the etcd running command (etcd --name myEtcd...) I could provide a file with the values I want in etcd, preferably (for me) from a json file, that etcd would parse and insert. leaf values should be key:value pairs, anything that is higher level should be a directory.
so, if my init.json file is:
"topVal1" : {
"key1" : "val1",
"key2" : "val2"
},
"topVal2" : {
"key3" : "val3"
}
than
etcd --name "myEtcd" ........ --init-file ./init.json
should yield a directory named topVal1 with 2 kv pairs (key1:val1, key2:val2) and another directory named topVal2 with one kv pair (key3:val3).
no. etcd will not load data from json file. you can write a script to do that after you bootstrap an etcd cluster.
for that matter, this is how i do it now using jq:
for topic in `jq -r 'keys[]' /opt/env `; do
echo;
for key in `jq .$topic /opt/env | jq -r 'keys[]'`; do
echo "$topic/$key:";
myVal=`jq -r [".$topic | .$key"] /opt/env | jq -r .[]`;
echo "myVal: $myVal";
ETCDCTL_API=3 etcdctl --endpoints=127.0.0.1:2379 put $topic/$key $myVal ;
curl http://127.0.0.1:2379/v2/keys/$topic/$key -XPUT -d value="$myVal"
done;
echo;
done
@ehudkaldor
your script looks good.
am i the first one to ask for this kind of functionality? can we make it into an enhancement?
Most helpful comment
am i the first one to ask for this kind of functionality? can we make it into an enhancement?