Skip to content

Commit

Permalink
Merge pull request #20189 from giuseppe/run--replace-print-only-cid
Browse files Browse the repository at this point in the history
podman: run --replace prints only the new container id
  • Loading branch information
openshift-merge-robot authored Sep 29, 2023
2 parents f3aa35a + f21c1d2 commit d602038
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion cmd/podman/containers/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ func replaceContainer(name string) error {
Force: true, // force stop & removal
Ignore: true, // ignore errors when a container doesn't exit
}
return removeContainers([]string{name}, rmOptions, false)
return removeContainers([]string{name}, rmOptions, false, true)
}

func createOrUpdateFlags(cmd *cobra.Command, vals *entities.ContainerCreateOptions) error {
Expand Down
12 changes: 8 additions & 4 deletions cmd/podman/containers/rm.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,14 @@ func rm(cmd *cobra.Command, args []string) error {
rmOptions.Depend = true
}

return removeContainers(utils.RemoveSlash(args), rmOptions, true)
return removeContainers(utils.RemoveSlash(args), rmOptions, true, false)
}

// removeContainers will remove the specified containers (names or IDs).
// Allows for sharing removal logic across commands. If setExit is set,
// removeContainers will set the exit code according to the `podman-rm` man
// page.
func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit bool) error {
func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit bool, quiet bool) error {
var errs utils.OutputErrors
responses, err := registry.ContainerEngine().ContainerRm(context.Background(), namesOrIDs, rmOptions)
if err != nil {
Expand All @@ -166,9 +166,13 @@ func removeContainers(namesOrIDs []string, rmOptions entities.RmOptions, setExit
}
errs = append(errs, r.Err)
case r.RawInput != "":
fmt.Println(r.RawInput)
if !quiet {
fmt.Println(r.RawInput)
}
default:
fmt.Println(r.Id)
if !quiet {
fmt.Println(r.Id)
}
}
}
return errs.PrintErrors()
Expand Down
5 changes: 4 additions & 1 deletion test/e2e/run_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1615,9 +1615,12 @@ VOLUME %s`, ALPINE, volPath, volPath)
// Run and replace 5 times in a row the "same" container.
ctrName := "testCtr"
for i := 0; i < 5; i++ {
session := podmanTest.Podman([]string{"run", "--detach", "--replace", "--name", ctrName, ALPINE, "/bin/sh"})
session := podmanTest.Podman([]string{"run", "--detach", "--replace", "--name", ctrName, ALPINE, "top"})
session.WaitWithDefaultTimeout()
Expect(session).Should(ExitCleanly())

// make sure Podman prints only one ID
Expect(session.OutputToString()).To(HaveLen(64))
}
})

Expand Down

2 comments on commit d602038

@packit-as-a-service
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

@lsm5
Copy link
Member

@lsm5 lsm5 commented on d602038 Sep 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

podman-next COPR build failed. @containers/packit-build please check.

This was another eln flake. There have been successful builds after this one.

Please sign in to comment.