Skip to content

Commit

Permalink
Update headscale to v0.20.0 which contains some breaking changes (#420)
Browse files Browse the repository at this point in the history
  • Loading branch information
majst01 authored Mar 6, 2023
1 parent 2156944 commit 0fac0a3
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 74 deletions.
25 changes: 12 additions & 13 deletions cmd/metal-api/internal/headscale/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,33 +81,33 @@ func (h *HeadscaleClient) GetControlPlaneAddress() string {
return h.controlPlaneAddress
}

func (h *HeadscaleClient) NamespaceExists(name string) bool {
getNSRequest := &headscalev1.GetNamespaceRequest{
func (h *HeadscaleClient) UserExists(name string) bool {
req := &headscalev1.GetUserRequest{
Name: name,
}
if _, err := h.client.GetNamespace(h.ctx, getNSRequest); err != nil {
if _, err := h.client.GetUser(h.ctx, req); err != nil {
return false
}

return true
}

func (h *HeadscaleClient) CreateNamespace(name string) error {
req := &headscalev1.CreateNamespaceRequest{
func (h *HeadscaleClient) CreateUser(name string) error {
req := &headscalev1.CreateUserRequest{
Name: name,
}
_, err := h.client.CreateNamespace(h.ctx, req)
_, err := h.client.CreateUser(h.ctx, req)
// TODO: this error check is pretty rough, but it's not easily possible to compare the proto error directly :/
if err != nil && !strings.Contains(err.Error(), headscalecore.ErrNamespaceExists.Error()) {
return fmt.Errorf("failed to create new VPN namespace: %w", err)
if err != nil && !strings.Contains(err.Error(), headscalecore.ErrUserExists.Error()) {
return fmt.Errorf("failed to create new VPN user: %w", err)
}

return nil
}

func (h *HeadscaleClient) CreatePreAuthKey(namespace string, expiration time.Time, isEphemeral bool) (key string, err error) {
func (h *HeadscaleClient) CreatePreAuthKey(user string, expiration time.Time, isEphemeral bool) (key string, err error) {
req := &headscalev1.CreatePreAuthKeyRequest{
Namespace: namespace,
User: user,
Expiration: timestamppb.New(expiration),
Ephemeral: isEphemeral,
}
Expand All @@ -128,8 +128,7 @@ func (h *HeadscaleClient) MachinesConnected() (connectedMap, error) {
}
result := connectedMap{}
for _, m := range resp.Machines {
connected := m.LastSeen.AsTime().After(time.Now().Add(-5 * time.Minute))
result[m.Name] = connected
result[m.Name] = m.Online
}

return result, nil
Expand All @@ -154,7 +153,7 @@ func (h *HeadscaleClient) DeleteMachine(machineID, projectID string) (err error)

func (h *HeadscaleClient) getMachine(machineID, projectID string) (machine *headscalev1.Machine, err error) {
req := &headscalev1.ListMachinesRequest{
Namespace: projectID,
User: projectID,
}
resp, err := h.client.ListMachines(h.ctx, req)
if err != nil || resp == nil {
Expand Down
6 changes: 3 additions & 3 deletions cmd/metal-api/internal/service/firewall-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,10 +236,10 @@ func (r firewallResource) setVPNConfigInSpec(allocationSpec *machineAllocationSp
return nil
}

// Try to create namespace in Headscale DB
// Try to create user in Headscale DB
projectID := allocationSpec.ProjectID
if err := r.headscaleClient.CreateNamespace(projectID); err != nil {
return fmt.Errorf("failed to create new VPN namespace for the project: %w", err)
if err := r.headscaleClient.CreateUser(projectID); err != nil {
return fmt.Errorf("failed to create new VPN user for the project: %w", err)
}

expiration := time.Now().Add(2 * time.Hour)
Expand Down
4 changes: 2 additions & 2 deletions cmd/metal-api/internal/service/vpn-service.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ func (r *vpnResource) getVPNAuthKey(request *restful.Request, response *restful.
}

pid := requestPayload.Pid
if ok := r.headscaleClient.NamespaceExists(pid); !ok {
if ok := r.headscaleClient.UserExists(pid); !ok {
r.sendError(
request, response,
httperrors.NotFound(fmt.Errorf("vpn namespace doesn't exist for project with ID %s", pid)),
httperrors.NotFound(fmt.Errorf("vpn user doesn't exist for project with ID %s", pid)),
)
return
}
Expand Down
37 changes: 19 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,23 @@ require (
github.com/google/uuid v1.3.0
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
github.com/grpc-ecosystem/go-grpc-prometheus v1.2.0
github.com/juanfont/headscale v0.17.1
github.com/juanfont/headscale v0.20.0
github.com/looplab/fsm v0.3.0
github.com/metal-stack/go-ipam v1.8.5
github.com/metal-stack/masterdata-api v0.9.0
github.com/metal-stack/metal-lib v0.11.3
github.com/metal-stack/metal-lib v0.11.4
github.com/metal-stack/security v0.6.6
github.com/metal-stack/v v1.0.3
github.com/nsqio/go-nsq v1.1.0
github.com/prometheus/client_golang v1.14.0
github.com/spf13/cobra v1.6.1
github.com/spf13/viper v1.15.0
github.com/stretchr/testify v1.8.1
github.com/stretchr/testify v1.8.2
github.com/testcontainers/testcontainers-go v0.18.0
github.com/undefinedlabs/go-mpatch v1.0.6
go.uber.org/multierr v1.9.0
go.uber.org/zap v1.24.0
golang.org/x/crypto v0.6.0
golang.org/x/crypto v0.7.0
golang.org/x/sync v0.1.0
google.golang.org/grpc v1.53.0
google.golang.org/protobuf v1.28.1
Expand All @@ -45,16 +45,16 @@ require (
github.com/akutz/memconn v0.1.0 // indirect
github.com/alexbrainman/sspi v0.0.0-20210105120005-909beea2cc74 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/asaskevich/govalidator v0.0.0-20210307081110-f21760c49a8d // indirect
github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect
github.com/avast/retry-go v3.0.0+incompatible // indirect
github.com/benbjohnson/clock v1.3.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/cenkalti/backoff/v4 v4.2.0 // indirect
github.com/cespare/xxhash/v2 v2.2.0 // indirect
github.com/containerd/containerd v1.6.18 // indirect
github.com/containerd/containerd v1.6.19 // indirect
github.com/coreos/go-oidc/v3 v3.5.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/deckarep/golang-set/v2 v2.1.0 // indirect
github.com/deckarep/golang-set/v2 v2.2.0 // indirect
github.com/decred/dcrd/dcrec/secp256k1/v4 v4.1.0 // indirect
github.com/docker/distribution v2.8.1+incompatible // indirect
github.com/docker/docker v23.0.1+incompatible // indirect
Expand Down Expand Up @@ -109,12 +109,12 @@ require (
github.com/lestrrat-go/httpcc v1.0.1 // indirect
github.com/lestrrat-go/iter v1.0.2 // indirect
github.com/lestrrat-go/jwx v1.2.25 // indirect
github.com/lestrrat-go/option v1.0.0 // indirect
github.com/lestrrat-go/option v1.0.1 // indirect
github.com/lib/pq v1.10.7 // indirect
github.com/magiconair/properties v1.8.7 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.16 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect
github.com/mdlayher/netlink v1.7.1 // indirect
github.com/mdlayher/socket v0.4.0 // indirect
Expand All @@ -133,7 +133,7 @@ require (
github.com/opencontainers/runc v1.1.4 // indirect
github.com/opentracing/opentracing-go v1.2.0 // indirect
github.com/patrickmn/go-cache v2.1.0+incompatible // indirect
github.com/pelletier/go-toml/v2 v2.0.6 // indirect
github.com/pelletier/go-toml/v2 v2.0.7 // indirect
github.com/philip-bui/grpc-zerolog v1.0.1 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -145,7 +145,7 @@ require (
github.com/robfig/cron v1.2.0
github.com/rs/zerolog v1.29.0 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/spf13/afero v1.9.3 // indirect
github.com/spf13/afero v1.9.4 // indirect
github.com/spf13/cast v1.5.0 // indirect
github.com/spf13/jwalterweatherman v1.1.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
Expand All @@ -162,16 +162,17 @@ require (
go4.org/mem v0.0.0-20220726221520-4f986261bf13 // indirect
go4.org/netipx v0.0.0-20220925034521-797b0c90d8ab // indirect
go4.org/unsafe/assume-no-moving-gc v0.0.0-20230221090011-e4bae7ad2296 // indirect
golang.org/x/mod v0.8.0 // indirect
golang.org/x/net v0.7.0 // indirect
golang.org/x/oauth2 v0.5.0 // indirect
golang.org/x/sys v0.5.0 // indirect
golang.org/x/text v0.7.0 // indirect
golang.org/x/exp v0.0.0-20230304125523-9ff063c70017 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.8.0 // indirect
golang.org/x/oauth2 v0.6.0 // indirect
golang.org/x/sys v0.6.0 // indirect
golang.org/x/text v0.8.0 // indirect
golang.org/x/time v0.3.0 // indirect; indirecct
golang.org/x/tools v0.6.0 // indirect
golang.zx2c4.com/wireguard/windows v0.5.3 // indirect
google.golang.org/appengine v1.6.7 // indirect
google.golang.org/genproto v0.0.0-20230222225845-10f96fb3dbec // indirect
google.golang.org/genproto v0.0.0-20230303212802-e74f57abe488 // indirect
gopkg.in/cenkalti/backoff.v2 v2.2.1 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/ini.v1 v1.67.0 // indirect
Expand All @@ -186,5 +187,5 @@ require (
modernc.org/memory v1.5.0 // indirect
modernc.org/sqlite v1.20.0 // indirect
nhooyr.io/websocket v1.8.7 // indirect
tailscale.com v1.32.3 // indirect
tailscale.com v1.34.0 // indirect
)
Loading

0 comments on commit 0fac0a3

Please sign in to comment.