Merge pull request #234 from stokito/refresh

docker connector: refresh() delete container only if it not found but keep on failures
This commit is contained in:
bradley
2020-11-22 19:00:31 -05:00
committed by GitHub

View File

@@ -15,7 +15,6 @@ import (
func init() { enabled["docker"] = NewDocker } func init() { enabled["docker"] = NewDocker }
var actionToStatus = map[string]string{ var actionToStatus = map[string]string{
"create": "created",
"start": "running", "start": "running",
"die": "exited", "die": "exited",
"stop": "exited", "stop": "exited",
@@ -161,9 +160,12 @@ func ipsFormat(networks map[string]api.ContainerNetwork) string {
} }
func (cm *Docker) refresh(c *container.Container) { func (cm *Docker) refresh(c *container.Container) {
insp := cm.inspect(c.Id) insp, found, failed := cm.inspect(c.Id)
if failed {
return
}
// remove container if no longer exists // remove container if no longer exists
if insp == nil { if !found {
cm.delByID(c.Id) cm.delByID(c.Id)
return return
} }
@@ -179,14 +181,17 @@ func (cm *Docker) refresh(c *container.Container) {
c.SetState(insp.State.Status) c.SetState(insp.State.Status)
} }
func (cm *Docker) inspect(id string) *api.Container { func (cm *Docker) inspect(id string) (insp *api.Container, found bool, failed bool) {
c, err := cm.client.InspectContainer(id) c, err := cm.client.InspectContainer(id)
if err != nil { if err != nil {
if _, ok := err.(*api.NoSuchContainer); !ok { if _, notFound := err.(*api.NoSuchContainer); notFound {
log.Errorf("%s (%T)", err.Error(), err) return c, false, false
} }
// other error e.g. connection failed
log.Errorf("%s (%T)", err.Error(), err)
return c, false, true
} }
return c return c, true, false
} }
// Mark all container IDs for refresh // Mark all container IDs for refresh