1
0
Fork 0

Allow discovering non-running Docker containers

This commit is contained in:
Alexis Couvreur 2025-10-24 08:08:04 -04:00 committed by GitHub
parent 5c489c05fc
commit 10be359327
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 600 additions and 11 deletions

View file

@ -114,6 +114,11 @@ func (p *DynConfBuilder) buildTCPServiceConfiguration(ctx context.Context, conta
}
}
// Keep an empty server load-balancer for non-running containers.
if container.Status != "" && container.Status != containertypes.StateRunning {
return nil
}
// Keep an empty server load-balancer for unhealthy containers.
if container.Health != "" && container.Health != containertypes.Healthy {
return nil
}
@ -138,6 +143,11 @@ func (p *DynConfBuilder) buildUDPServiceConfiguration(ctx context.Context, conta
}
}
// Keep an empty server load-balancer for non-running containers.
if container.Status != "" && container.Status != containertypes.StateRunning {
return nil
}
// Keep an empty server load-balancer for unhealthy containers.
if container.Health != "" && container.Health != containertypes.Healthy {
return nil
}
@ -164,6 +174,11 @@ func (p *DynConfBuilder) buildServiceConfiguration(ctx context.Context, containe
}
}
// Keep an empty server load-balancer for non-running containers.
if container.Status != "" && container.Status != containertypes.StateRunning {
return nil
}
// Keep an empty server load-balancer for unhealthy containers.
if container.Health != "" && container.Health != containertypes.Healthy {
return nil
}
@ -196,6 +211,19 @@ func (p *DynConfBuilder) keepContainer(ctx context.Context, container dockerData
return false
}
// AllowNonRunning has precedence over AllowEmptyServices.
// If AllowNonRunning is true, we don't care about the container health/status,
// and we need to quit before checking it.
// Only configurable with the Docker provider.
if container.ExtraConf.AllowNonRunning {
return true
}
if container.Status != "" && container.Status != containertypes.StateRunning {
logger.Debug().Msg("Filtering non running container")
return false
}
if !p.AllowEmptyServices && container.Health != "" && container.Health != containertypes.Healthy {
logger.Debug().Msg("Filtering unhealthy or starting container")
return false