Skip to content

Commit

Permalink
lint fix
Browse files Browse the repository at this point in the history
Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Nov 23, 2023
1 parent 895df70 commit 8520fee
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 75 deletions.
3 changes: 1 addition & 2 deletions hscontrol/db/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,6 @@ func (hsdb *HSDatabase) DeleteRoute(id uint64) error {
if err := hsdb.db.Unscoped().Delete(&route).Error; err != nil {
return err
}

} else {
routes, err := hsdb.getNodeRoutes(&node)
if err != nil {
Expand Down Expand Up @@ -290,7 +289,7 @@ func (hsdb *HSDatabase) deleteNodeRoutes(node *types.Node) error {
return err
}

// TODO(kradalby): This is a bit too agressive, we could probably
// TODO(kradalby): This is a bit too aggressive, we could probably
// figure out which routes needs to be failed over rather than all.
hsdb.failoverRouteWithNotify(&routes[i])
}
Expand Down
1 change: 0 additions & 1 deletion hscontrol/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ func (h *Headscale) handlePoll(
}

return

} else if mapRequest.OmitPeers && !mapRequest.Stream && mapRequest.ReadOnly {
// ReadOnly is whether the client just wants to fetch the
// MapResponse, without updating their Endpoints. The
Expand Down
2 changes: 1 addition & 1 deletion hscontrol/types/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (rs Routes) Prefixes() []netip.Prefix {
return prefixes
}

// Primaries returns Primary routes from a list of routes
// Primaries returns Primary routes from a list of routes.
func (rs Routes) Primaries() Routes {
res := make(Routes, 0)
for _, route := range rs {
Expand Down
134 changes: 67 additions & 67 deletions integration/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,9 @@ func TestEnablingRoutes(t *testing.T) {
assert.Len(t, routes, 3)

for _, route := range routes {
assert.Equal(t, route.Advertised, true)
assert.Equal(t, route.Enabled, false)
assert.Equal(t, route.IsPrimary, false)
assert.Equal(t, route.GetAdvertised(), true)
assert.Equal(t, route.GetEnabled(), false)
assert.Equal(t, route.GetIsPrimary(), false)
}

// Verify that no routes has been sent to the client,
Expand All @@ -109,7 +109,7 @@ func TestEnablingRoutes(t *testing.T) {
"routes",
"enable",
"--route",
strconv.Itoa(int(route.Id)),
strconv.Itoa(int(route.GetId())),
})
assertNoErr(t, err)
}
Expand All @@ -130,9 +130,9 @@ func TestEnablingRoutes(t *testing.T) {
assert.Len(t, enablingRoutes, 3)

for _, route := range enablingRoutes {
assert.Equal(t, route.Advertised, true)
assert.Equal(t, route.Enabled, true)
assert.Equal(t, route.IsPrimary, true)
assert.Equal(t, route.GetAdvertised(), true)
assert.Equal(t, route.GetEnabled(), true)
assert.Equal(t, route.GetIsPrimary(), true)
}

time.Sleep(5 * time.Second)
Expand Down Expand Up @@ -182,7 +182,7 @@ func TestEnablingRoutes(t *testing.T) {
"routes",
"disable",
"--route",
strconv.Itoa(int(routeToBeDisabled.Id)),
strconv.Itoa(int(routeToBeDisabled.GetId())),
})
assertNoErr(t, err)

Expand All @@ -201,14 +201,14 @@ func TestEnablingRoutes(t *testing.T) {
assertNoErr(t, err)

for _, route := range disablingRoutes {
assert.Equal(t, true, route.Advertised)
assert.Equal(t, true, route.GetAdvertised())

if route.Id == routeToBeDisabled.Id {
assert.Equal(t, route.Enabled, false)
assert.Equal(t, route.IsPrimary, false)
if route.GetId() == routeToBeDisabled.GetId() {
assert.Equal(t, route.GetEnabled(), false)
assert.Equal(t, route.GetIsPrimary(), false)
} else {
assert.Equal(t, route.Enabled, true)
assert.Equal(t, route.IsPrimary, true)
assert.Equal(t, route.GetEnabled(), true)
assert.Equal(t, route.GetIsPrimary(), true)
}
}

Expand All @@ -222,7 +222,7 @@ func TestEnablingRoutes(t *testing.T) {
for _, peerKey := range status.Peers() {
peerStatus := status.Peer[peerKey]

if string(peerStatus.ID) == fmt.Sprintf("%d", routeToBeDisabled.Node.Id) {
if string(peerStatus.ID) == fmt.Sprintf("%d", routeToBeDisabled.GetNode().GetId()) {
assert.Nilf(
t,
peerStatus.PrimaryRoutes,
Expand Down Expand Up @@ -324,9 +324,9 @@ func TestHASubnetRouterFailover(t *testing.T) {
assert.Len(t, routes, 2)

for _, route := range routes {
assert.Equal(t, true, route.Advertised)
assert.Equal(t, false, route.Enabled)
assert.Equal(t, false, route.IsPrimary)
assert.Equal(t, true, route.GetAdvertised())
assert.Equal(t, false, route.GetEnabled())
assert.Equal(t, false, route.GetIsPrimary())
}

// Verify that no routes has been sent to the client,
Expand All @@ -350,7 +350,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
"routes",
"enable",
"--route",
strconv.Itoa(int(route.Id)),
strconv.Itoa(int(route.GetId())),
})
assertNoErr(t, err)

Expand All @@ -373,14 +373,14 @@ func TestHASubnetRouterFailover(t *testing.T) {
assert.Len(t, enablingRoutes, 2)

// Node 1 is primary
assert.Equal(t, true, enablingRoutes[0].Advertised)
assert.Equal(t, true, enablingRoutes[0].Enabled)
assert.Equal(t, true, enablingRoutes[0].IsPrimary)
assert.Equal(t, true, enablingRoutes[0].GetAdvertised())
assert.Equal(t, true, enablingRoutes[0].GetEnabled())
assert.Equal(t, true, enablingRoutes[0].GetIsPrimary())

// Node 2 is not primary
assert.Equal(t, true, enablingRoutes[1].Advertised)
assert.Equal(t, true, enablingRoutes[1].Enabled)
assert.Equal(t, false, enablingRoutes[1].IsPrimary)
assert.Equal(t, true, enablingRoutes[1].GetAdvertised())
assert.Equal(t, true, enablingRoutes[1].GetEnabled())
assert.Equal(t, false, enablingRoutes[1].GetIsPrimary())

// Verify that the client has routes from the primary machine
srs1, err := subRouter1.Status()
Expand Down Expand Up @@ -424,14 +424,14 @@ func TestHASubnetRouterFailover(t *testing.T) {
assert.Len(t, routesAfterMove, 2)

// Node 1 is not primary
assert.Equal(t, true, routesAfterMove[0].Advertised)
assert.Equal(t, true, routesAfterMove[0].Enabled)
assert.Equal(t, false, routesAfterMove[0].IsPrimary)
assert.Equal(t, true, routesAfterMove[0].GetAdvertised())
assert.Equal(t, true, routesAfterMove[0].GetEnabled())
assert.Equal(t, false, routesAfterMove[0].GetIsPrimary())

// Node 2 is primary
assert.Equal(t, true, routesAfterMove[1].Advertised)
assert.Equal(t, true, routesAfterMove[1].Enabled)
assert.Equal(t, true, routesAfterMove[1].IsPrimary)
assert.Equal(t, true, routesAfterMove[1].GetAdvertised())
assert.Equal(t, true, routesAfterMove[1].GetEnabled())
assert.Equal(t, true, routesAfterMove[1].GetIsPrimary())

// TODO(kradalby): Check client status
// Route is expected to be on SR2
Expand Down Expand Up @@ -478,16 +478,16 @@ func TestHASubnetRouterFailover(t *testing.T) {
assert.Len(t, routesAfterBothDown, 2)

// Node 1 is not primary
assert.Equal(t, true, routesAfterBothDown[0].Advertised)
assert.Equal(t, true, routesAfterBothDown[0].Enabled)
assert.Equal(t, false, routesAfterBothDown[0].IsPrimary)
assert.Equal(t, true, routesAfterBothDown[0].GetAdvertised())
assert.Equal(t, true, routesAfterBothDown[0].GetEnabled())
assert.Equal(t, false, routesAfterBothDown[0].GetIsPrimary())

// Node 2 is primary
// if the node goes down, but no other suitable route is
// available, keep the last known good route.
assert.Equal(t, true, routesAfterBothDown[1].Advertised)
assert.Equal(t, true, routesAfterBothDown[1].Enabled)
assert.Equal(t, true, routesAfterBothDown[1].IsPrimary)
assert.Equal(t, true, routesAfterBothDown[1].GetAdvertised())
assert.Equal(t, true, routesAfterBothDown[1].GetEnabled())
assert.Equal(t, true, routesAfterBothDown[1].GetIsPrimary())

// TODO(kradalby): Check client status
// Both are expected to be down
Expand Down Expand Up @@ -533,14 +533,14 @@ func TestHASubnetRouterFailover(t *testing.T) {
assert.Len(t, routesAfter1Up, 2)

// Node 1 is primary
assert.Equal(t, true, routesAfter1Up[0].Advertised)
assert.Equal(t, true, routesAfter1Up[0].Enabled)
assert.Equal(t, true, routesAfter1Up[0].IsPrimary)
assert.Equal(t, true, routesAfter1Up[0].GetAdvertised())
assert.Equal(t, true, routesAfter1Up[0].GetEnabled())
assert.Equal(t, true, routesAfter1Up[0].GetIsPrimary())

// Node 2 is not primary
assert.Equal(t, true, routesAfter1Up[1].Advertised)
assert.Equal(t, true, routesAfter1Up[1].Enabled)
assert.Equal(t, false, routesAfter1Up[1].IsPrimary)
assert.Equal(t, true, routesAfter1Up[1].GetAdvertised())
assert.Equal(t, true, routesAfter1Up[1].GetEnabled())
assert.Equal(t, false, routesAfter1Up[1].GetIsPrimary())

// Verify that the route is announced from subnet router 1
clientStatus, err = client.Status()
Expand Down Expand Up @@ -583,14 +583,14 @@ func TestHASubnetRouterFailover(t *testing.T) {
assert.Len(t, routesAfter2Up, 2)

// Node 1 is not primary
assert.Equal(t, true, routesAfter2Up[0].Advertised)
assert.Equal(t, true, routesAfter2Up[0].Enabled)
assert.Equal(t, true, routesAfter2Up[0].IsPrimary)
assert.Equal(t, true, routesAfter2Up[0].GetAdvertised())
assert.Equal(t, true, routesAfter2Up[0].GetEnabled())
assert.Equal(t, true, routesAfter2Up[0].GetIsPrimary())

// Node 2 is primary
assert.Equal(t, true, routesAfter2Up[1].Advertised)
assert.Equal(t, true, routesAfter2Up[1].Enabled)
assert.Equal(t, false, routesAfter2Up[1].IsPrimary)
assert.Equal(t, true, routesAfter2Up[1].GetAdvertised())
assert.Equal(t, true, routesAfter2Up[1].GetEnabled())
assert.Equal(t, false, routesAfter2Up[1].GetIsPrimary())

// Verify that the route is announced from subnet router 1
clientStatus, err = client.Status()
Expand Down Expand Up @@ -618,7 +618,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
"routes",
"disable",
"--route",
fmt.Sprintf("%d", routesAfter2Up[0].Id),
fmt.Sprintf("%d", routesAfter2Up[0].GetId()),
})
assertNoErr(t, err)

Expand All @@ -640,14 +640,14 @@ func TestHASubnetRouterFailover(t *testing.T) {
assert.Len(t, routesAfterDisabling1, 2)

// Node 1 is not primary
assert.Equal(t, true, routesAfterDisabling1[0].Advertised)
assert.Equal(t, false, routesAfterDisabling1[0].Enabled)
assert.Equal(t, false, routesAfterDisabling1[0].IsPrimary)
assert.Equal(t, true, routesAfterDisabling1[0].GetAdvertised())
assert.Equal(t, false, routesAfterDisabling1[0].GetEnabled())
assert.Equal(t, false, routesAfterDisabling1[0].GetIsPrimary())

// Node 2 is primary
assert.Equal(t, true, routesAfterDisabling1[1].Advertised)
assert.Equal(t, true, routesAfterDisabling1[1].Enabled)
assert.Equal(t, true, routesAfterDisabling1[1].IsPrimary)
assert.Equal(t, true, routesAfterDisabling1[1].GetAdvertised())
assert.Equal(t, true, routesAfterDisabling1[1].GetEnabled())
assert.Equal(t, true, routesAfterDisabling1[1].GetIsPrimary())

// Verify that the route is announced from subnet router 1
clientStatus, err = client.Status()
Expand Down Expand Up @@ -675,7 +675,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
"routes",
"enable",
"--route",
fmt.Sprintf("%d", routesAfter2Up[0].Id),
fmt.Sprintf("%d", routesAfter2Up[0].GetId()),
})
assertNoErr(t, err)

Expand All @@ -697,14 +697,14 @@ func TestHASubnetRouterFailover(t *testing.T) {
assert.Len(t, routesAfterEnabling1, 2)

// Node 1 is not primary
assert.Equal(t, true, routesAfterEnabling1[0].Advertised)
assert.Equal(t, true, routesAfterEnabling1[0].Enabled)
assert.Equal(t, false, routesAfterEnabling1[0].IsPrimary)
assert.Equal(t, true, routesAfterEnabling1[0].GetAdvertised())
assert.Equal(t, true, routesAfterEnabling1[0].GetEnabled())
assert.Equal(t, false, routesAfterEnabling1[0].GetIsPrimary())

// Node 2 is primary
assert.Equal(t, true, routesAfterEnabling1[1].Advertised)
assert.Equal(t, true, routesAfterEnabling1[1].Enabled)
assert.Equal(t, true, routesAfterEnabling1[1].IsPrimary)
assert.Equal(t, true, routesAfterEnabling1[1].GetAdvertised())
assert.Equal(t, true, routesAfterEnabling1[1].GetEnabled())
assert.Equal(t, true, routesAfterEnabling1[1].GetIsPrimary())

// Verify that the route is announced from subnet router 1
clientStatus, err = client.Status()
Expand Down Expand Up @@ -732,7 +732,7 @@ func TestHASubnetRouterFailover(t *testing.T) {
"routes",
"delete",
"--route",
fmt.Sprintf("%d", routesAfterEnabling1[1].Id),
fmt.Sprintf("%d", routesAfterEnabling1[1].GetId()),
})
assertNoErr(t, err)

Expand All @@ -756,9 +756,9 @@ func TestHASubnetRouterFailover(t *testing.T) {
t.Logf("routes after deleting2 %#v", routesAfterDeleting2)

// Node 1 is primary
assert.Equal(t, true, routesAfterDeleting2[0].Advertised)
assert.Equal(t, true, routesAfterDeleting2[0].Enabled)
assert.Equal(t, true, routesAfterDeleting2[0].IsPrimary)
assert.Equal(t, true, routesAfterDeleting2[0].GetAdvertised())
assert.Equal(t, true, routesAfterDeleting2[0].GetEnabled())
assert.Equal(t, true, routesAfterDeleting2[0].GetIsPrimary())

// Verify that the route is announced from subnet router 1
clientStatus, err = client.Status()
Expand Down
1 change: 0 additions & 1 deletion integration/scenario.go
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,6 @@ func (s *Scenario) WaitForTailscaleSync() error {
for _, client := range user.Clients {
peers, _ := client.PrettyPeers()
log.Println(peers)

}
}
}
Expand Down
6 changes: 3 additions & 3 deletions integration/tsic/tsic.go
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ func (t *TailscaleInContainer) Logout() error {
return nil
}

// Helper that runs `tailscale up` with no arguments
// Helper that runs `tailscale up` with no arguments.
func (t *TailscaleInContainer) Up() error {
command := []string{
"tailscale",
Expand All @@ -436,7 +436,7 @@ func (t *TailscaleInContainer) Up() error {
return nil
}

// Helper that runs `tailscale down` with no arguments
// Helper that runs `tailscale down` with no arguments.
func (t *TailscaleInContainer) Down() error {
command := []string{
"tailscale",
Expand Down Expand Up @@ -524,7 +524,7 @@ func (t *TailscaleInContainer) FQDN() (string, error) {
return status.Self.DNSName, nil
}

// PrettyPeers returns a formatted-ish table of peers in the client
// PrettyPeers returns a formatted-ish table of peers in the client.
func (t *TailscaleInContainer) PrettyPeers() (string, error) {
status, err := t.Status()
if err != nil {
Expand Down

0 comments on commit 8520fee

Please sign in to comment.