diff options
Diffstat (limited to '')
20 files changed, 175 insertions, 0 deletions
diff --git a/modules/etcd/.packaging/centos/7/pre-test.sh b/modules/etcd/.packaging/centos/7/pre-test.sh new file mode 100755 index 0000000..4df79d9 --- /dev/null +++ b/modules/etcd/.packaging/centos/7/pre-test.sh @@ -0,0 +1 @@ +luarocks install etcd --from=https://mah0x211.github.io/rocks/ diff --git a/modules/etcd/.packaging/centos/7/rundeps b/modules/etcd/.packaging/centos/7/rundeps new file mode 100644 index 0000000..795a3c4 --- /dev/null +++ b/modules/etcd/.packaging/centos/7/rundeps @@ -0,0 +1,6 @@ +openssl-devel +lua-devel +luarocks +git +gcc +make diff --git a/modules/etcd/.packaging/centos/8/NOTSUPPORTED b/modules/etcd/.packaging/centos/8/NOTSUPPORTED new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/modules/etcd/.packaging/centos/8/NOTSUPPORTED diff --git a/modules/etcd/.packaging/debian/10/pre-test.sh b/modules/etcd/.packaging/debian/10/pre-test.sh new file mode 100755 index 0000000..20073dc --- /dev/null +++ b/modules/etcd/.packaging/debian/10/pre-test.sh @@ -0,0 +1 @@ +luarocks --lua-version 5.1 install etcd --from=https://mah0x211.github.io/rocks/ diff --git a/modules/etcd/.packaging/debian/10/rundeps b/modules/etcd/.packaging/debian/10/rundeps new file mode 100644 index 0000000..02d3fcf --- /dev/null +++ b/modules/etcd/.packaging/debian/10/rundeps @@ -0,0 +1,4 @@ +libssl-dev +luarocks +git +make diff --git a/modules/etcd/.packaging/debian/9/pre-test.sh b/modules/etcd/.packaging/debian/9/pre-test.sh new file mode 100755 index 0000000..4df79d9 --- /dev/null +++ b/modules/etcd/.packaging/debian/9/pre-test.sh @@ -0,0 +1 @@ +luarocks install etcd --from=https://mah0x211.github.io/rocks/ diff --git a/modules/etcd/.packaging/debian/9/rundeps b/modules/etcd/.packaging/debian/9/rundeps new file mode 100644 index 0000000..02d3fcf --- /dev/null +++ b/modules/etcd/.packaging/debian/9/rundeps @@ -0,0 +1,4 @@ +libssl-dev +luarocks +git +make diff --git a/modules/etcd/.packaging/fedora/31/NOTSUPPORTED b/modules/etcd/.packaging/fedora/31/NOTSUPPORTED new file mode 100644 index 0000000..b912289 --- /dev/null +++ b/modules/etcd/.packaging/fedora/31/NOTSUPPORTED @@ -0,0 +1,16 @@ +Error installing etcd using luarocks: + + + +Missing dependencies for process 1.9.0-1: + luarocks-fetch-gitrec >= 0.2 (not installed) + +process 1.9.0-1 depends on luarocks-fetch-gitrec >= 0.2 (not installed) +Installing https://luarocks.org/luarocks-fetch-gitrec-0.2-1.src.rock + +No existing manifest. Attempting to rebuild... +luarocks-fetch-gitrec 0.2-1 is now installed in /root/.luarocks (license: MIT) + + +Error: Unknown protocol gitrec + diff --git a/modules/etcd/.packaging/fedora/32/NOTSUPPORTED b/modules/etcd/.packaging/fedora/32/NOTSUPPORTED new file mode 100644 index 0000000..b912289 --- /dev/null +++ b/modules/etcd/.packaging/fedora/32/NOTSUPPORTED @@ -0,0 +1,16 @@ +Error installing etcd using luarocks: + + + +Missing dependencies for process 1.9.0-1: + luarocks-fetch-gitrec >= 0.2 (not installed) + +process 1.9.0-1 depends on luarocks-fetch-gitrec >= 0.2 (not installed) +Installing https://luarocks.org/luarocks-fetch-gitrec-0.2-1.src.rock + +No existing manifest. Attempting to rebuild... +luarocks-fetch-gitrec 0.2-1 is now installed in /root/.luarocks (license: MIT) + + +Error: Unknown protocol gitrec + diff --git a/modules/etcd/.packaging/leap/15.2/pre-test.sh b/modules/etcd/.packaging/leap/15.2/pre-test.sh new file mode 100755 index 0000000..20073dc --- /dev/null +++ b/modules/etcd/.packaging/leap/15.2/pre-test.sh @@ -0,0 +1 @@ +luarocks --lua-version 5.1 install etcd --from=https://mah0x211.github.io/rocks/ diff --git a/modules/etcd/.packaging/leap/15.2/rundeps b/modules/etcd/.packaging/leap/15.2/rundeps new file mode 100644 index 0000000..e8df59b --- /dev/null +++ b/modules/etcd/.packaging/leap/15.2/rundeps @@ -0,0 +1,6 @@ +libopenssl-devel +lua51-devel +lua51-luarocks +git +gcc +make diff --git a/modules/etcd/.packaging/test.config b/modules/etcd/.packaging/test.config new file mode 100644 index 0000000..1cc7e5a --- /dev/null +++ b/modules/etcd/.packaging/test.config @@ -0,0 +1,4 @@ +-- SPDX-License-Identifier: GPL-3.0-or-later +modules.load('etcd') +assert(etcd) +quit() diff --git a/modules/etcd/.packaging/ubuntu/16.04/pre-test.sh b/modules/etcd/.packaging/ubuntu/16.04/pre-test.sh new file mode 100755 index 0000000..4df79d9 --- /dev/null +++ b/modules/etcd/.packaging/ubuntu/16.04/pre-test.sh @@ -0,0 +1 @@ +luarocks install etcd --from=https://mah0x211.github.io/rocks/ diff --git a/modules/etcd/.packaging/ubuntu/16.04/rundeps b/modules/etcd/.packaging/ubuntu/16.04/rundeps new file mode 100644 index 0000000..a355a9f --- /dev/null +++ b/modules/etcd/.packaging/ubuntu/16.04/rundeps @@ -0,0 +1,3 @@ +libssl-dev +luarocks +git diff --git a/modules/etcd/.packaging/ubuntu/18.04/pre-test.sh b/modules/etcd/.packaging/ubuntu/18.04/pre-test.sh new file mode 100755 index 0000000..4df79d9 --- /dev/null +++ b/modules/etcd/.packaging/ubuntu/18.04/pre-test.sh @@ -0,0 +1 @@ +luarocks install etcd --from=https://mah0x211.github.io/rocks/ diff --git a/modules/etcd/.packaging/ubuntu/18.04/rundeps b/modules/etcd/.packaging/ubuntu/18.04/rundeps new file mode 100644 index 0000000..a355a9f --- /dev/null +++ b/modules/etcd/.packaging/ubuntu/18.04/rundeps @@ -0,0 +1,3 @@ +libssl-dev +luarocks +git diff --git a/modules/etcd/.packaging/ubuntu/20.04/pre-test.sh b/modules/etcd/.packaging/ubuntu/20.04/pre-test.sh new file mode 100755 index 0000000..20073dc --- /dev/null +++ b/modules/etcd/.packaging/ubuntu/20.04/pre-test.sh @@ -0,0 +1 @@ +luarocks --lua-version 5.1 install etcd --from=https://mah0x211.github.io/rocks/ diff --git a/modules/etcd/.packaging/ubuntu/20.04/rundeps b/modules/etcd/.packaging/ubuntu/20.04/rundeps new file mode 100644 index 0000000..02d3fcf --- /dev/null +++ b/modules/etcd/.packaging/ubuntu/20.04/rundeps @@ -0,0 +1,4 @@ +libssl-dev +luarocks +git +make diff --git a/modules/etcd/README.rst b/modules/etcd/README.rst new file mode 100644 index 0000000..0ffa781 --- /dev/null +++ b/modules/etcd/README.rst @@ -0,0 +1,46 @@ +.. SPDX-License-Identifier: GPL-3.0-or-later + +.. _mod-etcd: + +Etcd support +------------ + +The `etcd` module connects to `etcd <https://etcd.io/>`_ peers and watches +for configuration changes. By default, the module watches the subtree under +``/knot-resolver`` directory, but you can change this in the +`etcd library 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:: bash + + $ etcdctl set /knot-resolver/net/127.0.0.1 53 + $ etcdctl set /knot-resolver/cache/size 10000000 + +Configures all listening nodes to following configuration: + +.. code-block:: lua + + net = { '127.0.0.1' } + cache.size = 10000000 + +Example configuration +^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: lua + + modules.load('etcd') + etcd.config({ + prefix = '/knot-resolver', + peer = 'http://127.0.0.1:7001' + }) + +.. warning:: Work in progress! + +Dependencies +^^^^^^^^^^^^ + +* `lua-etcd <https://github.com/mah0x211/lua-etcd>`_ library available in LuaRocks + + ``$ luarocks --lua-version 5.1 install etcd --from=https://mah0x211.github.io/rocks/`` + diff --git a/modules/etcd/etcd.lua b/modules/etcd/etcd.lua new file mode 100644 index 0000000..ab58024 --- /dev/null +++ b/modules/etcd/etcd.lua @@ -0,0 +1,56 @@ +--- @module etcd +-- SPDX-License-Identifier: GPL-3.0-or-later +local etcd = {} + +-- @function update subtree configuration +local function update_subtree(tree) + if not tree then return end + for _, k in pairs(tree) do + if k.dir then + update_subtree(k.nodes) + else + local key,opt = k.key:gmatch('([^/]+)/([^/]+)$')() + if _G[key][opt] ~= k.value then + _G[key][opt] = k.value + end + end + end +end + +-- @function reload whole configuration +function etcd.reload() + local res, err = etcd.cli:readdir('/', true) + if err then + error(err) + end + update_subtree(res.body.node.nodes) +end + +function etcd.init() + etcd.Etcd = require('etcd.luasocket') + etcd.defaults = { prefix = '/knot-resolver' } +end + +function etcd.deinit() + if etcd.ev then event.cancel(etcd.ev) end +end + +function etcd.config(conf) + local options = etcd.defaults + if type(conf) == 'table' then + for k,v in pairs(conf) do options[k] = v end + end + -- create connection + local cli, err = etcd.Etcd.new(options) + if err then + error(err) + end + etcd.cli = cli + -- schedule recurrent polling + -- @todo: the etcd has watch() API, but this requires + -- coroutines on socket operations + if etcd.ev then event.cancel(etcd.ev) end + etcd.ev = event.recurrent(5 * sec, etcd.reload) +end + +return etcd |