mirror of https://github.com/containers/podman.git
Merge pull request #20369 from cgiradkar/Issue-16759-docs
Define better error message for container name conflicts with external storage
This commit is contained in:
commit
77d2658201
|
@ -21,6 +21,7 @@ import (
|
|||
"github.com/containers/podman/v4/pkg/domain/entities"
|
||||
"github.com/containers/podman/v4/pkg/parallel"
|
||||
"github.com/containers/podman/v4/version"
|
||||
"github.com/containers/storage"
|
||||
"github.com/sirupsen/logrus"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
@ -632,7 +633,8 @@ func rootFlags(cmd *cobra.Command, podmanConfig *entities.PodmanConfig) {
|
|||
|
||||
func formatError(err error) string {
|
||||
var message string
|
||||
if errors.Is(err, define.ErrOCIRuntime) {
|
||||
switch {
|
||||
case errors.Is(err, define.ErrOCIRuntime):
|
||||
// OCIRuntimeErrors include the reason for the failure in the
|
||||
// second to last message in the error chain.
|
||||
message = fmt.Sprintf(
|
||||
|
@ -640,7 +642,9 @@ func formatError(err error) string {
|
|||
define.ErrOCIRuntime.Error(),
|
||||
strings.TrimSuffix(err.Error(), ": "+define.ErrOCIRuntime.Error()),
|
||||
)
|
||||
} else {
|
||||
case errors.Is(err, storage.ErrDuplicateName):
|
||||
message = fmt.Sprintf("Error: %s, or use --replace to instruct Podman to do so.", err.Error())
|
||||
default:
|
||||
if logrus.IsLevelEnabled(logrus.TraceLevel) {
|
||||
message = fmt.Sprintf("Error: %+v", err)
|
||||
} else {
|
||||
|
|
|
@ -510,6 +510,11 @@ func (c *Container) setupStorage(ctx context.Context) error {
|
|||
}
|
||||
}
|
||||
if containerInfoErr != nil {
|
||||
if errors.Is(containerInfoErr, storage.ErrDuplicateName) {
|
||||
if _, err := c.runtime.LookupContainer(c.config.Name); errors.Is(err, define.ErrNoSuchCtr) {
|
||||
return fmt.Errorf("creating container storage: %w by an external entity", containerInfoErr)
|
||||
}
|
||||
}
|
||||
return fmt.Errorf("creating container storage: %w", containerInfoErr)
|
||||
}
|
||||
|
||||
|
|
|
@ -1311,4 +1311,29 @@ search | $IMAGE |
|
|||
run_podman rm -f -t0 $cid
|
||||
}
|
||||
|
||||
@test "podman create container with conflicting name" {
|
||||
local cname="$(random_string 10 | tr A-Z a-z)"
|
||||
local output_msg_ext="^Error: .*: the container name \"$cname\" is already in use by .* You have to remove that container to be able to reuse that name: that name is already in use by an external entity, or use --replace to instruct Podman to do so."
|
||||
local output_msg="^Error: .*: the container name \"$cname\" is already in use by .* You have to remove that container to be able to reuse that name: that name is already in use, or use --replace to instruct Podman to do so."
|
||||
if is_remote; then
|
||||
output_msg_ext="^Error: .*: the container name \"$cname\" is already in use by .* You have to remove that container to be able to reuse that name: that name is already in use by an external entity"
|
||||
output_msg="^Error: .*: the container name \"$cname\" is already in use by .* You have to remove that container to be able to reuse that name: that name is already in use"
|
||||
fi
|
||||
|
||||
# external container
|
||||
buildah from --name $cname scratch
|
||||
|
||||
run_podman 125 create --name $cname $IMAGE
|
||||
assert "$output" =~ "$output_msg_ext" "Trying to create two containers with same name"
|
||||
|
||||
run_podman container rm $cname
|
||||
|
||||
run_podman --noout create --name $cname $IMAGE
|
||||
|
||||
run_podman 125 create --name $cname $IMAGE
|
||||
assert "$output" =~ "$output_msg" "Trying to create two containers with same name"
|
||||
|
||||
run_podman container rm $cname
|
||||
}
|
||||
|
||||
# vim: filetype=sh
|
||||
|
|
Loading…
Reference in New Issue