Skip to content

Commit c935949

Browse files
authored
Merge pull request #91 from caesarxuchao/refactor
Restructure the directories
2 parents 92d98b0 + b752d63 commit c935949

16 files changed

+54
-54
lines changed

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ bin/proxy-agent: proto/agent/agent.pb.go konnectivity-client/proto/client/client
6262
bin/proxy-test-client: konnectivity-client/proto/client/client.pb.go bin cmd/client/main.go
6363
GO111MODULE=on go build -o bin/proxy-test-client cmd/client/main.go
6464

65-
bin/proxy-server: proto/agent/agent.pb.go konnectivity-client/proto/client/client.pb.go bin cmd/proxy/main.go
66-
GO111MODULE=on go build -o bin/proxy-server cmd/proxy/main.go
65+
bin/proxy-server: proto/agent/agent.pb.go konnectivity-client/proto/client/client.pb.go bin cmd/server/main.go
66+
GO111MODULE=on go build -o bin/proxy-server cmd/server/main.go
6767

6868
## --------------------------------------
6969
## Linting
@@ -157,7 +157,7 @@ docker-push/proxy-agent: docker-build/proxy-agent
157157
${DOCKER_CMD} push ${AGENT_FULL_IMAGE}-$(ARCH):${TAG}
158158

159159
.PHONY: docker-build/proxy-server
160-
docker-build/proxy-server: cmd/proxy/main.go proto/agent/agent.pb.go
160+
docker-build/proxy-server: cmd/server/main.go proto/agent/agent.pb.go
161161
@[ "${TAG}" ] || ( echo "TAG is not set"; exit 1 )
162162
echo "Building proxy-server for ${ARCH}"
163163
${DOCKER_CMD} build . --build-arg ARCH=$(ARCH) -f artifacts/images/server-build.Dockerfile -t ${SERVER_FULL_IMAGE}-$(ARCH):${TAG}

artifacts/images/server-build.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ COPY proto/ proto/
2323

2424
# Build
2525
ARG ARCH
26-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -ldflags '-extldflags "-static"' -o proxy-server sigs.k8s.io/apiserver-network-proxy/cmd/proxy
26+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${ARCH} go build -a -ldflags '-extldflags "-static"' -o proxy-server sigs.k8s.io/apiserver-network-proxy/cmd/server
2727

2828
# Copy the loader into a thin image
2929
FROM scratch

cmd/agent/main.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"google.golang.org/grpc"
3232
"google.golang.org/grpc/credentials"
3333
"k8s.io/klog"
34-
"sigs.k8s.io/apiserver-network-proxy/pkg/agent/agentclient"
34+
"sigs.k8s.io/apiserver-network-proxy/pkg/agent"
3535
"sigs.k8s.io/apiserver-network-proxy/pkg/util"
3636
)
3737

@@ -77,8 +77,8 @@ type GrpcProxyAgentOptions struct {
7777
serviceAccountTokenPath string
7878
}
7979

80-
func (o *GrpcProxyAgentOptions) ClientSetConfig(dialOption grpc.DialOption) *agentclient.ClientSetConfig {
81-
return &agentclient.ClientSetConfig{
80+
func (o *GrpcProxyAgentOptions) ClientSetConfig(dialOption grpc.DialOption) *agent.ClientSetConfig {
81+
return &agent.ClientSetConfig{
8282
Address: fmt.Sprintf("%s:%d", o.proxyServerHost, o.proxyServerPort),
8383
AgentID: o.agentID,
8484
SyncInterval: o.syncInterval,

cmd/proxy/main.go renamed to cmd/server/main.go

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,12 @@ import (
3535
"github.com/spf13/pflag"
3636
"google.golang.org/grpc"
3737
"google.golang.org/grpc/credentials"
38-
"k8s.io/klog"
3938
"k8s.io/client-go/kubernetes"
4039
"k8s.io/client-go/tools/clientcmd"
41-
"sigs.k8s.io/apiserver-network-proxy/pkg/agent/agentserver"
42-
"sigs.k8s.io/apiserver-network-proxy/pkg/util"
40+
"k8s.io/klog"
4341
"sigs.k8s.io/apiserver-network-proxy/konnectivity-client/proto/client"
42+
"sigs.k8s.io/apiserver-network-proxy/pkg/server"
43+
"sigs.k8s.io/apiserver-network-proxy/pkg/util"
4444
"sigs.k8s.io/apiserver-network-proxy/proto/agent"
4545
)
4646

@@ -304,14 +304,14 @@ func (p *Proxy) run(o *ProxyRunOptions) error {
304304
}
305305
}
306306

307-
authOpt := &agentserver.AgentTokenAuthenticationOptions{
307+
authOpt := &server.AgentTokenAuthenticationOptions{
308308
Enabled: o.agentNamespace != "",
309309
AgentNamespace: o.agentNamespace,
310310
AgentServiceAccount: o.agentServiceAccount,
311311
KubernetesClient: k8sClient,
312312
AuthenticationAudience: o.authenticationAudience,
313313
}
314-
server := agentserver.NewProxyServer(o.serverID, int(o.serverCount), authOpt)
314+
server := server.NewProxyServer(o.serverID, int(o.serverCount), authOpt)
315315

316316
klog.Info("Starting master server for client connections.")
317317
masterStop, err := p.runMasterServer(ctx, o, server)
@@ -358,18 +358,18 @@ func SetupSignalHandler() (stopCh <-chan struct{}) {
358358
return stop
359359
}
360360

361-
func (p *Proxy) runMasterServer(ctx context.Context, o *ProxyRunOptions, server *agentserver.ProxyServer) (StopFunc, error) {
361+
func (p *Proxy) runMasterServer(ctx context.Context, o *ProxyRunOptions, server *server.ProxyServer) (StopFunc, error) {
362362
if o.udsName != "" {
363363
return p.runUDSMasterServer(ctx, o, server)
364364
}
365365
return p.runMTLSMasterServer(ctx, o, server)
366366
}
367367

368-
func (p *Proxy) runUDSMasterServer(ctx context.Context, o *ProxyRunOptions, server *agentserver.ProxyServer) (StopFunc, error) {
368+
func (p *Proxy) runUDSMasterServer(ctx context.Context, o *ProxyRunOptions, s *server.ProxyServer) (StopFunc, error) {
369369
var stop StopFunc
370370
if o.mode == "grpc" {
371371
grpcServer := grpc.NewServer()
372-
client.RegisterProxyServiceServer(grpcServer, server)
372+
client.RegisterProxyServiceServer(grpcServer, s)
373373
var lc net.ListenConfig
374374
lis, err := lc.Listen(ctx, "unix", o.udsName)
375375
if err != nil {
@@ -380,8 +380,8 @@ func (p *Proxy) runUDSMasterServer(ctx context.Context, o *ProxyRunOptions, serv
380380
} else {
381381
// http-connect
382382
server := &http.Server{
383-
Handler: &agentserver.Tunnel{
384-
Server: server,
383+
Handler: &server.Tunnel{
384+
Server: s,
385385
},
386386
}
387387
stop = func() { server.Shutdown(ctx) }
@@ -432,7 +432,7 @@ func (p *Proxy) getTLSConfig(caFile, certFile, keyFile string) (*tls.Config, err
432432
return tlsConfig, nil
433433
}
434434

435-
func (p *Proxy) runMTLSMasterServer(ctx context.Context, o *ProxyRunOptions, server *agentserver.ProxyServer) (StopFunc, error) {
435+
func (p *Proxy) runMTLSMasterServer(ctx context.Context, o *ProxyRunOptions, s *server.ProxyServer) (StopFunc, error) {
436436
var stop StopFunc
437437

438438
var tlsConfig *tls.Config
@@ -446,7 +446,7 @@ func (p *Proxy) runMTLSMasterServer(ctx context.Context, o *ProxyRunOptions, ser
446446
if o.mode == "grpc" {
447447
serverOption := grpc.Creds(credentials.NewTLS(tlsConfig))
448448
grpcServer := grpc.NewServer(serverOption)
449-
client.RegisterProxyServiceServer(grpcServer, server)
449+
client.RegisterProxyServiceServer(grpcServer, s)
450450
lis, err := net.Listen("tcp", addr)
451451
if err != nil {
452452
return nil, fmt.Errorf("failed to listen on %s: %v", addr, err)
@@ -458,8 +458,8 @@ func (p *Proxy) runMTLSMasterServer(ctx context.Context, o *ProxyRunOptions, ser
458458
server := &http.Server{
459459
Addr: addr,
460460
TLSConfig: tlsConfig,
461-
Handler: &agentserver.Tunnel{
462-
Server: server,
461+
Handler: &server.Tunnel{
462+
Server: s,
463463
},
464464
TLSNextProto: make(map[string]func(*http.Server, *tls.Conn, http.Handler)),
465465
}
@@ -475,7 +475,7 @@ func (p *Proxy) runMTLSMasterServer(ctx context.Context, o *ProxyRunOptions, ser
475475
return stop, nil
476476
}
477477

478-
func (p *Proxy) runAgentServer(o *ProxyRunOptions, server *agentserver.ProxyServer) error {
478+
func (p *Proxy) runAgentServer(o *ProxyRunOptions, server *server.ProxyServer) error {
479479
var tlsConfig *tls.Config
480480
var err error
481481
if tlsConfig, err = p.getTLSConfig(o.clusterCaCert, o.clusterCert, o.clusterKey); err != nil {
@@ -495,7 +495,7 @@ func (p *Proxy) runAgentServer(o *ProxyRunOptions, server *agentserver.ProxyServ
495495
return nil
496496
}
497497

498-
func (p *Proxy) runAdminServer(o *ProxyRunOptions, server *agentserver.ProxyServer) error {
498+
func (p *Proxy) runAdminServer(o *ProxyRunOptions, server *server.ProxyServer) error {
499499
livenessHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
500500
fmt.Fprintf(w, "ok")
501501
})

pkg/agent/agentclient/client.go renamed to pkg/agent/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package agentclient
17+
package agent
1818

1919
import (
2020
"io"

pkg/agent/agentclient/client_test.go renamed to pkg/agent/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package agentclient
1+
package agent
22

33
import (
44
"errors"

pkg/agent/agentclient/clientset.go renamed to pkg/agent/clientset.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package agentclient
17+
package agent
1818

1919
import (
2020
"fmt"

pkg/agent/agentclient/stream.go renamed to pkg/agent/stream.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package agentclient
17+
package agent
1818

1919
import (
2020
"context"

pkg/agent/agentclient/stream_test.go renamed to pkg/agent/stream_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package agentclient
1+
package agent
22

33
import (
44
"fmt"

pkg/agent/agentserver/backend_manager.go renamed to pkg/server/backend_manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17-
package agentserver
17+
package server
1818

1919
import (
2020
"context"

0 commit comments

Comments
 (0)