libcluster icon indicating copy to clipboard operation
libcluster copied to clipboard

FEAT: Added function callback for kubernetes_node_basename

Open Zarathustra2 opened this issue 3 years ago • 1 comments
trafficstars

Summary of changes

  • Updated kubernetes_node_basename so 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

Zarathustra2 avatar Mar 19 '22 16:03 Zarathustra2

@bitwalker Gentle ping! :) Hope that is fine and thanks again for this awesome library!

Zarathustra2 avatar May 22 '22 13:05 Zarathustra2