Skip to content

Commit

Permalink
feat: use SSH-tunneling instead of custom GRPC over TCP tunnel (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredallard authored Sep 29, 2020
1 parent e8c2c43 commit 6fa2c77
Show file tree
Hide file tree
Showing 6 changed files with 237 additions and 90 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,9 @@ bin/
# Dependency directories (remove the comment below to include it)
vendor/

# Ignore our replacements directory for allowing testing of
# forked go modules
replacements/

# Build stuff
dist/
33 changes: 11 additions & 22 deletions cmd/localizer/localizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ package main
import (
"context"
"fmt"
"net/http"
"os"
"os/signal"
"os/user"
Expand All @@ -27,7 +26,6 @@ import (
"github.com/jaredallard/localizer/internal/expose"
"github.com/jaredallard/localizer/internal/kube"
"github.com/jaredallard/localizer/internal/proxier"
"github.com/omrikiei/ktunnel/pkg/server"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
Expand Down Expand Up @@ -69,28 +67,14 @@ func main() { //nolint:funlen,gocyclo
EnvVars: []string{"LOG_LEVEL"},
DefaultText: "INFO",
},
&cli.StringFlag{
Name: "log-format",
Usage: "Set the log format",
EnvVars: []string{"LOG_FORMAT"},
DefaultText: "TEXT",
},
},
Commands: []*cli.Command{
{
Name: "server",
Description: "Run a server that can be used with `expose`",
Usage: "server",
Action: func(c *cli.Context) error {
go func() {
if err := http.ListenAndServe(":51",
http.HandlerFunc(
func(w http.ResponseWriter, r *http.Request) { fmt.Fprintln(w, "ready") },
),
); err != nil {
log.WithError(err).Fatal("failed to start readiness prob server")
}
}()

// note: port 50 is chosen as least likely to collide with anything
// we may want to look into randomizing it in the future
return errors.Wrap(server.RunServer(ctx, server.WithPort(50), server.WithLogger(log)), "server failed")
},
},
{
Name: "expose",
Description: "Expose ports for a given service to Kubernetes",
Expand Down Expand Up @@ -202,6 +186,11 @@ func main() { //nolint:funlen,gocyclo
log.Debug("set logger to debug")
}

if strings.EqualFold(c.String("log-format"), "JSON") {
log.SetFormatter(&logrus.JSONFormatter{})
log.Debug("set log format to JSON")
}

kconf, k, err = kube.GetKubeClient(c.String("context"))
if err != nil {
return errors.Wrap(err, "failed to create kube client")
Expand Down
12 changes: 7 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,17 @@ go 1.15
require (
github.com/cenkalti/backoff/v4 v4.0.2
github.com/davecgh/go-spew v1.1.1
github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
github.com/elazarl/goproxy v0.0.0-20191011121108-aa519ddbe484 // indirect
github.com/elazarl/goproxy/ext v0.0.0-20191011121108-aa519ddbe484 // indirect
github.com/function61/gokit v0.0.0-20200923114939-f8d7e065a5c3
github.com/imdario/mergo v0.3.8 // indirect
github.com/metal-stack/go-ipam v1.6.0
github.com/omrikiei/ktunnel v1.2.8-beta.0.20200903140414-c553ba6656ef
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.6.0
github.com/txn2/txeh v1.3.0
github.com/urfave/cli/v2 v2.2.0
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9
google.golang.org/grpc v1.33.0-dev // indirect
google.golang.org/protobuf v1.25.0 // indirect
k8s.io/api v0.19.2
Expand All @@ -19,7 +24,4 @@ require (
k8s.io/kubectl v0.19.2
)

replace (
github.com/omrikiei/ktunnel => github.com/jaredallard/ktunnel v1.2.8-beta.0.20200926161618-3698a12ca694
k8s.io/client-go => github.com/jaredallard/client-go v0.0.0-20200919203213-e55c7f2b41ab
)
replace k8s.io/client-go => github.com/jaredallard/client-go v0.0.0-20200919203213-e55c7f2b41ab
Loading

0 comments on commit 6fa2c77

Please sign in to comment.