File tree 4 files changed +51
-1
lines changed
4 files changed +51
-1
lines changed Original file line number Diff line number Diff line change @@ -22,11 +22,15 @@ RUN git clone https://git.zx2c4.com/wireguard-tools && \
22
22
make && \
23
23
make install
24
24
25
+ COPY healthcheck.go /go/src/healthcheck.go
26
+ RUN go build -o /go/bin/healthcheck /go/src/healthcheck.go
27
+
25
28
FROM alpine:${ALPINE_VERSION}
26
29
27
30
RUN apk add --no-cache --update bash libmnl iptables openresolv iproute2
28
31
29
32
COPY --from=builder /usr/bin/wireguard-go /usr/bin/wg* /usr/bin/
33
+ COPY --from=builder /go/bin/healthcheck /usr/bin/healthcheck
30
34
COPY entrypoint.sh /entrypoint.sh
31
35
32
36
CMD ["/entrypoint.sh" ]
Original file line number Diff line number Diff line change @@ -134,6 +134,14 @@ spec:
134
134
- containerPort : 51820
135
135
protocol : UDP
136
136
name : wireguard
137
+ - containerPort : 8080
138
+ protocol : TCP
139
+ name : healthcheck
140
+ livenessProbe : &probe
141
+ httpGet :
142
+ path : /
143
+ port : healthcheck
144
+ readinessProbe : *probe
137
145
env :
138
146
- name : LOG_LEVEL
139
147
value : info
Original file line number Diff line number Diff line change @@ -8,6 +8,9 @@ trap finish SIGTERM SIGINT SIGQUIT
8
8
9
9
wg-quick up /etc/wireguard/wg0.conf
10
10
11
- # Inifinite sleep
11
+ # Infinite sleep
12
12
sleep infinity &
13
+
14
+ # Health check
15
+ /usr/bin/healthcheck &
13
16
wait $!
Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "fmt"
5
+ "io/ioutil"
6
+ "net/http"
7
+ "os"
8
+ "strings"
9
+ )
10
+
11
+ func isLinkUp (interfaceName string ) bool {
12
+ content , err := ioutil .ReadFile ("/sys/class/net/" + interfaceName + "/carrier" )
13
+ if err != nil {
14
+ return false
15
+ }
16
+ return strings .TrimSpace (string (content )) == "1"
17
+ }
18
+
19
+ func healthCheckHandler (w http.ResponseWriter , r * http.Request ) {
20
+ if isLinkUp ("wg0" ) {
21
+ w .WriteHeader (http .StatusOK )
22
+ fmt .Fprintf (w , "status: OK\n " )
23
+ } else {
24
+ w .WriteHeader (http .StatusServiceUnavailable )
25
+ fmt .Fprintf (w , "status: KO\n " )
26
+ }
27
+ }
28
+
29
+ func main () {
30
+ http .HandleFunc ("/" , healthCheckHandler )
31
+ if err := http .ListenAndServe (":8080" , nil ); err != nil {
32
+ fmt .Printf ("Failed to start server: %v\n " , err )
33
+ os .Exit (1 )
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments