Adds healthcheck

This PR adds support for HealthCheck, being able to supply, for example:

```yaml
version: "3"

services:
  redis:
    image: redis
    healthcheck:
      test: echo "hello world"
      interval: 10s
      timeout: 1s
      retries: 5
```

Which is then converted to:

```yaml
spec:
  containers:
  - image: redis
    livenessProbe:
      exec:
        command:
        - echo "hello world"
      failureThreshold: 5
      periodSeconds: 10
      timeoutSeconds: 1
    name: redis
    resources: {}
  restartPolicy: Always
```

At the moment, this only supports livenessProbe, with support for readinessProbe in the future.
This commit is contained in:
Charlie Drage
2017-08-25 10:02:51 -04:00
parent 2ff2d38ed1
commit 2e99b8fd3a
11 changed files with 391 additions and 3 deletions
+27
View File
@@ -381,6 +381,33 @@ func (k *Kubernetes) UpdateKubernetesObjects(name string, service kobject.Servic
template.Spec.Containers[0].TTY = service.Tty
template.Spec.Volumes = volumes
// Configure the HealthCheck
// We check to see if it's blank
if !reflect.DeepEqual(service.HealthChecks, kobject.HealthCheck{}) {
probe := api.Probe{}
if len(service.HealthChecks.Test) > 0 {
probe.Handler = api.Handler{
Exec: &api.ExecAction{
Command: service.HealthChecks.Test,
},
}
} else {
return errors.New("Health check must contain a command")
}
probe.TimeoutSeconds = service.HealthChecks.Timeout
probe.PeriodSeconds = service.HealthChecks.Interval
probe.FailureThreshold = service.HealthChecks.Retries
// See issue: https://github.com/docker/cli/issues/116
// StartPeriod has been added to docker/cli however, it is not yet added
// to compose. Once the feature has been implemented, this will automatically work
probe.InitialDelaySeconds = service.HealthChecks.StartPeriod
template.Spec.Containers[0].LivenessProbe = &probe
}
if service.StopGracePeriod != "" {
template.Spec.TerminationGracePeriodSeconds, err = DurationStrToSecondsInt(service.StopGracePeriod)
if err != nil {