Skip to content

Commit

Permalink
Add build flag to disable TS2019
Browse files Browse the repository at this point in the history
This commit starts an experiment to disable TS2019 (we also call it
legacy).

The two main goals for this right now is:

- Diasble TS2019, and verify that the integration test clients with the
  appropriate TS2021 support works as expected
- Get an overview of how coupled the protocol code is, if this is easy,
  it will be easy to remove when the time comes.

Also, users with "crazy" desires like only supporting the most modern
protocol _can_ build this version.

Signed-off-by: Kristoffer Dalby <[email protected]>
  • Loading branch information
kradalby committed Nov 3, 2022
1 parent 6e83b7f commit 51ca53f
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 9 deletions.
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,21 @@ ifeq ($(filter $(GOOS), openbsd netbsd soloaris plan9), )
else
endif

TAGS = -tags "ts2019"

# GO_SOURCES = $(wildcard *.go)
# PROTO_SOURCES = $(wildcard **/*.proto)
GO_SOURCES = $(call rwildcard,,*.go)
PROTO_SOURCES = $(call rwildcard,,*.proto)


build:
GOOS=$(GOOS) CGO_ENABLED=0 go build -trimpath $(pieflags) -mod=readonly -ldflags "-s -w -X github.com/juanfont/headscale/cmd/headscale/cli.Version=$(version)" cmd/headscale/headscale.go
nix build

dev: lint test build

test:
@go test -short -coverprofile=coverage.out ./...
@go test $(TAGS) -short -coverprofile=coverage.out ./...

test_integration: test_integration_cli test_integration_derp test_integration_oidc test_integration_v2_general

Expand All @@ -34,7 +36,7 @@ test_integration_cli:
-v ~/.cache/hs-integration-go:/go \
-v $$PWD:$$PWD -w $$PWD \
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
go test -failfast -timeout 30m -count=1 -run IntegrationCLI ./...
go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationCLI ./...

test_integration_derp:
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
Expand All @@ -44,7 +46,7 @@ test_integration_derp:
-v ~/.cache/hs-integration-go:/go \
-v $$PWD:$$PWD -w $$PWD \
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
go test -failfast -timeout 30m -count=1 -run IntegrationDERP ./...
go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationDERP ./...

test_integration_oidc:
docker network rm $$(docker network ls --filter name=headscale --quiet) || true
Expand All @@ -54,7 +56,7 @@ test_integration_oidc:
-v ~/.cache/hs-integration-go:/go \
-v $$PWD:$$PWD -w $$PWD \
-v /var/run/docker.sock:/var/run/docker.sock golang:1 \
go test -failfast -timeout 30m -count=1 -run IntegrationOIDC ./...
go test $(TAGS) -failfast -timeout 30m -count=1 -run IntegrationOIDC ./...

test_integration_v2_general:
docker run \
Expand All @@ -64,7 +66,7 @@ test_integration_v2_general:
-v $$PWD:$$PWD -w $$PWD/integration \
-v /var/run/docker.sock:/var/run/docker.sock \
golang:1 \
go test ./... -timeout 60m -parallel 6
go test $(TAGS) ./... -timeout 60m -parallel 6

coverprofile_func:
go tool cover -func=coverage.out
Expand Down
5 changes: 2 additions & 3 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -454,9 +454,6 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router {
router.HandleFunc("/health", h.HealthHandler).Methods(http.MethodGet)
router.HandleFunc("/key", h.KeyHandler).Methods(http.MethodGet)
router.HandleFunc("/register/{nkey}", h.RegisterWebAPI).Methods(http.MethodGet)
router.HandleFunc("/machine/{mkey}/map", h.PollNetMapHandler).
Methods(http.MethodPost)
router.HandleFunc("/machine/{mkey}", h.RegistrationHandler).Methods(http.MethodPost)
router.HandleFunc("/oidc/register/{nkey}", h.RegisterOIDC).Methods(http.MethodGet)
router.HandleFunc("/oidc/callback", h.OIDCCallback).Methods(http.MethodGet)
router.HandleFunc("/apple", h.AppleConfigMessage).Methods(http.MethodGet)
Expand All @@ -469,6 +466,8 @@ func (h *Headscale) createRouter(grpcMux *runtime.ServeMux) *mux.Router {
router.HandleFunc("/swagger/v1/openapiv2.json", SwaggerAPIv1).
Methods(http.MethodGet)

h.addLegacyHandlers(router)

if h.cfg.DERP.ServerEnabled {
router.HandleFunc("/derp", h.DERPHandler)
router.HandleFunc("/derp/probe", h.DERPProbeHandler)
Expand Down
2 changes: 2 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
version = headscaleVersion;
src = pkgs.lib.cleanSource self;

tags = ["ts2019"];

# Only run unit tests when testing a build
checkFlags = ["-short"];

Expand Down
15 changes: 15 additions & 0 deletions handler_legacy.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//go:build ts2019

package headscale

import (
"net/http"

"github.com/gorilla/mux"
)

func (h *Headscale) addLegacyHandlers(router *mux.Router) {
router.HandleFunc("/machine/{mkey}/map", h.PollNetMapHandler).
Methods(http.MethodPost)
router.HandleFunc("/machine/{mkey}", h.RegistrationHandler).Methods(http.MethodPost)
}
8 changes: 8 additions & 0 deletions handler_placeholder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build !ts2019

package headscale

import "github.com/gorilla/mux"

func (h *Headscale) addLegacyHandlers(router *mux.Router) {
}
2 changes: 2 additions & 0 deletions protocol_legacy.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build ts2019

package headscale

import (
Expand Down
2 changes: 2 additions & 0 deletions protocol_legacy_poll.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
//go:build ts2019

package headscale

import (
Expand Down

0 comments on commit 51ca53f

Please sign in to comment.