Skip to content

Commit 7954240

Browse files
committed
add deploy scripts
Signed-off-by: cwen0 <[email protected]>
1 parent 22bffa4 commit 7954240

File tree

11 files changed

+91
-20
lines changed

11 files changed

+91
-20
lines changed

Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
FROM alpine:3.10
2-
3-
RUN apk add tzdata --no-cache
1+
FROM centos:7
42

53
ADD ./bin/web-show /usr/local/bin/web-show
6-
ADD ./web/build /build
4+
ADD ./web/build /web
5+
6+
RUN setcap cap_net_raw=+ep /usr/local/bin/web-show
7+
# RUN sysctl -w net.ipv4.ping_group_range='0 2147483647'
78

89
CMD ["/usr/local/bin/web-show"]

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# web-show

deploy.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set -e
4+
5+
TARGET_IP=$(kubectl get pod -n kube-system -o wide| grep kube-controller | head -n 1 | awk '{print $6}')
6+
7+
sed "s/TARGETIP/$TARGET_IP/g" deploy/deployment.yaml > deploy/deployment.yamlg
8+
9+
mv deploy/deployment.yamlg deploy/deployment.yaml
10+
11+
kubectl apply -f deploy/
12+

deploy/deployment.yaml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: web-show
5+
labels:
6+
app: web-show
7+
spec:
8+
replicas: 1
9+
selector:
10+
matchLabels:
11+
app: web-show
12+
template:
13+
metadata:
14+
labels:
15+
app: web-show
16+
spec:
17+
containers:
18+
- name: web-show
19+
image: pingcap/web-show
20+
imagePullPolicy: Always
21+
command:
22+
- /usr/local/bin/web-show
23+
- --target-ip=TARGETIP
24+
ports:
25+
- name: web-port
26+
containerPort: 8081
27+
hostPort: 8081

deploy/service.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: web-show
5+
labels:
6+
app: web-show
7+
spec:
8+
selector:
9+
app: web-show
10+
ports:
11+
- protocol: TCP
12+
port: 8081
13+
targetPort: 8081

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ require (
1212
github.com/sparrc/go-ping v0.0.0-20190613174326-4e5b6552494c
1313
github.com/stretchr/testify v1.4.0 // indirect
1414
github.com/unrolled/render v1.0.2
15+
go.uber.org/zap v1.9.1
1516
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 // indirect
1617
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a // indirect
1718
gopkg.in/mgo.v2 v2.0.0-20190816093944-a6b53ec6cb22 // indirect

main.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
package main
22

33
import (
4+
"flag"
5+
46
"github.com/chaos-mesh/web-show/server"
57
"github.com/pingcap/log"
68
)
79

810
func main() {
11+
conf := &server.Config{}
12+
13+
flag.StringVar(&conf.Port, "port", ":8081", "the port of address")
14+
flag.StringVar(&conf.StaticPath, "static-path", "/web", "the path of static file")
15+
flag.StringVar(&conf.TargetIP, "target-ip", "", "the ip of target pod")
16+
flag.Parse()
17+
918
log.Info("Starting server")
10-
s := server.SetupServer()
19+
s := server.SetupServer(conf)
1120
s.Run()
1221
}

server/nework.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,6 @@ import (
99
"github.com/unrolled/render"
1010
)
1111

12-
const (
13-
GoogleAddress = "www.google.com"
14-
)
15-
1612
type PingD struct {
1713
Time int64 `json:"time"`
1814
Delay float64 `json:"delay"`
@@ -30,12 +26,13 @@ func (s *Server) startPing() {
3026
for {
3127
select {
3228
case <-ticker.C:
33-
pinger, err := ping.NewPinger(GoogleAddress)
29+
pinger, err := ping.NewPinger(s.conf.TargetIP)
3430
if err != nil {
3531
log.Error(err.Error())
3632
s.push(&PingD{Time: time.Now().UnixNano() / 1e6})
3733
continue
3834
}
35+
pinger.SetPrivileged(true)
3936
pinger.Timeout = 5 * time.Second
4037
pinger.Count = 1
4138
pinger.Run() // blocks until finished

server/server.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,38 +1,48 @@
11
package server
22

33
import (
4+
"go.uber.org/zap"
45
"net/http"
56

67
"github.com/chaos-mesh/web-show/pkg/queue"
78
"github.com/gorilla/mux"
89
"github.com/pingcap/log"
910
)
1011

11-
func SetupServer() Server {
12+
type Config struct {
13+
Port string
14+
StaticPath string
15+
TargetIP string
16+
}
17+
18+
func SetupServer(conf *Config) Server {
1219
r := mux.NewRouter()
1320

1421
server := Server{
1522
router: r,
1623
pingData: queue.NewListQueue(200),
24+
conf: conf,
1725
}
1826

1927
r.PathPrefix("/api/network").HandlerFunc(server.network)
2028

21-
r.PathPrefix("/").Handler(server.web("/", "./web/build"))
29+
r.PathPrefix("/").Handler(server.web("/", server.conf.StaticPath))
2230

2331
return server
2432
}
2533

2634
func (s *Server) Run() {
2735
go s.startPing()
28-
log.Info("Starting Server on 0.0.0.0:8081")
29-
err := http.ListenAndServe("0.0.0.0:8081", s.router)
36+
log.Info("Starting Server", zap.Reflect("config", s.conf))
37+
err := http.ListenAndServe(s.conf.Port, s.router)
3038
if err != nil {
31-
log.Error("Error while listening 0.0.0.0:8081")
39+
log.Error("Error while listening 0.0.0.0:8081", zap.Reflect("config", s.conf))
3240
}
3341
}
3442

3543
type Server struct {
3644
router *mux.Router
3745
pingData queue.Queue
46+
47+
conf *Config
3848
}

web/src/App.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const App: React.FC = () => {
5252
<Banner />
5353
<BodyStyles className="body">
5454
<Row>
55-
<TrafficChartContainer title="Ping www.google.com" />
55+
<TrafficChartContainer title="Ping kube-system Pod" />
5656
</Row>
5757
</BodyStyles>
5858
</AppStyles>

0 commit comments

Comments
 (0)