mirror of
https://github.com/containers/podman.git
synced 2025-06-24 11:28:24 +08:00
Merge pull request #9401 from rhatdan/stop
podman kill should report rawInput not container id
This commit is contained in:
@ -111,7 +111,7 @@ func kill(_ *cobra.Command, args []string) error {
|
|||||||
}
|
}
|
||||||
for _, r := range responses {
|
for _, r := range responses {
|
||||||
if r.Err == nil {
|
if r.Err == nil {
|
||||||
fmt.Println(r.Id)
|
fmt.Println(r.RawInput)
|
||||||
} else {
|
} else {
|
||||||
errs = append(errs, r.Err)
|
errs = append(errs, r.Err)
|
||||||
}
|
}
|
||||||
|
@ -112,6 +112,7 @@ type KillOptions struct {
|
|||||||
type KillReport struct {
|
type KillReport struct {
|
||||||
Err error
|
Err error
|
||||||
Id string //nolint
|
Id string //nolint
|
||||||
|
RawInput string
|
||||||
}
|
}
|
||||||
|
|
||||||
type RestartOptions struct {
|
type RestartOptions struct {
|
||||||
|
@ -208,15 +208,22 @@ func (ic *ContainerEngine) ContainerKill(ctx context.Context, namesOrIds []strin
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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))
|
reports := make([]*entities.KillReport, 0, len(ctrs))
|
||||||
for _, con := range ctrs {
|
for _, con := range ctrs {
|
||||||
reports = append(reports, &entities.KillReport{
|
reports = append(reports, &entities.KillReport{
|
||||||
Id: con.ID(),
|
Id: con.ID(),
|
||||||
Err: con.Kill(uint(sig)),
|
Err: con.Kill(uint(sig)),
|
||||||
|
RawInput: ctrMap[con.ID()],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return reports, nil
|
return reports, nil
|
||||||
|
@ -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) {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
ctrMap := map[string]string{}
|
||||||
|
for i := range ctrs {
|
||||||
|
ctrMap[ctrs[i].ID] = rawInputs[i]
|
||||||
|
}
|
||||||
options := new(containers.KillOptions).WithSignal(opts.Signal)
|
options := new(containers.KillOptions).WithSignal(opts.Signal)
|
||||||
reports := make([]*entities.KillReport, 0, len(ctrs))
|
reports := make([]*entities.KillReport, 0, len(ctrs))
|
||||||
for _, c := range ctrs {
|
for _, c := range ctrs {
|
||||||
reports = append(reports, &entities.KillReport{
|
reports = append(reports, &entities.KillReport{
|
||||||
Id: c.ID,
|
Id: c.ID,
|
||||||
Err: containers.Kill(ic.ClientCtx, c.ID, options),
|
Err: containers.Kill(ic.ClientCtx, c.ID, options),
|
||||||
|
RawInput: ctrMap[c.ID],
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
return reports, nil
|
return reports, nil
|
||||||
|
@ -51,6 +51,19 @@ var _ = Describe("Podman kill", func() {
|
|||||||
Expect(podmanTest.NumberOfContainersRunning()).To(Equal(0))
|
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() {
|
It("podman kill a running container by id", func() {
|
||||||
session := podmanTest.RunTopContainer("")
|
session := podmanTest.RunTopContainer("")
|
||||||
session.WaitWithDefaultTimeout()
|
session.WaitWithDefaultTimeout()
|
||||||
|
Reference in New Issue
Block a user