From 75638a72a8bab8c7fafcdcf0cbed1f60a314a94b Mon Sep 17 00:00:00 2001 From: Daniel J Walsh Date: Wed, 22 Nov 2023 07:27:43 -0500 Subject: [PATCH] If API calls for kube play --replace, then replace pod Currently if user specifies podman kube play --replace, the pod is removed on the client side, not the server side. If the API is called with replace=true, the pod was not being removed and this called the API to fail. This PR removes the pod if it exists and the caller specifies replace=true. Fixes: https://github.com/containers/podman/discussions/20705 Signed-off-by: Daniel J Walsh --- pkg/domain/infra/abi/play.go | 5 +++++ test/apiv2/80-kube.at | 7 +++++++ 2 files changed, 12 insertions(+) diff --git a/pkg/domain/infra/abi/play.go b/pkg/domain/infra/abi/play.go index 1d1f3a6407..9a1811bd87 100644 --- a/pkg/domain/infra/abi/play.go +++ b/pkg/domain/infra/abi/play.go @@ -714,6 +714,11 @@ func (ic *ContainerEngine) playKubePod(ctx context.Context, podName string, podY podSpec.PodSpecGen.ServiceContainerID = serviceContainer.ID() } + if options.Replace { + if _, err := ic.PodRm(ctx, []string{podName}, entities.PodRmOptions{Force: true, Ignore: true}); err != nil { + return nil, nil, fmt.Errorf("replacing pod %v: %w", podName, err) + } + } // Create the Pod pod, err := generate.MakePod(&podSpec, ic.Libpod) if err != nil { diff --git a/test/apiv2/80-kube.at b/test/apiv2/80-kube.at index 91afb2dc08..ef72171215 100644 --- a/test/apiv2/80-kube.at +++ b/test/apiv2/80-kube.at @@ -48,6 +48,13 @@ t POST libpod/kube/play $YAML 200 \ .Pods[0].ContainerErrors=null \ .Pods[0].Containers[0]~[0-9a-f]\\{64\\} +t POST libpod/kube/play $YAML 500 + +t POST 'libpod/kube/play?replace=true' $YAML 200 \ + .Pods[0].ID~[0-9a-f]\\{64\\} \ + .Pods[0].ContainerErrors=null \ + .Pods[0].Containers[0]~[0-9a-f]\\{64\\} + t DELETE libpod/kube/play $YAML 200 \ .StopReport[0].Id~[0-9a-f]\\{64\\} \ .RmReport[0].Id~[0-9a-f]\\{64\\}