-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathcontroller_state.go
More file actions
76 lines (66 loc) · 1.55 KB
/
controller_state.go
File metadata and controls
76 lines (66 loc) · 1.55 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package healthsrv
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
"github.com/deis/builder/pkg/controller"
)
// GetClient is an (*net/http).Client compatible interface that provides just the Get cross-section of functionality.
// It can also be implemented for unit tests.
type GetClient interface {
Get(string) (*http.Response, error)
}
type successGetClient struct{}
func (e successGetClient) Get(url string) (*http.Response, error) {
resp := &http.Response{
Body: ioutil.NopCloser(strings.NewReader("")),
StatusCode: http.StatusOK,
}
return resp, nil
}
type failureGetClient struct{}
func (e failureGetClient) Get(url string) (*http.Response, error) {
resp := &http.Response{
Body: ioutil.NopCloser(strings.NewReader("")),
StatusCode: http.StatusServiceUnavailable,
}
return resp, nil
}
type errGetClient struct {
err error
}
func (e errGetClient) Get(url string) (*http.Response, error) {
return nil, e.err
}
func controllerState(client GetClient, succCh chan<- string, errCh chan<- error, stopCh <-chan struct{}) {
url, err := controller.ControllerURLStr("healthz")
if err != nil {
select {
case errCh <- err:
case <-stopCh:
}
return
}
resp, err := client.Get(url)
if err != nil {
select {
case errCh <- err:
case <-stopCh:
}
return
}
defer resp.Body.Close()
if resp.StatusCode < 200 || resp.StatusCode > 299 {
select {
case errCh <- fmt.Errorf("Failed to get controller health status"):
case <-stopCh:
}
return
}
select {
case succCh <- "controller is healthy":
case <-stopCh:
return
}
}