Skip to content

Commit 9c5a7a3

Browse files
authored
Merge pull request #23 from inovex/expose-healthz-for-readiness-check
add healthz endpoint
2 parents 20c092a + d2fedf4 commit 9c5a7a3

File tree

3 files changed

+53
-4
lines changed

3 files changed

+53
-4
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ build/
22

33
# vim swap files
44
.*.sw*
5+
clouds.yaml

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,14 @@ This is an [ExternalDNS provider](https://github.com/kubernetes-sigs/external-dn
44
This projects externalizes the yet in-tree [OpenStack Designate provider](https://github.com/kubernetes-sigs/external-dns/tree/master/provider/designate).
55

66
### 🌪 This project is in a very early stage and likely does not do what you expect!
7+
8+
## Development
9+
10+
To run the webhook locally, you'll need to create a [clouds.yaml](https://docs.openstack.org/python-openstackclient/pike/configuration/index.html#clouds-yaml)
11+
file and put it in one of the standard-locations.
12+
Then set the cloud to be used in the `OS_CLOUD` environemnt variable.
13+
You can then start the webhook server using:
14+
15+
```sh
16+
go run cmd/webhook/main.go
17+
```

cmd/webhook/main.go

+41-4
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,59 @@
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() {
16+
log.SetLevel(log.DebugLevel)
17+
18+
startedChan := make(chan struct{})
19+
httpApiStarted := false
20+
21+
go func() {
22+
<-startedChan
23+
httpApiStarted = true
24+
}()
25+
26+
m := http.NewServeMux()
27+
m.HandleFunc("/healthz", func(w http.ResponseWriter, r *http.Request) {
28+
if !httpApiStarted {
29+
w.WriteHeader(http.StatusInternalServerError)
30+
}
31+
})
32+
33+
go func() {
34+
log.Debug("Starting status server on :8080")
35+
s := &http.Server{
36+
Addr: "0.0.0.0:8080",
37+
Handler: m,
38+
}
39+
40+
l, err := net.Listen("tcp", "0.0.0.0:8080")
41+
if err != nil {
42+
log.Fatal(err)
43+
}
44+
err = s.Serve(l)
45+
if err != nil {
46+
log.Fatalf("health listener stopped : %s", err)
47+
}
48+
}()
49+
50+
1351
epf := endpoint.NewDomainFilter([]string{})
1452
dp, err := provider.NewDesignateProvider(epf, false)
1553
if err != nil {
1654
log.Fatalf("NewDesignateProvider: %v", err)
1755
}
1856

19-
log.SetLevel(log.DebugLevel)
2057
log.Printf("Starting server")
21-
api.StartHTTPApi(dp, nil, 0, 0, "127.0.0.1:8888")
58+
api.StartHTTPApi(dp, startedChan, 0, 0, "127.0.0.1:8888")
2259
}

0 commit comments

Comments
 (0)