Fix probes

This commit is contained in:
2022-05-05 09:24:51 +02:00
parent 6eb8ec9915
commit 8ce0d64e62
2 changed files with 37 additions and 20 deletions

View File

@@ -482,14 +482,13 @@ func prepareProbes(name string, s types.ServiceConfig, container *helm.Container
}
} else {
// it's a command
container.LivenessProbe = &helm.Probe{
Exec: &helm.Exec{
container.LivenessProbe = helm.NewProbe(0, 0, 0, 0)
container.LivenessProbe.Exec = &helm.Exec{
Command: []string{
"sh",
"-c",
check,
},
},
}
}
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 {
probe := helm.Probe{}
probe := helm.NewProbe(0, 0, 0, 0)
port, err := strconv.Atoi(u.Port())
if err != nil {
port = 80
}
path := "/"
if u.Path != "" {
path = u.Path
}
switch u.Scheme {
case "http", "https":
probe.HttpGet = &helm.HttpGet{
Path: u.Path,
Path: path,
Port: port,
}
case "tcp":
@@ -520,30 +525,28 @@ func buildProtoProbe(u *url.URL) *helm.Probe {
logger.Redf("Error while parsing healthcheck url %s\n", u.String())
os.Exit(1)
}
return &probe
return probe
}
func buildCommandProbe(s types.ServiceConfig) *helm.Probe {
// Get the first element of the command from ServiceConfig
first := s.HealthCheck.Test[0]
p := helm.NewProbe(0, 0, 0, 0)
switch first {
case "CMD", "CMD-SHELL":
// CMD or CMD-SHELL
return &helm.Probe{
Exec: &helm.Exec{
p.Exec = &helm.Exec{
Command: s.HealthCheck.Test[1:],
},
}
return p
default:
// badly made but it should work...
return &helm.Probe{
Exec: &helm.Exec{
p.Exec = &helm.Exec{
Command: []string(s.HealthCheck.Test),
},
}
return p
}
}
// prepareEnvFromFiles generate configMap or secrets from environment files.

View File

@@ -77,13 +77,27 @@ type Probe struct {
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 {
return &Probe{
probe := &Probe{
Period: period,
Success: success,
Failure: failure,
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 {