RetryGettingDockerRoot and log when error

This commit is contained in:
chenkaiyue 2019-12-17 17:15:31 +08:00 committed by kaiyuechen
parent 7dfa1d0cb0
commit d553c7485e

View File

@ -22,6 +22,7 @@ import (
"strconv"
"strings"
"sync"
"time"
"github.com/blang/semver"
dockertypes "github.com/docker/docker/api/types"
@ -49,6 +50,12 @@ var ArgDockerCA = flag.String("docker-tls-ca", "ca.pem", "path to trusted CA")
// The namespace under which Docker aliases are unique.
const DockerNamespace = "docker"
// The retry times for getting docker root dir
const rootDirRetries = 5
//The retry period for getting docker root dir, Millisecond
const rootDirRetryPeriod time.Duration = 1000 * time.Millisecond
// Regexp that identifies docker cgroups, containers started with
// --cgroup-parent have another prefix than 'docker'
var dockerCgroupRegexp = regexp.MustCompile(`([a-z0-9]{64})`)
@ -72,10 +79,16 @@ var (
func RootDir() string {
dockerRootDirOnce.Do(func() {
status, err := Status()
if err == nil && status.RootDir != "" {
dockerRootDir = status.RootDir
} else {
for i := 0; i < rootDirRetries; i++ {
status, err := Status()
if err == nil && status.RootDir != "" {
dockerRootDir = status.RootDir
break
} else {
time.Sleep(rootDirRetryPeriod)
}
}
if dockerRootDir == "" {
dockerRootDir = *dockerRootDirFlag
}
})