Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

protocol-agnostic TCP proxy #15

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
3 changes: 1 addition & 2 deletions .codecov.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ignore:
- "cmd/.*"
- "test/.*"
- "pkg/vendor/.*"

1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
_*
test/bin
coverage.txt
go.sum
40 changes: 0 additions & 40 deletions .travis.entrypoint.sh

This file was deleted.

40 changes: 22 additions & 18 deletions .travis.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,36 @@
#!/bin/sh
set -e

exit_code=0
export GO111MODULE=on
export GOFLAGS=-mod-vendor

go get -v github.com/golang/lint/golint
[ "0" = "$?" ] || exit 1
WORKDIR=$(pwd)
exit_code=0

go get -u github.com/golang/dep/cmd/dep
[ "0" = "$?" ] || exit 2
#echo "go build ./..."
#go build ./...
#if [ "0" != "$?" ]; then
# exit 10
#fi

for dir in $(go list ./... | grep -v vendor); do
echo "golint $dir"
result=$(golint $dir)
if [ "" != "$result" ]; then
echo $result
exit_code=5
fi
if [ "0" != "$exit_code" ]; then
exit $exit_code
fi
done
#go get -v github.com/golang/lint/golint
#[ "0" = "$?" ] || exit 10
#
#for dir in $(go list ./... | grep -v vendor); do
# echo "golint $dir"
# result=$(GO111MODULE=on golint $dir)
# if [ "" != "$result" ]; then
# echo $result
# exit 20
# fi
#done

rm -f coverage.txt
for dir in $(go list ./... | grep -v vendor); do
GOCACHE=off go test -timeout 300s -coverprofile=profile.out $dir
go test -timeout=20s -coverprofile=profile.out $dir
exit_code=$?
if [ "0" != "$exit_code" ]; then
exit $exit_code
exit 30
fi
if [ -f profile.out ]; then
cat profile.out >> coverage.txt
Expand Down
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
notifications:
slack:
secure: JKpEAaObH9gmEEva1vXY1MfvOhhHEWkL1ujnGPgxoInrZQN3zg0ppPX6zjZyTNsOF00u/SO09xPFrKqKnY57Ies119fuM91ruoXc14vsBtqSuvVETZLTaxlhB+AVSaSq7vs3gX+DW2eB5rknbGKdCnVCQ523xIABr1MFjzAfWx6JuzgO5STe2WTjTfPK9A2Kh4qR5TdT7EvoyeiyW6kY+j5ZGtYIBNTMDgWxzlrYN0McaNyjlBuj2FDv4og8hf8DuIPJa4FkBntXBZZK+IPvAM8SRko+SBK93629KgEK8WUzHyojggKkJaxoX3f9LnfpAYcfpew7G9+uCu8vtrFBs3zlu2yeSyL+gRY08zxAmRV9rB0cu+4SyAtwcJyHoW3wPYK3s4aZ9SO7jFrgFNPQ1Gs93Tnvz0brKOXKDwAsi9JmgC76gV8kVHoF3VxvMTpgmp5amybpmxrWTJgMEh9mKkAzjucPOi4fPldjPpxgWs9w2qyANbfTYNwWm+atN4qyI7qsCfEb8of/TduQ1RKYGB1oX+71uc3OYscB/24rnF8oadtA7YOJbdT52NcNPy0VhLoTKNt6i0b5gw2Zos36eW2E+ktGfXopmJah1unL6wn5NjDjC98l//ulrU11CzpQKgUwNGf2eanlFLRmeUTuCPNGJeQka4cGTRwwB5ZlI5w=
secure: fMsf7qV6+SL18DQSkAqQX4yRsgiKOw5JpFlMhIRosJH3A8739/9E4feZE7cpBKuOb7/x50/Dd4hjFf7sTGSpqd65U7xDQTEOtEPwAUWMAjoXuJhKjtU1IyXssaEMXHhHF0Advz9ekq/cXIYqbWKcLo9hxnyZS8YAHBL/r5Cjm0/aIvmcvFnlcZCq2FG2MUaGm/wG8bSrJ84eCwIcN3lu1UD6/Z3Y3btmXE0/HGCRbWTsfIjn1F+xrfK/GCxr01vLsZGRm3ADRi+2rhOemPmgM0hGa9IiStzIKPVh0rN2M6gSFgczrYLJbrwujUCx+KgRJt+kR4D0J7rMxYGQIAA655nilXhzFxknwY4f8cRszJfEJe60oFOh4BruDR+d0IjO2DgLWhebqQS05lUlXV2L5GDTogxrl40nw661V7HewNLYFcykAKg4W1QXiaqhK+06pweRaTDPmqIHDJa2sUMupb8W3AMqOrBPX2wY73PCZGZzabesKeyk0oL6HOEgCdEH1m/uri92tNPX/GfWKQl0zgBBZmOyf8UcIWDQWtVPVuOwUi9dhn5/8SoQ2GKld9vlh3G8aDCwxjlW3NVJ67kv8v6fMV3qGZWqLQorDVwGLhlUsyApI0HR6QXCJHVmOBk3HP6wWvztJi6oJF88extJ0AAWTExD1zXUbMT/MfQJvQQ=

git:
depth: 1
Expand All @@ -12,15 +12,15 @@ install: true
branches:
only:
- master

env:
- GO111MODULE=on GOFLAGS=-mod-vendor
language: go
go_import_path: github.com/mkenney/k8s-proxy
go:
- 1.11.x

script:
- ./.travis.sh
- docker build -t mkenney/k8s-proxy:ci-build .

after_success:
- bash <(curl -s https://codecov.io/bash)
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Build binary
FROM golang:1.10-alpine AS build
FROM golang:1.11-alpine AS build
ENV DEFAULT_SERVICE=kubernetes \
K8S_PROXY_PORT=80 \
K8S_PROXY_SSLPORT=443 \
Expand Down
13 changes: 13 additions & 0 deletions cmd/k8s-proxy/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module github.com/mkenney/k8s-proxy/cmd/k8s-proxy

require (
github.com/bdlm/log v0.1.13
github.com/mkenney/k8s-proxy v0.0.0
github.com/pkg/errors v0.8.0 // indirect
golang.org/x/crypto v0.0.0-20181012144002-a92615f3c490 // indirect
golang.org/x/net v0.0.0-20181011144130-49bb7cea24b1 // indirect
golang.org/x/sys v0.0.0-20181011152604-fa43e7bc11ba // indirect
k8s.io/api v0.0.0-20181005203742-357ec6384fa7 // indirect
)

replace github.com/mkenney/k8s-proxy => ../..
70 changes: 70 additions & 0 deletions cmd/k8s-proxy/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

import (
"context"
"os"
"os/signal"
"time"

"github.com/bdlm/log"
"github.com/mkenney/k8s-proxy/pkg/proxy"
)

// K8SPROXYPORT defines the exposed k8s-proxy port.
var K8SPROXYPORT int

// K8SPROXYSSLPORT defines the exposed k8s-proxy SSL port.
var K8SPROXYSSLPORT int

// K8SPROXYSSLCERT defines the name of an SSL certificate located in the
// /ssl directory. Adding a certificate to the proxy requires buiding your
// own image (or executing the /test/start-dev.sh script which volmounts
// everything).
var K8SPROXYSSLCERT string

// K8SPROXYTIMEOUT defines the proxy timeout. Cannot be greater than 15 minutes
// (900 seconds).
var K8SPROXYTIMEOUT int

func init() {
// log level and format
levelFlag := os.Getenv("LOG_LEVEL")
if "" == levelFlag {
levelFlag = "info"
}
level, err := log.ParseLevel(levelFlag)
if nil != err {
log.WithField("err", err).Warnf("%-v", err)
level, _ = log.ParseLevel("debug")
}
log.SetFormatter(&log.TextFormatter{
ForceTTY: true,
})
log.SetLevel(level)
}

func main() {
proxy, err := proxy.New(context.Background())
if nil != err {
log.Fatalf("%-v", err)
}

log.Infof("starting services...")
proxy.ListenAndServe()

// Shutdown when a signal is received.
c := make(chan os.Signal, 1)
signal.Notify(c)
go func() {
sig := <-c
log.Infof("'%s' signal received, shutting down proxy", sig)
proxy.Stop()
}()

// debug
select {
case <-time.After(10 * time.Second):
log.Infof("stopping services...")
proxy.Stop()
}
}
2 changes: 2 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Package proxy provides an import entrypoint
package proxy
32 changes: 32 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
module github.com/mkenney/k8s-proxy

require (
github.com/bdlm/errors v0.1.3
github.com/bdlm/log v0.1.13
github.com/bdlm/std v0.0.0-20180922040903-fd3b596111c7
github.com/ghodss/yaml v1.0.0 // indirect
github.com/gogo/protobuf v1.1.1 // indirect
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b // indirect
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7 // indirect
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c // indirect
github.com/google/gofuzz v0.0.0-20170612174753-24818f796faf // indirect
github.com/googleapis/gnostic v0.2.0 // indirect
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7 // indirect
github.com/json-iterator/go v1.1.5 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
golang.org/x/crypto v0.0.0-20181001203147-e3636079e1a4 // indirect
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7 // indirect
golang.org/x/net v0.0.0-20181005035420-146acd28ed58 // indirect
golang.org/x/oauth2 v0.0.0-20181003184128-c57b0facaced // indirect
golang.org/x/sys v0.0.0-20181005133103-4497e2df6f9e // indirect
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2 // indirect
golang.org/x/tools v0.0.0-20181006002542-f60d9635b16a // indirect
google.golang.org/appengine v1.2.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
gopkg.in/yaml.v2 v2.2.1 // indirect
k8s.io/api v0.0.0-20180925152912-a191abe0b71e
k8s.io/apimachinery v0.0.0-20181003114359-ed5594dcf47b
k8s.io/client-go v9.0.0+incompatible
)
27 changes: 27 additions & 0 deletions internal/codes/codes.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package codes

import (
errs "github.com/bdlm/errors"
std "github.com/bdlm/std/error"
)

const (
// Unspecified - 1000: The error code was unspecified.
Unspecified std.Code = iota + 1000

// ContextCancelled - The referenced context has been cancelled.
ContextCancelled

// NetworkListenerExists - Network listner already exists, skipping.
NetworkListenerExists

// NetworkListenerListening - Network listner already running, skipping.
NetworkListenerListening

// NetworkListenerFailed - Could not open network listener.
NetworkListenerFailed
)

func init() {
errs.Codes[Unspecified] = errs.ErrCode{Ext: "An unknown error occurred", Int: "An unknown error occurred", HTTP: 500}
}
Loading