Merge pull request #29314 from vdemeester/no-more-utils
Remove the utils package
This commit is contained in:
commit
b9ee31ae02
32 changed files with 154 additions and 166 deletions
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package api
|
||||
|
||||
import "regexp"
|
||||
|
|
@ -10,7 +10,7 @@ import (
|
|||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/command/formatter"
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ import (
|
|||
"text/tabwriter"
|
||||
"text/template"
|
||||
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
)
|
||||
|
||||
// Format keys used to specify certain kinds of output formats
|
||||
|
|
|
@ -9,7 +9,7 @@ import (
|
|||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
)
|
||||
|
||||
// Inspector defines an interface to implement to process elements
|
||||
|
|
|
@ -5,7 +5,7 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
)
|
||||
|
||||
type testElement struct {
|
||||
|
|
|
@ -17,7 +17,7 @@ import (
|
|||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/docker/docker/pkg/jsonlog"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
|
|
@ -12,9 +12,9 @@ import (
|
|||
"github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
"github.com/docker/go-units"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -206,7 +206,7 @@ func prettyPrintInfo(dockerCli *command.DockerCli, info types.Info) error {
|
|||
ioutils.FprintfIfNotEmpty(dockerCli.Out(), "Name: %s\n", info.Name)
|
||||
ioutils.FprintfIfNotEmpty(dockerCli.Out(), "ID: %s\n", info.ID)
|
||||
fmt.Fprintf(dockerCli.Out(), "Docker Root Dir: %s\n", info.DockerRootDir)
|
||||
fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", utils.IsDebugEnabled())
|
||||
fmt.Fprintf(dockerCli.Out(), "Debug Mode (client): %v\n", debug.IsEnabled())
|
||||
fmt.Fprintf(dockerCli.Out(), "Debug Mode (server): %v\n", info.Debug)
|
||||
|
||||
if info.Debug {
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package debug
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -6,21 +6,21 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
// EnableDebug sets the DEBUG env var to true
|
||||
// Enable sets the DEBUG env var to true
|
||||
// and makes the logger to log at debug level.
|
||||
func EnableDebug() {
|
||||
func Enable() {
|
||||
os.Setenv("DEBUG", "1")
|
||||
logrus.SetLevel(logrus.DebugLevel)
|
||||
}
|
||||
|
||||
// DisableDebug sets the DEBUG env var to false
|
||||
// Disable sets the DEBUG env var to false
|
||||
// and makes the logger to log at info level.
|
||||
func DisableDebug() {
|
||||
func Disable() {
|
||||
os.Setenv("DEBUG", "")
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
}
|
||||
|
||||
// IsDebugEnabled checks whether the debug flag is set or not.
|
||||
func IsDebugEnabled() bool {
|
||||
// IsEnabled checks whether the debug flag is set or not.
|
||||
func IsEnabled() bool {
|
||||
return os.Getenv("DEBUG") != ""
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package debug
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
@ -7,12 +7,12 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
)
|
||||
|
||||
func TestEnableDebug(t *testing.T) {
|
||||
func TestEnable(t *testing.T) {
|
||||
defer func() {
|
||||
os.Setenv("DEBUG", "")
|
||||
logrus.SetLevel(logrus.InfoLevel)
|
||||
}()
|
||||
EnableDebug()
|
||||
Enable()
|
||||
if os.Getenv("DEBUG") != "1" {
|
||||
t.Fatalf("expected DEBUG=1, got %s\n", os.Getenv("DEBUG"))
|
||||
}
|
||||
|
@ -21,8 +21,8 @@ func TestEnableDebug(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDisableDebug(t *testing.T) {
|
||||
DisableDebug()
|
||||
func TestDisable(t *testing.T) {
|
||||
Disable()
|
||||
if os.Getenv("DEBUG") != "" {
|
||||
t.Fatalf("expected DEBUG=\"\", got %s\n", os.Getenv("DEBUG"))
|
||||
}
|
||||
|
@ -31,13 +31,13 @@ func TestDisableDebug(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestDebugEnabled(t *testing.T) {
|
||||
EnableDebug()
|
||||
if !IsDebugEnabled() {
|
||||
func TestEnabled(t *testing.T) {
|
||||
Enable()
|
||||
if !IsEnabled() {
|
||||
t.Fatal("expected debug enabled, got false")
|
||||
}
|
||||
DisableDebug()
|
||||
if IsDebugEnabled() {
|
||||
Disable()
|
||||
if IsEnabled() {
|
||||
t.Fatal("expected debug disabled, got true")
|
||||
}
|
||||
}
|
|
@ -10,11 +10,11 @@ import (
|
|||
"github.com/docker/docker/cli"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/command/commands"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
cliflags "github.com/docker/docker/cli/flags"
|
||||
"github.com/docker/docker/cliconfig"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
@ -130,7 +130,7 @@ func dockerPreRun(opts *cliflags.ClientOptions) {
|
|||
}
|
||||
|
||||
if opts.Common.Debug {
|
||||
utils.EnableDebug()
|
||||
debug.Enable()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,12 @@ import (
|
|||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/cli/command"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
func TestClientDebugEnabled(t *testing.T) {
|
||||
defer utils.DisableDebug()
|
||||
defer debug.Disable()
|
||||
|
||||
cmd := newDockerCommand(&command.DockerCli{})
|
||||
cmd.Flags().Set("debug", "true")
|
||||
|
|
|
@ -26,6 +26,7 @@ import (
|
|||
systemrouter "github.com/docker/docker/api/server/router/system"
|
||||
"github.com/docker/docker/api/server/router/volume"
|
||||
"github.com/docker/docker/builder/dockerfile"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
cliflags "github.com/docker/docker/cli/flags"
|
||||
"github.com/docker/docker/cliconfig"
|
||||
"github.com/docker/docker/daemon"
|
||||
|
@ -44,7 +45,6 @@ import (
|
|||
"github.com/docker/docker/plugin"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/go-connections/tlsconfig"
|
||||
"github.com/spf13/pflag"
|
||||
)
|
||||
|
@ -137,7 +137,7 @@ func (cli *DaemonCli) start(opts daemonOptions) (err error) {
|
|||
}
|
||||
|
||||
if cli.Config.Debug {
|
||||
utils.EnableDebug()
|
||||
debug.Enable()
|
||||
}
|
||||
|
||||
if cli.Config.Experimental {
|
||||
|
@ -351,13 +351,13 @@ func (cli *DaemonCli) reloadConfig() {
|
|||
}
|
||||
|
||||
if config.IsValueSet("debug") {
|
||||
debugEnabled := utils.IsDebugEnabled()
|
||||
debugEnabled := debug.IsEnabled()
|
||||
switch {
|
||||
case debugEnabled && !config.Debug: // disable debug
|
||||
utils.DisableDebug()
|
||||
debug.Disable()
|
||||
cli.api.DisableProfiler()
|
||||
case config.Debug && !debugEnabled: // enable debug
|
||||
utils.EnableDebug()
|
||||
debug.Enable()
|
||||
cli.api.EnableProfiler()
|
||||
}
|
||||
|
||||
|
@ -488,7 +488,7 @@ func initRouter(s *apiserver.Server, d *daemon.Daemon, c *cluster.Cluster) {
|
|||
}
|
||||
}
|
||||
|
||||
s.InitRouter(utils.IsDebugEnabled(), routers...)
|
||||
s.InitRouter(debug.IsEnabled(), routers...)
|
||||
}
|
||||
|
||||
func (cli *DaemonCli) initMiddlewares(s *apiserver.Server, cfg *apiserver.Config) error {
|
||||
|
|
|
@ -16,7 +16,6 @@ import (
|
|||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/pkg/symlink"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/opencontainers/runc/libcontainer/label"
|
||||
"golang.org/x/sys/unix"
|
||||
|
@ -69,7 +68,7 @@ func (container *Container) CreateDaemonEnvironment(tty bool, linkedEnv []string
|
|||
// because the env on the container can override certain default values
|
||||
// we need to replace the 'env' keys where they match and append anything
|
||||
// else.
|
||||
env = utils.ReplaceOrAppendEnvValues(env, container.Config.Env)
|
||||
env = ReplaceOrAppendEnvValues(env, container.Config.Env)
|
||||
return env
|
||||
}
|
||||
|
||||
|
|
|
@ -8,7 +8,6 @@ import (
|
|||
"path/filepath"
|
||||
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// Container holds fields specific to the Windows implementation. See
|
||||
|
@ -30,7 +29,7 @@ func (container *Container) CreateDaemonEnvironment(_ bool, linkedEnv []string)
|
|||
// because the env on the container can override certain default values
|
||||
// we need to replace the 'env' keys where they match and append anything
|
||||
// else.
|
||||
return utils.ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
|
||||
return ReplaceOrAppendEnvValues(linkedEnv, container.Config.Env)
|
||||
}
|
||||
|
||||
// UnmountIpcMounts unmounts Ipc related mounts.
|
||||
|
|
43
container/env.go
Normal file
43
container/env.go
Normal file
|
@ -0,0 +1,43 @@
|
|||
package container
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
// ReplaceOrAppendEnvValues returns the defaults with the overrides either
|
||||
// replaced by env key or appended to the list
|
||||
func ReplaceOrAppendEnvValues(defaults, overrides []string) []string {
|
||||
cache := make(map[string]int, len(defaults))
|
||||
for i, e := range defaults {
|
||||
parts := strings.SplitN(e, "=", 2)
|
||||
cache[parts[0]] = i
|
||||
}
|
||||
|
||||
for _, value := range overrides {
|
||||
// Values w/o = means they want this env to be removed/unset.
|
||||
if !strings.Contains(value, "=") {
|
||||
if i, exists := cache[value]; exists {
|
||||
defaults[i] = "" // Used to indicate it should be removed
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Just do a normal set/update
|
||||
parts := strings.SplitN(value, "=", 2)
|
||||
if i, exists := cache[parts[0]]; exists {
|
||||
defaults[i] = value
|
||||
} else {
|
||||
defaults = append(defaults, value)
|
||||
}
|
||||
}
|
||||
|
||||
// Now remove all entries that we want to "unset"
|
||||
for i := 0; i < len(defaults); i++ {
|
||||
if defaults[i] == "" {
|
||||
defaults = append(defaults[:i], defaults[i+1:]...)
|
||||
i--
|
||||
}
|
||||
}
|
||||
|
||||
return defaults
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package container
|
||||
|
||||
import "testing"
|
||||
|
|
@ -7,13 +7,13 @@ import (
|
|||
"os"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
validCheckpointNameChars = utils.RestrictedNameChars
|
||||
validCheckpointNamePattern = utils.RestrictedNamePattern
|
||||
validCheckpointNameChars = api.RestrictedNameChars
|
||||
validCheckpointNamePattern = api.RestrictedNamePattern
|
||||
)
|
||||
|
||||
// CheckpointCreate checkpoints the process running in a container with CRIU
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"github.com/docker/docker/pkg/pools"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
// Seconds to wait after sending TERM before trying KILL
|
||||
|
@ -94,7 +93,7 @@ func (d *Daemon) getActiveContainer(name string) (*container.Container, error) {
|
|||
|
||||
// ContainerExecCreate sets up an exec in a running container.
|
||||
func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (string, error) {
|
||||
container, err := d.getActiveContainer(name)
|
||||
cntr, err := d.getActiveContainer(name)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
@ -115,7 +114,7 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
|
|||
execConfig.OpenStdin = config.AttachStdin
|
||||
execConfig.OpenStdout = config.AttachStdout
|
||||
execConfig.OpenStderr = config.AttachStderr
|
||||
execConfig.ContainerID = container.ID
|
||||
execConfig.ContainerID = cntr.ID
|
||||
execConfig.DetachKeys = keys
|
||||
execConfig.Entrypoint = entrypoint
|
||||
execConfig.Args = args
|
||||
|
@ -123,18 +122,18 @@ func (d *Daemon) ContainerExecCreate(name string, config *types.ExecConfig) (str
|
|||
execConfig.Privileged = config.Privileged
|
||||
execConfig.User = config.User
|
||||
|
||||
linkedEnv, err := d.setupLinkedContainers(container)
|
||||
linkedEnv, err := d.setupLinkedContainers(cntr)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
execConfig.Env = utils.ReplaceOrAppendEnvValues(container.CreateDaemonEnvironment(config.Tty, linkedEnv), config.Env)
|
||||
execConfig.Env = container.ReplaceOrAppendEnvValues(cntr.CreateDaemonEnvironment(config.Tty, linkedEnv), config.Env)
|
||||
if len(execConfig.User) == 0 {
|
||||
execConfig.User = container.Config.User
|
||||
execConfig.User = cntr.Config.User
|
||||
}
|
||||
|
||||
d.registerExecCommand(container, execConfig)
|
||||
d.registerExecCommand(cntr, execConfig)
|
||||
|
||||
d.LogContainerEvent(container, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " "))
|
||||
d.LogContainerEvent(cntr, "exec_create: "+execConfig.Entrypoint+" "+strings.Join(execConfig.Args, " "))
|
||||
|
||||
return execConfig.ID, nil
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/cli/debug"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/pkg/fileutils"
|
||||
|
@ -19,7 +20,6 @@ import (
|
|||
"github.com/docker/docker/pkg/sysinfo"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/volume/drivers"
|
||||
"github.com/docker/go-connections/sockets"
|
||||
)
|
||||
|
@ -102,7 +102,7 @@ func (daemon *Daemon) SystemInfo() (*types.Info, error) {
|
|||
IPv4Forwarding: !sysInfo.IPv4ForwardingDisabled,
|
||||
BridgeNfIptables: !sysInfo.BridgeNFCallIPTablesDisabled,
|
||||
BridgeNfIP6tables: !sysInfo.BridgeNFCallIP6TablesDisabled,
|
||||
Debug: utils.IsDebugEnabled(),
|
||||
Debug: debug.IsEnabled(),
|
||||
NFd: fileutils.GetTotalUsedFds(),
|
||||
NGoroutines: runtime.NumGoroutine(),
|
||||
SystemTime: time.Now().Format(time.RFC3339Nano),
|
||||
|
|
|
@ -4,7 +4,7 @@ import (
|
|||
"bytes"
|
||||
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
)
|
||||
|
||||
// DefaultTemplate defines the defaults template logger should use.
|
||||
|
|
|
@ -5,16 +5,16 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/pkg/namesgenerator"
|
||||
"github.com/docker/docker/pkg/registrar"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/utils"
|
||||
)
|
||||
|
||||
var (
|
||||
validContainerNameChars = utils.RestrictedNameChars
|
||||
validContainerNamePattern = utils.RestrictedNamePattern
|
||||
validContainerNameChars = api.RestrictedNameChars
|
||||
validContainerNamePattern = api.RestrictedNamePattern
|
||||
)
|
||||
|
||||
func (daemon *Daemon) registerName(container *container.Container) error {
|
||||
|
|
|
@ -1,19 +1,23 @@
|
|||
package distribution
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"net/url"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api/types"
|
||||
registrytypes "github.com/docker/docker/api/types/registry"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/reference"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/docker/docker/utils"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
|
@ -38,7 +42,7 @@ func (h *tokenPassThruHandler) ServeHTTP(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
func testTokenPassThru(t *testing.T, ts *httptest.Server) {
|
||||
tmp, err := utils.TestDirectory("")
|
||||
tmp, err := testDirectory("")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
@ -134,3 +138,36 @@ func TestTokenPassThruDifferentHost(t *testing.T) {
|
|||
t.Fatal("Redirect should not forward Authorization header to another host")
|
||||
}
|
||||
}
|
||||
|
||||
// TestDirectory creates a new temporary directory and returns its path.
|
||||
// The contents of directory at path `templateDir` is copied into the
|
||||
// new directory.
|
||||
func testDirectory(templateDir string) (dir string, err error) {
|
||||
testID := stringid.GenerateNonCryptoID()[:4]
|
||||
prefix := fmt.Sprintf("docker-test%s-%s-", testID, getCallerName(2))
|
||||
if prefix == "" {
|
||||
prefix = "docker-test-"
|
||||
}
|
||||
dir, err = ioutil.TempDir("", prefix)
|
||||
if err = os.Remove(dir); err != nil {
|
||||
return
|
||||
}
|
||||
if templateDir != "" {
|
||||
if err = archive.CopyWithTar(templateDir, dir); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// getCallerName introspects the call stack and returns the name of the
|
||||
// function `depth` levels down in the stack.
|
||||
func getCallerName(depth int) string {
|
||||
// Use the caller function name as a prefix.
|
||||
// This helps trace temp directories back to their test.
|
||||
pc, _, _, _ := runtime.Caller(depth + 1)
|
||||
callerLongName := runtime.FuncForPC(pc).Name()
|
||||
parts := strings.Split(callerLongName, ".")
|
||||
callerShortName := parts[len(parts)-1]
|
||||
return callerShortName
|
||||
}
|
||||
|
|
|
@ -21,8 +21,7 @@ import (
|
|||
"github.com/Sirupsen/logrus"
|
||||
containerd "github.com/docker/containerd/api/grpc/types"
|
||||
"github.com/docker/docker/pkg/locker"
|
||||
sysinfo "github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/golang/protobuf/ptypes"
|
||||
"github.com/golang/protobuf/ptypes/timestamp"
|
||||
"golang.org/x/net/context"
|
||||
|
@ -81,7 +80,7 @@ func New(stateDir string, options ...RemoteOption) (_ Remote, err error) {
|
|||
}
|
||||
}
|
||||
|
||||
if err := sysinfo.MkdirAll(stateDir, 0700); err != nil {
|
||||
if err := system.MkdirAll(stateDir, 0700); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
|
@ -164,8 +163,8 @@ func (r *remote) handleConnectionChange() {
|
|||
transientFailureCount++
|
||||
if transientFailureCount >= maxConnectionRetryCount {
|
||||
transientFailureCount = 0
|
||||
if utils.IsProcessAlive(r.daemonPid) {
|
||||
utils.KillProcess(r.daemonPid)
|
||||
if system.IsProcessAlive(r.daemonPid) {
|
||||
system.KillProcess(r.daemonPid)
|
||||
}
|
||||
<-r.daemonWaitCh
|
||||
if err := r.runContainerdDaemon(); err != nil { //FIXME: Handle error
|
||||
|
@ -188,13 +187,13 @@ func (r *remote) Cleanup() {
|
|||
|
||||
// Wait up to 15secs for it to stop
|
||||
for i := time.Duration(0); i < containerdShutdownTimeout; i += time.Second {
|
||||
if !utils.IsProcessAlive(r.daemonPid) {
|
||||
if !system.IsProcessAlive(r.daemonPid) {
|
||||
break
|
||||
}
|
||||
time.Sleep(time.Second)
|
||||
}
|
||||
|
||||
if utils.IsProcessAlive(r.daemonPid) {
|
||||
if system.IsProcessAlive(r.daemonPid) {
|
||||
logrus.Warnf("libcontainerd: containerd (%d) didn't stop within 15 secs, killing it\n", r.daemonPid)
|
||||
syscall.Kill(r.daemonPid, syscall.SIGKILL)
|
||||
}
|
||||
|
@ -354,7 +353,7 @@ func (r *remote) runContainerdDaemon() error {
|
|||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if utils.IsProcessAlive(int(pid)) {
|
||||
if system.IsProcessAlive(int(pid)) {
|
||||
logrus.Infof("libcontainerd: previous instance of containerd still alive (%d)", pid)
|
||||
r.daemonPid = int(pid)
|
||||
return nil
|
||||
|
@ -417,11 +416,11 @@ func (r *remote) runContainerdDaemon() error {
|
|||
}
|
||||
logrus.Infof("libcontainerd: new containerd process, pid: %d", cmd.Process.Pid)
|
||||
if err := setOOMScore(cmd.Process.Pid, r.oomScore); err != nil {
|
||||
utils.KillProcess(cmd.Process.Pid)
|
||||
system.KillProcess(cmd.Process.Pid)
|
||||
return err
|
||||
}
|
||||
if _, err := f.WriteString(fmt.Sprintf("%d", cmd.Process.Pid)); err != nil {
|
||||
utils.KillProcess(cmd.Process.Pid)
|
||||
system.KillProcess(cmd.Process.Pid)
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
// +build linux freebsd solaris
|
||||
|
||||
package utils
|
||||
package system
|
||||
|
||||
import (
|
||||
"syscall"
|
|
@ -1,4 +1,4 @@
|
|||
package utils
|
||||
package system
|
||||
|
||||
// IsProcessAlive returns true if process with a given pid is running.
|
||||
func IsProcessAlive(pid int) bool {
|
|
@ -1,10 +1,9 @@
|
|||
package tempfile
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
|
||||
"github.com/docker/docker/pkg/testutil/assert"
|
||||
)
|
||||
|
||||
// TempFile is a temporary file that can be used with unit tests. TempFile
|
||||
|
|
|
@ -11,7 +11,7 @@ import (
|
|||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/aaparser"
|
||||
"github.com/docker/docker/utils/templates"
|
||||
"github.com/docker/docker/pkg/templates"
|
||||
)
|
||||
|
||||
var (
|
||||
|
|
|
@ -1,87 +0,0 @@
|
|||
package utils
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"runtime"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
)
|
||||
|
||||
var globalTestID string
|
||||
|
||||
// TestDirectory creates a new temporary directory and returns its path.
|
||||
// The contents of directory at path `templateDir` is copied into the
|
||||
// new directory.
|
||||
func TestDirectory(templateDir string) (dir string, err error) {
|
||||
if globalTestID == "" {
|
||||
globalTestID = stringid.GenerateNonCryptoID()[:4]
|
||||
}
|
||||
prefix := fmt.Sprintf("docker-test%s-%s-", globalTestID, GetCallerName(2))
|
||||
if prefix == "" {
|
||||
prefix = "docker-test-"
|
||||
}
|
||||
dir, err = ioutil.TempDir("", prefix)
|
||||
if err = os.Remove(dir); err != nil {
|
||||
return
|
||||
}
|
||||
if templateDir != "" {
|
||||
if err = archive.CopyWithTar(templateDir, dir); err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// GetCallerName introspects the call stack and returns the name of the
|
||||
// function `depth` levels down in the stack.
|
||||
func GetCallerName(depth int) string {
|
||||
// Use the caller function name as a prefix.
|
||||
// This helps trace temp directories back to their test.
|
||||
pc, _, _, _ := runtime.Caller(depth + 1)
|
||||
callerLongName := runtime.FuncForPC(pc).Name()
|
||||
parts := strings.Split(callerLongName, ".")
|
||||
callerShortName := parts[len(parts)-1]
|
||||
return callerShortName
|
||||
}
|
||||
|
||||
// ReplaceOrAppendEnvValues returns the defaults with the overrides either
|
||||
// replaced by env key or appended to the list
|
||||
func ReplaceOrAppendEnvValues(defaults, overrides []string) []string {
|
||||
cache := make(map[string]int, len(defaults))
|
||||
for i, e := range defaults {
|
||||
parts := strings.SplitN(e, "=", 2)
|
||||
cache[parts[0]] = i
|
||||
}
|
||||
|
||||
for _, value := range overrides {
|
||||
// Values w/o = means they want this env to be removed/unset.
|
||||
if !strings.Contains(value, "=") {
|
||||
if i, exists := cache[value]; exists {
|
||||
defaults[i] = "" // Used to indicate it should be removed
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
// Just do a normal set/update
|
||||
parts := strings.SplitN(value, "=", 2)
|
||||
if i, exists := cache[parts[0]]; exists {
|
||||
defaults[i] = value
|
||||
} else {
|
||||
defaults = append(defaults, value)
|
||||
}
|
||||
}
|
||||
|
||||
// Now remove all entries that we want to "unset"
|
||||
for i := 0; i < len(defaults); i++ {
|
||||
if defaults[i] == "" {
|
||||
defaults = append(defaults[:i], defaults[i+1:]...)
|
||||
i--
|
||||
}
|
||||
}
|
||||
|
||||
return defaults
|
||||
}
|
|
@ -16,9 +16,9 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
|
||||
"github.com/Sirupsen/logrus"
|
||||
"github.com/docker/docker/api"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/utils"
|
||||
"github.com/docker/docker/volume"
|
||||
)
|
||||
|
||||
|
@ -36,7 +36,7 @@ var (
|
|||
// volumeNameRegex ensures the name assigned for the volume is valid.
|
||||
// This name is used to create the bind directory, so we need to avoid characters that
|
||||
// would make the path to escape the root directory.
|
||||
volumeNameRegex = utils.RestrictedNamePattern
|
||||
volumeNameRegex = api.RestrictedNamePattern
|
||||
)
|
||||
|
||||
type validationError struct {
|
||||
|
@ -269,7 +269,7 @@ func (r *Root) validateName(name string) error {
|
|||
return validationError{fmt.Errorf("volume name is too short, names should be at least two alphanumeric characters")}
|
||||
}
|
||||
if !volumeNameRegex.MatchString(name) {
|
||||
return validationError{fmt.Errorf("%q includes invalid characters for a local volume name, only %q are allowed. If you intented to pass a host directory, use absolute path", name, utils.RestrictedNameChars)}
|
||||
return validationError{fmt.Errorf("%q includes invalid characters for a local volume name, only %q are allowed. If you intented to pass a host directory, use absolute path", name, api.RestrictedNameChars)}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue