@@ -46,6 +46,7 @@ metadata:
46
46
{{ end }}
47
47
48
48
spec:
49
+ restartPolicy: {{ .RestartPolicy }}
49
50
hostname: {{ .Hostname }}
50
51
hostAliases:
51
52
{{ range .HostAliases }}
@@ -165,6 +166,7 @@ spec:
165
166
{{- end }}
166
167
{{- end }}
167
168
spec:
169
+ restartPolicy: {{ .RestartPolicy }}
168
170
hostname: {{ .Hostname }}
169
171
containers:
170
172
{{ with .Ctrs }}
@@ -274,13 +276,14 @@ func generateDeploymentKubeYaml(deployment *Deployment, fileName string) error {
274
276
275
277
// Pod describes the options a kube yaml can be configured at pod level
276
278
type Pod struct {
277
- Name string
278
- Hostname string
279
- HostAliases []HostAlias
280
- Ctrs []* Ctr
281
- Volumes []* Volume
282
- Labels map [string ]string
283
- Annotations map [string ]string
279
+ Name string
280
+ RestartPolicy string
281
+ Hostname string
282
+ HostAliases []HostAlias
283
+ Ctrs []* Ctr
284
+ Volumes []* Volume
285
+ Labels map [string ]string
286
+ Annotations map [string ]string
284
287
}
285
288
286
289
type HostAlias struct {
@@ -293,13 +296,14 @@ type HostAlias struct {
293
296
// if no containers are added, it will add the default container
294
297
func getPod (options ... podOption ) * Pod {
295
298
p := Pod {
296
- Name : defaultPodName ,
297
- Hostname : "" ,
298
- HostAliases : nil ,
299
- Ctrs : make ([]* Ctr , 0 ),
300
- Volumes : make ([]* Volume , 0 ),
301
- Labels : make (map [string ]string ),
302
- Annotations : make (map [string ]string ),
299
+ Name : defaultPodName ,
300
+ RestartPolicy : "Never" ,
301
+ Hostname : "" ,
302
+ HostAliases : nil ,
303
+ Ctrs : make ([]* Ctr , 0 ),
304
+ Volumes : make ([]* Volume , 0 ),
305
+ Labels : make (map [string ]string ),
306
+ Annotations : make (map [string ]string ),
303
307
}
304
308
for _ , option := range options {
305
309
option (& p )
@@ -312,6 +316,12 @@ func getPod(options ...podOption) *Pod {
312
316
313
317
type podOption func (* Pod )
314
318
319
+ func withPodName (name string ) podOption {
320
+ return func (pod * Pod ) {
321
+ pod .Name = name
322
+ }
323
+ }
324
+
315
325
func withHostname (h string ) podOption {
316
326
return func (pod * Pod ) {
317
327
pod .Hostname = h
@@ -333,6 +343,12 @@ func withCtr(c *Ctr) podOption {
333
343
}
334
344
}
335
345
346
+ func withRestartPolicy (policy string ) podOption {
347
+ return func (pod * Pod ) {
348
+ pod .RestartPolicy = policy
349
+ }
350
+ }
351
+
336
352
func withLabel (k , v string ) podOption {
337
353
return func (pod * Pod ) {
338
354
pod .Labels [k ] = v
@@ -649,6 +665,30 @@ var _ = Describe("Podman generate kube", func() {
649
665
Expect (inspect .OutputToString ()).To (ContainSubstring (`[echo hello world]` ))
650
666
})
651
667
668
+ It ("podman play kube test restartPolicy" , func () {
669
+ // podName, set, expect
670
+ testSli := [][]string {
671
+ {"testPod1" , "" , "always" }, // Default eqaul to always
672
+ {"testPod2" , "Always" , "always" },
673
+ {"testPod3" , "OnFailure" , "on-failure" },
674
+ {"testPod4" , "Never" , "no" },
675
+ }
676
+ for _ , v := range testSli {
677
+ pod := getPod (withPodName (v [0 ]), withRestartPolicy (v [1 ]))
678
+ err := generatePodKubeYaml (pod , kubeYaml )
679
+ Expect (err ).To (BeNil ())
680
+
681
+ kube := podmanTest .Podman ([]string {"play" , "kube" , kubeYaml })
682
+ kube .WaitWithDefaultTimeout ()
683
+ Expect (kube .ExitCode ()).To (Equal (0 ))
684
+
685
+ inspect := podmanTest .Podman ([]string {"inspect" , getCtrNameInPod (pod ), "--format" , "{{.HostConfig.RestartPolicy.Name}}" })
686
+ inspect .WaitWithDefaultTimeout ()
687
+ Expect (inspect .ExitCode ()).To (Equal (0 ))
688
+ Expect (inspect .OutputToString ()).To (Equal (v [2 ]))
689
+ }
690
+ })
691
+
652
692
It ("podman play kube test hostname" , func () {
653
693
pod := getPod ()
654
694
err := generatePodKubeYaml (pod , kubeYaml )
0 commit comments