Skip to content

Commit

Permalink
Merge pull request #59 from Jefftree/split-stuff
Browse files Browse the repository at this point in the history
Move client libraries into separate module
  • Loading branch information
k8s-ci-robot authored Feb 11, 2020
2 parents 08d981c + a43037a commit 8bf6a95
Show file tree
Hide file tree
Showing 26 changed files with 1,027 additions and 1,296 deletions.
28 changes: 15 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
ARCH ?= amd64
ALL_ARCH = amd64 arm arm64 ppc64le s390x

GOPATH ?= $(GOPATH)

REGISTRY ?= gcr.io/$(shell gcloud config get-value project)
STAGING_REGISTRY := gcr.io/k8s-staging-kas-network-proxy

Expand Down Expand Up @@ -54,13 +56,13 @@ bin:
.PHONY: build
build: bin/proxy-agent bin/proxy-server bin/proxy-test-client

bin/proxy-agent: bin cmd/agent/main.go proto/agent/agent.pb.go
bin/proxy-agent: proto/agent/agent.pb.go proto/client/client.pb.go bin cmd/agent/main.go
GO111MODULE=on go build -o bin/proxy-agent cmd/agent/main.go

bin/proxy-test-client: bin cmd/client/main.go proto/proxy.pb.go
bin/proxy-test-client: proto/client/client.pb.go bin cmd/client/main.go
GO111MODULE=on go build -o bin/proxy-test-client cmd/client/main.go

bin/proxy-server: bin cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.go
bin/proxy-server: proto/agent/agent.pb.go proto/client/client.pb.go bin cmd/proxy/main.go
GO111MODULE=on go build -o bin/proxy-server cmd/proxy/main.go

## --------------------------------------
Expand All @@ -73,18 +75,18 @@ bin/proxy-server: bin cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.g
## --------------------------------------

.PHONY: gen
gen: proto/agent/agent.pb.go proto/proxy.pb.go mock_gen
gen: proto/agent/agent.pb.go proto/client/client.pb.go mock_gen

proto/client/client.pb.go: konnectivity-client/proto/client/client.proto
protoc -I . konnectivity-client/proto/client/client.proto --go_out=plugins=grpc:${GOPATH}/src
cat hack/go-license-header.txt konnectivity-client/proto/client/client.pb.go > konnectivity-client/proto/client/client.licensed.go
mv konnectivity-client/proto/client/client.licensed.go konnectivity-client/proto/client/client.pb.go

proto/agent/agent.pb.go: proto/agent/agent.proto
protoc -I proto proto/agent/agent.proto --go_out=plugins=grpc:proto
protoc -I . proto/agent/agent.proto --go_out=plugins=grpc:${GOPATH}/src
cat hack/go-license-header.txt proto/agent/agent.pb.go > proto/agent/agent.licensed.go
mv proto/agent/agent.licensed.go proto/agent/agent.pb.go

proto/proxy.pb.go: proto/proxy.proto
protoc -I proto proto/proxy.proto --go_out=plugins=grpc:proto
cat hack/go-license-header.txt proto/proxy.pb.go > proto/proxy.licensed.go
mv proto/proxy.licensed.go proto/proxy.pb.go

## --------------------------------------
## Certs
## --------------------------------------
Expand Down Expand Up @@ -155,7 +157,7 @@ docker-push/proxy-agent: docker-build/proxy-agent
${DOCKER_CMD} push ${AGENT_FULL_IMAGE}-$(ARCH):${TAG}

.PHONY: docker-build/proxy-server
docker-build/proxy-server: cmd/proxy/main.go proto/agent/agent.pb.go proto/proxy.pb.go
docker-build/proxy-server: cmd/proxy/main.go proto/agent/agent.pb.go
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
echo "Building proxy-server for ${ARCH}"
${DOCKER_CMD} build . --build-arg ARCH=$(ARCH) -f artifacts/images/server-build.Dockerfile -t ${SERVER_FULL_IMAGE}-$(ARCH):${TAG}
Expand All @@ -166,7 +168,7 @@ docker-push/proxy-server: docker-build/proxy-server
${DOCKER_CMD} push ${SERVER_FULL_IMAGE}-$(ARCH):${TAG}

.PHONY: docker-build/proxy-test-client
docker-build/proxy-test-client: cmd/client/main.go proto/agent/agent.pb.go proto/proxy.pb.go
docker-build/proxy-test-client: cmd/client/main.go proto/agent/agent.pb.go
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
echo "Building proxy-test-client for ${ARCH}"
${DOCKER_CMD} build . --build-arg ARCH=$(ARCH) -f artifacts/images/client-build.Dockerfile -t ${TEST_CLIENT_FULL_IMAGE}-$(ARCH):${TAG}
Expand Down Expand Up @@ -249,4 +251,4 @@ release-alias-tag: # Adds the tag to the last build tag. BASE_REF comes from the

.PHONY: clean
clean:
rm -rf proto/agent/agent.pb.go proto/proxy.pb.go easy-rsa.tar.gz easy-rsa-master cfssl cfssljson certs bin proto/agent/mocks
rm -rf proto/agent/agent.pb.go konnectivity-client/proto/client/client.pb.go easy-rsa.tar.gz easy-rsa-master cfssl cfssljson certs bin proto/agent/mocks
2 changes: 1 addition & 1 deletion cmd/client/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (
"google.golang.org/grpc/credentials"
"k8s.io/klog"

"sigs.k8s.io/apiserver-network-proxy/pkg/agent/client"
"sigs.k8s.io/apiserver-network-proxy/konnectivity-client/pkg/client"
"sigs.k8s.io/apiserver-network-proxy/pkg/util"
)

Expand Down
5 changes: 3 additions & 2 deletions cmd/proxy/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ import (
"k8s.io/client-go/tools/clientcmd"
"sigs.k8s.io/apiserver-network-proxy/pkg/agent/agentserver"
"sigs.k8s.io/apiserver-network-proxy/pkg/util"
"sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client"
"sigs.k8s.io/apiserver-network-proxy/proto/agent"
)

Expand Down Expand Up @@ -368,7 +369,7 @@ func (p *Proxy) runUDSMasterServer(ctx context.Context, o *ProxyRunOptions, serv
var stop StopFunc
if o.mode == "grpc" {
grpcServer := grpc.NewServer()
agent.RegisterProxyServiceServer(grpcServer, server)
client.RegisterProxyServiceServer(grpcServer, server)
var lc net.ListenConfig
lis, err := lc.Listen(ctx, "unix", o.udsName)
if err != nil {
Expand Down Expand Up @@ -445,7 +446,7 @@ func (p *Proxy) runMTLSMasterServer(ctx context.Context, o *ProxyRunOptions, ser
if o.mode == "grpc" {
serverOption := grpc.Creds(credentials.NewTLS(tlsConfig))
grpcServer := grpc.NewServer(serverOption)
agent.RegisterProxyServiceServer(grpcServer, server)
client.RegisterProxyServiceServer(grpcServer, server)
lis, err := net.Listen("tcp", addr)
if err != nil {
return nil, fmt.Errorf("failed to listen on %s: %v", addr, err)
Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,7 @@ require (
k8s.io/apimachinery v0.17.1
k8s.io/client-go v0.17.1
k8s.io/klog v1.0.0
sigs.k8s.io/apiserver-network-proxy/konnectivity-client v0.0.0
)

replace sigs.k8s.io/apiserver-network-proxy/konnectivity-client => ./konnectivity-client
9 changes: 9 additions & 0 deletions konnectivity-client/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module sigs.k8s.io/apiserver-network-proxy/konnectivity-client

go 1.13

require (
github.com/golang/protobuf v1.3.2
google.golang.org/grpc v1.26.0
k8s.io/klog v1.0.0
)
51 changes: 51 additions & 0 deletions konnectivity-client/go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/go-logr/logr v0.1.0/go.mod h1:ixOQHD9gLJUVQQ2ZOR7zLEifBX6tGkNJF4QyIY7sIas=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/google/go-cmp v0.2.0 h1:+dTQ8DZQJz0Mb/HjFlkptS1FeQ4cWSnN941F8aEG4SQ=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/klog v1.0.0 h1:Pt+yjF5aB1xDSVbau4VsWe+dQNzA0qv1LlXdC2dF6Q8=
k8s.io/klog v1.0.0/go.mod h1:4Bi6QPql/J/LkTDqv7R/cd3hPo4k2DG6Ptcz060Ez5I=
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ import (

"google.golang.org/grpc"
"k8s.io/klog"
"sigs.k8s.io/apiserver-network-proxy/proto/agent"
"sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client"
)

// Tunnel provides ability to dial a connection through a tunnel.
Expand All @@ -44,7 +44,7 @@ type dialResult struct {

// grpcTunnel implements Tunnel
type grpcTunnel struct {
stream agent.ProxyService_ProxyClient
stream client.ProxyService_ProxyClient
pendingDial map[int64]chan<- dialResult
conns map[int64]*conn
pendingDialLock sync.RWMutex
Expand All @@ -59,9 +59,9 @@ func CreateGrpcTunnel(address string, opts ...grpc.DialOption) (Tunnel, error) {
return nil, err
}

client := agent.NewProxyServiceClient(c)
grpcClient := client.NewProxyServiceClient(c)

stream, err := client.Proxy(context.Background())
stream, err := grpcClient.Proxy(context.Background())
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -91,7 +91,7 @@ func (t *grpcTunnel) serve() {
klog.Infof("[tracing] recv packet %+v", pkt)

switch pkt.Type {
case agent.PacketType_DIAL_RSP:
case client.PacketType_DIAL_RSP:
resp := pkt.GetDialResponse()
t.pendingDialLock.RLock()
ch, ok := t.pendingDial[resp.Random]
Expand All @@ -105,7 +105,7 @@ func (t *grpcTunnel) serve() {
connid: resp.ConnectID,
}
}
case agent.PacketType_DATA:
case client.PacketType_DATA:
resp := pkt.GetData()
// TODO: flow control
t.connsLock.RLock()
Expand All @@ -117,7 +117,7 @@ func (t *grpcTunnel) serve() {
} else {
klog.Warningf("connection id %d not recognized", resp.ConnectID)
}
case agent.PacketType_CLOSE_RSP:
case client.PacketType_CLOSE_RSP:
resp := pkt.GetCloseResponse()
t.connsLock.RLock()
conn, ok := t.conns[resp.ConnectID]
Expand Down Expand Up @@ -155,10 +155,10 @@ func (t *grpcTunnel) Dial(protocol, address string) (net.Conn, error) {
t.pendingDialLock.Unlock()
}()

req := &agent.Packet{
Type: agent.PacketType_DIAL_REQ,
Payload: &agent.Packet_DialRequest{
DialRequest: &agent.DialRequest{
req := &client.Packet{
Type: client.PacketType_DIAL_REQ,
Payload: &client.Packet_DialRequest{
DialRequest: &client.DialRequest{
Protocol: protocol,
Address: address,
Random: random,
Expand Down
Loading

0 comments on commit 8bf6a95

Please sign in to comment.