diff --git a/modules/ketcd/README.rst b/modules/ketcd/README.rst index 7a48127bff8676169ec7256cb9bada68dedbdd91..6e2b072a42e8684a7e21421c5cac1814b8d9eb04 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 <https://github.com/mah0x211/lua-etcd#cli-err--etcdnew-optiontable->`_. + +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 5a43af086b49d077ea7186f45c80abd55a8786ae..80fb3598c650b707de1532bbfaa608ff7ed7ea7b 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