Merge pull request #17041 from vrothberg/post-run

cobra: move engine shutdown to Execute
This commit is contained in:
Daniel J Walsh 2023-01-10 12:59:17 -05:00 committed by GitHub
commit 619933a530
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 7 deletions

View file

@ -115,6 +115,22 @@ func Execute() {
}
fmt.Fprintln(os.Stderr, formatError(err))
}
if requireCleanup {
// The cobra post-run is not being executed in case of
// a previous error , so make sure that the engine(s)
// are correctly shutdown.
//
// See https://github.com/spf13/cobra/issues/914
logrus.Debugf("Shutting down engines")
if engine := registry.ImageEngine(); engine != nil {
engine.Shutdown(registry.Context())
}
if engine := registry.ContainerEngine(); engine != nil {
engine.Shutdown(registry.Context())
}
}
os.Exit(registry.GetExitCode())
}
@ -298,13 +314,6 @@ func persistentPreRunE(cmd *cobra.Command, args []string) error {
func persistentPostRunE(cmd *cobra.Command, args []string) error {
logrus.Debugf("Called %s.PersistentPostRunE(%s)", cmd.Name(), strings.Join(os.Args, " "))
if !requireCleanup {
return nil
}
registry.ImageEngine().Shutdown(registry.Context())
registry.ContainerEngine().Shutdown(registry.Context())
if registry.IsRemote() {
return nil
}

View file

@ -238,4 +238,11 @@ run_podman --noout system connection ls
is "$output" "" "output should be empty"
}
@test "podman - shutdown engines" {
run_podman --log-level=debug run --rm $IMAGE true
is "$output" ".*Shutting down engines.*"
run_podman 125 --log-level=debug run dockah://rien.de/rien:latest
is "${lines[-1]}" ".*Shutting down engines"
}
# vim: filetype=sh