Use new machine types
This commit is contained in:
parent
8a95fe517a
commit
6477e6a583
4 changed files with 10 additions and 92 deletions
17
acls.go
17
acls.go
|
@ -247,13 +247,7 @@ func expandAlias(
|
||||||
for _, namespace := range owners {
|
for _, namespace := range owners {
|
||||||
machines := filterMachinesByNamespace(machines, namespace)
|
machines := filterMachinesByNamespace(machines, namespace)
|
||||||
for _, machine := range machines {
|
for _, machine := range machines {
|
||||||
if len(machine.HostInfo) == 0 {
|
hi := machine.GetHostInfo()
|
||||||
continue
|
|
||||||
}
|
|
||||||
hi, err := machine.GetHostInfo()
|
|
||||||
if err != nil {
|
|
||||||
return ips, err
|
|
||||||
}
|
|
||||||
for _, t := range hi.RequestTags {
|
for _, t := range hi.RequestTags {
|
||||||
if alias == t {
|
if alias == t {
|
||||||
ips = append(ips, machine.IPAddresses.ToStringSlice()...)
|
ips = append(ips, machine.IPAddresses.ToStringSlice()...)
|
||||||
|
@ -315,15 +309,8 @@ func excludeCorrectlyTaggedNodes(
|
||||||
}
|
}
|
||||||
// for each machine if tag is in tags list, don't append it.
|
// for each machine if tag is in tags list, don't append it.
|
||||||
for _, machine := range nodes {
|
for _, machine := range nodes {
|
||||||
if len(machine.HostInfo) == 0 {
|
hi := machine.GetHostInfo()
|
||||||
out = append(out, machine)
|
|
||||||
|
|
||||||
continue
|
|
||||||
}
|
|
||||||
hi, err := machine.GetHostInfo()
|
|
||||||
if err != nil {
|
|
||||||
return out, err
|
|
||||||
}
|
|
||||||
found := false
|
found := false
|
||||||
for _, t := range hi.RequestTags {
|
for _, t := range hi.RequestTags {
|
||||||
if containsString(tags, t) {
|
if containsString(tags, t) {
|
||||||
|
|
25
grpcv1.go
25
grpcv1.go
|
@ -3,12 +3,10 @@ package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/juanfont/headscale/gen/go/headscale/v1"
|
"github.com/juanfont/headscale/gen/go/headscale/v1"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"gorm.io/datatypes"
|
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -262,13 +260,8 @@ func (api headscaleV1APIServer) GetMachineRoute(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
routes, err := machine.RoutesToProto()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &v1.GetMachineRouteResponse{
|
return &v1.GetMachineRouteResponse{
|
||||||
Routes: routes,
|
Routes: machine.RoutesToProto(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,13 +279,8 @@ func (api headscaleV1APIServer) EnableMachineRoutes(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
routes, err := machine.RoutesToProto()
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &v1.EnableMachineRoutesResponse{
|
return &v1.EnableMachineRoutesResponse{
|
||||||
Routes: routes,
|
Routes: machine.RoutesToProto(),
|
||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -379,13 +367,6 @@ func (api headscaleV1APIServer) DebugCreateMachine(
|
||||||
Hostname: "DebugTestMachine",
|
Hostname: "DebugTestMachine",
|
||||||
}
|
}
|
||||||
|
|
||||||
log.Trace().Caller().Interface("hostinfo", hostinfo).Msg("")
|
|
||||||
|
|
||||||
hostinfoJson, err := json.Marshal(hostinfo)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
newMachine := Machine{
|
newMachine := Machine{
|
||||||
MachineKey: request.GetKey(),
|
MachineKey: request.GetKey(),
|
||||||
Name: request.GetName(),
|
Name: request.GetName(),
|
||||||
|
@ -395,7 +376,7 @@ func (api headscaleV1APIServer) DebugCreateMachine(
|
||||||
LastSeen: &time.Time{},
|
LastSeen: &time.Time{},
|
||||||
LastSuccessfulUpdate: &time.Time{},
|
LastSuccessfulUpdate: &time.Time{},
|
||||||
|
|
||||||
HostInfo: datatypes.JSON(hostinfoJson),
|
HostInfo: HostInfo(hostinfo),
|
||||||
}
|
}
|
||||||
|
|
||||||
// log.Trace().Caller().Interface("machine", newMachine).Msg("")
|
// log.Trace().Caller().Interface("machine", newMachine).Msg("")
|
||||||
|
|
21
poll.go
21
poll.go
|
@ -2,7 +2,6 @@ package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
|
@ -11,7 +10,6 @@ import (
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
"github.com/rs/zerolog/log"
|
"github.com/rs/zerolog/log"
|
||||||
"gorm.io/datatypes"
|
|
||||||
"gorm.io/gorm"
|
"gorm.io/gorm"
|
||||||
"tailscale.com/tailcfg"
|
"tailscale.com/tailcfg"
|
||||||
"tailscale.com/types/key"
|
"tailscale.com/types/key"
|
||||||
|
@ -85,12 +83,8 @@ func (h *Headscale) PollNetMapHandler(ctx *gin.Context) {
|
||||||
Str("machine", machine.Name).
|
Str("machine", machine.Name).
|
||||||
Msg("Found machine in database")
|
Msg("Found machine in database")
|
||||||
|
|
||||||
hostinfo, err := json.Marshal(req.Hostinfo)
|
|
||||||
if err != nil {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
machine.Name = req.Hostinfo.Hostname
|
machine.Name = req.Hostinfo.Hostname
|
||||||
machine.HostInfo = datatypes.JSON(hostinfo)
|
machine.HostInfo = HostInfo(*req.Hostinfo)
|
||||||
machine.DiscoKey = DiscoPublicKeyStripPrefix(req.DiscoKey)
|
machine.DiscoKey = DiscoPublicKeyStripPrefix(req.DiscoKey)
|
||||||
now := time.Now().UTC()
|
now := time.Now().UTC()
|
||||||
|
|
||||||
|
@ -114,18 +108,7 @@ func (h *Headscale) PollNetMapHandler(ctx *gin.Context) {
|
||||||
// The intended use is for clients to discover the DERP map at start-up
|
// The intended use is for clients to discover the DERP map at start-up
|
||||||
// before their first real endpoint update.
|
// before their first real endpoint update.
|
||||||
if !req.ReadOnly {
|
if !req.ReadOnly {
|
||||||
endpoints, err := json.Marshal(req.Endpoints)
|
machine.Endpoints = req.Endpoints
|
||||||
if err != nil {
|
|
||||||
log.Error().
|
|
||||||
Caller().
|
|
||||||
Str("func", "PollNetMapHandler").
|
|
||||||
Err(err).
|
|
||||||
Msg("Failed to mashal requested endpoints for the client")
|
|
||||||
ctx.String(http.StatusInternalServerError, ":(")
|
|
||||||
|
|
||||||
return
|
|
||||||
}
|
|
||||||
machine.Endpoints = datatypes.JSON(endpoints)
|
|
||||||
machine.LastSeen = &now
|
machine.LastSeen = &now
|
||||||
}
|
}
|
||||||
h.db.Updates(machine)
|
h.db.Updates(machine)
|
||||||
|
|
39
routes.go
39
routes.go
|
@ -1,9 +1,6 @@
|
||||||
package headscale
|
package headscale
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
|
||||||
|
|
||||||
"gorm.io/datatypes"
|
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,12 +20,7 @@ func (h *Headscale) GetAdvertisedNodeRoutes(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
hostInfo, err := machine.GetHostInfo()
|
return &machine.HostInfo.RoutableIPs, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
return &hostInfo.RoutableIPs, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use machine function instead
|
// Deprecated: use machine function instead
|
||||||
|
@ -43,27 +35,7 @@ func (h *Headscale) GetEnabledNodeRoutes(
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
data, err := machine.EnabledRoutes.MarshalJSON()
|
return machine.EnabledRoutes, nil
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
routesStr := []string{}
|
|
||||||
err = json.Unmarshal(data, &routesStr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
|
|
||||||
routes := make([]netaddr.IPPrefix, len(routesStr))
|
|
||||||
for index, routeStr := range routesStr {
|
|
||||||
route, err := netaddr.ParseIPPrefix(routeStr)
|
|
||||||
if err != nil {
|
|
||||||
return nil, err
|
|
||||||
}
|
|
||||||
routes[index] = route
|
|
||||||
}
|
|
||||||
|
|
||||||
return routes, nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Deprecated: use machine function instead
|
// Deprecated: use machine function instead
|
||||||
|
@ -135,12 +107,7 @@ func (h *Headscale) EnableNodeRoute(
|
||||||
return errRouteIsNotAvailable
|
return errRouteIsNotAvailable
|
||||||
}
|
}
|
||||||
|
|
||||||
routes, err := json.Marshal(enabledRoutes)
|
machine.EnabledRoutes = enabledRoutes
|
||||||
if err != nil {
|
|
||||||
return err
|
|
||||||
}
|
|
||||||
|
|
||||||
machine.EnabledRoutes = datatypes.JSON(routes)
|
|
||||||
h.db.Save(&machine)
|
h.db.Save(&machine)
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in a new issue