From 0deb3f0061af8d77430bffe0e9b153ce38e454f4 Mon Sep 17 00:00:00 2001 From: Lyncoln Date: Thu, 17 Sep 2026 17:08:06 -0400 Subject: [PATCH] Forward Pacemaker notifications to daemon shadow --- checksums/SHA256SUMS | 6 +- .../applications/postgresql/notify.sh | 57 +++++++++++++++++++ tests/run-all.sh | 1 + tests/test-notify-daemon-shadow.sh | 12 ++++ 4 files changed, 74 insertions(+), 2 deletions(-) create mode 100755 tests/test-notify-daemon-shadow.sh diff --git a/checksums/SHA256SUMS b/checksums/SHA256SUMS index 1786850..f2a6b9c 100644 --- a/checksums/SHA256SUMS +++ b/checksums/SHA256SUMS @@ -3,7 +3,7 @@ 10932919c4339b553c7c9dbf30b45a917c51c0a08f362e12678003d58b12fa82 ocf/loxthelion/managed-container.d/applications/postgresql/auth.sh 61d64b4a3a15c354f101ef34c5dc0425723f4204207d359b5377d2b9f04f6b23 ocf/loxthelion/managed-container.d/applications/postgresql/demote.sh 38323b217204132e572a9b1cfec8072773e502e49d6f0f96dfa2e565d332bbd1 ocf/loxthelion/managed-container.d/applications/postgresql/native_peers.sh -625e3b4fc6775164d351c98d1ef0e2c54cb2042c8a86015aa68649cb9c339260 ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh +54b10636f26f57691a1467c660682643c458bb8b5e8945bdab3d5caa4a5f3fb5 ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh 957a5a72ed277d0216e070abb80733483be3d421b9fa488e27fdd75bb2919548 ocf/loxthelion/managed-container.d/applications/postgresql/peer_config.sh 5091bc554915d1450fe939f94c0b0a370fecdb2ae5db9c4f0f55c340c0145519 ocf/loxthelion/managed-container.d/applications/postgresql/plugin.sh c1d878dabf22ad3928d66a5542bda3c150e5e9b039926629e7c5fd3401d29be4 ocf/loxthelion/managed-container.d/applications/postgresql/postgres.sh @@ -23,7 +23,9 @@ a42bb59a058ffeb59c1baa96e403856910bbbaea98f9104ff93daf4b5970c780 postgres-host/ 957a5a72ed277d0216e070abb80733483be3d421b9fa488e27fdd75bb2919548 postgres-host/postgres-ha-peer-config.sh deb09e3ae40629f43b262ba4f9a7ebf59a1dca3da9d8c94478f670aea28bd0e1 quadlet/postgres.container 04a125068677bbee6e71d313ca9d95d35faa32851b79de781cd7b9f466561445 quadlet/postgres.env.example -82162526c92a18c90ee425a28a89667fc211c7be4825ef2e91747e97efca41bd tests/run-all.sh +81dada1b948cf47a80521eb59761ea9d0b36a8c2b10f48fb0aea637b64de9adf tests/run-all.sh 5e5d4fdd2b6c7e0b8b146de7aad06c1f96b221a10fec525b00d40e0d85709fb0 tests/test-entrypoint-structure.sh +2faee72cf2fdcbfa667c3e1c2a7aabc053b96a9b8127ff7440ddb717fd2dc314 tests/test-notify-daemon-shadow.sh b83f0415c09f0be34c51722370e5b07c51b9a9756d305d3b3f50827f484aa4dd tests/test-proxy-client-actions.py +cc4482d229805c64d7df258a8a82984f244128d27fff4ea43b36caa004b56bef tests/test-proxy-client-parameters.py c3b988d7b2b1b138bb2530df9172f96bb0f5edc2f1561f38f0055695f4126134 tests/test-proxy-protocol.sh diff --git a/ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh b/ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh index 135994e..7df27f5 100755 --- a/ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh +++ b/ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh @@ -59,6 +59,61 @@ mc_pg_native_demote_target() mc_pg_demote_notification_target true } +mc_pg_notify_daemon_shadow() +{ + local socket_path resource parameters response rc + + socket_path="${MC_PROXY_SOCKET:-/run/user/1000/managed-containerd/managed-containerd.sock}" + resource="${OCF_RESOURCE_INSTANCE:-}" + resource="${resource%%:*}" + + [ -n "${resource}" ] || return 0 + + parameters="$( + python3 -c ' +import json +import os + +print(json.dumps({ + "type": os.environ.get("OCF_RESKEY_CRM_meta_notify_type", ""), + "operation": os.environ.get("OCF_RESKEY_CRM_meta_notify_operation", ""), + "promote_uname": os.environ.get("OCF_RESKEY_CRM_meta_notify_promote_uname", ""), + "demote_uname": os.environ.get("OCF_RESKEY_CRM_meta_notify_demote_uname", ""), + "promoted_uname": os.environ.get("OCF_RESKEY_CRM_meta_notify_promoted_uname", ""), + "unpromoted_uname": os.environ.get("OCF_RESKEY_CRM_meta_notify_unpromoted_uname", ""), +}, separators=(",", ":"))) +' + )" || { + ocf_log warn "unable to encode daemon notification parameters" + return 0 + } + + response="$( + timeout --kill-after=1s 3s \ + python3 \ + "${MC_PROXY_CLIENT:-/usr/lib/ocf/resource.d/loxthelion/managed-container.d/proxy_client.py}" \ + "${socket_path}" \ + "${resource}" \ + "notify" \ + 10 \ + 11 \ + "${parameters}" + )" + rc=$? + + if [ "${rc}" -ne 0 ]; then + ocf_log warn \ + "managed-containerd notify shadow unavailable rc=${rc}" + return 0 + fi + + ocf_log info \ + "managed-containerd notify shadow accepted: ${response}" + + return 0 +} + + managed_notify() { local state_dir state_file @@ -116,5 +171,7 @@ managed_notify() >> "${state_dir}/${OCF_RESOURCE_INSTANCE:-managed-container}.notify.log" } || true + mc_pg_notify_daemon_shadow + return "${OCF_SUCCESS}" } diff --git a/tests/run-all.sh b/tests/run-all.sh index ff6fa2d..2e49b7a 100755 --- a/tests/run-all.sh +++ b/tests/run-all.sh @@ -24,6 +24,7 @@ echo echo ">>> Generic proxy client actions" python3 ./tests/test-proxy-client-actions.py python3 ./tests/test-proxy-client-parameters.py +./tests/test-notify-daemon-shadow.sh echo echo ">>> Python syntax" diff --git a/tests/test-notify-daemon-shadow.sh b/tests/test-notify-daemon-shadow.sh new file mode 100755 index 0000000..a72daf8 --- /dev/null +++ b/tests/test-notify-daemon-shadow.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash +set -euo pipefail + +ROOT="$(CDPATH= cd -- "$(dirname -- "$0")/.." && pwd)" +FILE="$ROOT/ocf/loxthelion/managed-container.d/applications/postgresql/notify.sh" + +grep -q '^mc_pg_notify_daemon_shadow()' "$FILE" +grep -q '"notify"' "$FILE" +grep -q 'OCF_RESKEY_CRM_meta_notify_demote_uname' "$FILE" +grep -q 'managed-containerd notify shadow' "$FILE" + +echo "NOTIFY_DAEMON_SHADOW_TEST_PASS=1"