Merge component 'engine' from git@github.com:moby/moby master
This commit is contained in:
@ -27,6 +27,7 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates \
|
||||
e2fsprogs \
|
||||
iptables \
|
||||
pkg-config \
|
||||
procps \
|
||||
xfsprogs \
|
||||
xz-utils \
|
||||
|
||||
@ -4,9 +4,9 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/docker/api/errdefs"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/sirupsen/logrus"
|
||||
"google.golang.org/grpc"
|
||||
@ -35,7 +35,7 @@ func GetHTTPErrorStatusCode(err error) int {
|
||||
statusCode = http.StatusNotFound
|
||||
case errdefs.IsInvalidParameter(err):
|
||||
statusCode = http.StatusBadRequest
|
||||
case errdefs.IsConflict(err):
|
||||
case errdefs.IsConflict(err) || errdefs.IsAlreadyExists(err):
|
||||
statusCode = http.StatusConflict
|
||||
case errdefs.IsUnauthorized(err):
|
||||
statusCode = http.StatusUnauthorized
|
||||
@ -47,7 +47,7 @@ func GetHTTPErrorStatusCode(err error) int {
|
||||
statusCode = http.StatusNotModified
|
||||
case errdefs.IsNotImplemented(err):
|
||||
statusCode = http.StatusNotImplemented
|
||||
case errdefs.IsSystem(err) || errdefs.IsUnknown(err):
|
||||
case errdefs.IsSystem(err) || errdefs.IsUnknown(err) || errdefs.IsDataLoss(err) || errdefs.IsDeadline(err) || errdefs.IsCancelled(err):
|
||||
statusCode = http.StatusInternalServerError
|
||||
default:
|
||||
statusCode = statusCodeFromGRPCError(err)
|
||||
|
||||
@ -6,13 +6,16 @@ import (
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type contextKey string
|
||||
|
||||
// APIVersionKey is the client's requested API version.
|
||||
const APIVersionKey = "api-version"
|
||||
const APIVersionKey contextKey = "api-version"
|
||||
|
||||
// APIFunc is an adapter to allow the use of ordinary functions as Docker API endpoints.
|
||||
// Any function that has the appropriate signature can be registered as an API endpoint (e.g. getVersion).
|
||||
@ -43,20 +46,6 @@ func CloseStreams(streams ...interface{}) {
|
||||
}
|
||||
}
|
||||
|
||||
type validationError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e validationError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e validationError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
func (e validationError) InvalidParameter() {}
|
||||
|
||||
// CheckForJSON makes sure that the request's Content-Type is application/json.
|
||||
func CheckForJSON(r *http.Request) error {
|
||||
ct := r.Header.Get("Content-Type")
|
||||
@ -72,7 +61,7 @@ func CheckForJSON(r *http.Request) error {
|
||||
if matchesContentType(ct, "application/json") {
|
||||
return nil
|
||||
}
|
||||
return validationError{errors.Errorf("Content-Type specified (%s) must be 'application/json'", ct)}
|
||||
return errdefs.InvalidParameter(errors.Errorf("Content-Type specified (%s) must be 'application/json'", ct))
|
||||
}
|
||||
|
||||
// ParseForm ensures the request form is parsed even with invalid content types.
|
||||
@ -82,7 +71,7 @@ func ParseForm(r *http.Request) error {
|
||||
return nil
|
||||
}
|
||||
if err := r.ParseForm(); err != nil && !strings.HasPrefix(err.Error(), "mime:") {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"net/http"
|
||||
"runtime"
|
||||
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -57,8 +58,7 @@ func (v VersionMiddleware) WrapHandler(handler func(ctx context.Context, w http.
|
||||
if versions.GreaterThan(apiVersion, v.defaultVersion) {
|
||||
return versionUnsupportedError{version: apiVersion, maxVersion: v.defaultVersion}
|
||||
}
|
||||
// nolint: golint
|
||||
ctx = context.WithValue(ctx, "api-version", apiVersion)
|
||||
ctx = context.WithValue(ctx, httputils.APIVersionKey, apiVersion)
|
||||
return handler(ctx, w, r, vars)
|
||||
}
|
||||
|
||||
|
||||
@ -18,6 +18,7 @@ import (
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
"github.com/docker/docker/pkg/streamformatter"
|
||||
@ -83,7 +84,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
|
||||
}
|
||||
p := system.ParsePlatform(apiPlatform)
|
||||
if err := system.ValidatePlatform(p); err != nil {
|
||||
return nil, validationError{fmt.Errorf("invalid platform: %s", err)}
|
||||
return nil, errdefs.InvalidParameter(errors.Errorf("invalid platform: %s", err))
|
||||
}
|
||||
options.Platform = p.OS
|
||||
}
|
||||
@ -104,14 +105,14 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
|
||||
}
|
||||
|
||||
if runtime.GOOS != "windows" && options.SecurityOpt != nil {
|
||||
return nil, validationError{fmt.Errorf("The daemon on this platform does not support setting security options on build")}
|
||||
return nil, errdefs.InvalidParameter(errors.New("The daemon on this platform does not support setting security options on build"))
|
||||
}
|
||||
|
||||
var buildUlimits = []*units.Ulimit{}
|
||||
ulimitsJSON := r.FormValue("ulimits")
|
||||
if ulimitsJSON != "" {
|
||||
if err := json.Unmarshal([]byte(ulimitsJSON), &buildUlimits); err != nil {
|
||||
return nil, errors.Wrap(validationError{err}, "error reading ulimit settings")
|
||||
return nil, errors.Wrap(errdefs.InvalidParameter(err), "error reading ulimit settings")
|
||||
}
|
||||
options.Ulimits = buildUlimits
|
||||
}
|
||||
@ -132,7 +133,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
|
||||
if buildArgsJSON != "" {
|
||||
var buildArgs = map[string]*string{}
|
||||
if err := json.Unmarshal([]byte(buildArgsJSON), &buildArgs); err != nil {
|
||||
return nil, errors.Wrap(validationError{err}, "error reading build args")
|
||||
return nil, errors.Wrap(errdefs.InvalidParameter(err), "error reading build args")
|
||||
}
|
||||
options.BuildArgs = buildArgs
|
||||
}
|
||||
@ -141,7 +142,7 @@ func newImageBuildOptions(ctx context.Context, r *http.Request) (*types.ImageBui
|
||||
if labelsJSON != "" {
|
||||
var labels = map[string]string{}
|
||||
if err := json.Unmarshal([]byte(labelsJSON), &labels); err != nil {
|
||||
return nil, errors.Wrap(validationError{err}, "error reading labels")
|
||||
return nil, errors.Wrap(errdefs.InvalidParameter(err), "error reading labels")
|
||||
}
|
||||
options.Labels = labels
|
||||
}
|
||||
@ -167,16 +168,6 @@ func (br *buildRouter) postPrune(ctx context.Context, w http.ResponseWriter, r *
|
||||
return httputils.WriteJSON(w, http.StatusOK, report)
|
||||
}
|
||||
|
||||
type validationError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e validationError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e validationError) InvalidParameter() {}
|
||||
|
||||
func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
var (
|
||||
notVerboseBuffer = bytes.NewBuffer(nil)
|
||||
@ -210,7 +201,7 @@ func (br *buildRouter) postBuild(ctx context.Context, w http.ResponseWriter, r *
|
||||
buildOptions.AuthConfigs = getAuthConfigs(r.Header)
|
||||
|
||||
if buildOptions.Squash && !br.daemon.HasExperimental() {
|
||||
return validationError{errors.New("squash is only supported with experimental mode")}
|
||||
return errdefs.InvalidParameter(errors.New("squash is only supported with experimental mode"))
|
||||
}
|
||||
|
||||
out := io.Writer(output)
|
||||
|
||||
@ -5,20 +5,6 @@ import (
|
||||
"github.com/docker/docker/api/server/router"
|
||||
)
|
||||
|
||||
type validationError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e validationError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e validationError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
func (e validationError) InvalidParameter() {}
|
||||
|
||||
// containerRouter is a router to talk with the container controller
|
||||
type containerRouter struct {
|
||||
backend Backend
|
||||
|
||||
@ -8,7 +8,6 @@ import (
|
||||
"strconv"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/docker/api/errdefs"
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
@ -16,6 +15,7 @@ import (
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
containerpkg "github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/pkg/errors"
|
||||
@ -88,7 +88,7 @@ func (s *containerRouter) getContainersLogs(ctx context.Context, w http.Response
|
||||
// with the appropriate status code.
|
||||
stdout, stderr := httputils.BoolValue(r, "stdout"), httputils.BoolValue(r, "stderr")
|
||||
if !(stdout || stderr) {
|
||||
return validationError{errors.New("Bad parameters: you must choose at least one stream")}
|
||||
return errdefs.InvalidParameter(errors.New("Bad parameters: you must choose at least one stream"))
|
||||
}
|
||||
|
||||
containerName := vars["name"]
|
||||
@ -203,7 +203,7 @@ func (s *containerRouter) postContainersKill(ctx context.Context, w http.Respons
|
||||
if sigStr := r.Form.Get("signal"); sigStr != "" {
|
||||
var err error
|
||||
if sig, err = signal.ParseSignal(sigStr); err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -468,11 +468,11 @@ func (s *containerRouter) postContainersResize(ctx context.Context, w http.Respo
|
||||
|
||||
height, err := strconv.Atoi(r.Form.Get("h"))
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
width, err := strconv.Atoi(r.Form.Get("w"))
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
return s.backend.ContainerResize(vars["name"], height, width)
|
||||
@ -490,7 +490,7 @@ func (s *containerRouter) postContainersAttach(ctx context.Context, w http.Respo
|
||||
|
||||
hijacker, ok := w.(http.Hijacker)
|
||||
if !ok {
|
||||
return validationError{errors.Errorf("error attaching to container %s, hijack connection missing", containerName)}
|
||||
return errdefs.InvalidParameter(errors.Errorf("error attaching to container %s, hijack connection missing", containerName))
|
||||
}
|
||||
|
||||
setupStreams := func() (io.ReadCloser, io.Writer, io.Writer, error) {
|
||||
@ -611,7 +611,7 @@ func (s *containerRouter) postContainersPrune(ctx context.Context, w http.Respon
|
||||
|
||||
pruneFilters, err := filters.FromJSON(r.Form.Get("filters"))
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
pruneReport, err := s.backend.ContainersPrune(ctx, pruneFilters)
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/docker/docker/api/server/httputils"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/net/context"
|
||||
@ -137,11 +138,11 @@ func (s *containerRouter) postContainerExecResize(ctx context.Context, w http.Re
|
||||
}
|
||||
height, err := strconv.Atoi(r.Form.Get("h"))
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
width, err := strconv.Atoi(r.Form.Get("w"))
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
return s.backend.ContainerExecResize(vars["name"], height, width)
|
||||
|
||||
@ -15,6 +15,7 @@ import (
|
||||
"github.com/docker/docker/api/types/backend"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/docker/docker/pkg/streamformatter"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
@ -144,20 +145,6 @@ func (s *imageRouter) postImagesCreate(ctx context.Context, w http.ResponseWrite
|
||||
return nil
|
||||
}
|
||||
|
||||
type validationError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e validationError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e validationError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
func (validationError) InvalidParameter() {}
|
||||
|
||||
func (s *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
metaHeaders := map[string][]string{}
|
||||
for k, v := range r.Header {
|
||||
@ -181,7 +168,7 @@ func (s *imageRouter) postImagesPush(ctx context.Context, w http.ResponseWriter,
|
||||
} else {
|
||||
// the old format is supported for compatibility if there was no authConfig header
|
||||
if err := json.NewDecoder(r.Body).Decode(authConfig); err != nil {
|
||||
return errors.Wrap(validationError{err}, "Bad parameters and missing X-Registry-Auth")
|
||||
return errors.Wrap(errdefs.InvalidParameter(err), "Bad parameters and missing X-Registry-Auth")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,7 +12,7 @@ import (
|
||||
// Backend is all the methods that need to be implemented
|
||||
// to provide network specific functionality.
|
||||
type Backend interface {
|
||||
FindUniqueNetwork(idName string) (libnetwork.Network, error)
|
||||
FindNetwork(idName string) (libnetwork.Network, error)
|
||||
GetNetworks() []libnetwork.Network
|
||||
CreateNetwork(nc types.NetworkCreateRequest) (*types.NetworkCreateResponse, error)
|
||||
ConnectContainerToNetwork(containerName, networkName string, endpointConfig *network.EndpointSettings) error
|
||||
|
||||
@ -2,7 +2,6 @@ package network
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
@ -14,6 +13,7 @@ import (
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/libnetwork"
|
||||
netconst "github.com/docker/libnetwork/datastore"
|
||||
"github.com/docker/libnetwork/networkdb"
|
||||
@ -101,22 +101,8 @@ func (e ambigousResultsError) Error() string {
|
||||
|
||||
func (ambigousResultsError) InvalidParameter() {}
|
||||
|
||||
type conflictError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e conflictError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e conflictError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
func (e conflictError) Conflict() {}
|
||||
|
||||
func nameConflict(name string) error {
|
||||
return conflictError{libnetwork.NetworkNameError(name)}
|
||||
return errdefs.Conflict(libnetwork.NetworkNameError(name))
|
||||
}
|
||||
|
||||
func (n *networkRouter) getNetwork(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
@ -290,7 +276,7 @@ func (n *networkRouter) postNetworkConnect(ctx context.Context, w http.ResponseW
|
||||
}
|
||||
|
||||
// Always make sure there is no ambiguity with respect to the network ID/name
|
||||
nw, err := n.backend.FindUniqueNetwork(vars["id"])
|
||||
nw, err := n.backend.FindNetwork(vars["id"])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -530,7 +516,7 @@ func (n *networkRouter) postNetworksPrune(ctx context.Context, w http.ResponseWr
|
||||
}
|
||||
|
||||
// findUniqueNetwork will search network across different scopes (both local and swarm).
|
||||
// NOTE: This findUniqueNetwork is different from FindUniqueNetwork in the daemon.
|
||||
// NOTE: This findUniqueNetwork is different from FindNetwork in the daemon.
|
||||
// In case multiple networks have duplicate names, return error.
|
||||
// First find based on full ID, return immediately once one is found.
|
||||
// If a network appears both in swarm and local, assume it is in local first
|
||||
@ -589,7 +575,7 @@ func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, e
|
||||
}
|
||||
}
|
||||
if len(listByFullName) > 1 {
|
||||
return types.NetworkResource{}, fmt.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName))
|
||||
return types.NetworkResource{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName)))
|
||||
}
|
||||
|
||||
// Find based on partial ID, returns true only if no duplicates
|
||||
@ -599,8 +585,8 @@ func (n *networkRouter) findUniqueNetwork(term string) (types.NetworkResource, e
|
||||
}
|
||||
}
|
||||
if len(listByPartialID) > 1 {
|
||||
return types.NetworkResource{}, fmt.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID))
|
||||
return types.NetworkResource{}, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID)))
|
||||
}
|
||||
|
||||
return types.NetworkResource{}, libnetwork.ErrNoSuchNetwork(term)
|
||||
return types.NetworkResource{}, errdefs.NotFound(libnetwork.ErrNoSuchNetwork(term))
|
||||
}
|
||||
|
||||
@ -3,27 +3,14 @@ package session
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/docker/errdefs"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
|
||||
type invalidRequest struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e invalidRequest) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e invalidRequest) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
func (e invalidRequest) InvalidParameter() {}
|
||||
|
||||
func (sr *sessionRouter) startSession(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
err := sr.backend.HandleHTTPRequest(ctx, w, r)
|
||||
if err != nil {
|
||||
return invalidRequest{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
types "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/api/types/versions"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/net/context"
|
||||
@ -57,20 +58,6 @@ func (sr *swarmRouter) inspectCluster(ctx context.Context, w http.ResponseWriter
|
||||
return httputils.WriteJSON(w, http.StatusOK, swarm)
|
||||
}
|
||||
|
||||
type invalidRequestError struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (e invalidRequestError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
func (e invalidRequestError) Cause() error {
|
||||
return e.err
|
||||
}
|
||||
|
||||
func (e invalidRequestError) InvalidParameter() {}
|
||||
|
||||
func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
var swarm types.Spec
|
||||
if err := json.NewDecoder(r.Body).Decode(&swarm); err != nil {
|
||||
@ -81,7 +68,7 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter,
|
||||
version, err := strconv.ParseUint(rawVersion, 10, 64)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("invalid swarm version '%s': %v", rawVersion, err)
|
||||
return invalidRequestError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
var flags types.UpdateFlags
|
||||
@ -90,7 +77,7 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter,
|
||||
rot, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("invalid value for rotateWorkerToken: %s", value)
|
||||
return invalidRequestError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
flags.RotateWorkerToken = rot
|
||||
@ -100,7 +87,7 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter,
|
||||
rot, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("invalid value for rotateManagerToken: %s", value)
|
||||
return invalidRequestError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
flags.RotateManagerToken = rot
|
||||
@ -109,7 +96,7 @@ func (sr *swarmRouter) updateCluster(ctx context.Context, w http.ResponseWriter,
|
||||
if value := r.URL.Query().Get("rotateManagerUnlockKey"); value != "" {
|
||||
rot, err := strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
return invalidRequestError{fmt.Errorf("invalid value for rotateManagerUnlockKey: %s", value)}
|
||||
return errdefs.InvalidParameter(fmt.Errorf("invalid value for rotateManagerUnlockKey: %s", value))
|
||||
}
|
||||
|
||||
flags.RotateManagerUnlockKey = rot
|
||||
@ -153,7 +140,7 @@ func (sr *swarmRouter) getServices(ctx context.Context, w http.ResponseWriter, r
|
||||
}
|
||||
filter, err := filters.FromJSON(r.Form.Get("filters"))
|
||||
if err != nil {
|
||||
return invalidRequestError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
services, err := sr.backend.GetServices(basictypes.ServiceListOptions{Filters: filter})
|
||||
@ -172,7 +159,7 @@ func (sr *swarmRouter) getService(ctx context.Context, w http.ResponseWriter, r
|
||||
insertDefaults, err = strconv.ParseBool(value)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("invalid value for insertDefaults: %s", value)
|
||||
return errors.Wrapf(invalidRequestError{err}, "invalid value for insertDefaults: %s", value)
|
||||
return errors.Wrapf(errdefs.InvalidParameter(err), "invalid value for insertDefaults: %s", value)
|
||||
}
|
||||
}
|
||||
|
||||
@ -218,7 +205,7 @@ func (sr *swarmRouter) updateService(ctx context.Context, w http.ResponseWriter,
|
||||
version, err := strconv.ParseUint(rawVersion, 10, 64)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("invalid service version '%s': %v", rawVersion, err)
|
||||
return invalidRequestError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
var flags basictypes.ServiceUpdateOptions
|
||||
@ -311,7 +298,7 @@ func (sr *swarmRouter) updateNode(ctx context.Context, w http.ResponseWriter, r
|
||||
version, err := strconv.ParseUint(rawVersion, 10, 64)
|
||||
if err != nil {
|
||||
err := fmt.Errorf("invalid node version '%s': %v", rawVersion, err)
|
||||
return invalidRequestError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
if err := sr.backend.UpdateNode(vars["id"], version, node); err != nil {
|
||||
@ -417,13 +404,13 @@ func (sr *swarmRouter) getSecret(ctx context.Context, w http.ResponseWriter, r *
|
||||
func (sr *swarmRouter) updateSecret(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
var secret types.SecretSpec
|
||||
if err := json.NewDecoder(r.Body).Decode(&secret); err != nil {
|
||||
return invalidRequestError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
rawVersion := r.URL.Query().Get("version")
|
||||
version, err := strconv.ParseUint(rawVersion, 10, 64)
|
||||
if err != nil {
|
||||
return invalidRequestError{fmt.Errorf("invalid secret version")}
|
||||
return errdefs.InvalidParameter(fmt.Errorf("invalid secret version"))
|
||||
}
|
||||
|
||||
id := vars["id"]
|
||||
@ -484,13 +471,13 @@ func (sr *swarmRouter) getConfig(ctx context.Context, w http.ResponseWriter, r *
|
||||
func (sr *swarmRouter) updateConfig(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
|
||||
var config types.ConfigSpec
|
||||
if err := json.NewDecoder(r.Body).Decode(&config); err != nil {
|
||||
return invalidRequestError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
rawVersion := r.URL.Query().Get("version")
|
||||
version, err := strconv.ParseUint(rawVersion, 10, 64)
|
||||
if err != nil {
|
||||
return invalidRequestError{fmt.Errorf("invalid config version")}
|
||||
return errdefs.InvalidParameter(fmt.Errorf("invalid config version"))
|
||||
}
|
||||
|
||||
id := vars["id"]
|
||||
|
||||
@ -17,6 +17,7 @@ import (
|
||||
"github.com/docker/docker/builder/dockerfile/parser"
|
||||
"github.com/docker/docker/builder/fscache"
|
||||
"github.com/docker/docker/builder/remotecontext"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/streamformatter"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
@ -225,7 +226,7 @@ func (b *Builder) build(source builder.Source, dockerfile *parser.Result) (*buil
|
||||
if instructions.IsUnknownInstruction(err) {
|
||||
buildsFailed.WithValues(metricsUnknownInstructionError).Inc()
|
||||
}
|
||||
return nil, validationError{err}
|
||||
return nil, errdefs.InvalidParameter(err)
|
||||
}
|
||||
if b.options.Target != "" {
|
||||
targetIx, found := instructions.HasStage(stages, b.options.Target)
|
||||
@ -363,7 +364,7 @@ func BuildFromConfig(config *container.Config, changes []string) (*container.Con
|
||||
|
||||
dockerfile, err := parser.Parse(bytes.NewBufferString(strings.Join(changes, "\n")))
|
||||
if err != nil {
|
||||
return nil, validationError{err}
|
||||
return nil, errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
os := runtime.GOOS
|
||||
@ -378,7 +379,7 @@ func BuildFromConfig(config *container.Config, changes []string) (*container.Con
|
||||
// ensure that the commands are valid
|
||||
for _, n := range dockerfile.AST.Children {
|
||||
if !validCommitCommands[n.Value] {
|
||||
return nil, validationError{errors.Errorf("%s is not a valid change command", n.Value)}
|
||||
return nil, errdefs.InvalidParameter(errors.Errorf("%s is not a valid change command", n.Value))
|
||||
}
|
||||
}
|
||||
|
||||
@ -390,7 +391,7 @@ func BuildFromConfig(config *container.Config, changes []string) (*container.Con
|
||||
for _, n := range dockerfile.AST.Children {
|
||||
cmd, err := instructions.ParseCommand(n)
|
||||
if err != nil {
|
||||
return nil, validationError{err}
|
||||
return nil, errdefs.InvalidParameter(err)
|
||||
}
|
||||
commands = append(commands, cmd)
|
||||
}
|
||||
@ -402,7 +403,7 @@ func BuildFromConfig(config *container.Config, changes []string) (*container.Con
|
||||
for _, cmd := range commands {
|
||||
err := dispatch(dispatchRequest, cmd)
|
||||
if err != nil {
|
||||
return nil, validationError{err}
|
||||
return nil, errdefs.InvalidParameter(err)
|
||||
}
|
||||
dispatchRequest.state.updateRunConfig()
|
||||
}
|
||||
|
||||
@ -20,6 +20,7 @@ import (
|
||||
"github.com/docker/docker/builder"
|
||||
"github.com/docker/docker/builder/dockerfile/instructions"
|
||||
"github.com/docker/docker/builder/dockerfile/parser"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/pkg/jsonmessage"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
@ -510,7 +511,7 @@ func dispatchStopSignal(d dispatchRequest, c *instructions.StopSignalCommand) er
|
||||
|
||||
_, err := signal.ParseSignal(c.Signal)
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
d.state.runConfig.StopSignal = c.Signal
|
||||
return d.builder.commit(d.state, fmt.Sprintf("STOPSIGNAL %v", c.Signal))
|
||||
|
||||
@ -1,15 +0,0 @@
|
||||
package dockerfile
|
||||
|
||||
type validationError struct {
|
||||
err error
|
||||
}
|
||||
|
||||
func (e validationError) Error() string {
|
||||
return e.err.Error()
|
||||
}
|
||||
|
||||
func (e validationError) InvalidParameter() {}
|
||||
|
||||
func (e validationError) Cause() error {
|
||||
return e.err
|
||||
}
|
||||
@ -27,6 +27,7 @@ import (
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/builder"
|
||||
"github.com/docker/docker/builder/dockerfile/instructions"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/runconfig/opts"
|
||||
"github.com/pkg/errors"
|
||||
@ -37,7 +38,7 @@ func dispatch(d dispatchRequest, cmd instructions.Command) (err error) {
|
||||
optionsOS := system.ParsePlatform(d.builder.options.Platform).OS
|
||||
err := c.CheckPlatform(optionsOS)
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
}
|
||||
runConfigEnv := d.state.runConfig.Env
|
||||
@ -48,7 +49,7 @@ func dispatch(d dispatchRequest, cmd instructions.Command) (err error) {
|
||||
return d.shlex.ProcessWord(word, envs)
|
||||
})
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -485,10 +485,7 @@ func (s *fsCacheStore) delete(id string) error {
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := s.fs.Remove(src.BackendID); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return s.fs.Remove(src.BackendID)
|
||||
}
|
||||
|
||||
type sourceMeta struct {
|
||||
|
||||
@ -1,75 +0,0 @@
|
||||
package remotecontext
|
||||
|
||||
type notFoundError string
|
||||
|
||||
func (e notFoundError) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (notFoundError) NotFound() {}
|
||||
|
||||
type requestError string
|
||||
|
||||
func (e requestError) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (e requestError) InvalidParameter() {}
|
||||
|
||||
type unauthorizedError string
|
||||
|
||||
func (e unauthorizedError) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (unauthorizedError) Unauthorized() {}
|
||||
|
||||
type forbiddenError string
|
||||
|
||||
func (e forbiddenError) Error() string {
|
||||
return string(e)
|
||||
}
|
||||
|
||||
func (forbiddenError) Forbidden() {}
|
||||
|
||||
type dnsError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e dnsError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e dnsError) NotFound() {}
|
||||
|
||||
func (e dnsError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type systemError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e systemError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e systemError) SystemError() {}
|
||||
|
||||
func (e systemError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type unknownError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e unknownError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (unknownError) Unknown() {}
|
||||
|
||||
func (e unknownError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"net/url"
|
||||
"regexp"
|
||||
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
@ -26,7 +27,7 @@ var mimeRe = regexp.MustCompile(acceptableRemoteMIME)
|
||||
func downloadRemote(remoteURL string) (string, io.ReadCloser, error) {
|
||||
response, err := GetWithStatusError(remoteURL)
|
||||
if err != nil {
|
||||
return "", nil, fmt.Errorf("error downloading remote context %s: %v", remoteURL, err)
|
||||
return "", nil, errors.Wrapf(err, "error downloading remote context %s", remoteURL)
|
||||
}
|
||||
|
||||
contentType, contextReader, err := inspectResponse(
|
||||
@ -35,7 +36,7 @@ func downloadRemote(remoteURL string) (string, io.ReadCloser, error) {
|
||||
response.ContentLength)
|
||||
if err != nil {
|
||||
response.Body.Close()
|
||||
return "", nil, fmt.Errorf("error detecting content type for remote %s: %v", remoteURL, err)
|
||||
return "", nil, errors.Wrapf(err, "error detecting content type for remote %s", remoteURL)
|
||||
}
|
||||
|
||||
return contentType, ioutils.NewReadCloserWrapper(contextReader, response.Body.Close), nil
|
||||
@ -47,10 +48,10 @@ func GetWithStatusError(address string) (resp *http.Response, err error) {
|
||||
if resp, err = http.Get(address); err != nil {
|
||||
if uerr, ok := err.(*url.Error); ok {
|
||||
if derr, ok := uerr.Err.(*net.DNSError); ok && !derr.IsTimeout {
|
||||
return nil, dnsError{err}
|
||||
return nil, errdefs.NotFound(err)
|
||||
}
|
||||
}
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
if resp.StatusCode < 400 {
|
||||
return resp, nil
|
||||
@ -59,21 +60,21 @@ func GetWithStatusError(address string) (resp *http.Response, err error) {
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
resp.Body.Close()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(systemError{err}, msg+": error reading body")
|
||||
return nil, errdefs.System(errors.New(msg + ": error reading body"))
|
||||
}
|
||||
|
||||
msg += ": " + string(bytes.TrimSpace(body))
|
||||
switch resp.StatusCode {
|
||||
case http.StatusNotFound:
|
||||
return nil, notFoundError(msg)
|
||||
return nil, errdefs.NotFound(errors.New(msg))
|
||||
case http.StatusBadRequest:
|
||||
return nil, requestError(msg)
|
||||
return nil, errdefs.InvalidParameter(errors.New(msg))
|
||||
case http.StatusUnauthorized:
|
||||
return nil, unauthorizedError(msg)
|
||||
return nil, errdefs.Unauthorized(errors.New(msg))
|
||||
case http.StatusForbidden:
|
||||
return nil, forbiddenError(msg)
|
||||
return nil, errdefs.Forbidden(errors.New(msg))
|
||||
}
|
||||
return nil, unknownError{errors.New(msg)}
|
||||
return nil, errdefs.Unknown(errors.New(msg))
|
||||
}
|
||||
|
||||
// inspectResponse looks into the http response data at r to determine whether its
|
||||
|
||||
@ -14,9 +14,8 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
memdbContainersTable = "containers"
|
||||
memdbNamesTable = "names"
|
||||
|
||||
memdbContainersTable = "containers"
|
||||
memdbNamesTable = "names"
|
||||
memdbIDIndex = "id"
|
||||
memdbContainerIDIndex = "containerid"
|
||||
)
|
||||
@ -191,11 +190,7 @@ func (db *memDB) ReserveName(name, containerID string) error {
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := txn.Insert(memdbNamesTable, nameAssociation{name: name, containerID: containerID}); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return txn.Insert(memdbNamesTable, nameAssociation{name: name, containerID: containerID})
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/chrootarchive"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
@ -54,7 +55,7 @@ func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, err
|
||||
|
||||
// Make sure an online file-system operation is permitted.
|
||||
if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
|
||||
data, err := daemon.containerCopy(container, res)
|
||||
@ -65,7 +66,7 @@ func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, err
|
||||
if os.IsNotExist(err) {
|
||||
return nil, containerFileNotFound{res, name}
|
||||
}
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
|
||||
// ContainerStatPath stats the filesystem resource at the specified path in the
|
||||
@ -78,7 +79,7 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.C
|
||||
|
||||
// Make sure an online file-system operation is permitted.
|
||||
if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
|
||||
stat, err = daemon.containerStatPath(container, path)
|
||||
@ -89,7 +90,7 @@ func (daemon *Daemon) ContainerStatPath(name string, path string) (stat *types.C
|
||||
if os.IsNotExist(err) {
|
||||
return nil, containerFileNotFound{path, name}
|
||||
}
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
|
||||
// ContainerArchivePath creates an archive of the filesystem resource at the
|
||||
@ -103,7 +104,7 @@ func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io
|
||||
|
||||
// Make sure an online file-system operation is permitted.
|
||||
if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
|
||||
return nil, nil, systemError{err}
|
||||
return nil, nil, errdefs.System(err)
|
||||
}
|
||||
|
||||
content, stat, err = daemon.containerArchivePath(container, path)
|
||||
@ -114,7 +115,7 @@ func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io
|
||||
if os.IsNotExist(err) {
|
||||
return nil, nil, containerFileNotFound{path, name}
|
||||
}
|
||||
return nil, nil, systemError{err}
|
||||
return nil, nil, errdefs.System(err)
|
||||
}
|
||||
|
||||
// ContainerExtractToDir extracts the given archive to the specified location
|
||||
@ -131,7 +132,7 @@ func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOve
|
||||
|
||||
// Make sure an online file-system operation is permitted.
|
||||
if err := daemon.isOnlineFSOperationPermitted(container); err != nil {
|
||||
return systemError{err}
|
||||
return errdefs.System(err)
|
||||
}
|
||||
|
||||
err = daemon.containerExtractToDir(container, path, copyUIDGID, noOverwriteDirNonDir, content)
|
||||
@ -142,7 +143,7 @@ func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOve
|
||||
if os.IsNotExist(err) {
|
||||
return containerFileNotFound{path, name}
|
||||
}
|
||||
return systemError{err}
|
||||
return errdefs.System(err)
|
||||
}
|
||||
|
||||
// containerStatPath stats the filesystem resource at the specified path in this
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/container/stream"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/stdcopy"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
"github.com/pkg/errors"
|
||||
@ -22,7 +23,7 @@ func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerA
|
||||
if c.DetachKeys != "" {
|
||||
keys, err = term.ToBytes(c.DetachKeys)
|
||||
if err != nil {
|
||||
return validationError{errors.Errorf("Invalid detach keys (%s) provided", c.DetachKeys)}
|
||||
return errdefs.InvalidParameter(errors.Errorf("Invalid detach keys (%s) provided", c.DetachKeys))
|
||||
}
|
||||
}
|
||||
|
||||
@ -32,11 +33,11 @@ func (daemon *Daemon) ContainerAttach(prefixOrName string, c *backend.ContainerA
|
||||
}
|
||||
if container.IsPaused() {
|
||||
err := fmt.Errorf("container %s is paused, unpause the container before attach", prefixOrName)
|
||||
return stateConflictError{err}
|
||||
return errdefs.Conflict(err)
|
||||
}
|
||||
if container.IsRestarting() {
|
||||
err := fmt.Errorf("container %s is restarting, wait until the container is running", prefixOrName)
|
||||
return stateConflictError{err}
|
||||
return errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
cfg := stream.AttachConfig{
|
||||
|
||||
@ -6,9 +6,9 @@ import (
|
||||
"net/http"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/api/errdefs"
|
||||
enginetypes "github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/swarm/runtime"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/plugin"
|
||||
"github.com/docker/docker/plugin/v2"
|
||||
"github.com/docker/swarmkit/api"
|
||||
|
||||
@ -20,48 +20,6 @@ const (
|
||||
errSwarmNotManager notAvailableError = "This node is not a swarm manager. Worker nodes can't be used to view or modify cluster state. Please run this command on a manager node or promote the current node to a manager."
|
||||
)
|
||||
|
||||
type notFoundError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e notFoundError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e notFoundError) NotFound() {}
|
||||
|
||||
func (e notFoundError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type ambiguousResultsError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e ambiguousResultsError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e ambiguousResultsError) InvalidParameter() {}
|
||||
|
||||
func (e ambiguousResultsError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type convertError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e convertError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e convertError) InvalidParameter() {}
|
||||
|
||||
func (e convertError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type notAllowedError string
|
||||
|
||||
func (e notAllowedError) Error() string {
|
||||
@ -70,20 +28,6 @@ func (e notAllowedError) Error() string {
|
||||
|
||||
func (e notAllowedError) Forbidden() {}
|
||||
|
||||
type validationError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e validationError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e validationError) InvalidParameter() {}
|
||||
|
||||
func (e validationError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type notAvailableError string
|
||||
|
||||
func (e notAvailableError) Error() string {
|
||||
|
||||
@ -28,7 +28,7 @@ import (
|
||||
type Backend interface {
|
||||
CreateManagedNetwork(clustertypes.NetworkCreateRequest) error
|
||||
DeleteManagedNetwork(networkID string) error
|
||||
FindUniqueNetwork(idName string) (libnetwork.Network, error)
|
||||
FindNetwork(idName string) (libnetwork.Network, error)
|
||||
SetupIngress(clustertypes.NetworkCreateRequest, string) (<-chan struct{}, error)
|
||||
ReleaseIngress() (<-chan struct{}, error)
|
||||
PullImage(ctx context.Context, image, tag, platform string, metaHeaders map[string][]string, authConfig *types.AuthConfig, outStream io.Writer) error
|
||||
|
||||
@ -262,11 +262,7 @@ func (c *containerAdapter) create(ctx context.Context) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := c.backend.UpdateContainerServiceConfig(cr.ID, c.container.serviceConfig()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return c.backend.UpdateContainerServiceConfig(cr.ID, c.container.serviceConfig())
|
||||
}
|
||||
|
||||
// checkMounts ensures that the provided mounts won't have any host-specific
|
||||
|
||||
@ -507,7 +507,7 @@ func getEndpointConfig(na *api.NetworkAttachment, b executorpkg.Backend) *networ
|
||||
DriverOpts: na.DriverAttachmentOpts,
|
||||
}
|
||||
if v, ok := na.Network.Spec.Annotations.Labels["com.docker.swarm.predefined"]; ok && v == "true" {
|
||||
if ln, err := b.FindUniqueNetwork(na.Network.Spec.Annotations.Name); err == nil {
|
||||
if ln, err := b.FindNetwork(na.Network.Spec.Annotations.Name); err == nil {
|
||||
n.NetworkID = ln.ID()
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,6 +3,7 @@ package cluster
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/errdefs"
|
||||
swarmapi "github.com/docker/swarmkit/api"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/context"
|
||||
@ -48,11 +49,11 @@ func getNode(ctx context.Context, c swarmapi.ControlClient, input string) (*swar
|
||||
|
||||
if len(rl.Nodes) == 0 {
|
||||
err := fmt.Errorf("node %s not found", input)
|
||||
return nil, notFoundError{err}
|
||||
return nil, errdefs.NotFound(err)
|
||||
}
|
||||
|
||||
if l := len(rl.Nodes); l > 1 {
|
||||
return nil, ambiguousResultsError{fmt.Errorf("node %s is ambiguous (%d matches found)", input, l)}
|
||||
return nil, errdefs.InvalidParameter(fmt.Errorf("node %s is ambiguous (%d matches found)", input, l))
|
||||
}
|
||||
|
||||
return rl.Nodes[0], nil
|
||||
@ -84,11 +85,11 @@ func getService(ctx context.Context, c swarmapi.ControlClient, input string, ins
|
||||
|
||||
if len(rl.Services) == 0 {
|
||||
err := fmt.Errorf("service %s not found", input)
|
||||
return nil, notFoundError{err}
|
||||
return nil, errdefs.NotFound(err)
|
||||
}
|
||||
|
||||
if l := len(rl.Services); l > 1 {
|
||||
return nil, ambiguousResultsError{fmt.Errorf("service %s is ambiguous (%d matches found)", input, l)}
|
||||
return nil, errdefs.InvalidParameter(fmt.Errorf("service %s is ambiguous (%d matches found)", input, l))
|
||||
}
|
||||
|
||||
if !insertDefaults {
|
||||
@ -128,11 +129,11 @@ func getTask(ctx context.Context, c swarmapi.ControlClient, input string) (*swar
|
||||
|
||||
if len(rl.Tasks) == 0 {
|
||||
err := fmt.Errorf("task %s not found", input)
|
||||
return nil, notFoundError{err}
|
||||
return nil, errdefs.NotFound(err)
|
||||
}
|
||||
|
||||
if l := len(rl.Tasks); l > 1 {
|
||||
return nil, ambiguousResultsError{fmt.Errorf("task %s is ambiguous (%d matches found)", input, l)}
|
||||
return nil, errdefs.InvalidParameter(fmt.Errorf("task %s is ambiguous (%d matches found)", input, l))
|
||||
}
|
||||
|
||||
return rl.Tasks[0], nil
|
||||
@ -164,11 +165,11 @@ func getSecret(ctx context.Context, c swarmapi.ControlClient, input string) (*sw
|
||||
|
||||
if len(rl.Secrets) == 0 {
|
||||
err := fmt.Errorf("secret %s not found", input)
|
||||
return nil, notFoundError{err}
|
||||
return nil, errdefs.NotFound(err)
|
||||
}
|
||||
|
||||
if l := len(rl.Secrets); l > 1 {
|
||||
return nil, ambiguousResultsError{fmt.Errorf("secret %s is ambiguous (%d matches found)", input, l)}
|
||||
return nil, errdefs.InvalidParameter(fmt.Errorf("secret %s is ambiguous (%d matches found)", input, l))
|
||||
}
|
||||
|
||||
return rl.Secrets[0], nil
|
||||
@ -200,11 +201,11 @@ func getConfig(ctx context.Context, c swarmapi.ControlClient, input string) (*sw
|
||||
|
||||
if len(rl.Configs) == 0 {
|
||||
err := fmt.Errorf("config %s not found", input)
|
||||
return nil, notFoundError{err}
|
||||
return nil, errdefs.NotFound(err)
|
||||
}
|
||||
|
||||
if l := len(rl.Configs); l > 1 {
|
||||
return nil, ambiguousResultsError{fmt.Errorf("config %s is ambiguous (%d matches found)", input, l)}
|
||||
return nil, errdefs.InvalidParameter(fmt.Errorf("config %s is ambiguous (%d matches found)", input, l))
|
||||
}
|
||||
|
||||
return rl.Configs[0], nil
|
||||
@ -238,7 +239,7 @@ func getNetwork(ctx context.Context, c swarmapi.ControlClient, input string) (*s
|
||||
}
|
||||
|
||||
if l := len(rl.Networks); l > 1 {
|
||||
return nil, ambiguousResultsError{fmt.Errorf("network %s is ambiguous (%d matches found)", input, l)}
|
||||
return nil, errdefs.InvalidParameter(fmt.Errorf("network %s is ambiguous (%d matches found)", input, l))
|
||||
}
|
||||
|
||||
return rl.Networks[0], nil
|
||||
|
||||
@ -7,6 +7,7 @@ import (
|
||||
"github.com/docker/docker/api/types/network"
|
||||
types "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/daemon/cluster/convert"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/runconfig"
|
||||
swarmapi "github.com/docker/swarmkit/api"
|
||||
"github.com/pkg/errors"
|
||||
@ -292,13 +293,13 @@ func (c *Cluster) populateNetworkID(ctx context.Context, client swarmapi.Control
|
||||
for i, n := range networks {
|
||||
apiNetwork, err := getNetwork(ctx, client, n.Target)
|
||||
if err != nil {
|
||||
ln, _ := c.config.Backend.FindUniqueNetwork(n.Target)
|
||||
ln, _ := c.config.Backend.FindNetwork(n.Target)
|
||||
if ln != nil && runconfig.IsPreDefinedNetwork(ln.Name()) {
|
||||
// Need to retrieve the corresponding predefined swarm network
|
||||
// and use its id for the request.
|
||||
apiNetwork, err = getNetwork(ctx, client, ln.Name())
|
||||
if err != nil {
|
||||
return errors.Wrap(notFoundError{err}, "could not find the corresponding predefined swarm network")
|
||||
return errors.Wrap(errdefs.NotFound(err), "could not find the corresponding predefined swarm network")
|
||||
}
|
||||
goto setid
|
||||
}
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
apitypes "github.com/docker/docker/api/types"
|
||||
types "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/daemon/cluster/convert"
|
||||
"github.com/docker/docker/errdefs"
|
||||
swarmapi "github.com/docker/swarmkit/api"
|
||||
"golang.org/x/net/context"
|
||||
)
|
||||
@ -64,7 +65,7 @@ func (c *Cluster) UpdateNode(input string, version uint64, spec types.NodeSpec)
|
||||
return c.lockedManagerAction(func(ctx context.Context, state nodeState) error {
|
||||
nodeSpec, err := convert.NodeSpecToGRPC(spec)
|
||||
if err != nil {
|
||||
return convertError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
ctx, cancel := c.getRequestContext()
|
||||
|
||||
@ -16,6 +16,7 @@ import (
|
||||
types "github.com/docker/docker/api/types/swarm"
|
||||
timetypes "github.com/docker/docker/api/types/time"
|
||||
"github.com/docker/docker/daemon/cluster/convert"
|
||||
"github.com/docker/docker/errdefs"
|
||||
runconfigopts "github.com/docker/docker/runconfig/opts"
|
||||
swarmapi "github.com/docker/swarmkit/api"
|
||||
gogotypes "github.com/gogo/protobuf/types"
|
||||
@ -128,7 +129,7 @@ func (c *Cluster) CreateService(s types.ServiceSpec, encodedAuth string, queryRe
|
||||
|
||||
serviceSpec, err := convert.ServiceSpecToGRPC(s)
|
||||
if err != nil {
|
||||
return convertError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
resp = &apitypes.ServiceCreateResponse{}
|
||||
@ -232,7 +233,7 @@ func (c *Cluster) UpdateService(serviceIDOrName string, version uint64, spec typ
|
||||
|
||||
serviceSpec, err := convert.ServiceSpecToGRPC(spec)
|
||||
if err != nil {
|
||||
return convertError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
currentService, err := getService(ctx, state.controlClient, serviceIDOrName, false)
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
types "github.com/docker/docker/api/types/swarm"
|
||||
"github.com/docker/docker/daemon/cluster/convert"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
swarmapi "github.com/docker/swarmkit/api"
|
||||
@ -44,7 +45,7 @@ func (c *Cluster) Init(req types.InitRequest) (string, error) {
|
||||
}
|
||||
|
||||
if err := validateAndSanitizeInitRequest(&req); err != nil {
|
||||
return "", validationError{err}
|
||||
return "", errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
listenHost, listenPort, err := resolveListenAddr(req.ListenAddr)
|
||||
@ -140,7 +141,7 @@ func (c *Cluster) Join(req types.JoinRequest) error {
|
||||
c.mu.Unlock()
|
||||
|
||||
if err := validateAndSanitizeJoinRequest(&req); err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
listenHost, listenPort, err := resolveListenAddr(req.ListenAddr)
|
||||
@ -232,7 +233,7 @@ func (c *Cluster) Update(version uint64, spec types.Spec, flags types.UpdateFlag
|
||||
if spec.Annotations.Name == "" {
|
||||
spec.Annotations.Name = "default"
|
||||
} else if spec.Annotations.Name != "default" {
|
||||
return validationError{errors.New(`swarm spec must be named "default"`)}
|
||||
return errdefs.InvalidParameter(errors.New(`swarm spec must be named "default"`))
|
||||
}
|
||||
|
||||
// In update, client should provide the complete spec of the swarm, including
|
||||
@ -240,7 +241,7 @@ func (c *Cluster) Update(version uint64, spec types.Spec, flags types.UpdateFlag
|
||||
// will be used to swarmkit.
|
||||
clusterSpec, err := convert.SwarmSpecToGRPC(spec)
|
||||
if err != nil {
|
||||
return convertError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
_, err = state.controlClient.UpdateCluster(
|
||||
@ -311,7 +312,7 @@ func (c *Cluster) UnlockSwarm(req types.UnlockRequest) error {
|
||||
|
||||
key, err := encryption.ParseHumanReadableKey(req.UnlockKey)
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
config := nr.config
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/builder/dockerfile"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/layer"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
@ -136,12 +137,12 @@ func (daemon *Daemon) Commit(name string, c *backend.ContainerCommitConfig) (str
|
||||
|
||||
if container.IsDead() {
|
||||
err := fmt.Errorf("You cannot commit container %s which is Dead", container.ID)
|
||||
return "", stateConflictError{err}
|
||||
return "", errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
if container.IsRemovalInProgress() {
|
||||
err := fmt.Errorf("You cannot commit container %s which is being removed", container.ID)
|
||||
return "", stateConflictError{err}
|
||||
return "", errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
if c.Pause && !container.IsPaused() {
|
||||
|
||||
@ -511,11 +511,7 @@ func Validate(config *Config) error {
|
||||
}
|
||||
|
||||
// validate platform-specific settings
|
||||
if err := config.ValidatePlatformConfig(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return config.ValidatePlatformConfig()
|
||||
}
|
||||
|
||||
// ModifiedDiscoverySettings returns whether the discovery configuration has been modified or not.
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/docker/docker/api/types/strslice"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
@ -54,7 +55,7 @@ func (daemon *Daemon) GetContainer(prefixOrName string) (*container.Container, e
|
||||
if indexError == truncindex.ErrNotExist {
|
||||
return nil, containerNotFound(prefixOrName)
|
||||
}
|
||||
return nil, systemError{indexError}
|
||||
return nil, errdefs.System(indexError)
|
||||
}
|
||||
return daemon.containers.Get(containerID), nil
|
||||
}
|
||||
@ -139,7 +140,7 @@ func (daemon *Daemon) newContainer(name string, operatingSystem string, config *
|
||||
if config.Hostname == "" {
|
||||
config.Hostname, err = os.Hostname()
|
||||
if err != nil {
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
||||
@ -4,6 +4,7 @@ package daemon
|
||||
|
||||
import (
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
)
|
||||
|
||||
func (daemon *Daemon) saveApparmorConfig(container *container.Container) error {
|
||||
@ -14,7 +15,7 @@ func (daemon *Daemon) saveApparmorConfig(container *container.Container) error {
|
||||
}
|
||||
|
||||
if err := parseSecurityOpt(container, container.HostConfig); err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
if !container.HostConfig.Privileged {
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
networktypes "github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/opts"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/docker/docker/runconfig"
|
||||
@ -252,7 +253,7 @@ func (daemon *Daemon) updateNetworkSettings(container *container.Container, n li
|
||||
}
|
||||
|
||||
for s, v := range container.NetworkSettings.Networks {
|
||||
sn, err := daemon.FindUniqueNetwork(getNetworkID(s, v.EndpointSettings))
|
||||
sn, err := daemon.FindNetwork(getNetworkID(s, v.EndpointSettings))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -309,7 +310,7 @@ func (daemon *Daemon) updateNetwork(container *container.Container) error {
|
||||
// Find if container is connected to the default bridge network
|
||||
var n libnetwork.Network
|
||||
for name, v := range container.NetworkSettings.Networks {
|
||||
sn, err := daemon.FindUniqueNetwork(getNetworkID(name, v.EndpointSettings))
|
||||
sn, err := daemon.FindNetwork(getNetworkID(name, v.EndpointSettings))
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
@ -339,7 +340,7 @@ func (daemon *Daemon) updateNetwork(container *container.Container) error {
|
||||
}
|
||||
|
||||
func (daemon *Daemon) findAndAttachNetwork(container *container.Container, idOrName string, epConfig *networktypes.EndpointSettings) (libnetwork.Network, *networktypes.NetworkingConfig, error) {
|
||||
n, err := daemon.FindUniqueNetwork(getNetworkID(idOrName, epConfig))
|
||||
n, err := daemon.FindNetwork(getNetworkID(idOrName, epConfig))
|
||||
if err != nil {
|
||||
// We should always be able to find the network for a
|
||||
// managed container.
|
||||
@ -383,7 +384,7 @@ func (daemon *Daemon) findAndAttachNetwork(container *container.Container, idOrN
|
||||
}
|
||||
}
|
||||
|
||||
n, err = daemon.FindUniqueNetwork(getNetworkID(idOrName, epConfig))
|
||||
n, err = daemon.FindNetwork(getNetworkID(idOrName, epConfig))
|
||||
if err != nil {
|
||||
if daemon.clusterProvider != nil {
|
||||
if err := daemon.clusterProvider.DetachNetwork(getNetworkID(idOrName, epConfig), container.ID); err != nil {
|
||||
@ -437,7 +438,7 @@ func (daemon *Daemon) updateContainerNetworkSettings(container *container.Contai
|
||||
if mode.IsUserDefined() {
|
||||
var err error
|
||||
|
||||
n, err = daemon.FindUniqueNetwork(networkName)
|
||||
n, err = daemon.FindNetwork(networkName)
|
||||
if err == nil {
|
||||
networkName = n.Name()
|
||||
}
|
||||
@ -797,7 +798,7 @@ func (daemon *Daemon) connectToNetwork(container *container.Container, idOrName
|
||||
|
||||
// ForceEndpointDelete deletes an endpoint from a network forcefully
|
||||
func (daemon *Daemon) ForceEndpointDelete(name string, networkName string) error {
|
||||
n, err := daemon.FindUniqueNetwork(networkName)
|
||||
n, err := daemon.FindNetwork(networkName)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -922,7 +923,7 @@ func (daemon *Daemon) getNetworkedContainer(containerID, connectedContainerID st
|
||||
}
|
||||
if !nc.IsRunning() {
|
||||
err := fmt.Errorf("cannot join network of a non running container: %s", connectedContainerID)
|
||||
return nil, stateConflictError{err}
|
||||
return nil, errdefs.Conflict(err)
|
||||
}
|
||||
if nc.IsRestarting() {
|
||||
return nil, errContainerIsRestarting(connectedContainerID)
|
||||
@ -949,7 +950,7 @@ func (daemon *Daemon) releaseNetwork(container *container.Container) {
|
||||
|
||||
var networks []libnetwork.Network
|
||||
for n, epSettings := range settings {
|
||||
if nw, err := daemon.FindUniqueNetwork(getNetworkID(n, epSettings.EndpointSettings)); err == nil {
|
||||
if nw, err := daemon.FindNetwork(getNetworkID(n, epSettings.EndpointSettings)); err == nil {
|
||||
networks = append(networks, nw)
|
||||
}
|
||||
|
||||
@ -993,7 +994,7 @@ func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName
|
||||
return errRemovalContainer(container.ID)
|
||||
}
|
||||
|
||||
n, err := daemon.FindUniqueNetwork(idOrName)
|
||||
n, err := daemon.FindNetwork(idOrName)
|
||||
if err == nil && n != nil {
|
||||
if err := daemon.updateNetworkConfig(container, n, endpointConfig, true); err != nil {
|
||||
return err
|
||||
@ -1016,7 +1017,7 @@ func (daemon *Daemon) ConnectToNetwork(container *container.Container, idOrName
|
||||
|
||||
// DisconnectFromNetwork disconnects container from network n.
|
||||
func (daemon *Daemon) DisconnectFromNetwork(container *container.Container, networkName string, force bool) error {
|
||||
n, err := daemon.FindUniqueNetwork(networkName)
|
||||
n, err := daemon.FindNetwork(networkName)
|
||||
container.Lock()
|
||||
defer container.Unlock()
|
||||
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/links"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/mount"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
@ -91,7 +92,7 @@ func (daemon *Daemon) getPidContainer(container *container.Container) (*containe
|
||||
|
||||
func containerIsRunning(c *container.Container) error {
|
||||
if !c.IsRunning() {
|
||||
return stateConflictError{errors.Errorf("container %s is not running", c.ID)}
|
||||
return errdefs.Conflict(errors.Errorf("container %s is not running", c.ID))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -170,7 +170,7 @@ func (daemon *Daemon) initializeNetworkingPaths(container *container.Container,
|
||||
|
||||
if nc.NetworkSettings != nil {
|
||||
for n := range nc.NetworkSettings.Networks {
|
||||
sn, err := daemon.FindUniqueNetwork(n)
|
||||
sn, err := daemon.FindNetwork(n)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
networktypes "github.com/docker/docker/api/types/network"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/layer"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
@ -36,7 +37,7 @@ func (daemon *Daemon) ContainerCreate(params types.ContainerCreateConfig) (conta
|
||||
func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, managed bool) (containertypes.ContainerCreateCreatedBody, error) {
|
||||
start := time.Now()
|
||||
if params.Config == nil {
|
||||
return containertypes.ContainerCreateCreatedBody{}, validationError{errors.New("Config cannot be empty in order to create a container")}
|
||||
return containertypes.ContainerCreateCreatedBody{}, errdefs.InvalidParameter(errors.New("Config cannot be empty in order to create a container"))
|
||||
}
|
||||
|
||||
os := runtime.GOOS
|
||||
@ -55,12 +56,12 @@ func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, manage
|
||||
|
||||
warnings, err := daemon.verifyContainerSettings(os, params.HostConfig, params.Config, false)
|
||||
if err != nil {
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, validationError{err}
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
err = verifyNetworkingConfig(params.NetworkingConfig)
|
||||
if err != nil {
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, validationError{err}
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
if params.HostConfig == nil {
|
||||
@ -68,7 +69,7 @@ func (daemon *Daemon) containerCreate(params types.ContainerCreateConfig, manage
|
||||
}
|
||||
err = daemon.adaptContainerSettings(params.HostConfig, params.AdjustCPUShares)
|
||||
if err != nil {
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, validationError{err}
|
||||
return containertypes.ContainerCreateCreatedBody{Warnings: warnings}, errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
container, err := daemon.create(params, managed)
|
||||
@ -115,11 +116,11 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
|
||||
}
|
||||
|
||||
if err := daemon.mergeAndVerifyConfig(params.Config, img); err != nil {
|
||||
return nil, validationError{err}
|
||||
return nil, errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
if err := daemon.mergeAndVerifyLogConfig(¶ms.HostConfig.LogConfig); err != nil {
|
||||
return nil, validationError{err}
|
||||
return nil, errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
if container, err = daemon.newContainer(params.Name, os, params.Config, params.HostConfig, imgID, managed); err != nil {
|
||||
@ -158,7 +159,7 @@ func (daemon *Daemon) create(params types.ContainerCreateConfig, managed bool) (
|
||||
|
||||
// Set RWLayer for container after mount labels have been set
|
||||
if err := daemon.setRWLayer(container); err != nil {
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
|
||||
rootIDs := daemon.idMappings.RootPair()
|
||||
|
||||
@ -18,7 +18,6 @@ import (
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/errdefs"
|
||||
"github.com/docker/docker/api/types"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/api/types/swarm"
|
||||
@ -29,6 +28,7 @@ import (
|
||||
"github.com/docker/docker/daemon/exec"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/sirupsen/logrus"
|
||||
// register graph drivers
|
||||
_ "github.com/docker/docker/daemon/graphdriver/register"
|
||||
@ -1046,11 +1046,7 @@ func (daemon *Daemon) Shutdown() error {
|
||||
daemon.netController.Stop()
|
||||
}
|
||||
|
||||
if err := daemon.cleanupMounts(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return daemon.cleanupMounts()
|
||||
}
|
||||
|
||||
// Mount sets container.BaseFS
|
||||
|
||||
@ -7,9 +7,9 @@ import (
|
||||
"runtime"
|
||||
"testing"
|
||||
|
||||
"github.com/docker/docker/api/errdefs"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
_ "github.com/docker/docker/pkg/discovery/memory"
|
||||
"github.com/docker/docker/pkg/idtools"
|
||||
"github.com/docker/docker/pkg/truncindex"
|
||||
@ -317,7 +317,7 @@ func TestValidateContainerIsolation(t *testing.T) {
|
||||
|
||||
func TestFindNetworkErrorType(t *testing.T) {
|
||||
d := Daemon{}
|
||||
_, err := d.FindUniqueNetwork("fakeNet")
|
||||
_, err := d.FindNetwork("fakeNet")
|
||||
_, ok := errors.Cause(err).(libnetwork.ErrNoSuchNetwork)
|
||||
if !errdefs.IsNotFound(err) || !ok {
|
||||
assert.Fail(t, "The FindNetwork method MUST always return an error that implements the NotFound interface and is ErrNoSuchNetwork")
|
||||
|
||||
@ -1501,10 +1501,7 @@ func (daemon *Daemon) initCgroupsPath(path string) error {
|
||||
if err := maybeCreateCPURealTimeFile(sysinfo.CPURealtimePeriod, daemon.configStore.CPURealtimePeriod, "cpu.rt_period_us", path); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := maybeCreateCPURealTimeFile(sysinfo.CPURealtimeRuntime, daemon.configStore.CPURealtimeRuntime, "cpu.rt_runtime_us", path); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return maybeCreateCPURealTimeFile(sysinfo.CPURealtimeRuntime, daemon.configStore.CPURealtimeRuntime, "cpu.rt_runtime_us", path)
|
||||
}
|
||||
|
||||
func maybeCreateCPURealTimeFile(sysinfoPresent bool, configValue int64, file string, path string) error {
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/layer"
|
||||
"github.com/docker/docker/pkg/system"
|
||||
"github.com/docker/docker/volume"
|
||||
@ -31,7 +32,7 @@ func (daemon *Daemon) ContainerRm(name string, config *types.ContainerRmConfig)
|
||||
// Container state RemovalInProgress should be used to avoid races.
|
||||
if inProgress := container.SetRemovalInProgress(); inProgress {
|
||||
err := fmt.Errorf("removal of container %s is already in progress", name)
|
||||
return stateConflictError{err}
|
||||
return errdefs.Conflict(err)
|
||||
}
|
||||
defer container.ResetRemovalInProgress()
|
||||
|
||||
@ -87,7 +88,7 @@ func (daemon *Daemon) cleanupContainer(container *container.Container, forceRemo
|
||||
procedure = "Unpause and then " + strings.ToLower(procedure)
|
||||
}
|
||||
err := fmt.Errorf("You cannot remove a %s container %s. %s", state, container.ID, procedure)
|
||||
return stateConflictError{err}
|
||||
return errdefs.Conflict(err)
|
||||
}
|
||||
if err := daemon.Kill(container); err != nil {
|
||||
return fmt.Errorf("Could not kill running container %s, cannot remove - %v", container.ID, err)
|
||||
@ -164,7 +165,7 @@ func (daemon *Daemon) VolumeRm(name string, force bool) error {
|
||||
|
||||
err = daemon.volumeRm(v)
|
||||
if err != nil && volumestore.IsInUse(err) {
|
||||
return stateConflictError{err}
|
||||
return errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
if err == nil || force {
|
||||
|
||||
@ -5,12 +5,13 @@ import (
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc"
|
||||
)
|
||||
|
||||
func errNotRunning(id string) error {
|
||||
return stateConflictError{errors.Errorf("Container %s is not running", id)}
|
||||
return errdefs.Conflict(errors.Errorf("Container %s is not running", id))
|
||||
}
|
||||
|
||||
func containerNotFound(id string) error {
|
||||
@ -32,23 +33,9 @@ func (e objNotFoundError) Error() string {
|
||||
|
||||
func (e objNotFoundError) NotFound() {}
|
||||
|
||||
type stateConflictError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e stateConflictError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e stateConflictError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
func (e stateConflictError) Conflict() {}
|
||||
|
||||
func errContainerIsRestarting(containerID string) error {
|
||||
cause := errors.Errorf("Container %s is restarting, wait until the container is running", containerID)
|
||||
return stateConflictError{cause}
|
||||
return errdefs.Conflict(cause)
|
||||
}
|
||||
|
||||
func errExecNotFound(id string) error {
|
||||
@ -57,12 +44,12 @@ func errExecNotFound(id string) error {
|
||||
|
||||
func errExecPaused(id string) error {
|
||||
cause := errors.Errorf("Container %s is paused, unpause the container before exec", id)
|
||||
return stateConflictError{cause}
|
||||
return errdefs.Conflict(cause)
|
||||
}
|
||||
|
||||
func errNotPaused(id string) error {
|
||||
cause := errors.Errorf("Container %s is already paused", id)
|
||||
return stateConflictError{cause}
|
||||
return errdefs.Conflict(cause)
|
||||
}
|
||||
|
||||
type nameConflictError struct {
|
||||
@ -76,34 +63,6 @@ func (e nameConflictError) Error() string {
|
||||
|
||||
func (nameConflictError) Conflict() {}
|
||||
|
||||
type validationError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e validationError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e validationError) InvalidParameter() {}
|
||||
|
||||
func (e validationError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type notAllowedError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e notAllowedError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e notAllowedError) Forbidden() {}
|
||||
|
||||
func (e notAllowedError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type containerNotModifiedError struct {
|
||||
running bool
|
||||
}
|
||||
@ -117,20 +76,6 @@ func (e containerNotModifiedError) Error() string {
|
||||
|
||||
func (e containerNotModifiedError) NotModified() {}
|
||||
|
||||
type systemError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e systemError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e systemError) SystemError() {}
|
||||
|
||||
func (e systemError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type invalidIdentifier string
|
||||
|
||||
func (e invalidIdentifier) Error() string {
|
||||
@ -172,20 +117,6 @@ func (e invalidFilter) Error() string {
|
||||
|
||||
func (e invalidFilter) InvalidParameter() {}
|
||||
|
||||
type unknownError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e unknownError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (unknownError) Unknown() {}
|
||||
|
||||
func (e unknownError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type startInvalidConfigError string
|
||||
|
||||
func (e startInvalidConfigError) Error() string {
|
||||
@ -199,7 +130,7 @@ func translateContainerdStartErr(cmd string, setExitCode func(int), err error) e
|
||||
contains := func(s1, s2 string) bool {
|
||||
return strings.Contains(strings.ToLower(s1), s2)
|
||||
}
|
||||
var retErr error = unknownError{errors.New(errDesc)}
|
||||
var retErr = errdefs.Unknown(errors.New(errDesc))
|
||||
// if we receive an internal error from the initial start of a container then lets
|
||||
// return it instead of entering the restart loop
|
||||
// set to 127 for container cmd not found/does not exist)
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/container/stream"
|
||||
"github.com/docker/docker/daemon/exec"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/pools"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/docker/docker/pkg/term"
|
||||
@ -161,12 +162,12 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
|
||||
if ec.ExitCode != nil {
|
||||
ec.Unlock()
|
||||
err := fmt.Errorf("Error: Exec command %s has already run", ec.ID)
|
||||
return stateConflictError{err}
|
||||
return errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
if ec.Running {
|
||||
ec.Unlock()
|
||||
return stateConflictError{fmt.Errorf("Error: Exec command %s is already running", ec.ID)}
|
||||
return errdefs.Conflict(fmt.Errorf("Error: Exec command %s is already running", ec.ID))
|
||||
}
|
||||
ec.Running = true
|
||||
ec.Unlock()
|
||||
@ -267,7 +268,7 @@ func (d *Daemon) ContainerExecStart(ctx context.Context, name string, stdin io.R
|
||||
case err := <-attachErr:
|
||||
if err != nil {
|
||||
if _, ok := err.(term.EscapeError); !ok {
|
||||
return errors.Wrap(systemError{err}, "exec attach failed")
|
||||
return errdefs.System(errors.Wrap(err, "exec attach failed"))
|
||||
}
|
||||
d.LogContainerEvent(c, "exec_detach")
|
||||
}
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
"github.com/docker/docker/pkg/ioutils"
|
||||
)
|
||||
@ -24,12 +25,12 @@ func (daemon *Daemon) ContainerExport(name string, out io.Writer) error {
|
||||
|
||||
if container.IsDead() {
|
||||
err := fmt.Errorf("You cannot export container %s which is Dead", container.ID)
|
||||
return stateConflictError{err}
|
||||
return errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
if container.IsRemovalInProgress() {
|
||||
err := fmt.Errorf("You cannot export container %s which is being removed", container.ID)
|
||||
return stateConflictError{err}
|
||||
return errdefs.Conflict(err)
|
||||
}
|
||||
|
||||
data, err := daemon.containerExport(container)
|
||||
|
||||
@ -579,10 +579,7 @@ func (a *Driver) unmount(mountPath string) error {
|
||||
if mounted, err := a.mounted(mountPath); err != nil || !mounted {
|
||||
return err
|
||||
}
|
||||
if err := Unmount(mountPath); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return Unmount(mountPath)
|
||||
}
|
||||
|
||||
func (a *Driver) mounted(mountpoint string) (bool, error) {
|
||||
|
||||
@ -14,8 +14,5 @@ func Unmount(target string) error {
|
||||
if err := exec.Command("auplink", target, "flush").Run(); err != nil {
|
||||
logrus.Warnf("Couldn't run auplink before unmount %s: %s", target, err)
|
||||
}
|
||||
if err := unix.Unmount(target, 0); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return unix.Unmount(target, 0)
|
||||
}
|
||||
|
||||
@ -598,16 +598,10 @@ func (d *Driver) setStorageSize(dir string, driver *Driver) error {
|
||||
if d.options.minSpace > 0 && driver.options.size < d.options.minSpace {
|
||||
return fmt.Errorf("btrfs: storage size cannot be less than %s", units.HumanSize(float64(d.options.minSpace)))
|
||||
}
|
||||
|
||||
if err := d.subvolEnableQuota(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := subvolLimitQgroup(dir, driver.options.size); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return subvolLimitQgroup(dir, driver.options.size)
|
||||
}
|
||||
|
||||
// Remove the filesystem with given id.
|
||||
@ -634,10 +628,7 @@ func (d *Driver) Remove(id string) error {
|
||||
if err := system.EnsureRemoveAll(dir); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := d.subvolRescanQuota(); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return d.subvolRescanQuota()
|
||||
}
|
||||
|
||||
// Get the requested filesystem id.
|
||||
|
||||
@ -273,8 +273,5 @@ func doCopyXattrs(srcPath, dstPath string) error {
|
||||
// this function is used to copy those. It is set by overlay if a directory
|
||||
// is removed and then re-created and should not inherit anything from the
|
||||
// same dir in the lower dir.
|
||||
if err := copyXattr(srcPath, dstPath, "trusted.overlay.opaque"); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return copyXattr(srcPath, dstPath, "trusted.overlay.opaque")
|
||||
}
|
||||
|
||||
@ -129,15 +129,10 @@ func verifyBlockDevice(dev string, force bool) error {
|
||||
if err := checkDevInVG(dev); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if force {
|
||||
return nil
|
||||
}
|
||||
|
||||
if err := checkDevHasFS(dev); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return checkDevHasFS(dev)
|
||||
}
|
||||
|
||||
func readLVMConfig(root string) (directLVMConfig, error) {
|
||||
|
||||
@ -355,10 +355,7 @@ func (devices *DeviceSet) saveMetadata(info *devInfo) error {
|
||||
if err != nil {
|
||||
return fmt.Errorf("devmapper: Error encoding metadata to json: %s", err)
|
||||
}
|
||||
if err := devices.writeMetaFile(jsonData, devices.metadataFile(info)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return devices.writeMetaFile(jsonData, devices.metadataFile(info))
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) markDeviceIDUsed(deviceID int) {
|
||||
@ -889,11 +886,7 @@ func (devices *DeviceSet) takeSnapshot(hash string, baseInfo *devInfo, size uint
|
||||
defer devicemapper.ResumeDevice(baseInfo.Name())
|
||||
}
|
||||
|
||||
if err = devices.createRegisterSnapDevice(hash, baseInfo, size); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return devices.createRegisterSnapDevice(hash, baseInfo, size)
|
||||
}
|
||||
|
||||
func (devices *DeviceSet) createRegisterSnapDevice(hash string, baseInfo *devInfo, size uint64) error {
|
||||
@ -1233,12 +1226,7 @@ func (devices *DeviceSet) setupBaseImage() error {
|
||||
if err := devices.setupVerifyBaseImageUUIDFS(oldInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := devices.checkGrowBaseDeviceFS(oldInfo); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return devices.checkGrowBaseDeviceFS(oldInfo)
|
||||
}
|
||||
|
||||
logrus.Debug("devmapper: Removing uninitialized base image")
|
||||
@ -1259,11 +1247,7 @@ func (devices *DeviceSet) setupBaseImage() error {
|
||||
}
|
||||
|
||||
// Create new base image device
|
||||
if err := devices.createBaseImage(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return devices.createBaseImage()
|
||||
}
|
||||
|
||||
func setCloseOnExec(name string) {
|
||||
@ -2082,11 +2066,7 @@ func (devices *DeviceSet) deleteDevice(info *devInfo, syncDelete bool) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := devices.deleteTransaction(info, syncDelete); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return devices.deleteTransaction(info, syncDelete)
|
||||
}
|
||||
|
||||
// DeleteDevice will return success if device has been marked for deferred
|
||||
|
||||
@ -146,12 +146,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) error {
|
||||
if opts != nil {
|
||||
storageOpt = opts.StorageOpt
|
||||
}
|
||||
|
||||
if err := d.DeviceSet.AddDevice(id, parent, storageOpt); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return d.DeviceSet.AddDevice(id, parent, storageOpt)
|
||||
}
|
||||
|
||||
// Remove removes a device with a given id, unmounts the filesystem.
|
||||
|
||||
@ -263,11 +263,7 @@ func addLayerFiles(drv graphdriver.Driver, layer, parent string, i int) error {
|
||||
if err := driver.WriteFile(root, root.Join(layerDir, "layer-id"), []byte(layer), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := driver.WriteFile(root, root.Join(layerDir, "parent-id"), []byte(parent), 0755); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return driver.WriteFile(root, root.Join(layerDir, "parent-id"), []byte(parent), 0755)
|
||||
}
|
||||
|
||||
func addManyLayers(drv graphdriver.Driver, baseLayer string, count int) (string, error) {
|
||||
|
||||
@ -309,10 +309,7 @@ func (d *Driver) Create(id, parent string, opts *graphdriver.CreateOpts) (retErr
|
||||
if err := idtools.MkdirAndChown(path.Join(dir, "work"), 0700, root); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := ioutil.WriteFile(path.Join(dir, "lower-id"), []byte(parent), 0666); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return ioutil.WriteFile(path.Join(dir, "lower-id"), []byte(parent), 0666)
|
||||
}
|
||||
|
||||
// Otherwise, copy the upper and the lower-id from the parent
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package quota
|
||||
|
||||
import "github.com/docker/docker/api/errdefs"
|
||||
import "github.com/docker/docker/errdefs"
|
||||
|
||||
var (
|
||||
_ errdefs.ErrNotImplemented = (*errQuotaNotSupported)(nil)
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"runtime"
|
||||
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
)
|
||||
|
||||
@ -28,7 +29,7 @@ func (e errImageDoesNotExist) NotFound() {}
|
||||
func (daemon *Daemon) GetImageIDAndOS(refOrID string) (image.ID, string, error) {
|
||||
ref, err := reference.ParseAnyReference(refOrID)
|
||||
if err != nil {
|
||||
return "", "", validationError{err}
|
||||
return "", "", errdefs.InvalidParameter(err)
|
||||
}
|
||||
namedRef, ok := ref.(reference.Named)
|
||||
if !ok {
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/docker/distribution/reference"
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/pkg/errors"
|
||||
@ -85,7 +86,7 @@ func (daemon *Daemon) ImageDelete(imageRef string, force, prune bool) ([]types.I
|
||||
// we really want to avoid that the client must
|
||||
// explicitly force its removal.
|
||||
err := errors.Errorf("conflict: unable to remove repository reference %q (must force) - container %s is using its referenced image %s", imageRef, stringid.TruncateID(container.ID), stringid.TruncateID(imgID.String()))
|
||||
return nil, stateConflictError{err}
|
||||
return nil, errdefs.Conflict(err)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ import (
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/distribution"
|
||||
progressutils "github.com/docker/docker/distribution/utils"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/progress"
|
||||
"github.com/docker/docker/registry"
|
||||
"github.com/opencontainers/go-digest"
|
||||
@ -26,7 +27,7 @@ func (daemon *Daemon) PullImage(ctx context.Context, image, tag, platform string
|
||||
|
||||
ref, err := reference.ParseNormalizedNamed(image)
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
if tag != "" {
|
||||
@ -39,7 +40,7 @@ func (daemon *Daemon) PullImage(ctx context.Context, image, tag, platform string
|
||||
ref, err = reference.WithTag(ref, tag)
|
||||
}
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +97,7 @@ func (daemon *Daemon) GetRepository(ctx context.Context, ref reference.Named, au
|
||||
}
|
||||
// makes sure name is not empty or `scratch`
|
||||
if err := distribution.ValidateRepoName(repoInfo.Name); err != nil {
|
||||
return nil, false, validationError{err}
|
||||
return nil, false, errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
// get endpoints
|
||||
|
||||
@ -14,6 +14,7 @@ import (
|
||||
"github.com/docker/docker/builder/dockerfile"
|
||||
"github.com/docker/docker/builder/remotecontext"
|
||||
"github.com/docker/docker/dockerversion"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/layer"
|
||||
"github.com/docker/docker/pkg/archive"
|
||||
@ -42,16 +43,16 @@ func (daemon *Daemon) ImportImage(src string, repository, os string, tag string,
|
||||
var err error
|
||||
newRef, err = reference.ParseNormalizedNamed(repository)
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
if _, isCanonical := newRef.(reference.Canonical); isCanonical {
|
||||
return validationError{errors.New("cannot import digest reference")}
|
||||
return errdefs.InvalidParameter(errors.New("cannot import digest reference"))
|
||||
}
|
||||
|
||||
if tag != "" {
|
||||
newRef, err = reference.WithTag(newRef, tag)
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -69,7 +70,7 @@ func (daemon *Daemon) ImportImage(src string, repository, os string, tag string,
|
||||
}
|
||||
u, err := url.Parse(src)
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
resp, err = remotecontext.GetWithStatusError(u.String())
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/docker/docker/api/types/versions/v1p20"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/network"
|
||||
"github.com/docker/docker/errdefs"
|
||||
volumestore "github.com/docker/docker/volume/store"
|
||||
"github.com/docker/go-connections/nat"
|
||||
)
|
||||
@ -188,7 +189,7 @@ func (daemon *Daemon) getInspectData(container *container.Container) (*types.Con
|
||||
// could have been removed, it will cause error if we try to get the metadata,
|
||||
// we can ignore the error if the container is dead.
|
||||
if err != nil && !container.Dead {
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
contJSONBase.GraphDriver.Data = graphDriverData
|
||||
|
||||
@ -232,7 +233,7 @@ func (daemon *Daemon) VolumeInspect(name string) (*types.Volume, error) {
|
||||
if volumestore.IsNotExist(err) {
|
||||
return nil, volumeNotFound(name)
|
||||
}
|
||||
return nil, systemError{err}
|
||||
return nil, errdefs.System(err)
|
||||
}
|
||||
apiV := volumeToAPIType(v)
|
||||
apiV.Mountpoint = v.Path()
|
||||
|
||||
@ -7,8 +7,8 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/docker/docker/api/errdefs"
|
||||
containerpkg "github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/libcontainerd"
|
||||
"github.com/docker/docker/pkg/signal"
|
||||
"github.com/pkg/errors"
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/filters"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/image"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/docker/go-connections/nat"
|
||||
@ -290,7 +291,7 @@ func (daemon *Daemon) foldFilter(view container.View, config *types.ContainerLis
|
||||
|
||||
err = psFilters.WalkValues("health", func(value string) error {
|
||||
if !container.IsValidHealthString(value) {
|
||||
return validationError{errors.Errorf("Unrecognised filter value for health: %s", value)}
|
||||
return errdefs.InvalidParameter(errors.Errorf("Unrecognised filter value for health: %s", value))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
timetypes "github.com/docker/docker/api/types/time"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/logger"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -30,7 +31,7 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
||||
})
|
||||
|
||||
if !(config.ShowStdout || config.ShowStderr) {
|
||||
return nil, false, validationError{errors.New("You must choose at least one stream")}
|
||||
return nil, false, errdefs.InvalidParameter(errors.New("You must choose at least one stream"))
|
||||
}
|
||||
container, err := daemon.GetContainer(containerName)
|
||||
if err != nil {
|
||||
@ -38,7 +39,7 @@ func (daemon *Daemon) ContainerLogs(ctx context.Context, containerName string, c
|
||||
}
|
||||
|
||||
if container.RemovalInProgress || container.Dead {
|
||||
return nil, false, stateConflictError{errors.New("can not get logs from container which is dead or marked for removal")}
|
||||
return nil, false, errdefs.Conflict(errors.New("can not get logs from container which is dead or marked for removal"))
|
||||
}
|
||||
|
||||
if container.HostConfig.LogConfig.Type == "none" {
|
||||
|
||||
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/daemon/names"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/namesgenerator"
|
||||
"github.com/docker/docker/pkg/stringid"
|
||||
"github.com/pkg/errors"
|
||||
@ -56,7 +57,7 @@ func (daemon *Daemon) generateIDAndName(name string) (string, string, error) {
|
||||
|
||||
func (daemon *Daemon) reserveName(id, name string) (string, error) {
|
||||
if !validContainerNamePattern.MatchString(strings.TrimPrefix(name, "/")) {
|
||||
return "", validationError{errors.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars)}
|
||||
return "", errdefs.InvalidParameter(errors.Errorf("Invalid container name (%s), only %s are allowed", name, validContainerNameChars))
|
||||
}
|
||||
if name[0] != '/' {
|
||||
name = "/" + name
|
||||
|
||||
@ -11,6 +11,7 @@ import (
|
||||
"github.com/docker/docker/api/types"
|
||||
"github.com/docker/docker/api/types/network"
|
||||
clustertypes "github.com/docker/docker/daemon/cluster/provider"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/pkg/plugingetter"
|
||||
"github.com/docker/docker/runconfig"
|
||||
"github.com/docker/libnetwork"
|
||||
@ -29,12 +30,12 @@ func (daemon *Daemon) NetworkControllerEnabled() bool {
|
||||
return daemon.netController != nil
|
||||
}
|
||||
|
||||
// FindUniqueNetwork returns a network based on:
|
||||
// FindNetwork returns a network based on:
|
||||
// 1. Full ID
|
||||
// 2. Full Name
|
||||
// 3. Partial ID
|
||||
// as long as there is no ambiguity
|
||||
func (daemon *Daemon) FindUniqueNetwork(term string) (libnetwork.Network, error) {
|
||||
func (daemon *Daemon) FindNetwork(term string) (libnetwork.Network, error) {
|
||||
listByFullName := []libnetwork.Network{}
|
||||
listByPartialID := []libnetwork.Network{}
|
||||
for _, nw := range daemon.GetNetworks() {
|
||||
@ -52,13 +53,17 @@ func (daemon *Daemon) FindUniqueNetwork(term string) (libnetwork.Network, error)
|
||||
case len(listByFullName) == 1:
|
||||
return listByFullName[0], nil
|
||||
case len(listByFullName) > 1:
|
||||
return nil, fmt.Errorf("network %s is ambiguous (%d matches found based on name)", term, len(listByFullName))
|
||||
return nil, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found on name)", term, len(listByFullName)))
|
||||
case len(listByPartialID) == 1:
|
||||
return listByPartialID[0], nil
|
||||
case len(listByPartialID) > 1:
|
||||
return nil, fmt.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID))
|
||||
return nil, errdefs.InvalidParameter(errors.Errorf("network %s is ambiguous (%d matches found based on ID prefix)", term, len(listByPartialID)))
|
||||
}
|
||||
return nil, libnetwork.ErrNoSuchNetwork(term)
|
||||
|
||||
// Be very careful to change the error type here, the
|
||||
// libnetwork.ErrNoSuchNetwork error is used by the controller
|
||||
// to retry the creation of the network as managed through the swarm manager
|
||||
return nil, errdefs.NotFound(libnetwork.ErrNoSuchNetwork(term))
|
||||
}
|
||||
|
||||
// GetNetworkByID function returns a network whose ID matches the given ID.
|
||||
@ -264,7 +269,7 @@ func (daemon *Daemon) CreateNetwork(create types.NetworkCreateRequest) (*types.N
|
||||
func (daemon *Daemon) createNetwork(create types.NetworkCreateRequest, id string, agent bool) (*types.NetworkCreateResponse, error) {
|
||||
if runconfig.IsPreDefinedNetwork(create.Name) && !agent {
|
||||
err := fmt.Errorf("%s is a pre-defined network and cannot be created", create.Name)
|
||||
return nil, notAllowedError{err}
|
||||
return nil, errdefs.Forbidden(err)
|
||||
}
|
||||
|
||||
var warning string
|
||||
@ -522,7 +527,7 @@ func (daemon *Daemon) deleteLoadBalancerSandbox(n libnetwork.Network) {
|
||||
func (daemon *Daemon) deleteNetwork(nw libnetwork.Network, dynamic bool) error {
|
||||
if runconfig.IsPreDefinedNetwork(nw.Name()) && !dynamic {
|
||||
err := fmt.Errorf("%s is a pre-defined network and cannot be removed", nw.Name())
|
||||
return notAllowedError{err}
|
||||
return errdefs.Forbidden(err)
|
||||
}
|
||||
|
||||
if dynamic && !nw.Info().Dynamic() {
|
||||
@ -532,7 +537,7 @@ func (daemon *Daemon) deleteNetwork(nw libnetwork.Network, dynamic bool) error {
|
||||
return nil
|
||||
}
|
||||
err := fmt.Errorf("%s is not a dynamic network", nw.Name())
|
||||
return notAllowedError{err}
|
||||
return errdefs.Forbidden(err)
|
||||
}
|
||||
|
||||
if err := nw.Delete(); err != nil {
|
||||
|
||||
@ -159,7 +159,7 @@ func (daemon *Daemon) createSpec(c *container.Container) (*specs.Spec, error) {
|
||||
gwHNSID := ""
|
||||
if c.NetworkSettings != nil {
|
||||
for n := range c.NetworkSettings.Networks {
|
||||
sn, err := daemon.FindUniqueNetwork(n)
|
||||
sn, err := daemon.FindNetwork(n)
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
@ -14,12 +14,7 @@ func (daemon *Daemon) ContainerPause(name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := daemon.containerPause(container); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return daemon.containerPause(container)
|
||||
}
|
||||
|
||||
// containerPause pauses the container execution without stopping the process.
|
||||
|
||||
@ -61,10 +61,7 @@ func (daemon *Daemon) Reload(conf *config.Config) (err error) {
|
||||
if err := daemon.reloadLiveRestore(conf, attributes); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := daemon.reloadNetworkDiagnosticPort(conf, attributes); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return daemon.reloadNetworkDiagnosticPort(conf, attributes)
|
||||
}
|
||||
|
||||
// reloadDebug updates configuration with Debug option
|
||||
|
||||
@ -4,6 +4,7 @@ import (
|
||||
"strings"
|
||||
|
||||
dockercontainer "github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/libnetwork"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
@ -19,7 +20,7 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
||||
)
|
||||
|
||||
if oldName == "" || newName == "" {
|
||||
return validationError{errors.New("Neither old nor new names may be empty")}
|
||||
return errdefs.InvalidParameter(errors.New("Neither old nor new names may be empty"))
|
||||
}
|
||||
|
||||
if newName[0] != '/' {
|
||||
@ -38,13 +39,13 @@ func (daemon *Daemon) ContainerRename(oldName, newName string) error {
|
||||
oldIsAnonymousEndpoint := container.NetworkSettings.IsAnonymousEndpoint
|
||||
|
||||
if oldName == newName {
|
||||
return validationError{errors.New("Renaming a container with the same name as its current name")}
|
||||
return errdefs.InvalidParameter(errors.New("Renaming a container with the same name as its current name"))
|
||||
}
|
||||
|
||||
links := map[string]*dockercontainer.Container{}
|
||||
for k, v := range daemon.linkIndex.children(container) {
|
||||
if !strings.HasPrefix(k, oldName) {
|
||||
return validationError{errors.Errorf("Linked container %s does not match parent %s", k, oldName)}
|
||||
return errdefs.InvalidParameter(errors.Errorf("Linked container %s does not match parent %s", k, oldName))
|
||||
}
|
||||
links[strings.TrimPrefix(k, oldName)] = v
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ import (
|
||||
"github.com/docker/docker/api/types"
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -15,7 +16,7 @@ import (
|
||||
// ContainerStart starts a container.
|
||||
func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.HostConfig, checkpoint string, checkpointDir string) error {
|
||||
if checkpoint != "" && !daemon.HasExperimental() {
|
||||
return validationError{errors.New("checkpoint is only supported in experimental mode")}
|
||||
return errdefs.InvalidParameter(errors.New("checkpoint is only supported in experimental mode"))
|
||||
}
|
||||
|
||||
container, err := daemon.GetContainer(name)
|
||||
@ -28,7 +29,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
|
||||
defer container.Unlock()
|
||||
|
||||
if container.Paused {
|
||||
return stateConflictError{errors.New("cannot start a paused container, try unpause instead")}
|
||||
return errdefs.Conflict(errors.New("cannot start a paused container, try unpause instead"))
|
||||
}
|
||||
|
||||
if container.Running {
|
||||
@ -36,7 +37,7 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
|
||||
}
|
||||
|
||||
if container.RemovalInProgress || container.Dead {
|
||||
return stateConflictError{errors.New("container is marked for removal and cannot be started")}
|
||||
return errdefs.Conflict(errors.New("container is marked for removal and cannot be started"))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
@ -53,13 +54,13 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
|
||||
logrus.Warn("DEPRECATED: Setting host configuration options when the container starts is deprecated and has been removed in Docker 1.12")
|
||||
oldNetworkMode := container.HostConfig.NetworkMode
|
||||
if err := daemon.setSecurityOptions(container, hostConfig); err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
if err := daemon.mergeAndVerifyLogConfig(&hostConfig.LogConfig); err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
if err := daemon.setHostConfig(container, hostConfig); err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
newNetworkMode := container.HostConfig.NetworkMode
|
||||
if string(oldNetworkMode) != string(newNetworkMode) {
|
||||
@ -67,34 +68,30 @@ func (daemon *Daemon) ContainerStart(name string, hostConfig *containertypes.Hos
|
||||
// old networks. It is a deprecated feature and has been removed in Docker 1.12
|
||||
container.NetworkSettings.Networks = nil
|
||||
if err := container.CheckpointTo(daemon.containersReplica); err != nil {
|
||||
return systemError{err}
|
||||
return errdefs.System(err)
|
||||
}
|
||||
}
|
||||
container.InitDNSHostConfig()
|
||||
}
|
||||
} else {
|
||||
if hostConfig != nil {
|
||||
return validationError{errors.New("Supplying a hostconfig on start is not supported. It should be supplied on create")}
|
||||
return errdefs.InvalidParameter(errors.New("Supplying a hostconfig on start is not supported. It should be supplied on create"))
|
||||
}
|
||||
}
|
||||
|
||||
// check if hostConfig is in line with the current system settings.
|
||||
// It may happen cgroups are umounted or the like.
|
||||
if _, err = daemon.verifyContainerSettings(container.OS, container.HostConfig, nil, false); err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
// Adapt for old containers in case we have updates in this function and
|
||||
// old containers never have chance to call the new function in create stage.
|
||||
if hostConfig != nil {
|
||||
if err := daemon.adaptContainerSettings(container.HostConfig, false); err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
}
|
||||
|
||||
if err := daemon.containerStart(container, checkpoint, checkpointDir, true); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return daemon.containerStart(container, checkpoint, checkpointDir, true)
|
||||
}
|
||||
|
||||
// containerStart prepares the container to run by setting up everything the
|
||||
@ -111,12 +108,12 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
|
||||
}
|
||||
|
||||
if container.RemovalInProgress || container.Dead {
|
||||
return stateConflictError{errors.New("container is marked for removal and cannot be started")}
|
||||
return errdefs.Conflict(errors.New("container is marked for removal and cannot be started"))
|
||||
}
|
||||
|
||||
if checkpointDir != "" {
|
||||
// TODO(mlaventure): how would we support that?
|
||||
return notAllowedError{errors.New("custom checkpointdir is not supported")}
|
||||
return errdefs.Forbidden(errors.New("custom checkpointdir is not supported"))
|
||||
}
|
||||
|
||||
// if we encounter an error during start we need to ensure that any other
|
||||
@ -155,7 +152,7 @@ func (daemon *Daemon) containerStart(container *container.Container, checkpoint
|
||||
|
||||
spec, err := daemon.createSpec(container)
|
||||
if err != nil {
|
||||
return systemError{err}
|
||||
return errdefs.System(err)
|
||||
}
|
||||
|
||||
if resetRestartManager {
|
||||
|
||||
@ -9,6 +9,7 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/linux/runctypes"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -16,7 +17,7 @@ func (daemon *Daemon) getRuntimeScript(container *container.Container) (string,
|
||||
name := container.HostConfig.Runtime
|
||||
rt := daemon.configStore.GetRuntime(name)
|
||||
if rt == nil {
|
||||
return "", validationError{errors.Errorf("no such runtime '%s'", name)}
|
||||
return "", errdefs.InvalidParameter(errors.Errorf("no such runtime '%s'", name))
|
||||
}
|
||||
|
||||
if len(rt.Args) > 0 {
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
containerpkg "github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
@ -28,7 +29,7 @@ func (daemon *Daemon) ContainerStop(name string, seconds *int) error {
|
||||
seconds = &stopTimeout
|
||||
}
|
||||
if err := daemon.containerStop(container, *seconds); err != nil {
|
||||
return errors.Wrapf(systemError{err}, "cannot stop container: %s", name)
|
||||
return errdefs.System(errors.Wrapf(err, "cannot stop container: %s", name))
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
@ -14,12 +14,7 @@ func (daemon *Daemon) ContainerUnpause(name string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := daemon.containerUnpause(container); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return daemon.containerUnpause(container)
|
||||
}
|
||||
|
||||
// containerUnpause resumes the container execution after the container is paused.
|
||||
|
||||
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/docker/docker/api/types/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
@ -19,7 +20,7 @@ func (daemon *Daemon) ContainerUpdate(name string, hostConfig *container.HostCon
|
||||
|
||||
warnings, err = daemon.verifyContainerSettings(c.OS, hostConfig, nil, true)
|
||||
if err != nil {
|
||||
return container.ContainerUpdateOKBody{Warnings: warnings}, validationError{err}
|
||||
return container.ContainerUpdateOKBody{Warnings: warnings}, errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
if err := daemon.update(name, hostConfig); err != nil {
|
||||
@ -80,7 +81,7 @@ func (daemon *Daemon) update(name string, hostConfig *container.HostConfig) erro
|
||||
if err := daemon.containerd.UpdateResources(context.Background(), container.ID, toContainerdResources(hostConfig.Resources)); err != nil {
|
||||
restoreConfig = true
|
||||
// TODO: it would be nice if containerd responded with better errors here so we can classify this better.
|
||||
return errCannotUpdate(container.ID, systemError{err})
|
||||
return errCannotUpdate(container.ID, errdefs.System(err))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import (
|
||||
containertypes "github.com/docker/docker/api/types/container"
|
||||
mounttypes "github.com/docker/docker/api/types/mount"
|
||||
"github.com/docker/docker/container"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/docker/docker/volume"
|
||||
"github.com/docker/docker/volume/drivers"
|
||||
"github.com/pkg/errors"
|
||||
@ -175,7 +176,7 @@ func (daemon *Daemon) registerMountPoints(container *container.Container, hostCo
|
||||
for _, cfg := range hostConfig.Mounts {
|
||||
mp, err := parser.ParseMountSpec(cfg)
|
||||
if err != nil {
|
||||
return validationError{err}
|
||||
return errdefs.InvalidParameter(err)
|
||||
}
|
||||
|
||||
if binds[mp.Destination] {
|
||||
|
||||
@ -13,6 +13,7 @@ import (
|
||||
"github.com/docker/distribution/registry/client"
|
||||
"github.com/docker/distribution/registry/client/auth"
|
||||
"github.com/docker/docker/distribution/xfer"
|
||||
"github.com/docker/docker/errdefs"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
@ -85,20 +86,6 @@ func (e notFoundError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
type unknownError struct {
|
||||
cause error
|
||||
}
|
||||
|
||||
func (e unknownError) Error() string {
|
||||
return e.cause.Error()
|
||||
}
|
||||
|
||||
func (e unknownError) Cause() error {
|
||||
return e.cause
|
||||
}
|
||||
|
||||
func (e unknownError) Unknown() {}
|
||||
|
||||
// TranslatePullError is used to convert an error from a registry pull
|
||||
// operation to an error representing the entire pull operation. Any error
|
||||
// information which is not used by the returned error gets output to
|
||||
@ -121,7 +108,7 @@ func TranslatePullError(err error, ref reference.Named) error {
|
||||
return TranslatePullError(v.Err, ref)
|
||||
}
|
||||
|
||||
return unknownError{err}
|
||||
return errdefs.Unknown(err)
|
||||
}
|
||||
|
||||
// continueOnError returns true if we should fallback to the next endpoint
|
||||
|
||||
@ -43,6 +43,11 @@ type ErrNotModified interface {
|
||||
NotModified()
|
||||
}
|
||||
|
||||
// ErrAlreadyExists is a special case of ErrConflict which signals that the desired object already exists
|
||||
type ErrAlreadyExists interface {
|
||||
AlreadyExists()
|
||||
}
|
||||
|
||||
// ErrNotImplemented signals that the requested action/feature is not implemented on the system as configured.
|
||||
type ErrNotImplemented interface {
|
||||
NotImplemented()
|
||||
@ -52,3 +57,18 @@ type ErrNotImplemented interface {
|
||||
type ErrUnknown interface {
|
||||
Unknown()
|
||||
}
|
||||
|
||||
// ErrCancelled signals that the action was cancelled.
|
||||
type ErrCancelled interface {
|
||||
Cancelled()
|
||||
}
|
||||
|
||||
// ErrDeadline signals that the deadline was reached before the action completed.
|
||||
type ErrDeadline interface {
|
||||
DeadlineExceeded()
|
||||
}
|
||||
|
||||
// ErrDataLoss indicates that data was lost or there is data corruption.
|
||||
type ErrDataLoss interface {
|
||||
DataLoss()
|
||||
}
|
||||
240
components/engine/errdefs/helpers.go
Normal file
240
components/engine/errdefs/helpers.go
Normal file
@ -0,0 +1,240 @@
|
||||
package errdefs
|
||||
|
||||
import "context"
|
||||
|
||||
type errNotFound struct{ error }
|
||||
|
||||
func (errNotFound) NotFound() {}
|
||||
|
||||
func (e errNotFound) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// NotFound is a helper to create an error of the class with the same name from any error type
|
||||
func NotFound(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errNotFound{err}
|
||||
}
|
||||
|
||||
type errInvalidParameter struct{ error }
|
||||
|
||||
func (errInvalidParameter) InvalidParameter() {}
|
||||
|
||||
func (e errInvalidParameter) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// InvalidParameter is a helper to create an error of the class with the same name from any error type
|
||||
func InvalidParameter(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errInvalidParameter{err}
|
||||
}
|
||||
|
||||
type errConflict struct{ error }
|
||||
|
||||
func (errConflict) Conflict() {}
|
||||
|
||||
func (e errConflict) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Conflict is a helper to create an error of the class with the same name from any error type
|
||||
func Conflict(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errConflict{err}
|
||||
}
|
||||
|
||||
type errUnauthorized struct{ error }
|
||||
|
||||
func (errUnauthorized) Unauthorized() {}
|
||||
|
||||
func (e errUnauthorized) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Unauthorized is a helper to create an error of the class with the same name from any error type
|
||||
func Unauthorized(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errUnauthorized{err}
|
||||
}
|
||||
|
||||
type errUnavailable struct{ error }
|
||||
|
||||
func (errUnavailable) Unavailable() {}
|
||||
|
||||
func (e errUnavailable) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Unavailable is a helper to create an error of the class with the same name from any error type
|
||||
func Unavailable(err error) error {
|
||||
return errUnavailable{err}
|
||||
}
|
||||
|
||||
type errForbidden struct{ error }
|
||||
|
||||
func (errForbidden) Forbidden() {}
|
||||
|
||||
func (e errForbidden) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Forbidden is a helper to create an error of the class with the same name from any error type
|
||||
func Forbidden(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errForbidden{err}
|
||||
}
|
||||
|
||||
type errSystem struct{ error }
|
||||
|
||||
func (errSystem) System() {}
|
||||
|
||||
func (e errSystem) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// System is a helper to create an error of the class with the same name from any error type
|
||||
func System(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errSystem{err}
|
||||
}
|
||||
|
||||
type errNotModified struct{ error }
|
||||
|
||||
func (errNotModified) NotModified() {}
|
||||
|
||||
func (e errNotModified) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// NotModified is a helper to create an error of the class with the same name from any error type
|
||||
func NotModified(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errNotModified{err}
|
||||
}
|
||||
|
||||
type errAlreadyExists struct{ error }
|
||||
|
||||
func (errAlreadyExists) AlreadyExists() {}
|
||||
|
||||
func (e errAlreadyExists) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// AlreadyExists is a helper to create an error of the class with the same name from any error type
|
||||
func AlreadyExists(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errAlreadyExists{err}
|
||||
}
|
||||
|
||||
type errNotImplemented struct{ error }
|
||||
|
||||
func (errNotImplemented) NotImplemented() {}
|
||||
|
||||
func (e errNotImplemented) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// NotImplemented is a helper to create an error of the class with the same name from any error type
|
||||
func NotImplemented(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errNotImplemented{err}
|
||||
}
|
||||
|
||||
type errUnknown struct{ error }
|
||||
|
||||
func (errUnknown) Unknown() {}
|
||||
|
||||
func (e errUnknown) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Unknown is a helper to create an error of the class with the same name from any error type
|
||||
func Unknown(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errUnknown{err}
|
||||
}
|
||||
|
||||
type errCancelled struct{ error }
|
||||
|
||||
func (errCancelled) Cancelled() {}
|
||||
|
||||
func (e errCancelled) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Cancelled is a helper to create an error of the class with the same name from any error type
|
||||
func Cancelled(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errCancelled{err}
|
||||
}
|
||||
|
||||
type errDeadline struct{ error }
|
||||
|
||||
func (errDeadline) DeadlineExceeded() {}
|
||||
|
||||
func (e errDeadline) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// Deadline is a helper to create an error of the class with the same name from any error type
|
||||
func Deadline(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errDeadline{err}
|
||||
}
|
||||
|
||||
type errDataLoss struct{ error }
|
||||
|
||||
func (errDataLoss) DataLoss() {}
|
||||
|
||||
func (e errDataLoss) Cause() error {
|
||||
return e.error
|
||||
}
|
||||
|
||||
// DataLoss is a helper to create an error of the class with the same name from any error type
|
||||
func DataLoss(err error) error {
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
return errDataLoss{err}
|
||||
}
|
||||
|
||||
// FromContext returns the error class from the passed in context
|
||||
func FromContext(ctx context.Context) error {
|
||||
e := ctx.Err()
|
||||
if e == nil {
|
||||
return nil
|
||||
}
|
||||
|
||||
if e == context.Canceled {
|
||||
return Cancelled(e)
|
||||
}
|
||||
if e == context.DeadlineExceeded {
|
||||
return Deadline(e)
|
||||
}
|
||||
return Unknown(e)
|
||||
}
|
||||
132
components/engine/errdefs/helpers_test.go
Normal file
132
components/engine/errdefs/helpers_test.go
Normal file
@ -0,0 +1,132 @@
|
||||
package errdefs
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"testing"
|
||||
)
|
||||
|
||||
var errTest = errors.New("this is a test")
|
||||
|
||||
type causal interface {
|
||||
Cause() error
|
||||
}
|
||||
|
||||
func TestNotFound(t *testing.T) {
|
||||
e := NotFound(errTest)
|
||||
if !IsNotFound(e) {
|
||||
t.Fatalf("expected not found error, got: %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestConflict(t *testing.T) {
|
||||
e := Conflict(errTest)
|
||||
if !IsConflict(e) {
|
||||
t.Fatalf("expected conflcit error, got: %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestForbidden(t *testing.T) {
|
||||
e := Forbidden(errTest)
|
||||
if !IsForbidden(e) {
|
||||
t.Fatalf("expected forbidden error, got: %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestInvalidParameter(t *testing.T) {
|
||||
e := InvalidParameter(errTest)
|
||||
if !IsInvalidParameter(e) {
|
||||
t.Fatalf("expected invalid argument error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotImplemented(t *testing.T) {
|
||||
e := NotImplemented(errTest)
|
||||
if !IsNotImplemented(e) {
|
||||
t.Fatalf("expected not implemented error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestNotModified(t *testing.T) {
|
||||
e := NotModified(errTest)
|
||||
if !IsNotModified(e) {
|
||||
t.Fatalf("expected not modified error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestAlreadyExists(t *testing.T) {
|
||||
e := AlreadyExists(errTest)
|
||||
if !IsAlreadyExists(e) {
|
||||
t.Fatalf("expected already exists error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnauthorized(t *testing.T) {
|
||||
e := Unauthorized(errTest)
|
||||
if !IsUnauthorized(e) {
|
||||
t.Fatalf("expected unauthorized error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestUnknown(t *testing.T) {
|
||||
e := Unknown(errTest)
|
||||
if !IsUnknown(e) {
|
||||
t.Fatalf("expected unknown error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCancelled(t *testing.T) {
|
||||
e := Cancelled(errTest)
|
||||
if !IsCancelled(e) {
|
||||
t.Fatalf("expected canclled error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestDeadline(t *testing.T) {
|
||||
e := Deadline(errTest)
|
||||
if !IsDeadline(e) {
|
||||
t.Fatalf("expected deadline error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsDataLoss(t *testing.T) {
|
||||
e := DataLoss(errTest)
|
||||
if !IsDataLoss(e) {
|
||||
t.Fatalf("expected data loss error, got %T", e)
|
||||
}
|
||||
if cause := e.(causal).Cause(); cause != errTest {
|
||||
t.Fatalf("causual should be errTest, got: %v", cause)
|
||||
}
|
||||
}
|
||||
@ -15,7 +15,11 @@ func getImplementer(err error) error {
|
||||
ErrForbidden,
|
||||
ErrSystem,
|
||||
ErrNotModified,
|
||||
ErrAlreadyExists,
|
||||
ErrNotImplemented,
|
||||
ErrCancelled,
|
||||
ErrDeadline,
|
||||
ErrDataLoss,
|
||||
ErrUnknown:
|
||||
return e
|
||||
case causer:
|
||||
@ -73,6 +77,12 @@ func IsNotModified(err error) bool {
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsAlreadyExists returns if the passed in error is a AlreadyExists error
|
||||
func IsAlreadyExists(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrAlreadyExists)
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsNotImplemented returns if the passed in error is an ErrNotImplemented
|
||||
func IsNotImplemented(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrNotImplemented)
|
||||
@ -84,3 +94,21 @@ func IsUnknown(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrUnknown)
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsCancelled returns if the passed in error is an ErrCancelled
|
||||
func IsCancelled(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrCancelled)
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsDeadline returns if the passed in error is an ErrDeadline
|
||||
func IsDeadline(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrDeadline)
|
||||
return ok
|
||||
}
|
||||
|
||||
// IsDataLoss returns if the passed in error is an ErrDataLoss
|
||||
func IsDataLoss(err error) bool {
|
||||
_, ok := getImplementer(err).(ErrDataLoss)
|
||||
return ok
|
||||
}
|
||||
@ -133,10 +133,7 @@ func (s *fs) Delete(dgst digest.Digest) error {
|
||||
if err := os.RemoveAll(s.metadataDir(dgst)); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := os.Remove(s.contentFile(dgst)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
return os.Remove(s.contentFile(dgst))
|
||||
}
|
||||
|
||||
// SetMetadata sets metadata for a given ID. It fails if there's no base file.
|
||||
|
||||
@ -129,7 +129,7 @@ func (s *DockerRegistrySuite) SetUpTest(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, registry.Hosting, SameHostDaemon)
|
||||
s.reg = setupRegistry(c, false, "", "")
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
||||
Experimental: testEnv.ExperimentalDaemon(),
|
||||
Experimental: testEnv.DaemonInfo.ExperimentalBuild,
|
||||
})
|
||||
}
|
||||
|
||||
@ -163,7 +163,7 @@ func (s *DockerSchema1RegistrySuite) SetUpTest(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, registry.Hosting, NotArm64, SameHostDaemon)
|
||||
s.reg = setupRegistry(c, true, "", "")
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
||||
Experimental: testEnv.ExperimentalDaemon(),
|
||||
Experimental: testEnv.DaemonInfo.ExperimentalBuild,
|
||||
})
|
||||
}
|
||||
|
||||
@ -197,7 +197,7 @@ func (s *DockerRegistryAuthHtpasswdSuite) SetUpTest(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, registry.Hosting, SameHostDaemon)
|
||||
s.reg = setupRegistry(c, false, "htpasswd", "")
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
||||
Experimental: testEnv.ExperimentalDaemon(),
|
||||
Experimental: testEnv.DaemonInfo.ExperimentalBuild,
|
||||
})
|
||||
}
|
||||
|
||||
@ -232,7 +232,7 @@ func (s *DockerRegistryAuthTokenSuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerRegistryAuthTokenSuite) SetUpTest(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, registry.Hosting, SameHostDaemon)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
||||
Experimental: testEnv.ExperimentalDaemon(),
|
||||
Experimental: testEnv.DaemonInfo.ExperimentalBuild,
|
||||
})
|
||||
}
|
||||
|
||||
@ -273,7 +273,7 @@ func (s *DockerDaemonSuite) OnTimeout(c *check.C) {
|
||||
func (s *DockerDaemonSuite) SetUpTest(c *check.C) {
|
||||
testRequires(c, DaemonIsLinux, SameHostDaemon)
|
||||
s.d = daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
||||
Experimental: testEnv.ExperimentalDaemon(),
|
||||
Experimental: testEnv.DaemonInfo.ExperimentalBuild,
|
||||
})
|
||||
}
|
||||
|
||||
@ -331,7 +331,7 @@ func (s *DockerSwarmSuite) SetUpTest(c *check.C) {
|
||||
func (s *DockerSwarmSuite) AddDaemon(c *check.C, joinSwarm, manager bool) *daemon.Swarm {
|
||||
d := &daemon.Swarm{
|
||||
Daemon: daemon.New(c, dockerBinary, dockerdBinary, daemon.Config{
|
||||
Experimental: testEnv.ExperimentalDaemon(),
|
||||
Experimental: testEnv.DaemonInfo.ExperimentalBuild,
|
||||
}),
|
||||
Port: defaultSwarmPort + s.portIndex,
|
||||
}
|
||||
|
||||
@ -348,11 +348,7 @@ func (d *Daemon) Kill() error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
|
||||
}
|
||||
|
||||
// Pid returns the pid of the daemon
|
||||
@ -459,11 +455,7 @@ out2:
|
||||
|
||||
d.cmd.Wait()
|
||||
|
||||
if err := os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
return os.Remove(fmt.Sprintf("%s/docker.pid", d.Folder))
|
||||
}
|
||||
|
||||
// Restart will restart the daemon by first stopping it and the starting it.
|
||||
|
||||
@ -30,7 +30,7 @@ func (s *DockerSuite) TestBuildAPIDockerFileRemote(c *check.C) {
|
||||
testRequires(c, NotUserNamespace)
|
||||
|
||||
var testD string
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
testD = `FROM busybox
|
||||
RUN find / -name ba*
|
||||
RUN find /tmp/`
|
||||
@ -460,6 +460,7 @@ COPY file /file`
|
||||
assert.Equal(c, http.StatusOK, res.StatusCode)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
require.NoError(c, err)
|
||||
|
||||
ids := getImageIDsFromBuild(c, out)
|
||||
return ids[len(ids)-1]
|
||||
@ -498,6 +499,7 @@ ADD file /file`
|
||||
assert.Equal(c, http.StatusOK, res.StatusCode)
|
||||
|
||||
out, err := request.ReadBody(body)
|
||||
require.NoError(c, err)
|
||||
|
||||
ids := getImageIDsFromBuild(c, out)
|
||||
return ids[len(ids)-1]
|
||||
|
||||
@ -1016,7 +1016,7 @@ func (s *DockerSuite) TestContainerAPIWait(c *check.C) {
|
||||
name := "test-api-wait"
|
||||
|
||||
sleepCmd := "/bin/sleep"
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
sleepCmd = "sleep"
|
||||
}
|
||||
dockerCmd(c, "run", "--name", name, "busybox", sleepCmd, "2")
|
||||
@ -1216,7 +1216,7 @@ func (s *DockerSuite) TestContainerAPIDeleteRemoveVolume(c *check.C) {
|
||||
testRequires(c, SameHostDaemon)
|
||||
|
||||
vol := "/testvolume"
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
vol = `c:\testvolume`
|
||||
}
|
||||
|
||||
@ -1890,7 +1890,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
|
||||
var (
|
||||
testImg string
|
||||
)
|
||||
if testEnv.DaemonPlatform() != "windows" {
|
||||
if testEnv.OSType != "windows" {
|
||||
testImg = "test-mount-config"
|
||||
buildImageSuccessfully(c, testImg, build.WithDockerfile(`
|
||||
FROM busybox
|
||||
@ -1987,7 +1987,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsCreate(c *check.C) {
|
||||
}
|
||||
}
|
||||
|
||||
if testEnv.DaemonPlatform() != "windows" { // Windows does not support volume populate
|
||||
if testEnv.OSType != "windows" { // Windows does not support volume populate
|
||||
cases = append(cases, []testCase{
|
||||
{
|
||||
spec: mounttypes.Mount{Type: "volume", Target: destPath, VolumeOptions: &mounttypes.VolumeOptions{NoCopy: true}},
|
||||
|
||||
@ -47,7 +47,7 @@ func (s *DockerSuite) TestContainersAPICreateMountsBindNamedPipe(c *check.C) {
|
||||
|
||||
name := "test-bind-npipe"
|
||||
data := map[string]interface{}{
|
||||
"Image": testEnv.MinimalBaseImage(),
|
||||
"Image": testEnv.PlatformDefaults.BaseImage,
|
||||
"Cmd": []string{"cmd", "/c", cmd},
|
||||
"HostConfig": map[string]interface{}{"Mounts": []map[string]interface{}{{"Type": "npipe", "Source": hostPipeName, "Target": containerPipeName}}},
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ func (s *DockerSuite) TestAPIImagesDelete(c *check.C) {
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cli.Close()
|
||||
|
||||
if testEnv.DaemonPlatform() != "windows" {
|
||||
if testEnv.OSType != "windows" {
|
||||
testRequires(c, Network)
|
||||
}
|
||||
name := "test-api-images-delete"
|
||||
@ -104,7 +104,7 @@ func (s *DockerSuite) TestAPIImagesHistory(c *check.C) {
|
||||
c.Assert(err, checker.IsNil)
|
||||
defer cli.Close()
|
||||
|
||||
if testEnv.DaemonPlatform() != "windows" {
|
||||
if testEnv.OSType != "windows" {
|
||||
testRequires(c, Network)
|
||||
}
|
||||
name := "test-api-images-history"
|
||||
|
||||
@ -28,7 +28,7 @@ func (s *DockerSuite) TestInspectAPIContainerResponse(c *check.C) {
|
||||
|
||||
var cases []acase
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
cases = []acase{
|
||||
{"v1.25", append(keysBase, "Mounts")},
|
||||
}
|
||||
|
||||
@ -328,9 +328,8 @@ func createNetwork(c *check.C, config types.NetworkCreateRequest, expectedStatus
|
||||
c.Assert(err, checker.IsNil)
|
||||
|
||||
return nr.ID
|
||||
} else {
|
||||
return ""
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
func connectNetwork(c *check.C, nid, cid string) {
|
||||
|
||||
@ -39,7 +39,7 @@ func (s *DockerSuite) TestAPIStatsNoStreamGetCpu(c *check.C) {
|
||||
|
||||
var cpuPercent = 0.0
|
||||
|
||||
if testEnv.DaemonPlatform() != "windows" {
|
||||
if testEnv.OSType != "windows" {
|
||||
cpuDelta := float64(v.CPUStats.CPUUsage.TotalUsage - v.PreCPUStats.CPUUsage.TotalUsage)
|
||||
systemDelta := float64(v.CPUStats.SystemUsage - v.PreCPUStats.SystemUsage)
|
||||
cpuPercent = (cpuDelta / systemDelta) * float64(len(v.CPUStats.CPUUsage.PercpuUsage)) * 100.0
|
||||
@ -105,7 +105,7 @@ func (s *DockerSuite) TestAPIStatsNetworkStats(c *check.C) {
|
||||
|
||||
// Retrieve the container address
|
||||
net := "bridge"
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
net = "nat"
|
||||
}
|
||||
contIP := findContainerIP(c, id, net)
|
||||
@ -153,7 +153,7 @@ func (s *DockerSuite) TestAPIStatsNetworkStats(c *check.C) {
|
||||
// On Linux, account for ARP.
|
||||
expRxPkts := preRxPackets + uint64(numPings)
|
||||
expTxPkts := preTxPackets + uint64(numPings)
|
||||
if testEnv.DaemonPlatform() != "windows" {
|
||||
if testEnv.OSType != "windows" {
|
||||
expRxPkts++
|
||||
expTxPkts++
|
||||
}
|
||||
|
||||
@ -1031,7 +1031,7 @@ func (s *DockerSwarmSuite) TestAPINetworkInspectWithScope(c *check.C) {
|
||||
v := url.Values{}
|
||||
v.Set("scope", "local")
|
||||
|
||||
status, body, err = d.SockRequest("GET", "/networks/"+name+"?"+v.Encode(), nil)
|
||||
status, _, err = d.SockRequest("GET", "/networks/"+name+"?"+v.Encode(), nil)
|
||||
c.Assert(err, checker.IsNil, check.Commentf(string(out)))
|
||||
c.Assert(status, checker.Equals, http.StatusNotFound, check.Commentf(string(out)))
|
||||
}
|
||||
|
||||
@ -33,7 +33,7 @@ func (s *DockerSuite) TestAPIGetEnabledCORS(c *check.C) {
|
||||
}
|
||||
|
||||
func (s *DockerSuite) TestAPIClientVersionOldNotSupported(c *check.C) {
|
||||
if testEnv.DaemonPlatform() != runtime.GOOS {
|
||||
if testEnv.OSType != runtime.GOOS {
|
||||
c.Skip("Daemon platform doesn't match test platform")
|
||||
}
|
||||
if api.MinVersion == api.DefaultVersion {
|
||||
|
||||
@ -40,7 +40,7 @@ func (s *DockerSuite) TestBuildJSONEmptyRun(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildShCmdJSONEntrypoint(c *check.C) {
|
||||
name := "testbuildshcmdjsonentrypoint"
|
||||
expected := "/bin/sh -c echo test"
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = "cmd /S /C echo test"
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ func (s *DockerSuite) TestBuildEnvironmentReplacementVolume(c *check.C) {
|
||||
|
||||
var volumePath string
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
volumePath = "c:/quux"
|
||||
} else {
|
||||
volumePath = "/quux"
|
||||
@ -135,7 +135,7 @@ func (s *DockerSuite) TestBuildEnvironmentReplacementWorkdir(c *check.C) {
|
||||
res := inspectFieldJSON(c, name, "Config.WorkingDir")
|
||||
|
||||
expected := `"/work"`
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = `"C:\\work"`
|
||||
}
|
||||
if res != expected {
|
||||
@ -610,7 +610,7 @@ RUN [ $(cat "/test dir/test_file6") = 'test6' ]`, command, command, command, com
|
||||
|
||||
func (s *DockerSuite) TestBuildCopyFileWithWhitespaceOnWindows(c *check.C) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
dockerfile := `FROM ` + testEnv.MinimalBaseImage() + `
|
||||
dockerfile := `FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
RUN mkdir "C:/test dir"
|
||||
RUN mkdir "C:/test_dir"
|
||||
COPY [ "test file1", "/test_file1" ]
|
||||
@ -1311,7 +1311,7 @@ func (s *DockerSuite) TestBuildRelativeWorkdir(c *check.C) {
|
||||
expectedFinal string
|
||||
)
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected1 = `C:/`
|
||||
expected2 = `C:/test1`
|
||||
expected3 = `C:/test2`
|
||||
@ -1390,7 +1390,7 @@ func (s *DockerSuite) TestBuildWorkdirWithEnvVariables(c *check.C) {
|
||||
name := "testbuildworkdirwithenvvariables"
|
||||
|
||||
var expected string
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = `C:\test1\test2`
|
||||
} else {
|
||||
expected = `/test1/test2`
|
||||
@ -1412,7 +1412,7 @@ func (s *DockerSuite) TestBuildRelativeCopy(c *check.C) {
|
||||
testRequires(c, NotUserNamespace)
|
||||
|
||||
var expected string
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = `C:/test1/test2`
|
||||
} else {
|
||||
expected = `/test1/test2`
|
||||
@ -1521,7 +1521,7 @@ func (s *DockerSuite) TestBuildContextCleanup(c *check.C) {
|
||||
testRequires(c, SameHostDaemon)
|
||||
|
||||
name := "testbuildcontextcleanup"
|
||||
entries, err := ioutil.ReadDir(filepath.Join(testEnv.DockerBasePath(), "tmp"))
|
||||
entries, err := ioutil.ReadDir(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "tmp"))
|
||||
if err != nil {
|
||||
c.Fatalf("failed to list contents of tmp dir: %s", err)
|
||||
}
|
||||
@ -1529,7 +1529,7 @@ func (s *DockerSuite) TestBuildContextCleanup(c *check.C) {
|
||||
buildImageSuccessfully(c, name, build.WithDockerfile(`FROM `+minimalBaseImage()+`
|
||||
ENTRYPOINT ["/bin/echo"]`))
|
||||
|
||||
entriesFinal, err := ioutil.ReadDir(filepath.Join(testEnv.DockerBasePath(), "tmp"))
|
||||
entriesFinal, err := ioutil.ReadDir(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "tmp"))
|
||||
if err != nil {
|
||||
c.Fatalf("failed to list contents of tmp dir: %s", err)
|
||||
}
|
||||
@ -1543,7 +1543,7 @@ func (s *DockerSuite) TestBuildContextCleanupFailedBuild(c *check.C) {
|
||||
testRequires(c, SameHostDaemon)
|
||||
|
||||
name := "testbuildcontextcleanup"
|
||||
entries, err := ioutil.ReadDir(filepath.Join(testEnv.DockerBasePath(), "tmp"))
|
||||
entries, err := ioutil.ReadDir(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "tmp"))
|
||||
if err != nil {
|
||||
c.Fatalf("failed to list contents of tmp dir: %s", err)
|
||||
}
|
||||
@ -1553,7 +1553,7 @@ func (s *DockerSuite) TestBuildContextCleanupFailedBuild(c *check.C) {
|
||||
ExitCode: 1,
|
||||
})
|
||||
|
||||
entriesFinal, err := ioutil.ReadDir(filepath.Join(testEnv.DockerBasePath(), "tmp"))
|
||||
entriesFinal, err := ioutil.ReadDir(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "tmp"))
|
||||
if err != nil {
|
||||
c.Fatalf("failed to list contents of tmp dir: %s", err)
|
||||
}
|
||||
@ -2196,7 +2196,7 @@ func (s *DockerSuite) TestBuildAddFileNotFound(c *check.C) {
|
||||
name := "testbuildaddnotfound"
|
||||
expected := "foo: no such file or directory"
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = "foo: The system cannot find the file specified"
|
||||
}
|
||||
|
||||
@ -2250,7 +2250,7 @@ func (s *DockerSuite) TestBuildOnBuild(c *check.C) {
|
||||
// gh #2446
|
||||
func (s *DockerSuite) TestBuildAddToSymlinkDest(c *check.C) {
|
||||
makeLink := `ln -s /foo /bar`
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
makeLink = `mklink /D C:\bar C:\foo`
|
||||
}
|
||||
name := "testbuildaddtosymlinkdest"
|
||||
@ -3205,7 +3205,7 @@ func (s *DockerSuite) TestBuildCmdShDashC(c *check.C) {
|
||||
|
||||
res := inspectFieldJSON(c, name, "Config.Cmd")
|
||||
expected := `["/bin/sh","-c","echo cmd"]`
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = `["cmd","/S","/C","echo cmd"]`
|
||||
}
|
||||
if res != expected {
|
||||
@ -3278,7 +3278,7 @@ func (s *DockerSuite) TestBuildEntrypointCanBeOverriddenByChildInspect(c *check.
|
||||
expected = `["/bin/sh","-c","echo quux"]`
|
||||
)
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = `["cmd","/S","/C","echo quux"]`
|
||||
}
|
||||
|
||||
@ -3335,7 +3335,7 @@ func (s *DockerSuite) TestBuildVerifySingleQuoteFails(c *check.C) {
|
||||
// it should barf on it.
|
||||
name := "testbuildsinglequotefails"
|
||||
expectedExitCode := 2
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expectedExitCode = 127
|
||||
}
|
||||
|
||||
@ -3351,7 +3351,7 @@ func (s *DockerSuite) TestBuildVerboseOut(c *check.C) {
|
||||
name := "testbuildverboseout"
|
||||
expected := "\n123\n"
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = "\n123\r\n"
|
||||
}
|
||||
|
||||
@ -3367,7 +3367,7 @@ func (s *DockerSuite) TestBuildWithTabs(c *check.C) {
|
||||
res := inspectFieldJSON(c, name, "ContainerConfig.Cmd")
|
||||
expected1 := `["/bin/sh","-c","echo\tone\t\ttwo"]`
|
||||
expected2 := `["/bin/sh","-c","echo\u0009one\u0009\u0009two"]` // syntactically equivalent, and what Go 1.3 generates
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected1 = `["cmd","/S","/C","echo\tone\t\ttwo"]`
|
||||
expected2 = `["cmd","/S","/C","echo\u0009one\u0009\u0009two"]` // syntactically equivalent, and what Go 1.3 generates
|
||||
}
|
||||
@ -3562,7 +3562,7 @@ func (s *DockerSuite) TestBuildStderr(c *check.C) {
|
||||
result.Assert(c, icmd.Success)
|
||||
|
||||
// Windows to non-Windows should have a security warning
|
||||
if runtime.GOOS == "windows" && testEnv.DaemonPlatform() != "windows" && !strings.Contains(result.Stdout(), "SECURITY WARNING:") {
|
||||
if runtime.GOOS == "windows" && testEnv.OSType != "windows" && !strings.Contains(result.Stdout(), "SECURITY WARNING:") {
|
||||
c.Fatalf("Stdout contains unexpected output: %q", result.Stdout())
|
||||
}
|
||||
|
||||
@ -3674,7 +3674,7 @@ func (s *DockerSuite) TestBuildVolumesRetainContents(c *check.C) {
|
||||
volName = "/foo"
|
||||
)
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
volName = "C:/foo"
|
||||
}
|
||||
|
||||
@ -3975,7 +3975,7 @@ RUN echo " \
|
||||
|
||||
expected := "\n foo \n"
|
||||
// Windows uses the builtin echo, which preserves quotes
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expected = "\" foo \""
|
||||
}
|
||||
|
||||
@ -4009,7 +4009,7 @@ func (s *DockerSuite) TestBuildMissingArgs(c *check.C) {
|
||||
"INSERT": {},
|
||||
}
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
skipCmds = map[string]struct{}{
|
||||
"CMD": {},
|
||||
"RUN": {},
|
||||
@ -4142,7 +4142,7 @@ func (s *DockerSuite) TestBuildRUNErrMsg(c *check.C) {
|
||||
name := "testbuildbadrunerrmsg"
|
||||
shell := "/bin/sh -c"
|
||||
exitCode := 127
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
shell = "cmd /S /C"
|
||||
// architectural - Windows has to start the container to determine the exe is bad, Linux does not
|
||||
exitCode = 1
|
||||
@ -4294,7 +4294,7 @@ func (s *DockerTrustSuite) TestTrustedBuildTagIgnoresOtherDelegationRoles(c *che
|
||||
func (s *DockerSuite) TestBuildNullStringInAddCopyVolume(c *check.C) {
|
||||
name := "testbuildnullstringinaddcopyvolume"
|
||||
volName := "nullvolume"
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
volName = `C:\\nullvolume`
|
||||
}
|
||||
|
||||
@ -4334,7 +4334,7 @@ func (s *DockerSuite) TestBuildBuildTimeArg(c *check.C) {
|
||||
envKey := "foo"
|
||||
envVal := "bar"
|
||||
var dockerfile string
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
// Bugs in Windows busybox port - use the default base image and native cmd stuff
|
||||
dockerfile = fmt.Sprintf(`FROM `+minimalBaseImage()+`
|
||||
ARG %s
|
||||
@ -4949,7 +4949,7 @@ func (s *DockerSuite) TestBuildMultiStageUnusedArg(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildNoNamedVolume(c *check.C) {
|
||||
volName := "testname:/foo"
|
||||
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
volName = "testname:C:\\foo"
|
||||
}
|
||||
dockerCmd(c, "run", "-v", volName, "busybox", "sh", "-c", "touch /foo/oops")
|
||||
@ -5155,7 +5155,7 @@ func (s *DockerSuite) TestBuildWorkdirWindowsPath(c *check.C) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
name := "testbuildworkdirwindowspath"
|
||||
buildImageSuccessfully(c, name, build.WithDockerfile(`
|
||||
FROM `+testEnv.MinimalBaseImage()+`
|
||||
FROM `+testEnv.PlatformDefaults.BaseImage+`
|
||||
RUN mkdir C:\\work
|
||||
WORKDIR C:\\work
|
||||
RUN if "%CD%" NEQ "C:\work" exit -1
|
||||
@ -6150,7 +6150,7 @@ func (s *DockerTrustSuite) TestBuildMultiStageTrusted(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildMultiStageMultipleBuildsWindows(c *check.C) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
dockerfile := `
|
||||
FROM ` + testEnv.MinimalBaseImage() + `
|
||||
FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
COPY foo c:\\bar`
|
||||
ctx := fakecontext.New(c, "",
|
||||
fakecontext.WithDockerfile(dockerfile),
|
||||
@ -6163,7 +6163,7 @@ func (s *DockerSuite) TestBuildMultiStageMultipleBuildsWindows(c *check.C) {
|
||||
|
||||
dockerfile = `
|
||||
FROM build1:latest
|
||||
FROM ` + testEnv.MinimalBaseImage() + `
|
||||
FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
COPY --from=0 c:\\bar /
|
||||
COPY foo /`
|
||||
ctx = fakecontext.New(c, "",
|
||||
@ -6184,8 +6184,8 @@ func (s *DockerSuite) TestBuildMultiStageMultipleBuildsWindows(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildCopyFromForbidWindowsSystemPaths(c *check.C) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
dockerfile := `
|
||||
FROM ` + testEnv.MinimalBaseImage() + `
|
||||
FROM ` + testEnv.MinimalBaseImage() + `
|
||||
FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
COPY --from=0 %s c:\\oscopy
|
||||
`
|
||||
exp := icmd.Expected{
|
||||
@ -6201,8 +6201,8 @@ func (s *DockerSuite) TestBuildCopyFromForbidWindowsSystemPaths(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildCopyFromForbidWindowsRelativePaths(c *check.C) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
dockerfile := `
|
||||
FROM ` + testEnv.MinimalBaseImage() + `
|
||||
FROM ` + testEnv.MinimalBaseImage() + `
|
||||
FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
COPY --from=0 %s c:\\oscopy
|
||||
`
|
||||
exp := icmd.Expected{
|
||||
@ -6219,9 +6219,9 @@ func (s *DockerSuite) TestBuildCopyFromForbidWindowsRelativePaths(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildCopyFromWindowsIsCaseInsensitive(c *check.C) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
dockerfile := `
|
||||
FROM ` + testEnv.MinimalBaseImage() + `
|
||||
FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
COPY foo /
|
||||
FROM ` + testEnv.MinimalBaseImage() + `
|
||||
FROM ` + testEnv.PlatformDefaults.BaseImage + `
|
||||
COPY --from=0 c:\\fOo c:\\copied
|
||||
RUN type c:\\copied
|
||||
`
|
||||
@ -6301,7 +6301,7 @@ func (s *DockerSuite) TestBuildOpaqueDirectory(c *check.C) {
|
||||
func (s *DockerSuite) TestBuildWindowsUser(c *check.C) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
name := "testbuildwindowsuser"
|
||||
buildImage(name, build.WithDockerfile(`FROM `+testEnv.MinimalBaseImage()+`
|
||||
buildImage(name, build.WithDockerfile(`FROM `+testEnv.PlatformDefaults.BaseImage+`
|
||||
RUN net user user /add
|
||||
USER user
|
||||
RUN set username
|
||||
@ -6332,7 +6332,7 @@ func (s *DockerSuite) TestBuildWindowsEnvCaseInsensitive(c *check.C) {
|
||||
testRequires(c, DaemonIsWindows)
|
||||
name := "testbuildwindowsenvcaseinsensitive"
|
||||
buildImageSuccessfully(c, name, build.WithDockerfile(`
|
||||
FROM `+testEnv.MinimalBaseImage()+`
|
||||
FROM `+testEnv.PlatformDefaults.BaseImage+`
|
||||
ENV FOO=bar foo=baz
|
||||
`))
|
||||
res := inspectFieldJSON(c, name, "Config.Env")
|
||||
@ -6352,7 +6352,7 @@ WORKDIR /foo/bar
|
||||
|
||||
// The Windows busybox image has a blank `cmd`
|
||||
lookingFor := `["sh"]`
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
lookingFor = "null"
|
||||
}
|
||||
c.Assert(strings.TrimSpace(out), checker.Equals, lookingFor)
|
||||
|
||||
@ -635,7 +635,7 @@ func (s *DockerRegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
|
||||
// digest verification for the target layer digest.
|
||||
|
||||
// Remove distribution cache to force a re-pull of the blobs
|
||||
if err := os.RemoveAll(filepath.Join(testEnv.DockerBasePath(), "image", s.d.StorageDriver(), "distribution")); err != nil {
|
||||
if err := os.RemoveAll(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "image", s.d.StorageDriver(), "distribution")); err != nil {
|
||||
c.Fatalf("error clearing distribution cache: %v", err)
|
||||
}
|
||||
|
||||
@ -678,7 +678,7 @@ func (s *DockerSchema1RegistrySuite) TestPullFailsWithAlteredLayer(c *check.C) {
|
||||
// digest verification for the target layer digest.
|
||||
|
||||
// Remove distribution cache to force a re-pull of the blobs
|
||||
if err := os.RemoveAll(filepath.Join(testEnv.DockerBasePath(), "image", s.d.StorageDriver(), "distribution")); err != nil {
|
||||
if err := os.RemoveAll(filepath.Join(testEnv.DaemonInfo.DockerRootDir, "image", s.d.StorageDriver(), "distribution")); err != nil {
|
||||
c.Fatalf("error clearing distribution cache: %v", err)
|
||||
}
|
||||
|
||||
|
||||
@ -125,7 +125,7 @@ func (s *DockerSuite) TestCommitChange(c *check.C) {
|
||||
// ENV. On windows, the container doesn't have a `PATH` ENV variable so
|
||||
// the ordering is the same as the cli.
|
||||
expectedEnv := "[PATH=/foo DEBUG=true test=1]"
|
||||
if testEnv.DaemonPlatform() == "windows" {
|
||||
if testEnv.OSType == "windows" {
|
||||
expectedEnv = "[DEBUG=true test=1 PATH=/foo]"
|
||||
}
|
||||
|
||||
|
||||
@ -64,7 +64,7 @@ func (s *DockerSuite) TestCpCheckDestOwnership(c *check.C) {
|
||||
}
|
||||
|
||||
func getRootUIDGID() (int, int, error) {
|
||||
uidgid := strings.Split(filepath.Base(testEnv.DockerBasePath()), ".")
|
||||
uidgid := strings.Split(filepath.Base(testEnv.DaemonInfo.DockerRootDir), ".")
|
||||
if len(uidgid) == 1 {
|
||||
//user namespace remapping is not turned on; return 0
|
||||
return 0, 0, nil
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user