libcluster
libcluster copied to clipboard
FEAT: Added function callback for kubernetes_node_basename
Summary of changes
- Updated
kubernetes_node_basenameso that it can be supplied with a function called which allows dynamic node basenames based on the given pod information
Imagine if you have 2 separate apps oban-workers & a phoenix api both with replicas 2. Now you want to connect them and both have different hostnames, one has oban the other one has api.
As a selector you could choose: kubernetes_selector: "app in (oban-workers, api)"
but the kubernetes_node_basename is a static variable so far. If you set it to api in the phoenix api pod, then it would successful connect to its other replica but fail to connect with the oban-workers as it tries to connect with the api hostname.
As a solution with a custom function, this can be dynamically set based on the pod information
kubernetes_node_basename: fn %{labels: %{"app" => app}} ->
case app do
"oban-workers" -> "oban"
"api" -> "api"
end
end
Hope this makes sense! :)
Best regards, Dario
@bitwalker Gentle ping! :) Hope that is fine and thanks again for this awesome library!