Skip to content

Commit da8b7aa

Browse files
committed
1 parent 20c092a commit da8b7aa

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

cmd/webhook/main.go

+39-3
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
package main
22

33
import (
4+
"net"
5+
"net/http"
6+
47
log "github.com/sirupsen/logrus"
58

9+
"external-dns-openstack-webhook/internal/designate/provider"
10+
611
"sigs.k8s.io/external-dns/endpoint"
712
"sigs.k8s.io/external-dns/provider/webhook/api"
813
)
914

10-
import "external-dns-openstack-webhook/internal/designate/provider"
11-
1215
func main() {
1316
epf := endpoint.NewDomainFilter([]string{})
1417
dp, err := provider.NewDesignateProvider(epf, false)
@@ -17,6 +20,39 @@ func main() {
1720
}
1821

1922
log.SetLevel(log.DebugLevel)
23+
24+
startedChan := make(chan struct{})
25+
httpApiStarted := false
26+
27+
go func() {
28+
<-startedChan
29+
httpApiStarted = true
30+
}()
31+
32+
m := http.NewServeMux()
33+
m.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
34+
if !httpApiStarted {
35+
w.WriteHeader(http.StatusInternalServerError)
36+
}
37+
})
38+
39+
go func() {
40+
log.Debug("Starting status server on :8080")
41+
s := &http.Server{
42+
Addr: "0.0.0.0:8080",
43+
Handler: m,
44+
}
45+
46+
l, err := net.Listen("tcp", "0.0.0.0:8080")
47+
if err != nil {
48+
log.Fatal(err)
49+
}
50+
err = s.Serve(l)
51+
if err != nil {
52+
log.Fatalf("health listener stopped : %s", err)
53+
}
54+
}()
55+
2056
log.Printf("Starting server")
21-
api.StartHTTPApi(dp, nil, 0, 0, "127.0.0.1:8888")
57+
api.StartHTTPApi(dp, startedChan, 0, 0, "127.0.0.1:8888")
2258
}

0 commit comments

Comments
 (0)