/
health.go
61 lines (48 loc) · 1.17 KB
/
health.go
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
package component
import (
"errors"
"fmt"
"github.com/rycus86/podlike/pkg/healthcheck"
)
func parseHealthcheckTest(value interface{}) ([]string, error) {
if value == nil {
return nil, nil
}
stringValue, ok := value.(string)
if ok {
return []string{"CMD-SHELL", stringValue}, nil
}
sliceValue, ok := value.([]string)
if ok {
return sliceValue, nil
}
slice, ok := value.([]interface{})
if ok {
values := make([]string, len(slice), len(slice))
for idx, item := range slice {
values[idx] = fmt.Sprintf("%s", item)
}
return values, nil
} else {
return nil, errors.New(fmt.Sprintf("invalid string or slice: %T %+v", value, value))
}
}
func (c *Component) initHealthCheckingIfNecessary() error {
if c.disableHealthChecking {
return nil
}
hasHealthcheck, err := c.hasHealthcheck()
if err != nil {
return err
}
if hasHealthcheck {
healthcheck.Initialize(c.container.ID, healthcheck.StateStarting)
}
return nil
}
func (c *Component) hasHealthcheck() (bool, error) {
return c.container.Config.Healthcheck != nil && c.container.Config.Healthcheck.Test != nil, nil
}
func (c *Component) DisableHealthChecking() {
c.disableHealthChecking = true
}