Skip to content

Commit

Permalink
fix(cmr) expose all controller addresses cross-controller
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
manadart committed Jun 26, 2024
1 parent d3ac273 commit b95555c
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions apiserver/facades/controller/crosscontroller/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
package crosscontroller

import (
"github.com/juju/juju/core/network"
"github.com/juju/juju/state"
"reflect"

"github.com/juju/errors"

"github.com/juju/juju/apiserver/common"
"github.com/juju/juju/apiserver/facade"
)

Expand All @@ -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()
Expand All @@ -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
}

0 comments on commit b95555c

Please sign in to comment.