-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathreadiness_handler.go
More file actions
55 lines (46 loc) · 1.47 KB
/
readiness_handler.go
File metadata and controls
55 lines (46 loc) · 1.47 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package healthsrv
import (
"log"
"net/http"
"time"
drycc "github.com/drycc/controller-sdk-go"
v1 "k8s.io/api/core/v1"
)
func readinessHandler(client *drycc.Client, nsLister NamespaceLister) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
stopCh := make(chan struct{})
numChecks := 0
namespaceListerCh := make(chan *v1.NamespaceList)
namespaceListerErrCh := make(chan error)
go listNamespaces(nsLister, namespaceListerCh, namespaceListerErrCh, stopCh)
numChecks++
controllerStateCh := make(chan string)
controllerStateErrCh := make(chan error)
go controllerState(client, controllerStateCh, controllerStateErrCh, stopCh)
numChecks++
timeoutCh := time.After(waitTimeout)
defer close(stopCh)
for i := 0; i < numChecks; i++ {
select {
// listing k8s namespaces
case <-namespaceListerCh:
case err := <-namespaceListerErrCh:
log.Printf("Readinesscheck error listing namespaces (%s)", err)
w.WriteHeader(http.StatusServiceUnavailable)
return
// listing k8s namespaces
case <-controllerStateCh:
case err := <-controllerStateErrCh:
log.Printf("Readinesscheck error listning controller (%s)", err)
w.WriteHeader(http.StatusServiceUnavailable)
return
// timeout for everything all of the above
case <-timeoutCh:
log.Printf("Readinesscheck endpoint timed out after %s", waitTimeout)
w.WriteHeader(http.StatusServiceUnavailable)
return
}
}
w.WriteHeader(http.StatusOK)
})
}