@@ -328,6 +328,109 @@ var _ = Describe("Podman generate kube", func() {
328
328
Expect (pod .Spec .HostAliases [1 ]).To (HaveField ("IP" , testIP ))
329
329
})
330
330
331
+ It ("podman generate kube with network sharing" , func () {
332
+ // Expect error with default sharing options as Net namespace is shared
333
+ podName := "testPod"
334
+ podSession := podmanTest .Podman ([]string {"pod" , "create" , "--name" , podName })
335
+ podSession .WaitWithDefaultTimeout ()
336
+ Expect (podSession ).Should (Exit (0 ))
337
+
338
+ ctrSession := podmanTest .Podman ([]string {"create" , "--name" , "testCtr" , "--pod" , podName , "-p" , "9000:8000" , ALPINE , "top" })
339
+ ctrSession .WaitWithDefaultTimeout ()
340
+ Expect (ctrSession ).Should (Exit (125 ))
341
+
342
+ // Ports without Net sharing should work with ports being set for each container in the generated kube yaml
343
+ podName = "testNet"
344
+ podSession = podmanTest .Podman ([]string {"pod" , "create" , "--name" , podName , "--share" , "ipc" })
345
+ podSession .WaitWithDefaultTimeout ()
346
+ Expect (podSession ).Should (Exit (0 ))
347
+
348
+ ctr1Name := "ctr1"
349
+ ctr1Session := podmanTest .Podman ([]string {"create" , "--name" , ctr1Name , "--pod" , podName , "-p" , "9000:8000" , ALPINE , "top" })
350
+ ctr1Session .WaitWithDefaultTimeout ()
351
+ Expect (ctr1Session ).Should (Exit (0 ))
352
+
353
+ ctr2Name := "ctr2"
354
+ ctr2Session := podmanTest .Podman ([]string {"create" , "--name" , ctr2Name , "--pod" , podName , "-p" , "6000:5000" , ALPINE , "top" })
355
+ ctr2Session .WaitWithDefaultTimeout ()
356
+ Expect (ctr2Session ).Should (Exit (0 ))
357
+
358
+ kube := podmanTest .Podman ([]string {"generate" , "kube" , podName })
359
+ kube .WaitWithDefaultTimeout ()
360
+ Expect (kube ).Should (Exit (0 ))
361
+
362
+ pod := new (v1.Pod )
363
+ err := yaml .Unmarshal (kube .Out .Contents (), pod )
364
+ Expect (err ).To (BeNil ())
365
+ Expect (pod .Spec .Containers ).To (HaveLen (2 ))
366
+ Expect (pod .Spec .Containers [0 ].Ports [0 ].ContainerPort ).To (Equal (int32 (8000 )))
367
+ Expect (pod .Spec .Containers [1 ].Ports [0 ].ContainerPort ).To (Equal (int32 (5000 )))
368
+ Expect (pod .Spec .Containers [0 ].Ports [0 ].HostPort ).To (Equal (int32 (9000 )))
369
+ Expect (pod .Spec .Containers [1 ].Ports [0 ].HostPort ).To (Equal (int32 (6000 )))
370
+ })
371
+
372
+ It ("podman generate kube with and without hostname" , func () {
373
+ // Expect error with default sharing options as UTS namespace is shared
374
+ podName := "testPod"
375
+ podSession := podmanTest .Podman ([]string {"pod" , "create" , "--name" , podName })
376
+ podSession .WaitWithDefaultTimeout ()
377
+ Expect (podSession ).Should (Exit (0 ))
378
+
379
+ ctrSession := podmanTest .Podman ([]string {"create" , "--name" , "testCtr" , "--pod" , podName , "--hostname" , "test-hostname" , ALPINE , "top" })
380
+ ctrSession .WaitWithDefaultTimeout ()
381
+ Expect (ctrSession ).Should (Exit (125 ))
382
+
383
+ // Hostname without uts sharing should work, but generated kube yaml will have pod hostname
384
+ // set to the hostname of the first container
385
+ podName = "testHostname"
386
+ podSession = podmanTest .Podman ([]string {"pod" , "create" , "--name" , podName , "--share" , "ipc" })
387
+ podSession .WaitWithDefaultTimeout ()
388
+ Expect (podSession ).Should (Exit (0 ))
389
+
390
+ ctr1Name := "ctr1"
391
+ ctr1HostName := "ctr1-hostname"
392
+ ctr1Session := podmanTest .Podman ([]string {"create" , "--name" , ctr1Name , "--pod" , podName , "--hostname" , ctr1HostName , ALPINE , "top" })
393
+ ctr1Session .WaitWithDefaultTimeout ()
394
+ Expect (ctr1Session ).Should (Exit (0 ))
395
+
396
+ ctr2Name := "ctr2"
397
+ ctr2Session := podmanTest .Podman ([]string {"create" , "--name" , ctr2Name , "--pod" , podName , ALPINE , "top" })
398
+ ctr2Session .WaitWithDefaultTimeout ()
399
+ Expect (ctr2Session ).Should (Exit (0 ))
400
+
401
+ kube := podmanTest .Podman ([]string {"generate" , "kube" , podName })
402
+ kube .WaitWithDefaultTimeout ()
403
+ Expect (kube ).Should (Exit (0 ))
404
+
405
+ pod := new (v1.Pod )
406
+ err := yaml .Unmarshal (kube .Out .Contents (), pod )
407
+ Expect (err ).To (BeNil ())
408
+ Expect (pod .Spec .Containers ).To (HaveLen (2 ))
409
+ Expect (pod .Spec .Hostname ).To (Equal (ctr1HostName ))
410
+
411
+ // No hostname
412
+
413
+ podName = "testNoHostname"
414
+ podSession = podmanTest .Podman ([]string {"pod" , "create" , "--name" , podName , "--share" , "ipc" })
415
+ podSession .WaitWithDefaultTimeout ()
416
+ Expect (podSession ).Should (Exit (0 ))
417
+
418
+ ctr3Name := "ctr3"
419
+ ctr3Session := podmanTest .Podman ([]string {"create" , "--name" , ctr3Name , "--pod" , podName , ALPINE , "top" })
420
+ ctr3Session .WaitWithDefaultTimeout ()
421
+ Expect (ctr3Session ).Should (Exit (0 ))
422
+
423
+ kube = podmanTest .Podman ([]string {"generate" , "kube" , podName })
424
+ kube .WaitWithDefaultTimeout ()
425
+ Expect (kube ).Should (Exit (0 ))
426
+
427
+ pod = new (v1.Pod )
428
+ err = yaml .Unmarshal (kube .Out .Contents (), pod )
429
+ Expect (err ).To (BeNil ())
430
+ Expect (pod .Spec .Containers ).To (HaveLen (1 ))
431
+ Expect (pod .Spec .Hostname ).To (BeEmpty ())
432
+ })
433
+
331
434
It ("podman generate service kube on pod" , func () {
332
435
session := podmanTest .Podman ([]string {"create" , "--pod" , "new:test-pod" , "-p" , "4000:4000/udp" , ALPINE , "ls" })
333
436
session .WaitWithDefaultTimeout ()
0 commit comments