quadlet kube: consider empty pod as running

Since commit 945aade38b we do tear down the kube units if all pods
failed to start. This however broke the use case of an empty pod as we
did not consider that being starting successfully which is wrong and
caused a regression for at least one user.

To fix this special case the empty pod and consider that running.

Fixes: #25786
Fixes: 945aade38b ("quadlet kube: correctly mark unit as failed")

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
This commit is contained in:
Paul Holzinger 2025-04-04 18:28:36 +02:00
parent 0a0d05b3e3
commit 8d1c373475
No known key found for this signature in database
GPG Key ID: EB145DD938A3CAF2
2 changed files with 38 additions and 1 deletions

View File

@ -287,8 +287,16 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, options
setRanContainers := func(r *entities.PlayKubeReport) {
if !ranContainers {
for _, p := range r.Pods {
numCons := len(p.Containers) + len(p.InitContainers)
if numCons == 0 {
// special case, the pod has no containers (besides infra)
// That seems to be valid per https://github.com/containers/podman/issues/25786
// and users could depend on it so mark it as running in that case.
ranContainers = true
break
}
// If the list of container errors is less then the total number of pod containers then we know it did start.
if len(p.ContainerErrors) < len(p.Containers)+len(p.InitContainers) {
if len(p.ContainerErrors) < numCons {
ranContainers = true
break
}

View File

@ -1160,6 +1160,35 @@ EOF
kill "$nc_pid"
}
# https://github.com/containers/podman/issues/25786
@test "quadlet kube - pod without containers" {
local port=$(random_free_port)
# Create the YAML file
pod_name="p-$(safename)"
yaml_source="$PODMAN_TMPDIR/no_cons_$(safename).yaml"
cat >$yaml_source <<EOF
apiVersion: v1
kind: Pod
metadata:
name: $pod_name
EOF
# Create the Quadlet file
local quadlet_file=$PODMAN_TMPDIR/no_cons_$(safename).kube
cat > $quadlet_file <<EOF
[Kube]
Yaml=${yaml_source}
EOF
run_quadlet "$quadlet_file"
service_setup $QUADLET_SERVICE_NAME
run_podman pod ps --format "{{.Name}}--{{.Status}}"
assert "$output" =~ "$pod_name--Running" "pod is running"
service_cleanup $QUADLET_SERVICE_NAME inactive
}
@test "quadlet - image files" {
local quadlet_tmpdir=$PODMAN_TMPDIR/quadlets