summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcdoern <cbdoer23@g.holycross.edu>2022-04-20 21:40:47 -0400
committercdoern <cbdoer23@g.holycross.edu>2022-04-21 15:00:32 -0400
commit5375401960cf0a9b716bb18eacdb07ffbb0e6da1 (patch)
treeb35639c169b65c5e5d44ccfa3e9e75fe8aa4f47f
parent02ab86a68aa3c510dc8be8aefbd1029efb657438 (diff)
downloadpodman-5375401960cf0a9b716bb18eacdb07ffbb0e6da1.tar.gz
podman-5375401960cf0a9b716bb18eacdb07ffbb0e6da1.tar.bz2
podman-5375401960cf0a9b716bb18eacdb07ffbb0e6da1.zip
podman container clone -f
add the option -f to force remove the parent container if --destory is specified resolves #13917 Signed-off-by: cdoern <cbdoer23@g.holycross.edu>
-rw-r--r--cmd/podman/containers/clone.go9
-rw-r--r--docs/source/markdown/podman-container-clone.1.md4
-rw-r--r--pkg/domain/entities/containers.go1
-rw-r--r--pkg/domain/infra/abi/containers.go2
-rw-r--r--test/e2e/container_clone_test.go32
5 files changed, 46 insertions, 2 deletions
diff --git a/cmd/podman/containers/clone.go b/cmd/podman/containers/clone.go
index 8a1473608..6912da1fc 100644
--- a/cmd/podman/containers/clone.go
+++ b/cmd/podman/containers/clone.go
@@ -38,6 +38,9 @@ func cloneFlags(cmd *cobra.Command) {
runFlagName := "run"
flags.BoolVar(&ctrClone.Run, runFlagName, false, "run the new container")
+ forceFlagName := "force"
+ flags.BoolVarP(&ctrClone.Force, forceFlagName, "f", false, "force the existing container to be destroyed")
+
common.DefineCreateFlags(cmd, &ctrClone.CreateOpts, false, true)
}
func init() {
@@ -52,7 +55,7 @@ func init() {
func clone(cmd *cobra.Command, args []string) error {
switch len(args) {
case 0:
- return errors.Wrapf(define.ErrInvalidArg, "Must Specify at least 1 argument")
+ return errors.Wrapf(define.ErrInvalidArg, "must specify at least 1 argument")
case 2:
ctrClone.CreateOpts.Name = args[1]
case 3:
@@ -68,6 +71,10 @@ func clone(cmd *cobra.Command, args []string) error {
ctrClone.RawImageName = rawImageName
}
}
+ if ctrClone.Force && !ctrClone.Destroy {
+ return errors.Wrapf(define.ErrInvalidArg, "cannot set --force without --destroy")
+ }
+
ctrClone.ID = args[0]
ctrClone.CreateOpts.IsClone = true
rep, err := registry.ContainerEngine().ContainerClone(registry.GetContext(), ctrClone)
diff --git a/docs/source/markdown/podman-container-clone.1.md b/docs/source/markdown/podman-container-clone.1.md
index 7d5e1c262..69423113d 100644
--- a/docs/source/markdown/podman-container-clone.1.md
+++ b/docs/source/markdown/podman-container-clone.1.md
@@ -125,6 +125,10 @@ If none are specified, the original container's CPU memory nodes are used.
Remove the original container that we are cloning once used to mimic the configuration.
+#### **--force**, **-f**
+
+Force removal of the original container that we are cloning. Can only be used in conjunction with **--destroy**.
+
#### **--memory**, **-m**=*limit*
Memory limit (format: `<number>[<unit>]`, where unit = b (bytes), k (kilobytes), m (megabytes), or g (gigabytes))
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index 072514d0f..99b000c2c 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -475,4 +475,5 @@ type ContainerCloneOptions struct {
Image string
RawImageName string
Run bool
+ Force bool
}
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 100842c69..db58569c5 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -1589,7 +1589,7 @@ func (ic *ContainerEngine) ContainerClone(ctx context.Context, ctrCloneOpts enti
if ctrCloneOpts.Destroy {
var time *uint
- err := ic.Libpod.RemoveContainer(context.Background(), c, false, false, time)
+ err = ic.Libpod.RemoveContainer(context.Background(), c, ctrCloneOpts.Force, false, time)
if err != nil {
return nil, err
}
diff --git a/test/e2e/container_clone_test.go b/test/e2e/container_clone_test.go
index 1d5944d1a..1ff4b3b5f 100644
--- a/test/e2e/container_clone_test.go
+++ b/test/e2e/container_clone_test.go
@@ -235,4 +235,36 @@ var _ = Describe("Podman container clone", func() {
Expect(ctrInspect.InspectContainerToJSON()[0].HostConfig.NetworkMode).Should(ContainSubstring("container:"))
})
+
+ It("podman container clone --destroy --force test", func() {
+ create := podmanTest.Podman([]string{"create", ALPINE})
+ create.WaitWithDefaultTimeout()
+ Expect(create).To(Exit(0))
+ clone := podmanTest.Podman([]string{"container", "clone", "--destroy", create.OutputToString()})
+ clone.WaitWithDefaultTimeout()
+ Expect(clone).To(Exit(0))
+
+ inspect := podmanTest.Podman([]string{"inspect", create.OutputToString()})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect).ToNot(Exit(0))
+
+ run := podmanTest.Podman([]string{"run", "-dt", ALPINE})
+ run.WaitWithDefaultTimeout()
+ Expect(run).To(Exit(0))
+ clone = podmanTest.Podman([]string{"container", "clone", "--destroy", "-f", run.OutputToString()})
+ clone.WaitWithDefaultTimeout()
+ Expect(clone).To(Exit(0))
+
+ inspect = podmanTest.Podman([]string{"inspect", run.OutputToString()})
+ inspect.WaitWithDefaultTimeout()
+ Expect(inspect).ToNot(Exit(0))
+
+ run = podmanTest.Podman([]string{"run", "-dt", ALPINE})
+ run.WaitWithDefaultTimeout()
+ Expect(run).To(Exit(0))
+ clone = podmanTest.Podman([]string{"container", "clone", "-f", run.OutputToString()})
+ clone.WaitWithDefaultTimeout()
+ Expect(clone).ToNot(Exit(0))
+
+ })
})