mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
fn: cleanup of docker timeouts and docker health check (#1292)
Moving the timeout management of various docker operations to agent. This allows for finer control over what operation should use. For instance, for pause/unpause our tolerance is very low to avoid resource issues. For docker remove, the consequences of failure will lead to potential agent failure and therefore we wait up to 10 minute. For cookie create/prepare (which includes docker-pull) we cap this at 10 minutes by default. With new UDS/FDK contract, health check is now obsoleted as container advertise health using UDS availibility.
This commit is contained in:
@@ -233,7 +233,6 @@ func (drv *DockerDriver) CreateCookie(ctx context.Context, task drivers.Containe
|
||||
ReadonlyRootfs: drv.conf.EnableReadOnlyRootFs,
|
||||
Init: drv.conf.EnableTini,
|
||||
},
|
||||
Context: ctx,
|
||||
}
|
||||
|
||||
cookie := &cookie{
|
||||
@@ -276,6 +275,7 @@ func (drv *DockerDriver) PrepareCookie(ctx context.Context, c drivers.Cookie) er
|
||||
return err
|
||||
}
|
||||
|
||||
cookie.opts.Context = ctx
|
||||
_, err = drv.docker.CreateContainer(cookie.opts)
|
||||
if err != nil {
|
||||
// since we retry under the hood, if the container gets created and retry fails, we can just ignore error
|
||||
@@ -577,36 +577,7 @@ func (drv *DockerDriver) startTask(ctx context.Context, container string) error
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
// see if there's any healthcheck, and if so, wait for it to complete
|
||||
return drv.awaitHealthcheck(ctx, container)
|
||||
}
|
||||
|
||||
func (drv *DockerDriver) awaitHealthcheck(ctx context.Context, container string) error {
|
||||
// inspect the container and check if there is any health check presented,
|
||||
// if there is, then wait for it to move to healthy before returning.
|
||||
for {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
default:
|
||||
}
|
||||
|
||||
cont, err := drv.docker.InspectContainerWithContext(container, ctx)
|
||||
if err != nil {
|
||||
// TODO unknown fiddling to be had
|
||||
return err
|
||||
}
|
||||
|
||||
// if no health check for this image (""), or it's healthy, then stop waiting.
|
||||
// state machine is "starting" -> "healthy" | "unhealthy"
|
||||
if cont.State.Health.Status == "" || cont.State.Health.Status == "healthy" {
|
||||
break
|
||||
}
|
||||
|
||||
time.Sleep(100 * time.Millisecond) // avoid spin loop in case docker is actually fast
|
||||
}
|
||||
return nil
|
||||
return err
|
||||
}
|
||||
|
||||
func (w *waitResult) wait(ctx context.Context) (status string, err error) {
|
||||
|
||||
Reference in New Issue
Block a user