summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/podman/containers/kill.go2
-rw-r--r--pkg/domain/entities/containers.go5
-rw-r--r--pkg/domain/infra/abi/containers.go13
-rw-r--r--pkg/domain/infra/tunnel/containers.go11
-rw-r--r--test/e2e/kill_test.go13
5 files changed, 35 insertions, 9 deletions
diff --git a/cmd/podman/containers/kill.go b/cmd/podman/containers/kill.go
index 36e3e5f59..990a6e3e7 100644
--- a/cmd/podman/containers/kill.go
+++ b/cmd/podman/containers/kill.go
@@ -111,7 +111,7 @@ func kill(_ *cobra.Command, args []string) error {
}
for _, r := range responses {
if r.Err == nil {
- fmt.Println(r.Id)
+ fmt.Println(r.RawInput)
} else {
errs = append(errs, r.Err)
}
diff --git a/pkg/domain/entities/containers.go b/pkg/domain/entities/containers.go
index b89c42eab..116da888d 100644
--- a/pkg/domain/entities/containers.go
+++ b/pkg/domain/entities/containers.go
@@ -110,8 +110,9 @@ type KillOptions struct {
}
type KillReport struct {
- Err error
- Id string //nolint
+ Err error
+ Id string //nolint
+ RawInput string
}
type RestartOptions struct {
diff --git a/pkg/domain/infra/abi/containers.go b/pkg/domain/infra/abi/containers.go
index 9bef97a5c..0ee4048d1 100644
--- a/pkg/domain/infra/abi/containers.go
+++ b/pkg/domain/infra/abi/containers.go
@@ -208,15 +208,22 @@ func (ic *ContainerEngine) ContainerKill(ctx context.Context, namesOrIds []strin
if err != nil {
return nil, err
}
- ctrs, err := getContainersByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
+ ctrs, rawInputs, err := getContainersAndInputByContext(options.All, options.Latest, namesOrIds, ic.Libpod)
if err != nil {
return nil, err
}
+ ctrMap := map[string]string{}
+ if len(rawInputs) == len(ctrs) {
+ for i := range ctrs {
+ ctrMap[ctrs[i].ID()] = rawInputs[i]
+ }
+ }
reports := make([]*entities.KillReport, 0, len(ctrs))
for _, con := range ctrs {
reports = append(reports, &entities.KillReport{
- Id: con.ID(),
- Err: con.Kill(uint(sig)),
+ Id: con.ID(),
+ Err: con.Kill(uint(sig)),
+ RawInput: ctrMap[con.ID()],
})
}
return reports, nil
diff --git a/pkg/domain/infra/tunnel/containers.go b/pkg/domain/infra/tunnel/containers.go
index 5a83faaf0..b0a07cd27 100644
--- a/pkg/domain/infra/tunnel/containers.go
+++ b/pkg/domain/infra/tunnel/containers.go
@@ -124,16 +124,21 @@ func (ic *ContainerEngine) ContainerStop(ctx context.Context, namesOrIds []strin
}
func (ic *ContainerEngine) ContainerKill(ctx context.Context, namesOrIds []string, opts entities.KillOptions) ([]*entities.KillReport, error) {
- ctrs, err := getContainersByContext(ic.ClientCtx, opts.All, false, namesOrIds)
+ ctrs, rawInputs, err := getContainersAndInputByContext(ic.ClientCtx, opts.All, false, namesOrIds)
if err != nil {
return nil, err
}
+ ctrMap := map[string]string{}
+ for i := range ctrs {
+ ctrMap[ctrs[i].ID] = rawInputs[i]
+ }
options := new(containers.KillOptions).WithSignal(opts.Signal)
reports := make([]*entities.KillReport, 0, len(ctrs))
for _, c := range ctrs {
reports = append(reports, &entities.KillReport{
- Id: c.ID,
- Err: containers.Kill(ic.ClientCtx, c.ID, options),
+ Id: c.ID,
+ Err: containers.Kill(ic.ClientCtx, c.ID, options),
+ RawInput: ctrMap[c.ID],
})
}
return reports, nil
diff --git a/test/e2e/kill_test.go b/test/e2e/kill_test.go
index c1c1b003e..6d6fe788b 100644
--- a/test/e2e/kill_test.go
+++ b/test/e2e/kill_test.go
@@ -51,6 +51,19 @@ var _ = Describe("Podman kill", func() {
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
})
+ It("podman container kill a running container by short id", func() {
+ session := podmanTest.RunTopContainer("")
+ session.WaitWithDefaultTimeout()
+ Expect(session.ExitCode()).To(Equal(0))
+ cid := session.OutputToString()
+
+ result := podmanTest.Podman([]string{"container", "kill", cid[:5]})
+ result.WaitWithDefaultTimeout()
+ Expect(result.ExitCode()).To(Equal(0))
+ Expect(result.OutputToString()).To(Equal(cid[:5]))
+ Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
+ })
+
It("podman kill a running container by id", func() {
session := podmanTest.RunTopContainer("")
session.WaitWithDefaultTimeout()