6
. "github.com/containers/podman/v5/test/utils"
7
. "github.com/onsi/ginkgo/v2"
8
. "github.com/onsi/gomega"
11
var _ = Describe("Podman pod create", func() {
13
It("podman create infra container", func() {
14
session := podmanTest.Podman([]string{"pod", "create"})
15
session.WaitWithDefaultTimeout()
16
Expect(session).Should(ExitCleanly())
17
podID := session.OutputToString()
19
check := podmanTest.Podman([]string{"pod", "ps", "-q", "--no-trunc"})
20
check.WaitWithDefaultTimeout()
21
Expect(check.OutputToString()).To(ContainSubstring(podID))
22
Expect(check.OutputToStringArray()).To(HaveLen(1))
24
check = podmanTest.Podman([]string{"ps", "-qa", "--no-trunc"})
25
check.WaitWithDefaultTimeout()
26
Expect(check.OutputToStringArray()).To(HaveLen(1))
29
It("podman start infra container", func() {
30
session := podmanTest.Podman([]string{"pod", "create"})
31
session.WaitWithDefaultTimeout()
32
Expect(session).Should(ExitCleanly())
33
podID := session.OutputToString()
35
session = podmanTest.Podman([]string{"pod", "start", podID})
36
session.WaitWithDefaultTimeout()
37
Expect(session).Should(ExitCleanly())
39
check := podmanTest.Podman([]string{"ps", "-qa", "--no-trunc", "--filter", "status=running"})
40
check.WaitWithDefaultTimeout()
41
Expect(session).Should(ExitCleanly())
42
Expect(check.OutputToStringArray()).To(HaveLen(1))
45
It("podman start infra container different image", func() {
46
session := podmanTest.Podman([]string{"pod", "create", "--infra-image", BB})
47
session.WaitWithDefaultTimeout()
48
Expect(session).Should(ExitCleanly())
49
podID := session.OutputToString()
51
session = podmanTest.Podman([]string{"pod", "start", podID})
52
session.WaitWithDefaultTimeout()
53
// If we use the default entry point, we should exit with no error
54
Expect(session).Should(ExitCleanly())
57
It("podman infra container namespaces", func() {
58
session := podmanTest.Podman([]string{"pod", "create"})
59
session.WaitWithDefaultTimeout()
60
Expect(session).Should(ExitCleanly())
61
podID := session.OutputToString()
63
session = podmanTest.Podman([]string{"pod", "start", podID})
64
session.WaitWithDefaultTimeout()
65
Expect(session).Should(ExitCleanly())
67
session = podmanTest.RunTopContainerInPod("", podID)
68
session.WaitWithDefaultTimeout()
69
Expect(session).Should(ExitCleanly())
71
check := podmanTest.Podman([]string{"ps", "-a", "--no-trunc", "--ns", "--format", "{{.Namespaces.IPC}} {{.Namespaces.NET}}"})
72
check.WaitWithDefaultTimeout()
73
Expect(session).Should(ExitCleanly())
74
Expect(check.OutputToStringArray()).To(HaveLen(2))
75
Expect(check.OutputToStringArray()[0]).To(Equal(check.OutputToStringArray()[1]))
77
check = podmanTest.Podman([]string{"ps", "-a", "--no-trunc", "--ns", "--format", "{{.IPC}} {{.NET}}"})
78
check.WaitWithDefaultTimeout()
79
Expect(session).Should(ExitCleanly())
80
Expect(check.OutputToStringArray()).To(HaveLen(2))
81
Expect(check.OutputToStringArray()[0]).To(Equal(check.OutputToStringArray()[1]))
84
It("podman pod correctly sets up NetNS", func() {
85
session := podmanTest.Podman([]string{"pod", "create", "--share", "net"})
86
session.WaitWithDefaultTimeout()
87
Expect(session).Should(ExitCleanly())
88
podID := session.OutputToString()
90
session = podmanTest.Podman([]string{"pod", "start", podID})
91
session.WaitWithDefaultTimeout()
92
Expect(session).Should(ExitCleanly())
94
session = podmanTest.Podman([]string{"run", "-d", "--pod", podID, NGINX_IMAGE})
95
session.WaitWithDefaultTimeout()
96
Expect(session).Should(ExitCleanly())
98
session = podmanTest.Podman([]string{"run", "--pod", podID, fedoraMinimal, "curl", "-s", "--retry", "2", "--retry-connrefused", "-f", "localhost:80"})
99
session.WaitWithDefaultTimeout()
100
Expect(session).Should(ExitCleanly())
102
session = podmanTest.Podman([]string{"run", fedoraMinimal, "curl", "-f", "localhost"})
103
session.WaitWithDefaultTimeout()
104
Expect(session).To(ExitWithError())
106
session = podmanTest.Podman([]string{"pod", "create", "--network", "host"})
107
session.WaitWithDefaultTimeout()
108
Expect(session).Should(ExitCleanly())
110
session = podmanTest.Podman([]string{"run", "--name", "hostCtr", "--pod", session.OutputToString(), ALPINE, "readlink", "/proc/self/ns/net"})
111
session.WaitWithDefaultTimeout()
112
Expect(session).Should(ExitCleanly())
114
ns := SystemExec("readlink", []string{"/proc/self/ns/net"})
115
ns.WaitWithDefaultTimeout()
116
Expect(ns).Should(ExitCleanly())
117
netns := ns.OutputToString()
118
Expect(netns).ToNot(BeEmpty())
120
Expect(session.OutputToString()).To(Equal(netns))
122
// Sanity Check for podman inspect
123
session = podmanTest.Podman([]string{"inspect", "--format", "'{{.NetworkSettings.SandboxKey}}'", "hostCtr"})
124
session.WaitWithDefaultTimeout()
125
Expect(session).Should(ExitCleanly())
126
Expect(session.OutputToString()).Should(Equal("''")) // no network path... host
130
It("podman pod correctly sets up IPCNS", func() {
131
session := podmanTest.Podman([]string{"pod", "create", "--share", "ipc"})
132
session.WaitWithDefaultTimeout()
133
Expect(session).Should(ExitCleanly())
134
podID := session.OutputToString()
136
session = podmanTest.Podman([]string{"pod", "start", podID})
137
session.WaitWithDefaultTimeout()
138
Expect(session).Should(ExitCleanly())
140
session = podmanTest.Podman([]string{"run", "--pod", podID, fedoraMinimal, "/bin/sh", "-c", "'touch /dev/shm/hi'"})
141
session.WaitWithDefaultTimeout()
142
if session.ExitCode() != 0 {
143
Skip("ShmDir not initialized, skipping...")
145
Expect(session).Should(ExitCleanly())
147
session = podmanTest.Podman([]string{"run", "--pod", podID, fedoraMinimal, "/bin/sh", "-c", "'ls /dev/shm'"})
148
session.WaitWithDefaultTimeout()
149
Expect(session).Should(ExitCleanly())
150
Expect(session.OutputToString()).To(Equal("hi"))
153
It("podman pod correctly sets up PIDNS", func() {
154
session := podmanTest.Podman([]string{"pod", "create", "--share", "pid", "--name", "test-pod"})
155
session.WaitWithDefaultTimeout()
156
Expect(session).Should(ExitCleanly())
157
podID := session.OutputToString()
159
session = podmanTest.Podman([]string{"pod", "start", podID})
160
session.WaitWithDefaultTimeout()
161
Expect(session).Should(ExitCleanly())
163
session = podmanTest.RunTopContainerInPod("test-ctr", podID)
164
session.WaitWithDefaultTimeout()
165
Expect(session).Should(ExitCleanly())
167
check := podmanTest.Podman([]string{"top", "test-ctr", "pid"})
168
check.WaitWithDefaultTimeout()
169
Expect(check).Should(ExitCleanly())
170
PIDs := check.OutputToStringArray()
171
Expect(PIDs).To(HaveLen(3))
173
ctrPID, _ := strconv.Atoi(PIDs[1])
174
infraPID, _ := strconv.Atoi(PIDs[2])
175
Expect(ctrPID).To(BeNumerically("<", infraPID))
178
It("podman pod doesn't share PIDNS if requested to not", func() {
179
session := podmanTest.Podman([]string{"pod", "create", "--share", "net", "--name", "test-pod"})
180
session.WaitWithDefaultTimeout()
181
Expect(session).Should(ExitCleanly())
182
podID := session.OutputToString()
184
session = podmanTest.Podman([]string{"pod", "start", podID})
185
session.WaitWithDefaultTimeout()
186
Expect(session).Should(ExitCleanly())
188
session = podmanTest.RunTopContainerInPod("test-ctr", podID)
189
session.WaitWithDefaultTimeout()
190
Expect(session).Should(ExitCleanly())
192
check := podmanTest.Podman([]string{"top", "test-ctr", "pid"})
193
check.WaitWithDefaultTimeout()
194
Expect(check).Should(ExitCleanly())
195
ctrTop := check.OutputToStringArray()
197
check = podmanTest.Podman([]string{"top", podID[:12] + "-infra", "pid"})
198
check.WaitWithDefaultTimeout()
199
Expect(check).Should(ExitCleanly())
200
infraTop := check.OutputToStringArray()
202
ctrPID, _ := strconv.Atoi(ctrTop[1])
203
infraPID, _ := strconv.Atoi(infraTop[1])
204
Expect(ctrPID).To(Equal(infraPID))
207
It("podman pod container can override pod net NS", func() {
208
session := podmanTest.Podman([]string{"pod", "create", "--share", "net"})
209
session.WaitWithDefaultTimeout()
210
Expect(session).Should(ExitCleanly())
211
podID := session.OutputToString()
213
session = podmanTest.Podman([]string{"pod", "start", podID})
214
session.WaitWithDefaultTimeout()
215
Expect(session).Should(ExitCleanly())
217
session = podmanTest.Podman([]string{"run", "-d", "--pod", podID, NGINX_IMAGE})
218
session.WaitWithDefaultTimeout()
219
Expect(session).Should(ExitCleanly())
221
session = podmanTest.Podman([]string{"run", "--pod", podID, "--network", "bridge", NGINX_IMAGE, "curl", "-f", "localhost"})
222
session.WaitWithDefaultTimeout()
223
Expect(session).To(ExitWithError())
226
It("podman pod container can override pod pid NS", func() {
227
SkipIfRootlessCgroupsV1("Not supported for rootless + CgroupsV1")
228
session := podmanTest.Podman([]string{"pod", "create", "--share", "pid"})
229
session.WaitWithDefaultTimeout()
230
Expect(session).Should(ExitCleanly())
231
podID := session.OutputToString()
233
session = podmanTest.Podman([]string{"pod", "start", podID})
234
session.WaitWithDefaultTimeout()
235
Expect(session).Should(ExitCleanly())
237
session = podmanTest.Podman([]string{"run", "--pod", podID, "--pid", "host", "-d", ALPINE, "top"})
238
session.WaitWithDefaultTimeout()
239
Expect(session).Should(ExitCleanly())
241
check := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "{{.Namespaces.PIDNS}}"})
242
check.WaitWithDefaultTimeout()
243
Expect(check).Should(ExitCleanly())
244
outputArray := check.OutputToStringArray()
245
Expect(outputArray).To(HaveLen(2))
247
check = podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "{{.PIDNS}}"})
248
check.WaitWithDefaultTimeout()
249
Expect(check).Should(ExitCleanly())
250
outputArray = check.OutputToStringArray()
251
Expect(outputArray).To(HaveLen(2))
253
PID1 := outputArray[0]
254
PID2 := outputArray[1]
255
Expect(PID1).To(Not(Equal(PID2)))
258
It("podman pod container can override pod not sharing pid", func() {
259
session := podmanTest.Podman([]string{"pod", "create", "--share", "net"})
260
session.WaitWithDefaultTimeout()
261
Expect(session).Should(ExitCleanly())
262
podID := session.OutputToString()
264
session = podmanTest.Podman([]string{"pod", "start", podID})
265
session.WaitWithDefaultTimeout()
266
Expect(session).Should(ExitCleanly())
268
session = podmanTest.Podman([]string{"run", "--pod", podID, "--pid", "pod", "-d", ALPINE, "top"})
269
session.WaitWithDefaultTimeout()
270
Expect(session).Should(ExitCleanly())
272
check := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "{{.PIDNS}}"})
273
check.WaitWithDefaultTimeout()
274
Expect(check).Should(ExitCleanly())
275
outputArray := check.OutputToStringArray()
276
Expect(outputArray).To(HaveLen(2))
278
PID1 := outputArray[0]
279
PID2 := outputArray[1]
280
Expect(PID1).To(Equal(PID2))
283
It("podman pod container can override pod ipc NS", func() {
284
session := podmanTest.Podman([]string{"pod", "create", "--share", "ipc"})
285
session.WaitWithDefaultTimeout()
286
Expect(session).Should(ExitCleanly())
287
podID := session.OutputToString()
289
session = podmanTest.Podman([]string{"pod", "start", podID})
290
session.WaitWithDefaultTimeout()
291
Expect(session).Should(ExitCleanly())
293
session = podmanTest.Podman([]string{"run", "--pod", podID, "--ipc", "host", "-d", ALPINE, "top"})
294
session.WaitWithDefaultTimeout()
295
Expect(session).Should(ExitCleanly())
297
check := podmanTest.Podman([]string{"ps", "-a", "--ns", "--format", "{{.IPC}}"})
298
check.WaitWithDefaultTimeout()
299
Expect(check).Should(ExitCleanly())
300
outputArray := check.OutputToStringArray()
301
Expect(outputArray).To(HaveLen(2))
303
PID1 := outputArray[0]
304
PID2 := outputArray[1]
305
Expect(PID1).To(Not(Equal(PID2)))
308
It("podman pod infra container deletion", func() {
309
session := podmanTest.Podman([]string{"pod", "create", "--share", "ipc"})
310
session.WaitWithDefaultTimeout()
311
Expect(session).Should(ExitCleanly())
312
podID := session.OutputToString()
314
session = podmanTest.Podman([]string{"ps", "-aq"})
315
session.WaitWithDefaultTimeout()
316
Expect(session).Should(ExitCleanly())
317
infraID := session.OutputToString()
319
session = podmanTest.Podman([]string{"rm", infraID})
320
session.WaitWithDefaultTimeout()
321
Expect(session).To(ExitWithError())
323
session = podmanTest.Podman([]string{"pod", "rm", podID})
324
session.WaitWithDefaultTimeout()
325
Expect(session).Should(ExitCleanly())
328
It("podman run in pod starts infra", func() {
329
session := podmanTest.Podman([]string{"pod", "create"})
330
session.WaitWithDefaultTimeout()
331
Expect(session).Should(ExitCleanly())
332
podID := session.OutputToString()
334
result := podmanTest.Podman([]string{"ps", "-aq"})
335
result.WaitWithDefaultTimeout()
336
Expect(result).Should(ExitCleanly())
337
infraID := result.OutputToString()
339
result = podmanTest.Podman([]string{"run", "--pod", podID, "-d", ALPINE, "top"})
340
result.WaitWithDefaultTimeout()
341
Expect(result).Should(ExitCleanly())
343
result = podmanTest.Podman([]string{"ps", "-aq"})
344
result.WaitWithDefaultTimeout()
345
Expect(result).Should(ExitCleanly())
346
Expect(result.OutputToStringArray()).ShouldNot(BeEmpty())
348
Expect(result.OutputToString()).To(ContainSubstring(infraID))
351
It("podman start in pod starts infra", func() {
352
session := podmanTest.Podman([]string{"pod", "create"})
353
session.WaitWithDefaultTimeout()
354
Expect(session).Should(ExitCleanly())
355
podID := session.OutputToString()
357
result := podmanTest.Podman([]string{"ps", "-aq"})
358
result.WaitWithDefaultTimeout()
359
Expect(result).Should(ExitCleanly())
360
infraID := result.OutputToString()
362
result = podmanTest.Podman([]string{"create", "--pod", podID, ALPINE, "ls"})
363
result.WaitWithDefaultTimeout()
364
Expect(result).Should(ExitCleanly())
365
ctrID := result.OutputToString()
367
result = podmanTest.Podman([]string{"start", ctrID})
368
result.WaitWithDefaultTimeout()
369
Expect(result).Should(ExitCleanly())
371
result = podmanTest.Podman([]string{"ps", "-aq"})
372
result.WaitWithDefaultTimeout()
373
Expect(result).Should(ExitCleanly())
374
Expect(result.OutputToStringArray()).ShouldNot(BeEmpty())
376
Expect(result.OutputToString()).To(ContainSubstring(infraID))
379
It("podman run --add-host in pod should fail", func() {
380
session := podmanTest.Podman([]string{"pod", "create", "--add-host", "host1:127.0.0.1"})
381
session.WaitWithDefaultTimeout()
382
Expect(session).Should(ExitCleanly())
383
podID := session.OutputToString()
385
session = podmanTest.Podman([]string{"create", "--pod", podID, "--add-host", "foobar:127.0.0.1", ALPINE, "ping", "-c", "1", "foobar"})
386
session.WaitWithDefaultTimeout()
387
Expect(session).Should(ExitWithError())
388
Expect(session.ErrorToString()).To(ContainSubstring("extra host entries must be specified on the pod: network cannot be configured when it is shared with a pod"))
390
// verify we can see the pods hosts
391
session = podmanTest.Podman([]string{"run", "--cap-add", "net_raw", "--pod", podID, ALPINE, "ping", "-c", "1", "host1"})
392
session.WaitWithDefaultTimeout()
393
Expect(session).Should(ExitCleanly())
396
It("podman run hostname is shared", func() {
397
session := podmanTest.Podman([]string{"pod", "create"})
398
session.WaitWithDefaultTimeout()
399
Expect(session).Should(ExitCleanly())
400
podID := session.OutputToString()
402
// verify we can add a host to the infra's /etc/hosts
403
session = podmanTest.Podman([]string{"run", "--pod", podID, ALPINE, "hostname"})
404
session.WaitWithDefaultTimeout()
405
Expect(session).Should(ExitCleanly())
406
hostname := session.OutputToString()
408
infraName := podID[:12] + "-infra"
409
// verify we can see the other hosts of infra's /etc/hosts
410
session = podmanTest.Podman([]string{"inspect", infraName})
411
session.WaitWithDefaultTimeout()
412
Expect(session).Should(ExitCleanly())
413
Expect(session.OutputToString()).To(ContainSubstring(hostname))
416
tests := []string{"", "none"}
417
for _, test := range tests {
419
It("podman pod create --share="+test+" should not create an infra ctr", func() {
420
session := podmanTest.Podman([]string{"pod", "create", "--share", test})
421
session.WaitWithDefaultTimeout()
422
Expect(session).Should(ExitCleanly())
424
session = podmanTest.Podman([]string{"pod", "inspect", "--format", "{{.NumContainers}}", session.OutputToString()})
425
session.WaitWithDefaultTimeout()
426
Expect(session).Should(ExitCleanly())
427
Expect(session.OutputToString()).Should(Equal("0"))