Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to batch-load (initialize) from json file? #8205

Closed
ehudkaldor opened this issue Jul 3, 2017 · 7 comments
Closed

how to batch-load (initialize) from json file? #8205

ehudkaldor opened this issue Jul 3, 2017 · 7 comments

Comments

@ehudkaldor
Copy link

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...

@gyuho
Copy link
Contributor

gyuho commented Jul 5, 2017

@ehudkaldor
Copy link
Author

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).

@xiang90
Copy link
Contributor

xiang90 commented Jul 5, 2017

no. etcd will not load data from json file. you can write a script to do that after you bootstrap an etcd cluster.

@xiang90 xiang90 closed this as completed Jul 5, 2017
@ehudkaldor
Copy link
Author

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

@xiang90
Copy link
Contributor

xiang90 commented Jul 5, 2017

@ehudkaldor

your script looks good.

@ehudkaldor
Copy link
Author

am i the first one to ask for this kind of functionality? can we make it into an enhancement?

@sbutzek
Copy link

sbutzek commented Mar 8, 2021

In our team, we also had a hard time in loading initial values into etcd.
We came up with starting a second etcd container in our docker-compose setup, which does the job.
Maybe this is still helpful for someone: https://github.com/andrena/etcd-initializer

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

4 participants