Skip to content

Commit

Permalink
add timeouts for docker reconciler docker calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Mahmood Ali committed Oct 18, 2019
1 parent 31ff46b commit 4114138
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions drivers/docker/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,13 @@ func (r *containerReconciler) removeDanglingContainersIteration() error {
}

for _, id := range untracked {
ctx, cancel := context.WithTimeout(context.Background(), r.config.period)
err := client.RemoveContainer(docker.RemoveContainerOptions{
ID: id,
Force: true,
Context: ctx,
ID: id,
Force: true,
})
cancel()
if err != nil {
r.logger.Warn("failed to remove untracked container", "container_id", id, "error", err)
} else {
Expand All @@ -125,8 +128,12 @@ func (r *containerReconciler) removeDanglingContainersIteration() error {
func (r *containerReconciler) untrackedContainers(tracked map[string]bool, cutoffTime time.Time) ([]string, error) {
result := []string{}

ctx, cancel := context.WithTimeout(context.Background(), r.config.period)
defer cancel()

cc, err := client.ListContainers(docker.ListContainersOptions{
All: false, // only reconcile running containers
Context: ctx,
All: false, // only reconcile running containers
})
if err != nil {
return nil, fmt.Errorf("failed to list containers: %v", err)
Expand Down

0 comments on commit 4114138

Please sign in to comment.