@@ -33,6 +33,7 @@ import (
33
33
34
34
const (
35
35
PostStartPrefix = "PostStart"
36
+ PreStopPrefix = "PreStop"
36
37
)
37
38
38
39
var containerRestartPolicyAlways = v1 .ContainerRestartPolicyAlways
@@ -596,6 +597,138 @@ var _ = SIGDescribe("[NodeConformance] Containers Lifecycle ", func() {
596
597
framework .ExpectNoError (err )
597
598
})
598
599
})
600
+
601
+ ginkgo .It ("should call the container's preStop hook and terminate it if its startup probe fails" , func () {
602
+ regular1 := "regular-1"
603
+
604
+ podSpec := & v1.Pod {
605
+ ObjectMeta : metav1.ObjectMeta {
606
+ Name : "test-pod" ,
607
+ },
608
+ Spec : v1.PodSpec {
609
+ RestartPolicy : v1 .RestartPolicyNever ,
610
+ Containers : []v1.Container {
611
+ {
612
+ Name : regular1 ,
613
+ Image : busyboxImage ,
614
+ Command : ExecCommand (regular1 , execCommand {
615
+ Delay : 100 ,
616
+ TerminationSeconds : 15 ,
617
+ ExitCode : 0 ,
618
+ }),
619
+ StartupProbe : & v1.Probe {
620
+ ProbeHandler : v1.ProbeHandler {
621
+ Exec : & v1.ExecAction {
622
+ Command : []string {
623
+ "sh" ,
624
+ "-c" ,
625
+ "exit 1" ,
626
+ },
627
+ },
628
+ },
629
+ InitialDelaySeconds : 10 ,
630
+ FailureThreshold : 1 ,
631
+ },
632
+ Lifecycle : & v1.Lifecycle {
633
+ PreStop : & v1.LifecycleHandler {
634
+ Exec : & v1.ExecAction {
635
+ Command : ExecCommand (prefixedName (PreStopPrefix , regular1 ), execCommand {
636
+ Delay : 1 ,
637
+ ExitCode : 0 ,
638
+ }),
639
+ },
640
+ },
641
+ },
642
+ },
643
+ },
644
+ },
645
+ }
646
+
647
+ preparePod (podSpec )
648
+
649
+ client := e2epod .NewPodClient (f )
650
+ podSpec = client .Create (context .TODO (), podSpec )
651
+
652
+ ginkgo .By ("Waiting for the pod to complete" )
653
+ err := e2epod .WaitForPodNoLongerRunningInNamespace (context .TODO (), f .ClientSet , podSpec .Name , podSpec .Namespace )
654
+ framework .ExpectNoError (err )
655
+
656
+ ginkgo .By ("Parsing results" )
657
+ podSpec , err = client .Get (context .TODO (), podSpec .Name , metav1.GetOptions {})
658
+ framework .ExpectNoError (err )
659
+ results := parseOutput (podSpec )
660
+
661
+ ginkgo .By ("Analyzing results" )
662
+ framework .ExpectNoError (results .RunTogether (regular1 , prefixedName (PreStopPrefix , regular1 )))
663
+ framework .ExpectNoError (results .Starts (prefixedName (PreStopPrefix , regular1 )))
664
+ framework .ExpectNoError (results .Exits (regular1 ))
665
+ })
666
+
667
+ ginkgo .It ("should call the container's preStop hook and terminate it if its liveness probe fails" , func () {
668
+ regular1 := "regular-1"
669
+
670
+ podSpec := & v1.Pod {
671
+ ObjectMeta : metav1.ObjectMeta {
672
+ Name : "test-pod" ,
673
+ },
674
+ Spec : v1.PodSpec {
675
+ RestartPolicy : v1 .RestartPolicyNever ,
676
+ Containers : []v1.Container {
677
+ {
678
+ Name : regular1 ,
679
+ Image : busyboxImage ,
680
+ Command : ExecCommand (regular1 , execCommand {
681
+ Delay : 100 ,
682
+ TerminationSeconds : 15 ,
683
+ ExitCode : 0 ,
684
+ }),
685
+ LivenessProbe : & v1.Probe {
686
+ ProbeHandler : v1.ProbeHandler {
687
+ Exec : & v1.ExecAction {
688
+ Command : []string {
689
+ "sh" ,
690
+ "-c" ,
691
+ "exit 1" ,
692
+ },
693
+ },
694
+ },
695
+ InitialDelaySeconds : 10 ,
696
+ FailureThreshold : 1 ,
697
+ },
698
+ Lifecycle : & v1.Lifecycle {
699
+ PreStop : & v1.LifecycleHandler {
700
+ Exec : & v1.ExecAction {
701
+ Command : ExecCommand (prefixedName (PreStopPrefix , regular1 ), execCommand {
702
+ Delay : 1 ,
703
+ ExitCode : 0 ,
704
+ }),
705
+ },
706
+ },
707
+ },
708
+ },
709
+ },
710
+ },
711
+ }
712
+
713
+ preparePod (podSpec )
714
+
715
+ client := e2epod .NewPodClient (f )
716
+ podSpec = client .Create (context .TODO (), podSpec )
717
+
718
+ ginkgo .By ("Waiting for the pod to complete" )
719
+ err := e2epod .WaitForPodNoLongerRunningInNamespace (context .TODO (), f .ClientSet , podSpec .Name , podSpec .Namespace )
720
+ framework .ExpectNoError (err )
721
+
722
+ ginkgo .By ("Parsing results" )
723
+ podSpec , err = client .Get (context .TODO (), podSpec .Name , metav1.GetOptions {})
724
+ framework .ExpectNoError (err )
725
+ results := parseOutput (podSpec )
726
+
727
+ ginkgo .By ("Analyzing results" )
728
+ framework .ExpectNoError (results .RunTogether (regular1 , prefixedName (PreStopPrefix , regular1 )))
729
+ framework .ExpectNoError (results .Starts (prefixedName (PreStopPrefix , regular1 )))
730
+ framework .ExpectNoError (results .Exits (regular1 ))
731
+ })
599
732
})
600
733
601
734
var _ = SIGDescribe ("[NodeAlphaFeature:SidecarContainers] Containers Lifecycle " , func () {
0 commit comments