From e1c77303a37ca2570db9813837a9aa0aab2c1171 Mon Sep 17 00:00:00 2001 From: Joseph Phillips Date: Wed, 26 Jun 2024 12:10:04 +0200 Subject: [PATCH] fix(cmr) expose all controller addresses cross-controller We were previously sourcing addresses for cross-controller info from APIHostPortsForAgents and prioritising for local-cloud scope. This meant that we were not exposing public addresses resulting in some CMRs not being able to contact remote controllers. Here we user APIHostPortsForClients, which includes public addresses, and we prioritise for the public scope. --- .../controller/crosscontroller/register.go | 30 +++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) diff --git a/apiserver/facades/controller/crosscontroller/register.go b/apiserver/facades/controller/crosscontroller/register.go index ebc2fa089d54..c46f094ff3db 100644 --- a/apiserver/facades/controller/crosscontroller/register.go +++ b/apiserver/facades/controller/crosscontroller/register.go @@ -8,8 +8,9 @@ import ( "github.com/juju/errors" - "github.com/juju/juju/apiserver/common" "github.com/juju/juju/apiserver/facade" + "github.com/juju/juju/core/network" + "github.com/juju/juju/state" ) // Register is called to expose a package of facades onto a given registry. @@ -26,7 +27,7 @@ func newStateCrossControllerAPI(ctx facade.Context) (*CrossControllerAPI, error) return NewCrossControllerAPI( ctx.Resources(), func() ([]string, string, error) { - return common.StateControllerInfo(st) + return controllerInfo(st) }, func() (string, error) { config, err := st.ControllerConfig() @@ -38,3 +39,28 @@ func newStateCrossControllerAPI(ctx facade.Context) (*CrossControllerAPI, error) st.WatchAPIHostPortsForClients, ) } + +func controllerInfo(st *state.State) ([]string, string, error) { + apiHostPorts, err := st.APIHostPortsForClients() + if err != nil { + return nil, "", errors.Trace(err) + } + + var addrs []string + for _, hostPorts := range apiHostPorts { + ordered := hostPorts.HostPorts().PrioritizedForScope(network.ScopeMatchPublic) + for _, addr := range ordered { + if addr != "" { + addrs = append(addrs, addr) + } + } + } + + controllerConfig, err := st.ControllerConfig() + if err != nil { + return nil, "", errors.Trace(err) + } + + caCert, _ := controllerConfig.CACert() + return addrs, caCert, nil +}