-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreadiness_handler.go
More file actions
34 lines (29 loc) · 934 Bytes
/
readiness_handler.go
File metadata and controls
34 lines (29 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package healthsrv
import (
"log"
"net/http"
"time"
"k8s.io/kubernetes/pkg/api"
)
func readinessHandler(nsLister NamespaceLister) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
stopCh := make(chan struct{})
namespaceListerCh := make(chan *api.NamespaceList)
namespaceListerErrCh := make(chan error)
go listNamespaces(nsLister, namespaceListerCh, namespaceListerErrCh, stopCh)
timeoutCh := time.After(waitTimeout)
defer close(stopCh)
select {
// listing k8s namespaces
case <-namespaceListerCh:
case err := <-namespaceListerErrCh:
log.Printf("Healthcheck error listing namespaces (%s)", err)
w.WriteHeader(http.StatusServiceUnavailable)
// timeout for everything all of the above
case <-timeoutCh:
log.Printf("Healthcheck endpoint timed out after %s", waitTimeout)
w.WriteHeader(http.StatusServiceUnavailable)
}
w.WriteHeader(http.StatusOK)
})
}