mirror of
https://github.com/tailscale/tailscale.git
synced 2026-11-30 13:32:46 -08:00
feature/conn25: check online when picking connector
So that when control notices a node isn't responding and sends that info down in a netmap we will stop picking that node as a connector. This doesn't provide great failover (it takes several minutes) but it's better than not failing over at all. Updates tailscale/corp#47250 Signed-off-by: Fran Bull <[email protected]>
This commit is contained in:
1 parent
247c67809b
commit
a7769cbc33
2 files changed
+27
-5
No files matched your search
@@ -1104,7 +1104,7 @@ func makePeerAPIReq(ctx context.Context, httpClient *http.Client, urlBase string
|
||||
|
||||
func (e *extension) pickConnectorURLBase(app appctype.Conn25Attr) (tailcfg.NodeView, string) {
|
||||
nb := e.host.NodeBackend()
|
||||
peers := PickConnector(nb, app)
|
||||
peers := pickConnector(nb, app)
|
||||
var urlBase string
|
||||
var conn tailcfg.NodeView
|
||||
for _, p := range peers {
|
||||
@@ -1690,14 +1690,17 @@ func sortByPreference(ns []tailcfg.NodeView) {
|
||||
})
|
||||
}
|
||||
|
||||
// PickConnector returns peers the backend knows about that match the app, in order of preference to use as
|
||||
// pickConnector returns peers the backend knows about that match the app, in order of preference to use as
|
||||
// a connector.
|
||||
func PickConnector(nb ipnext.NodeBackend, app appctype.Conn25Attr) []tailcfg.NodeView {
|
||||
func pickConnector(nb ipnext.NodeBackend, app appctype.Conn25Attr) []tailcfg.NodeView {
|
||||
appTagsSet := set.SetOf(app.Connectors)
|
||||
matches := nb.AppendMatchingPeers(nil, func(n tailcfg.NodeView) bool {
|
||||
if !isPeerEligibleConnector(n) {
|
||||
return false
|
||||
}
|
||||
if !n.Online().Get() {
|
||||
return false
|
||||
}
|
||||
for _, t := range n.Tags().All() {
|
||||
if appTagsSet.Contains(t) {
|
||||
return true
|
||||
|
||||
@@ -1668,6 +1668,7 @@ func TestAddressAssignmentIsHandled(t *testing.T) {
|
||||
Tags: []string{"tag:woo"},
|
||||
Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(true)}).View(),
|
||||
Key: key.NodePublicFromRaw32(mem.B([]byte{0: 0xff, 1: 0xff, 31: 0x01})),
|
||||
Online: new(true),
|
||||
}).View()
|
||||
|
||||
ext := &extension{
|
||||
@@ -2362,12 +2363,14 @@ func TestHandleAddressAssignmentStoresTransitIPs(t *testing.T) {
|
||||
Tags: []string{"tag:woo"},
|
||||
Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(true)}).View(),
|
||||
Key: key.NodePublicFromRaw32(mem.B([]byte{0: 0xff, 31: 0x01})),
|
||||
Online: new(true),
|
||||
}).View(),
|
||||
(&tailcfg.Node{
|
||||
ID: tailcfg.NodeID(2),
|
||||
Tags: []string{"tag:hoo"},
|
||||
Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(true)}).View(),
|
||||
Key: key.NodePublicFromRaw32(mem.B([]byte{0: 0xff, 31: 0x02})),
|
||||
Online: new(true),
|
||||
}).View(),
|
||||
}
|
||||
|
||||
@@ -3256,6 +3259,16 @@ func TestPickConnector(t *testing.T) {
|
||||
ID: id,
|
||||
Tags: tags,
|
||||
Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(isConnector)}).View(),
|
||||
Online: new(true),
|
||||
}).View()
|
||||
}
|
||||
|
||||
nvWithOnlineSet := func(id tailcfg.NodeID, online bool, tags ...string) tailcfg.NodeView {
|
||||
return (&tailcfg.Node{
|
||||
ID: id,
|
||||
Tags: tags,
|
||||
Hostinfo: (&tailcfg.Hostinfo{AppConnector: opt.NewBool(true)}).View(),
|
||||
Online: new(online),
|
||||
}).View()
|
||||
}
|
||||
|
||||
@@ -3318,7 +3331,7 @@ func TestPickConnector(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "not-a-connector",
|
||||
candidates: []tailcfg.NodeView{nvWithConnectorSet(1, false, "tag:example.com"), nv(2, "tag:example")},
|
||||
candidates: []tailcfg.NodeView{nvWithConnectorSet(1, false, "tag:example"), nv(2, "tag:example")},
|
||||
app: exampleApp,
|
||||
want: []tailcfg.NodeView{nv(2, "tag:example")},
|
||||
},
|
||||
@@ -3370,9 +3383,15 @@ func TestPickConnector(t *testing.T) {
|
||||
nv(7, "tag:example1", "tag:example"),
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "not-online",
|
||||
candidates: []tailcfg.NodeView{nvWithOnlineSet(1, false, "tag:example"), nv(2, "tag:example")},
|
||||
app: exampleApp,
|
||||
want: []tailcfg.NodeView{nv(2, "tag:example")},
|
||||
},
|
||||
} {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
got := PickConnector(&testNodeBackend{peers: tt.candidates}, tt.app)
|
||||
got := pickConnector(&testNodeBackend{peers: tt.candidates}, tt.app)
|
||||
if diff := cmp.Diff(tt.want, got); diff != "" {
|
||||
t.Fatalf("PickConnectors (-want, +got):\n%s", diff)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user