confd icon indicating copy to clipboard operation
confd copied to clipboard

Can not read key from etcd if prefix not "/"

Open metanovii opened this issue 6 years ago • 5 comments

 $  ETCDCTL_API=3 etcdctl  --user=root:root --endpoints="https://127.0.0.1:32771" put someprefix/somekey  "somevalue"

 $  ETCDCTL_API=3 etcdctl  --user=root:root --endpoints="https://127.0.0.1:32771" get "" --prefix  --keys-only | grep some
someprefix/somekey

cat conf.d/listdomains.toml 
[template]
src = "list_domains.tmpl"
dest = "/tmp/list_domains"
prefix = "someprefix"
keys = [
    "/somekey"    
]
 cat templates/list_domains.tmpl 
{{getv "someprefix/somekey"}}
root@nix-pc-10:/etc/confd# confd  -backend etcdv3 -interval 3 -node https://127.0.0.1:32771
2018-07-12T11:33:51+03:00 nix-pc-10 confd[13761]: INFO Backend set to etcdv3
2018-07-12T11:33:51+03:00 nix-pc-10 confd[13761]: INFO Starting confd
2018-07-12T11:33:51+03:00 nix-pc-10 confd[13761]: INFO Backend source(s) set to https://127.0.0.1:32771
2018-07-12T11:33:51+03:00 nix-pc-10 confd[13761]: ERROR template: list_domains.tmpl:1:2: executing "list_domains.tmpl" at <getv "someprefix/som...>: error calling getv: key does not exist: someprefix/somekey

metanovii avatar Jul 12 '18 08:07 metanovii

+1

zeast avatar Jul 13 '18 07:07 zeast

@metanovii thanks for opening an issue! All keys are internally converted to a unified form by confd, so even if the key doesn't have a / as a prefix it will, in fact, have a / as a prefix after it was fetched by confd. Therefore, you can reference the key someprefix/somekey as a /someprefix/somekey in confd.

okushchenko avatar Jul 14 '18 19:07 okushchenko

I try

{{getv "/someprefix/somekey"}}

and

{{getv "/someprefix/somekey"}}

and get

confd[10956]: ERROR template: list_domains.tmpl:1:2: executing "list_domains.tmpl" at <getv "/someprefix/so...>: error calling getv: key does not exist: /someprefix/somekey

metanovii avatar Jul 16 '18 16:07 metanovii

I’m having the same problem! K8s POD confd log follow

2019-01-29T07:26:14Z kube-hou02-pac543edaf18b546c1add5ab5abb795627-w1.cloud.ibm confd[6]: DEBUG Loading template resources from confdir /etc/confd 2019-01-29T07:26:14Z kube-hou02-pac543edaf18b546c1add5ab5abb795627-w1.cloud.ibm confd[6]: DEBUG Found template: /etc/confd/conf.d/..2019_01_29_07_15_13.065511479/config/haproxy-confd.toml 2019-01-29T07:26:14Z kube-hou02-pac543edaf18b546c1add5ab5abb795627-w1.cloud.ibm confd[6]: DEBUG Loading template resource from /etc/confd/conf.d/..2019_01_29_07_15_13.065511479/config/haproxy-confd.toml 2019-01-29T07:26:14Z kube-hou02-pac543edaf18b546c1add5ab5abb795627-w1.cloud.ibm confd[6]: DEBUG Retrieving keys from store 2019-01-29T07:26:14Z kube-hou02-pac543edaf18b546c1add5ab5abb795627-w1.cloud.ibm confd[6]: DEBUG Key prefix set to / 2019-01-29T07:26:14Z kube-hou02-pac543edaf18b546c1add5ab5abb795627-w1.cloud.ibm confd[6]: ERROR 100: Key not found (/gitlabsvc) [7]

my template file

[template] src = "haproxy-config.tmpl" dest = "/usr/local/etc/haproxy/haproxy.cfg" prefix = "/" keys = [ "/gitlabsvc" ] reload_cmd = "/etc/init.d/haproxy reload"

root@kube-hou02-pac543edaf18b546c1add5ab5abb795627-w1:/etcd-v3.3.11-linux-amd64# ./etcdctl --cacert=/etc/confd/ssl/etcd-ca --cert=/etc/confd/ssl/etcd-cert --key=/etc/confd/ssl/etcd-key --endpoints=https://172.20.0.x:2041 get gitlabsvc gitlabsvc 172.21.0.x

zhangyan1298 avatar Jan 29 '19 07:01 zhangyan1298

guys you can try my fork https://github.com/zyf0330/confd/, I have removed this annoying feature.

zyf0330 avatar Feb 25 '19 07:02 zyf0330