aprs.me/lib/aprsme/cluster/topology.ex
Graham McIntire 4804bd16be
Add distributed Erlang clustering for single APRS-IS connection
Implement leader election to ensure only one APRS-IS connection across
multiple Kubernetes replicas. This prevents duplicate packet processing
and respects APRS-IS usage policies.

Key changes:
- Add leader election using :global registry
- Create connection manager for dynamic APRS-IS management
- Implement packet distribution from leader to all nodes
- Add Kubernetes headless service for node discovery
- Configure DNS-based clustering with libcluster
- Update deployment to support 3 replicas with clustering

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-07-25 10:30:29 -05:00

43 lines
945 B
Elixir

defmodule Aprsme.Cluster.Topology do
@moduledoc """
Cluster topology configuration for different environments.
"""
def child_spec(opts) do
cluster_config = config()
if cluster_config do
{Cluster.Supervisor, [cluster_config, opts]}
else
# Return a no-op spec when clustering is disabled
%{
id: __MODULE__,
start: {__MODULE__, :start_link, [opts]},
type: :worker
}
end
end
def start_link(_opts), do: :ignore
defp config do
if Application.get_env(:aprsme, :cluster_enabled, false) do
kubernetes_config()
end
end
defp kubernetes_config do
[
kubernetes: [
strategy: Cluster.Strategy.Kubernetes,
config: [
mode: :dns,
kubernetes_node_basename: "aprs",
kubernetes_selector: "app=aprs",
kubernetes_namespace: "aprs",
polling_interval: 10_000
]
]
]
end
end