From: Marek VavruĊĦa Date: Thu, 7 May 2015 19:42:38 +0000 (+0200) Subject: modules/ketcd: cleanup, added some documentation X-Git-Tag: v1.0.0-beta1~198 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b05c13c96fafb71fc700b7c4a97bdf248c50f882;p=thirdparty%2Fknot-resolver.git modules/ketcd: cleanup, added some documentation --- diff --git a/modules/ketcd/README.rst b/modules/ketcd/README.rst index 7a48127bf..6e2b072a4 100644 --- a/modules/ketcd/README.rst +++ b/modules/ketcd/README.rst @@ -3,6 +3,38 @@ Etcd module ----------- +The module connects to Etcd peers and watches for configuration change. +By default, the module looks for the subtree under ``/kresolved`` directory, +but you can change this `in the configuration `_. + +The subtree structure corresponds to the configuration variables in the declarative style. + +.. code-block:: + + $ etcdctl set /kresolved/net/127.0.0.1 53 + $ etcdctl set /kresolved/modules/cachectl true + $ etcdctl set /kresolved/cache/size 10000000 + +Configures all listening nodes to following configuration: + +.. code-block:: lua + + net = { '127.0.0.1' } + modules = { 'cachectl' } + cache.size = 10000000 + +Example configuration +^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: lua + + modules = { + ketcd = { + prefix = '/kresolved', + peer = 'http://127.0.0.1:7001' + } + } + .. warning:: Work in progress! Dependencies diff --git a/modules/ketcd/ketcd.lua b/modules/ketcd/ketcd.lua index 5a43af086..80fb3598c 100644 --- a/modules/ketcd/ketcd.lua +++ b/modules/ketcd/ketcd.lua @@ -9,13 +9,15 @@ local function update_subtree(tree) update_subtree(k.nodes) else local key,opt = k.key:gmatch('([^/]+)/([^/]+)$')() - eval_cmd(key..'='..'{'..opt..'='..k.value..'}') + if _G[key][opt] ~= k.value then + _G[key][opt] = k.value + end end end end -- @function reload whole configuration -function ketcd.reload() +local function reload() local res, err = ketcd.cli:readdir('/', true) if err then error(err) @@ -49,7 +51,7 @@ function ketcd.config(conf) -- @todo: the etcd has watch() API, but this requires -- coroutines on socket operations if ketcd.ev then event.cancel(ketcd.ev) end - ketcd.ev = event.recurrent(5 * sec, ketcd.reload) + ketcd.ev = event.recurrent(5 * sec, reload) end return ketcd