Skip to content

Commit fd8ed0b

Browse files
Merge pull request #25796 from Luap99/kube-pod-empty
quadlet kube: consider empty pod as running
2 parents c89aa95 + 8d1c373 commit fd8ed0b

File tree

2 files changed

+38
-1
lines changed

2 files changed

+38
-1
lines changed

pkg/domain/infra/abi/play.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,16 @@ func (ic *ContainerEngine) PlayKube(ctx context.Context, body io.Reader, options
287287
setRanContainers := func(r *entities.PlayKubeReport) {
288288
if !ranContainers {
289289
for _, p := range r.Pods {
290+
numCons := len(p.Containers) + len(p.InitContainers)
291+
if numCons == 0 {
292+
// special case, the pod has no containers (besides infra)
293+
// That seems to be valid per https://github.com/containers/podman/issues/25786
294+
// and users could depend on it so mark it as running in that case.
295+
ranContainers = true
296+
break
297+
}
290298
// If the list of container errors is less then the total number of pod containers then we know it did start.
291-
if len(p.ContainerErrors) < len(p.Containers)+len(p.InitContainers) {
299+
if len(p.ContainerErrors) < numCons {
292300
ranContainers = true
293301
break
294302
}

test/system/252-quadlet.bats

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,35 @@ EOF
11601160
kill "$nc_pid"
11611161
}
11621162

1163+
# https://github.com/containers/podman/issues/25786
1164+
@test "quadlet kube - pod without containers" {
1165+
local port=$(random_free_port)
1166+
# Create the YAML file
1167+
pod_name="p-$(safename)"
1168+
yaml_source="$PODMAN_TMPDIR/no_cons_$(safename).yaml"
1169+
cat >$yaml_source <<EOF
1170+
apiVersion: v1
1171+
kind: Pod
1172+
metadata:
1173+
name: $pod_name
1174+
EOF
1175+
1176+
# Create the Quadlet file
1177+
local quadlet_file=$PODMAN_TMPDIR/no_cons_$(safename).kube
1178+
cat > $quadlet_file <<EOF
1179+
[Kube]
1180+
Yaml=${yaml_source}
1181+
EOF
1182+
1183+
run_quadlet "$quadlet_file"
1184+
service_setup $QUADLET_SERVICE_NAME
1185+
1186+
run_podman pod ps --format "{{.Name}}--{{.Status}}"
1187+
assert "$output" =~ "$pod_name--Running" "pod is running"
1188+
1189+
service_cleanup $QUADLET_SERVICE_NAME inactive
1190+
}
1191+
11631192
@test "quadlet - image files" {
11641193
local quadlet_tmpdir=$PODMAN_TMPDIR/quadlets
11651194

0 commit comments

Comments
 (0)