fix(peering): replicating wan address (#15108)

* fix(peering): replicating wan address

* add changelog

* unit test
This commit is contained in:
cskh 2022-10-24 15:44:57 -04:00 committed by GitHub
parent a3a6743e0a
commit a5acb987fa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 39 additions and 1 deletions

3
.changelog/15108.txt Normal file
View File

@ -0,0 +1,3 @@
```release-note:bug
peering: when wan address is set, peering stream should use the wan address.
```

View File

@ -908,7 +908,13 @@ func (m *subscriptionManager) subscribeServerAddrs(
if srv.ExtGRPCPort == 0 {
continue
}
grpcAddr := srv.Address + ":" + strconv.Itoa(srv.ExtGRPCPort)
addr := srv.Address
// wan address is preferred
if v, ok := srv.TaggedAddresses[structs.TaggedAddressWAN]; ok && v != "" {
addr = v
}
grpcAddr := addr + ":" + strconv.Itoa(srv.ExtGRPCPort)
serverAddrs = append(serverAddrs, grpcAddr)
}
if len(serverAddrs) == 0 {

View File

@ -711,6 +711,35 @@ func TestSubscriptionManager_ServerAddrs(t *testing.T) {
)
})
testutil.RunStep(t, "added server with WAN address", func(t *testing.T) {
payload = append(payload, autopilotevents.ReadyServerInfo{
ID: "eec8721f-c42b-48da-a5a5-07565158015e",
Address: "198.18.0.3",
Version: "1.13.1",
ExtGRPCPort: 9502,
TaggedAddresses: map[string]string{
structs.TaggedAddressWAN: "198.18.0.103",
},
})
backend.Publish([]stream.Event{
{
Topic: autopilotevents.EventTopicReadyServers,
Index: 3,
Payload: payload,
},
})
expectEvents(t, subCh,
func(t *testing.T, got cache.UpdateEvent) {
require.Equal(t, subServerAddrs, got.CorrelationID)
addrs, ok := got.Result.(*pbpeering.PeeringServerAddresses)
require.True(t, ok)
require.Equal(t, []string{"198.18.0.1:8502", "198.18.0.2:9502", "198.18.0.103:9502"}, addrs.GetAddresses())
},
)
})
testutil.RunStep(t, "flipped to peering through mesh gateways", func(t *testing.T) {
require.NoError(t, backend.store.EnsureConfigEntry(1, &structs.MeshConfigEntry{
Peering: &structs.PeeringMeshConfig{