From 39134f74c36a33768c0b40f33553d196278e38e9 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 5 Mar 2023 20:51:20 +0100 Subject: [PATCH] cluster/services/patroni: switch to consul, remove etcd --- cluster/services/patroni/default.nix | 22 +--------------------- cluster/services/patroni/etcd.nix | 28 ---------------------------- cluster/services/patroni/worker.nix | 2 +- 3 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 cluster/services/patroni/etcd.nix diff --git a/cluster/services/patroni/default.nix b/cluster/services/patroni/default.nix index a490000..d127a56 100644 --- a/cluster/services/patroni/default.nix +++ b/cluster/services/patroni/default.nix @@ -1,32 +1,14 @@ { config, lib, ... }: -let - cfg = config.services.patroni; - - renameToLink = mode: n: lib.nameValuePair "patroni-etcd-node-${mode}-${n}"; - - genLinks = mode: nodes: f: lib.mapAttrs' (renameToLink mode) (lib.genAttrs nodes f); - - getMeshIp = name: config.vars.mesh.${name}.meshIp; - - mkLink = name: { - ipv4 = getMeshIp name; - protocol = "http"; - }; -in { vars.patroni = { - etcdNodes = lib.genAttrs cfg.nodes.etcd (name: config.links."patroni-etcd-node-peer-${name}"); - etcdNodesClient = lib.genAttrs cfg.nodes.etcd (name: config.links."patroni-etcd-node-client-${name}"); passwords = { PATRONI_REPLICATION_PASSWORD = ./passwords/replication.age; PATRONI_SUPERUSER_PASSWORD = ./passwords/superuser.age; PATRONI_REWIND_PASSWORD = ./passwords/rewind.age; }; }; - links = genLinks "client" cfg.nodes.etcd mkLink - // genLinks "peer" cfg.nodes.etcd mkLink - // { + links = { patroni-pg-internal.ipv4 = "0.0.0.0"; patroni-api.ipv4 = "0.0.0.0"; patroni-pg-access.ipv4 = "127.0.0.1"; @@ -34,12 +16,10 @@ in services.patroni = { nodes = { worker = [ "VEGAS" "prophet" ]; - etcd = [ "checkmate" "VEGAS" "prophet" ]; haproxy = [ "VEGAS" "prophet" ]; }; nixos = { worker = ./worker.nix; - etcd = ./etcd.nix; haproxy = ./haproxy.nix; }; }; diff --git a/cluster/services/patroni/etcd.nix b/cluster/services/patroni/etcd.nix deleted file mode 100644 index bb4b6fd..0000000 --- a/cluster/services/patroni/etcd.nix +++ /dev/null @@ -1,28 +0,0 @@ -{ cluster, lib, pkgs, ... }: - -let - inherit (cluster.config) vars; - - getEtcdUrl = name: vars.patroni.etcdNodes.${name}.url; - - mkMember = n: "${n}=${getEtcdUrl n}"; -in - -{ - services.etcd = { - enable = true; - dataDir = "/srv/storage/private/etcd"; - initialCluster = map mkMember cluster.config.services.patroni.nodes.etcd; - listenPeerUrls = lib.singleton vars.patroni.etcdNodes.${vars.hostName}.url; - listenClientUrls = lib.singleton vars.patroni.etcdNodesClient.${vars.hostName}.url; - }; - systemd.services.etcd = { - # run on any architecture - environment.ETCD_UNSUPPORTED_ARCH = pkgs.go.GOARCH; - serviceConfig = { - TimeoutStartSec = "900s"; - RestartSec = "5s"; - Restart = "on-failure"; - }; - }; -} diff --git a/cluster/services/patroni/worker.nix b/cluster/services/patroni/worker.nix index 5f129d2..be6e50f 100644 --- a/cluster/services/patroni/worker.nix +++ b/cluster/services/patroni/worker.nix @@ -40,7 +40,7 @@ in raft = false; softwareWatchdog = true; settings = { - etcd3.hosts = map (x: x.tuple) (lib.attrValues vars.patroni.etcdNodesClient); + consul.host = "127.0.0.1:8500"; bootstrap.dcs = { ttl = 30; loop_wait = 10;