Skip to content

Commit

Permalink
Merge pull request #18 from Escape-Technologies/feat/auto-provisioning
Browse files Browse the repository at this point in the history
feat: auto create repeater
  • Loading branch information
QuentinN42 authored Jan 30, 2025
2 parents 8f5820a + 276981c commit 6530a66
Show file tree
Hide file tree
Showing 8 changed files with 347 additions and 128 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ go-repeater
main
.vscode
.idea
__*
._*
.env
72 changes: 51 additions & 21 deletions cmd/repeater/repeater.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package main

import (
"context"
"crypto/tls"
"log"
"net/http"
"os"
"regexp"
"sync/atomic"

"github.com/Escape-Technologies/repeater/pkg/autoprovisioning"
"github.com/Escape-Technologies/repeater/pkg/health"
"github.com/Escape-Technologies/repeater/pkg/kube"
"github.com/Escape-Technologies/repeater/pkg/logger"
Expand Down Expand Up @@ -95,45 +97,73 @@ func setupProxyURL() string {
return proxyURL
}

func main() {
logger.Info("Running Escape repeater version %s, commit %s", version, commit)
var isConnected = &atomic.Bool{}

go func() {
logger.Info("Starting pprof on http://0.0.0.0:6060/debug/pprof/")
err := http.ListenAndServe(":6060", nil)
if err != nil {
logger.Info("Failed to start pprof server, %s", err.Error())
func startHealth() {
isConnected.Store(false)
healthCheckPort := os.Getenv("HEALTH_CHECK_PORT")
if healthCheckPort != "" {
if !PORT.MatchString(healthCheckPort) {
logger.Error("HEALTH_CHECK_PORT must be a valid port number, falling back to no health check")
} else {
logger.Info("Started pprof on http://0.0.0.0:6060/debug/pprof/")
health.HealthCheck(healthCheckPort, isConnected)
}
}()

isConnected := &atomic.Bool{}
isConnected.Store(false)
}
}

func getRepeaterId(ctx context.Context, ap *autoprovisioning.Autoprovisioner) string {
repeaterId := os.Getenv("ESCAPE_REPEATER_ID")
if ap != nil && repeaterId == "" {
logger.Info("ESCAPE_REPEATER_ID is not set, using autoprovisioning")
repeaterId, err := ap.GetId(ctx)
if err != nil {
logger.Error("Failed to get repeater id from autoprovisioning, %s", err.Error())
os.Exit(1)
}
return repeaterId
}
if !UUID.MatchString(repeaterId) {
logger.Error("ESCAPE_REPEATER_ID must be a UUID in lowercase")
logger.Error("To get your repeater id, go to https://app.escape.tech/organization/network/")
logger.Error("For more information, read the docs at https://docs.escape.tech/enterprise/repeater")
os.Exit(1)
}
return repeaterId
}

healthCheckPort := os.Getenv("HEALTH_CHECK_PORT")
if healthCheckPort != "" {
if !PORT.MatchString(healthCheckPort) {
logger.Error("HEALTH_CHECK_PORT must be a valid port number, falling back to no health check")
} else {
go health.HealthCheck(healthCheckPort, isConnected)
}
func pprof() {
logger.Info("Starting pprof on http://0.0.0.0:6060/debug/pprof/")
err := http.ListenAndServe(":6060", nil)
if err != nil {
logger.Info("Failed to start pprof server, %s", err.Error())
} else {
logger.Info("Started pprof on http://0.0.0.0:6060/debug/pprof/")
}
}

func getAutoprovisioner() *autoprovisioning.Autoprovisioner {
ap, err := autoprovisioning.NewAutoprovisioner()
if err != nil {
logger.Info("Unable to setup autoprovisioning, using only local repeater id: %s", err.Error())
return nil
}
return ap
}

func main() {
ctx := context.Background()
logger.Info("Running Escape repeater version %s, commit %s", version, commit)
go pprof()
go startHealth()

url := setupHTTPClients()
proxyURL := setupProxyURL()
ap := getAutoprovisioner()
repeaterId := getRepeaterId(ctx, ap)
url := setupHTTPClients()

logger.Info("Starting repeater client...")

go logger.AlwaysConnect(url, repeaterId, proxyURL)
go kube.AlwaysConnectAndRun()
go kube.AlwaysConnectAndRun(ctx, ap, isConnected)
stream.AlwaysConnectAndRun(url, repeaterId, isConnected, proxyURL)
}
58 changes: 25 additions & 33 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,57 +1,49 @@
module github.com/Escape-Technologies/repeater

go 1.22.0
go 1.23.0

toolchain go1.22.2
toolchain go1.23.4

require (
github.com/Escape-Technologies/cli v0.0.12
github.com/google/uuid v1.6.0
github.com/pixelbender/go-traceroute v0.0.0-20190414152342-e631ab553a80
golang.org/x/sys v0.27.0
google.golang.org/grpc v1.67.1
google.golang.org/protobuf v1.35.1
k8s.io/client-go v0.31.3
k8s.io/kubectl v0.31.3
github.com/sirupsen/logrus v1.9.3
golang.org/x/sys v0.29.0
google.golang.org/grpc v1.70.0
google.golang.org/protobuf v1.36.4
k8s.io/client-go v0.32.1
k8s.io/kubectl v0.32.1
)

require (
github.com/apapsch/go-jsonmerge/v2 v2.0.0 // indirect
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
github.com/fxamacker/cbor/v2 v2.7.0 // indirect
github.com/go-logr/logr v1.4.2 // indirect
github.com/go-openapi/jsonpointer v0.19.6 // indirect
github.com/go-openapi/jsonreference v0.20.2 // indirect
github.com/go-openapi/swag v0.22.4 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/gnostic-models v0.6.8 // indirect
github.com/google/go-cmp v0.6.0 // indirect
github.com/google/gofuzz v1.2.0 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/imdario/mergo v0.3.6 // indirect
github.com/josharian/intern v1.0.0 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/mailru/easyjson v0.7.7 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/oapi-codegen/runtime v1.1.1 // indirect
github.com/spf13/pflag v1.0.6 // indirect
github.com/x448/float16 v0.8.4 // indirect
golang.org/x/net v0.31.0 // indirect
golang.org/x/oauth2 v0.22.0 // indirect
golang.org/x/term v0.26.0 // indirect
golang.org/x/text v0.20.0 // indirect
golang.org/x/time v0.3.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20241104194629-dd2ea8efbc28 // indirect
golang.org/x/net v0.34.0 // indirect
golang.org/x/oauth2 v0.25.0 // indirect
golang.org/x/term v0.28.0 // indirect
golang.org/x/text v0.21.0 // indirect
golang.org/x/time v0.9.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20250127172529-29210b9bc287 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
k8s.io/api v0.31.3 // indirect
k8s.io/apimachinery v0.31.3 // indirect
k8s.io/api v0.32.1 // indirect
k8s.io/apimachinery v0.32.1 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect
k8s.io/utils v0.0.0-20240711033017-18e509b52bc8 // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect
k8s.io/utils v0.0.0-20241210054802-24370beab758 // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.5.0 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)
Loading

0 comments on commit 6530a66

Please sign in to comment.