From 398e48a24a9b43511365a6f3684e7a68e26d78ed Mon Sep 17 00:00:00 2001 From: Matthew Heon Date: Thu, 11 May 2023 14:57:45 -0400 Subject: [PATCH] Change Inherit to use a pointer to a container This fixes a lint issue, but I'm keeping it in its own commit so it can be reverted independently if necessary; I don't know what side effects this may have. I don't *think* there are any issues, but I'm not sure why it wasn't a pointer in the first place, so there may have been a reason. Signed-off-by: Matthew Heon --- cmd/podman/pods/rm.go | 5 ++++- libpod/define/errors.go | 4 ++++ libpod/runtime_pod_common.go | 2 +- pkg/specgen/generate/container_create.go | 4 ++-- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cmd/podman/pods/rm.go b/cmd/podman/pods/rm.go index 69eeae21fd..9251ff9ebe 100644 --- a/cmd/podman/pods/rm.go +++ b/cmd/podman/pods/rm.go @@ -113,7 +113,10 @@ func removePods(namesOrIDs []string, rmOptions entities.PodRmOptions, printIDs b return nil } setExitCode(err) - return append(errs, err) + errs = append(errs, err) + if !strings.Contains(err.Error(), define.ErrRemovingCtrs.Error()) { + return errs + } } // in the cli, first we print out all the successful attempts diff --git a/libpod/define/errors.go b/libpod/define/errors.go index be471c27e3..9849660042 100644 --- a/libpod/define/errors.go +++ b/libpod/define/errors.go @@ -211,4 +211,8 @@ var ( // ErrConmonVersionFormat is used when the expected version format of conmon // has changed. ErrConmonVersionFormat = "conmon version changed format" + + // ErrRemovingCtrs indicates that there was an error removing all + // containers from a pod. + ErrRemovingCtrs = errors.New("removing pod containers") ) diff --git a/libpod/runtime_pod_common.go b/libpod/runtime_pod_common.go index 22375c4616..56c8a6153f 100644 --- a/libpod/runtime_pod_common.go +++ b/libpod/runtime_pod_common.go @@ -248,7 +248,7 @@ func (r *Runtime) removePod(ctx context.Context, p *Pod, removeCtrs, force bool, } if len(ctrErrors) > 0 { - return removedCtrs, fmt.Errorf("not all containers could be removed from pod %s: %w", p.ID(), define.ErrCtrExists) + return removedCtrs, fmt.Errorf("not all containers could be removed from pod %s: %w", p.ID(), define.ErrRemovingCtrs) } } diff --git a/pkg/specgen/generate/container_create.go b/pkg/specgen/generate/container_create.go index 6ce2eea2ca..65143ca641 100644 --- a/pkg/specgen/generate/container_create.go +++ b/pkg/specgen/generate/container_create.go @@ -79,7 +79,7 @@ func MakeContainer(ctx context.Context, rt *libpod.Runtime, s *specgen.SpecGener compatibleOptions := &libpod.InfraInherit{} var infraSpec *specs.Spec if infra != nil { - options, infraSpec, compatibleOptions, err = Inherit(*infra, s, rt) + options, infraSpec, compatibleOptions, err = Inherit(infra, s, rt) if err != nil { return nil, nil, nil, err } @@ -636,7 +636,7 @@ func createContainerOptions(rt *libpod.Runtime, s *specgen.SpecGenerator, pod *l return options, nil } -func Inherit(infra libpod.Container, s *specgen.SpecGenerator, rt *libpod.Runtime) (opts []libpod.CtrCreateOption, infraS *specs.Spec, compat *libpod.InfraInherit, err error) { +func Inherit(infra *libpod.Container, s *specgen.SpecGenerator, rt *libpod.Runtime) (opts []libpod.CtrCreateOption, infraS *specs.Spec, compat *libpod.InfraInherit, err error) { inheritSpec := &specgen.SpecGenerator{} _, compatibleOptions, err := ConfigToSpec(rt, inheritSpec, infra.ID()) if err != nil {