Skip to content

Commit 3b44a3d

Browse files
authored
Merge pull request #32 from Sh4d1/add_ci
add CI and fix code to pass linting
2 parents 72862c0 + a1a1a1b commit 3b44a3d

File tree

11 files changed

+90
-15
lines changed

11 files changed

+90
-15
lines changed

.golangci.yml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# taken from https://github.com/kubernetes-sigs/kustomize/blob/master/.golangci.yml
2+
run:
3+
deadline: 5m
4+
5+
linters:
6+
disable-all: true
7+
enable:
8+
- dupl
9+
- goconst
10+
# - gocyclo
11+
- gofmt
12+
- golint
13+
- govet
14+
- ineffassign
15+
# - interfacer
16+
- lll
17+
- misspell
18+
- nakedret
19+
- structcheck
20+
# - unparam
21+
- varcheck
22+
23+
linters-settings:
24+
dupl:
25+
threshold: 400
26+
lll:
27+
line-length: 170
28+
# gocyclo:
29+
# min-complexity: 15
30+
golint:
31+
min-confidence: 0.85

.travis.yml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
language: go
2+
go:
3+
- 1.13.x
4+
git:
5+
depth: 1
6+
install: true
7+
notifications:
8+
email: false
9+
before_script:
10+
- go install github.com/golangci/golangci-lint/cmd/golangci-lint
11+
script:
12+
- golangci-lint run --skip-files ".*.pb.go"
13+
- go test -v ./... # go test -v -race ./... is failing, should be fixed

cmd/agent/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func (a *Agent) run(o *GrpcProxyAgentOptions) error {
157157
return nil
158158
}
159159

160-
func (p *Agent) runProxyConnection(o *GrpcProxyAgentOptions) error {
160+
func (a *Agent) runProxyConnection(o *GrpcProxyAgentOptions) error {
161161
agentCert, err := tls.LoadX509KeyPair(o.agentCert, o.agentKey)
162162
if err != nil {
163163
return fmt.Errorf("failed to load X509 key pair %s and %s: %v", o.agentCert, o.agentKey, err)
@@ -190,7 +190,7 @@ func (p *Agent) runProxyConnection(o *GrpcProxyAgentOptions) error {
190190
return nil
191191
}
192192

193-
func (p *Agent) runAdminServer(o *GrpcProxyAgentOptions) error {
193+
func (a *Agent) runAdminServer(o *GrpcProxyAgentOptions) error {
194194
livenessHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
195195
fmt.Fprintf(w, "ok")
196196
})

cmd/proxy/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"net"
2626
"net/http"
2727
"os"
28-
28+
2929
"github.com/prometheus/client_golang/prometheus"
3030
"github.com/spf13/cobra"
3131
"github.com/spf13/pflag"

pkg/agent/agentclient/client.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,10 @@ func (a *AgentClient) Serve(stopCh <-chan struct{}) {
8787
pkt, err := a.stream.Recv()
8888
if err != nil {
8989
if err2, ok := err.(*ReconnectError); ok {
90-
err = err2.Wait()
90+
err3 := err2.Wait()
91+
if err3 != nil {
92+
klog.Warningf("reconnect error: %v", err3)
93+
}
9194
continue
9295
} else if err == io.EOF {
9396
klog.Info("received EOF, exit")
@@ -102,6 +105,11 @@ func (a *AgentClient) Serve(stopCh <-chan struct{}) {
102105

103106
klog.Infof("[tracing] recv packet %+v", pkt)
104107

108+
if pkt == nil {
109+
klog.Warningf("empty packet received")
110+
continue
111+
}
112+
105113
switch pkt.Type {
106114
case agent.PacketType_DIAL_REQ:
107115
klog.Info("received DIAL_REQ")

pkg/agent/agentclient/client_test.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
)
1616

1717
func TestServeData_HTTP(t *testing.T) {
18+
var err error
1819
var stream agent.AgentService_ConnectClient
1920
client := &AgentClient{
2021
connContext: make(map[int64]*connContext),
@@ -35,12 +36,18 @@ func TestServeData_HTTP(t *testing.T) {
3536

3637
// Stimulate sending KAS DIAL_REQ to AgentClient
3738
dialPacket := newDialPacket("tcp", ts.URL[len("http://"):], 111)
38-
stream.Send(dialPacket)
39+
err = stream.Send(dialPacket)
40+
if err != nil {
41+
t.Fatal(err.Error())
42+
}
3943

4044
// Expect receiving DIAL_RSP packet from AgentClient
41-
pkg, _ := stream.Recv()
45+
pkg, err := stream.Recv()
46+
if err != nil {
47+
t.Fatal(err.Error())
48+
}
4249
if pkg == nil {
43-
t.Error("unexpected nil packet")
50+
t.Fatal("unexpected nil packet")
4451
}
4552
if pkg.Type != agent.PacketType_DIAL_RSP {
4653
t.Errorf("expect PacketType_DIAL_RSP; got %v", pkg.Type)
@@ -53,7 +60,10 @@ func TestServeData_HTTP(t *testing.T) {
5360

5461
// Send Data (HTTP Request) via AgentClient to the test http server
5562
dataPacket := newDataPacket(connID, []byte("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n"))
56-
stream.Send(dataPacket)
63+
err = stream.Send(dataPacket)
64+
if err != nil {
65+
t.Error(err.Error())
66+
}
5767

5868
// Expect receiving http response via AgentClient
5969
pkg, _ = stream.Recv()
@@ -128,7 +138,7 @@ func TestClose_Client(t *testing.T) {
128138
// Expect receiving DIAL_RSP packet from AgentClient
129139
pkg, _ := stream.Recv()
130140
if pkg == nil {
131-
t.Error("unexpected nil packet")
141+
t.Fatal("unexpected nil packet")
132142
}
133143
if pkg.Type != agent.PacketType_DIAL_RSP {
134144
t.Errorf("expect PacketType_DIAL_RSP; got %v", pkg.Type)

pkg/agent/agentclient/stream.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,20 @@ func (c *RedialableAgentClient) Recv() (*agent.Packet, error) {
152152
c.recvLock.Lock()
153153
defer c.recvLock.Unlock()
154154

155-
if pkt, err := c.stream.Recv(); err != nil {
155+
var pkt *agent.Packet
156+
var err error
157+
158+
if pkt, err = c.stream.Recv(); err != nil {
156159
if err == io.EOF {
157160
return pkt, err
158161
}
159162
return pkt, &ReconnectError{
160163
internalErr: err,
161164
errChan: c.triggerReconnect(),
162165
}
163-
} else {
164-
return pkt, nil
165166
}
167+
168+
return pkt, nil
166169
}
167170

168171
func (c *RedialableAgentClient) Connect() error {

pkg/agent/agentserver/server.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (c *ProxyClientConnection) send(pkt *agent.Packet) error {
5454
}
5555
}
5656

57-
// ProxyServer
57+
// ProxyServer
5858
type ProxyServer struct {
5959
Backend agent.AgentService_ConnectServer
6060

pkg/agent/agentserver/tunnel.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,11 @@ func (t *Tunnel) ServeHTTP(w http.ResponseWriter, r *http.Request) {
121121
},
122122
},
123123
}
124-
t.Server.Backend.Send(packet)
124+
err = t.Server.Backend.Send(packet)
125+
if err != nil {
126+
klog.Errorf("error sending packet %v", err)
127+
continue
128+
}
125129
klog.Infof("Forwarding on tunnel, packet %v", string(pkt[:n]))
126130
}
127131

pkg/util/flags.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ import "strings"
2222
// we should always use hyphens instead of underscores when registering component flags
2323
func Normalize(s string) string {
2424
return strings.Replace(s, "_", "-", -1)
25-
}
25+
}

tests/proxy_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ func TestBasicProxy_GRPC(t *testing.T) {
3535
defer close(stopCh)
3636

3737
proxy, cleanup, err := runGRPCProxyServer()
38+
if err != nil {
39+
t.Fatal(err)
40+
}
3841
defer cleanup()
3942

4043
if err := runAgent(proxy.agent, stopCh); err != nil {
@@ -79,6 +82,9 @@ func TestBasicProxy_HTTPCONN(t *testing.T) {
7982
defer close(stopCh)
8083

8184
proxy, cleanup, err := runHTTPConnProxyServer()
85+
if err != nil {
86+
t.Fatal(err)
87+
}
8288
defer cleanup()
8389

8490
if err := runAgent(proxy.agent, stopCh); err != nil {

0 commit comments

Comments
 (0)