فهرست منبع

Merge pull request #44208 from thaJeztah/container_cleanup_package_vars

daemon: replaced exported errors with errdefs
Brian Goff 2 سال پیش
والد
کامیت
02ee154558

+ 4 - 9
daemon/archive.go

@@ -16,11 +16,6 @@ import (
 	"github.com/pkg/errors"
 	"github.com/pkg/errors"
 )
 )
 
 
-// ErrExtractPointNotDirectory is used to convey that the operation to extract
-// a tar archive to a directory in a container has failed because the specified
-// path does not refer to a directory.
-var ErrExtractPointNotDirectory = errors.New("extraction point is not a directory")
-
 // ContainerCopy performs a deprecated operation of archiving the resource at
 // ContainerCopy performs a deprecated operation of archiving the resource at
 // the specified path in the container identified by the given name.
 // the specified path in the container identified by the given name.
 func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, error) {
 func (daemon *Daemon) ContainerCopy(name string, res string) (io.ReadCloser, error) {
@@ -97,7 +92,7 @@ func (daemon *Daemon) ContainerArchivePath(name string, path string) (content io
 // ContainerExtractToDir extracts the given archive to the specified location
 // ContainerExtractToDir extracts the given archive to the specified location
 // in the filesystem of the container identified by the given name. The given
 // in the filesystem of the container identified by the given name. The given
 // path must be of a directory in the container. If it is not, the error will
 // path must be of a directory in the container. If it is not, the error will
-// be ErrExtractPointNotDirectory. If noOverwriteDirNonDir is true then it will
+// be an errdefs.InvalidParameter. If noOverwriteDirNonDir is true then it will
 // be an error if unpacking the given content would cause an existing directory
 // be an error if unpacking the given content would cause an existing directory
 // to be replaced with a non-directory and vice versa.
 // to be replaced with a non-directory and vice versa.
 func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error {
 func (daemon *Daemon) ContainerExtractToDir(name, path string, copyUIDGID, noOverwriteDirNonDir bool, content io.Reader) error {
@@ -239,7 +234,7 @@ func (daemon *Daemon) containerArchivePath(container *container.Container, path
 
 
 // containerExtractToDir extracts the given tar archive to the specified location in the
 // containerExtractToDir extracts the given tar archive to the specified location in the
 // filesystem of this container. The given path must be of a directory in the
 // filesystem of this container. The given path must be of a directory in the
-// container. If it is not, the error will be ErrExtractPointNotDirectory. If
+// container. If it is not, the error will be an errdefs.InvalidParameter. If
 // noOverwriteDirNonDir is true then it will be an error if unpacking the
 // noOverwriteDirNonDir is true then it will be an error if unpacking the
 // given content would cause an existing directory to be replaced with a non-
 // given content would cause an existing directory to be replaced with a non-
 // directory and vice versa.
 // directory and vice versa.
@@ -288,7 +283,7 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
 	}
 	}
 
 
 	if !stat.IsDir() {
 	if !stat.IsDir() {
-		return ErrExtractPointNotDirectory
+		return errdefs.InvalidParameter(errors.New("extraction point is not a directory"))
 	}
 	}
 
 
 	// Need to check if the path is in a volume. If it is, it cannot be in a
 	// Need to check if the path is in a volume. If it is, it cannot be in a
@@ -326,7 +321,7 @@ func (daemon *Daemon) containerExtractToDir(container *container.Container, path
 	}
 	}
 
 
 	if !toVolume && container.HostConfig.ReadonlyRootfs {
 	if !toVolume && container.HostConfig.ReadonlyRootfs {
-		return ErrRootFSReadOnly
+		return errdefs.InvalidParameter(errors.New("container rootfs is marked read-only"))
 	}
 	}
 
 
 	options := daemon.defaultTarCopyOptions(noOverwriteDirNonDir)
 	options := daemon.defaultTarCopyOptions(noOverwriteDirNonDir)

+ 3 - 1
daemon/archive_unix.go

@@ -5,7 +5,9 @@ package daemon // import "github.com/docker/docker/daemon"
 
 
 import (
 import (
 	"github.com/docker/docker/container"
 	"github.com/docker/docker/container"
+	"github.com/docker/docker/errdefs"
 	volumemounts "github.com/docker/docker/volume/mounts"
 	volumemounts "github.com/docker/docker/volume/mounts"
+	"github.com/pkg/errors"
 )
 )
 
 
 // checkIfPathIsInAVolume checks if the path is in a volume. If it is, it
 // checkIfPathIsInAVolume checks if the path is in a volume. If it is, it
@@ -19,7 +21,7 @@ func checkIfPathIsInAVolume(container *container.Container, absPath string) (boo
 			if mnt.RW {
 			if mnt.RW {
 				break
 				break
 			}
 			}
-			return false, ErrVolumeReadonly
+			return false, errdefs.InvalidParameter(errors.New("mounted volume is marked read-only"))
 		}
 		}
 	}
 	}
 	return toVolume, nil
 	return toVolume, nil

+ 0 - 7
daemon/container_operations.go

@@ -26,13 +26,6 @@ import (
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 )
 )
 
 
-var (
-	// ErrRootFSReadOnly is returned when a container
-	// rootfs is marked readonly.
-	ErrRootFSReadOnly = errors.New("container rootfs is marked read-only")
-	getPortMapInfo    = getSandboxPortMapInfo
-)
-
 func (daemon *Daemon) getDNSSearchSettings(container *container.Container) []string {
 func (daemon *Daemon) getDNSSearchSettings(container *container.Container) []string {
 	if len(container.HostConfig.DNSSearch) > 0 {
 	if len(container.HostConfig.DNSSearch) > 0 {
 		return container.HostConfig.DNSSearch
 		return container.HostConfig.DNSSearch

+ 3 - 3
daemon/network.go

@@ -883,7 +883,7 @@ func buildCreateEndpointOptions(c *container.Container, n libnetwork.Network, ep
 	}
 	}
 
 
 	// Port-mapping rules belong to the container & applicable only to non-internal networks
 	// Port-mapping rules belong to the container & applicable only to non-internal networks
-	portmaps := getSandboxPortMapInfo(sb)
+	portmaps := getPortMapInfo(sb)
 	if n.Info().Internal() || len(portmaps) > 0 {
 	if n.Info().Internal() || len(portmaps) > 0 {
 		return createOptions, nil
 		return createOptions, nil
 	}
 	}
@@ -957,8 +957,8 @@ func buildCreateEndpointOptions(c *container.Container, n libnetwork.Network, ep
 	return createOptions, nil
 	return createOptions, nil
 }
 }
 
 
-// getSandboxPortMapInfo retrieves the current port-mapping programmed for the given sandbox
-func getSandboxPortMapInfo(sb libnetwork.Sandbox) nat.PortMap {
+// getPortMapInfo retrieves the current port-mapping programmed for the given sandbox
+func getPortMapInfo(sb libnetwork.Sandbox) nat.PortMap {
 	pm := nat.PortMap{}
 	pm := nat.PortMap{}
 	if sb == nil {
 	if sb == nil {
 		return pm
 		return pm

+ 0 - 6
daemon/volumes.go

@@ -21,12 +21,6 @@ import (
 	"github.com/sirupsen/logrus"
 	"github.com/sirupsen/logrus"
 )
 )
 
 
-var (
-	// ErrVolumeReadonly is used to signal an error when trying to copy data into
-	// a volume mount that is not writable.
-	ErrVolumeReadonly = errors.New("mounted volume is marked read-only")
-)
-
 type mounts []container.Mount
 type mounts []container.Mount
 
 
 // Len returns the number of mounts. Used in sorting.
 // Len returns the number of mounts. Used in sorting.

+ 2 - 5
integration-cli/docker_cli_cp_to_container_test.go

@@ -411,9 +411,7 @@ func (s *DockerCLICpSuite) TestCpToErrReadOnlyRootfs(c *testing.T) {
 	dstPath := containerCpPath(containerID, "/root/shouldNotExist")
 	dstPath := containerCpPath(containerID, "/root/shouldNotExist")
 
 
 	err := runDockerCp(c, srcPath, dstPath)
 	err := runDockerCp(c, srcPath, dstPath)
-	assert.ErrorContains(c, err, "")
-
-	assert.Assert(c, isCpCannotCopyReadOnly(err), "expected ErrContainerRootfsReadonly error, but got %T: %s", err, err)
+	assert.ErrorContains(c, err, "marked read-only")
 	assert.NilError(c, containerStartOutputEquals(c, containerID, ""), "dstPath should not have existed")
 	assert.NilError(c, containerStartOutputEquals(c, containerID, ""), "dstPath should not have existed")
 }
 }
 
 
@@ -436,8 +434,7 @@ func (s *DockerCLICpSuite) TestCpToErrReadOnlyVolume(c *testing.T) {
 	dstPath := containerCpPath(containerID, "/vol_ro/shouldNotExist")
 	dstPath := containerCpPath(containerID, "/vol_ro/shouldNotExist")
 
 
 	err := runDockerCp(c, srcPath, dstPath)
 	err := runDockerCp(c, srcPath, dstPath)
-	assert.ErrorContains(c, err, "")
+	assert.ErrorContains(c, err, "marked read-only")
 
 
-	assert.Assert(c, isCpCannotCopyReadOnly(err), "expected ErrVolumeReadonly error, but got %T: %s", err, err)
 	assert.NilError(c, containerStartOutputEquals(c, containerID, ""), "dstPath should not have existed")
 	assert.NilError(c, containerStartOutputEquals(c, containerID, ""), "dstPath should not have existed")
 }
 }

+ 0 - 4
integration-cli/docker_cli_cp_utils_test.go

@@ -232,10 +232,6 @@ func isCpCannotCopyDir(err error) bool {
 	return strings.Contains(err.Error(), archive.ErrCannotCopyDir.Error())
 	return strings.Contains(err.Error(), archive.ErrCannotCopyDir.Error())
 }
 }
 
 
-func isCpCannotCopyReadOnly(err error) bool {
-	return strings.Contains(err.Error(), "marked read-only")
-}
-
 func fileContentEquals(c *testing.T, filename, contents string) error {
 func fileContentEquals(c *testing.T, filename, contents string) error {
 	c.Helper()
 	c.Helper()