From 13135f924f073ea6076271b2785a102f52e8bb6d Mon Sep 17 00:00:00 2001 From: Urvashi Mohnani Date: Thu, 6 Apr 2023 11:13:22 -0400 Subject: [PATCH] Properly remove the service container during kube down Ensure that we are actually looking up the service container ID and actually removing it during kube teardown for the --wait use case. This ensures that we don't have a service container waiting around in removing state before we return from kube play in the remote case. [NO NEW TESTS NEEDED] Signed-off-by: Urvashi Mohnani --- pkg/domain/infra/abi/play.go | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index d71f182885..dfcdb0ce70 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -1343,6 +1343,23 @@ func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, opt } } + // Get the service containers associated with the pods if any + serviceCtrIDs := []string{} + for _, name := range podNames { + pod, err := ic.Libpod.LookupPod(name) + if err != nil { + return nil, err + } + ctr, err := pod.ServiceContainer() + if errors.Is(err, define.ErrNoSuchCtr) { + continue + } + if err != nil { + return nil, err + } + serviceCtrIDs = append(serviceCtrIDs, ctr.ID()) + } + // Add the reports reports.StopReport, err = ic.PodStop(ctx, podNames, entities.PodStopOptions{}) if err != nil { @@ -1368,10 +1385,12 @@ func (ic *ContainerEngine) PlayKubeDown(ctx context.Context, body io.Reader, opt // Remove the service container to ensure it is removed before we return for the remote case // Needed for the clean up with podman kube play --wait in the remote case - if reports.ServiceContainerID != "" { - _, err = ic.ContainerRm(ctx, []string{reports.ServiceContainerID}, entities.RmOptions{}) - if err != nil && !errors.Is(err, define.ErrNoSuchCtr) { - return nil, err + if len(serviceCtrIDs) > 0 { + for _, ctrID := range serviceCtrIDs { + _, err = ic.ContainerRm(ctx, []string{ctrID}, entities.RmOptions{}) + if err != nil && !errors.Is(err, define.ErrNoSuchCtr) { + return nil, err + } } }