Fix probes
This commit is contained in:
@@ -482,14 +482,13 @@ func prepareProbes(name string, s types.ServiceConfig, container *helm.Container
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// it's a command
|
// it's a command
|
||||||
container.LivenessProbe = &helm.Probe{
|
container.LivenessProbe = helm.NewProbe(0, 0, 0, 0)
|
||||||
Exec: &helm.Exec{
|
container.LivenessProbe.Exec = &helm.Exec{
|
||||||
Command: []string{
|
Command: []string{
|
||||||
"sh",
|
"sh",
|
||||||
"-c",
|
"-c",
|
||||||
check,
|
check,
|
||||||
},
|
},
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return // label overrides everything
|
return // label overrides everything
|
||||||
@@ -501,15 +500,21 @@ func prepareProbes(name string, s types.ServiceConfig, container *helm.Container
|
|||||||
}
|
}
|
||||||
|
|
||||||
func buildProtoProbe(u *url.URL) *helm.Probe {
|
func buildProtoProbe(u *url.URL) *helm.Probe {
|
||||||
probe := helm.Probe{}
|
probe := helm.NewProbe(0, 0, 0, 0)
|
||||||
port, err := strconv.Atoi(u.Port())
|
port, err := strconv.Atoi(u.Port())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
port = 80
|
port = 80
|
||||||
}
|
}
|
||||||
|
|
||||||
|
path := "/"
|
||||||
|
if u.Path != "" {
|
||||||
|
path = u.Path
|
||||||
|
}
|
||||||
|
|
||||||
switch u.Scheme {
|
switch u.Scheme {
|
||||||
case "http", "https":
|
case "http", "https":
|
||||||
probe.HttpGet = &helm.HttpGet{
|
probe.HttpGet = &helm.HttpGet{
|
||||||
Path: u.Path,
|
Path: path,
|
||||||
Port: port,
|
Port: port,
|
||||||
}
|
}
|
||||||
case "tcp":
|
case "tcp":
|
||||||
@@ -520,30 +525,28 @@ func buildProtoProbe(u *url.URL) *helm.Probe {
|
|||||||
logger.Redf("Error while parsing healthcheck url %s\n", u.String())
|
logger.Redf("Error while parsing healthcheck url %s\n", u.String())
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
return &probe
|
return probe
|
||||||
}
|
}
|
||||||
|
|
||||||
func buildCommandProbe(s types.ServiceConfig) *helm.Probe {
|
func buildCommandProbe(s types.ServiceConfig) *helm.Probe {
|
||||||
|
|
||||||
// Get the first element of the command from ServiceConfig
|
// Get the first element of the command from ServiceConfig
|
||||||
first := s.HealthCheck.Test[0]
|
first := s.HealthCheck.Test[0]
|
||||||
|
p := helm.NewProbe(0, 0, 0, 0)
|
||||||
switch first {
|
switch first {
|
||||||
case "CMD", "CMD-SHELL":
|
case "CMD", "CMD-SHELL":
|
||||||
// CMD or CMD-SHELL
|
// CMD or CMD-SHELL
|
||||||
return &helm.Probe{
|
p.Exec = &helm.Exec{
|
||||||
Exec: &helm.Exec{
|
|
||||||
Command: s.HealthCheck.Test[1:],
|
Command: s.HealthCheck.Test[1:],
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return p
|
||||||
default:
|
default:
|
||||||
// badly made but it should work...
|
// badly made but it should work...
|
||||||
return &helm.Probe{
|
p.Exec = &helm.Exec{
|
||||||
Exec: &helm.Exec{
|
|
||||||
Command: []string(s.HealthCheck.Test),
|
Command: []string(s.HealthCheck.Test),
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// prepareEnvFromFiles generate configMap or secrets from environment files.
|
// prepareEnvFromFiles generate configMap or secrets from environment files.
|
||||||
|
@@ -77,13 +77,27 @@ type Probe struct {
|
|||||||
InitialDelay int `yaml:"initialDelaySeconds"`
|
InitialDelay int `yaml:"initialDelaySeconds"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create a new Probe object that can be apply to HttpProbe or TCPProbe.
|
||||||
func NewProbe(period, initialDelaySeconds, success, failure int) *Probe {
|
func NewProbe(period, initialDelaySeconds, success, failure int) *Probe {
|
||||||
return &Probe{
|
probe := &Probe{
|
||||||
Period: period,
|
Period: period,
|
||||||
Success: success,
|
Success: success,
|
||||||
Failure: failure,
|
Failure: failure,
|
||||||
InitialDelay: initialDelaySeconds,
|
InitialDelay: initialDelaySeconds,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// fix default values from
|
||||||
|
// https://kubernetes.io/docs/tasks/configure-pod-container/configure-liveness-readiness-startup-probes/
|
||||||
|
if period == 0 {
|
||||||
|
probe.Period = 10
|
||||||
|
}
|
||||||
|
if success == 0 {
|
||||||
|
probe.Success = 1
|
||||||
|
}
|
||||||
|
if failure == 0 {
|
||||||
|
probe.Failure = 3
|
||||||
|
}
|
||||||
|
return probe
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewContainer(name, image string, environment types.MappingWithEquals, labels map[string]string) *Container {
|
func NewContainer(name, image string, environment types.MappingWithEquals, labels map[string]string) *Container {
|
||||||
|
Reference in New Issue
Block a user