@@ -2001,4 +2001,66 @@ EXPOSE 2004-2005/tcp`, CITEST_IMAGE)
20012001 kube .WaitWithDefaultTimeout ()
20022002 Expect (kube ).Should (ExitWithError (125 , "k8s DaemonSets can only have restartPolicy set to Always" ))
20032003 })
2004+
2005+ It ("on container with healthcheck exports LivenessProbe" , func () {
2006+ ctrName := "test-hc-ctr"
2007+ session := podmanTest .Podman ([]string {
2008+ "create" , "--name" , ctrName ,
2009+ "--health-cmd" , "CMD /bin/true" ,
2010+ "--health-interval" , "10s" ,
2011+ "--health-timeout" , "5s" ,
2012+ "--health-retries" , "3" ,
2013+ "--health-start-period" , "2s" ,
2014+ CITEST_IMAGE , "top" ,
2015+ })
2016+ session .WaitWithDefaultTimeout ()
2017+ Expect (session ).Should (ExitCleanly ())
2018+
2019+ kube := podmanTest .Podman ([]string {"kube" , "generate" , ctrName })
2020+ kube .WaitWithDefaultTimeout ()
2021+ Expect (kube ).Should (ExitCleanly ())
2022+
2023+ pod := new (v1.Pod )
2024+ err := yaml .Unmarshal (kube .Out .Contents (), pod )
2025+ Expect (err ).ToNot (HaveOccurred ())
2026+ Expect (pod .Spec .Containers ).To (HaveLen (1 ))
2027+
2028+ probe := pod .Spec .Containers [0 ].LivenessProbe
2029+ Expect (probe ).ToNot (BeNil (), "LivenessProbe should be set when container has a healthcheck" )
2030+ Expect (probe .Exec ).ToNot (BeNil ())
2031+ Expect (probe .Exec .Command ).To (ContainElement ("/bin/true" ))
2032+ Expect (probe .PeriodSeconds ).To (Equal (int32 (10 )))
2033+ Expect (probe .TimeoutSeconds ).To (Equal (int32 (5 )))
2034+ Expect (probe .FailureThreshold ).To (Equal (int32 (3 )))
2035+ Expect (probe .InitialDelaySeconds ).To (Equal (int32 (2 )))
2036+ })
2037+
2038+ It ("on container with CMD-SHELL healthcheck wraps LivenessProbe with /bin/sh -c" , func () {
2039+ ctrName := "test-hc-shell-ctr"
2040+ session := podmanTest .Podman ([]string {
2041+ "create" , "--name" , ctrName ,
2042+ "--health-cmd" , "CMD-SHELL /bin/true" ,
2043+ "--health-interval" , "10s" ,
2044+ "--health-timeout" , "5s" ,
2045+ "--health-retries" , "3" ,
2046+ "--health-start-period" , "2s" ,
2047+ CITEST_IMAGE , "top" ,
2048+ })
2049+ session .WaitWithDefaultTimeout ()
2050+ Expect (session ).Should (ExitCleanly ())
2051+
2052+ kube := podmanTest .Podman ([]string {"kube" , "generate" , ctrName })
2053+ kube .WaitWithDefaultTimeout ()
2054+ Expect (kube ).Should (ExitCleanly ())
2055+
2056+ pod := new (v1.Pod )
2057+ err := yaml .Unmarshal (kube .Out .Contents (), pod )
2058+ Expect (err ).ToNot (HaveOccurred ())
2059+ Expect (pod .Spec .Containers ).To (HaveLen (1 ))
2060+
2061+ probe := pod .Spec .Containers [0 ].LivenessProbe
2062+ Expect (probe ).ToNot (BeNil (), "LivenessProbe should be set when container has a healthcheck" )
2063+ Expect (probe .Exec ).ToNot (BeNil ())
2064+ Expect (probe .Exec .Command ).To (Equal ([]string {"/bin/sh" , "-c" , "/bin/true" }))
2065+ })
20042066})
0 commit comments