@@ -4657,3 +4657,92 @@ func TestValidateInvalidLabelValueInNodeSelectorOption(t *testing.T) {
4657
4657
})
4658
4658
}
4659
4659
}
4660
+
4661
+ func TestValidateAllowPodLifecycleSleepActionZeroValue (t * testing.T ) {
4662
+ testCases := []struct {
4663
+ name string
4664
+ podSpec * api.PodSpec
4665
+ expectAllowPodLifecycleSleepActionZeroValue bool
4666
+ }{
4667
+ {
4668
+ name : "no lifecycle hooks" ,
4669
+ podSpec : & api.PodSpec {},
4670
+ expectAllowPodLifecycleSleepActionZeroValue : false ,
4671
+ },
4672
+ {
4673
+ name : "Prestop with non-zero second duration" ,
4674
+ podSpec : & api.PodSpec {
4675
+ Containers : []api.Container {
4676
+ {
4677
+ Lifecycle : & api.Lifecycle {
4678
+ PreStop : & api.LifecycleHandler {
4679
+ Sleep : & api.SleepAction {
4680
+ Seconds : 1 ,
4681
+ },
4682
+ },
4683
+ },
4684
+ },
4685
+ },
4686
+ },
4687
+ expectAllowPodLifecycleSleepActionZeroValue : false ,
4688
+ },
4689
+ {
4690
+ name : "PostStart with non-zero second duration" ,
4691
+ podSpec : & api.PodSpec {
4692
+ Containers : []api.Container {
4693
+ {
4694
+ Lifecycle : & api.Lifecycle {
4695
+ PostStart : & api.LifecycleHandler {
4696
+ Sleep : & api.SleepAction {
4697
+ Seconds : 1 ,
4698
+ },
4699
+ },
4700
+ },
4701
+ },
4702
+ },
4703
+ },
4704
+ expectAllowPodLifecycleSleepActionZeroValue : false ,
4705
+ },
4706
+ {
4707
+ name : "PreStop with zero seconds" ,
4708
+ podSpec : & api.PodSpec {
4709
+ Containers : []api.Container {
4710
+ {
4711
+ Lifecycle : & api.Lifecycle {
4712
+ PreStop : & api.LifecycleHandler {
4713
+ Sleep : & api.SleepAction {
4714
+ Seconds : 0 ,
4715
+ },
4716
+ },
4717
+ },
4718
+ },
4719
+ },
4720
+ },
4721
+ expectAllowPodLifecycleSleepActionZeroValue : true ,
4722
+ },
4723
+ {
4724
+ name : "PostStart with zero seconds" ,
4725
+ podSpec : & api.PodSpec {
4726
+ Containers : []api.Container {
4727
+ {
4728
+ Lifecycle : & api.Lifecycle {
4729
+ PostStart : & api.LifecycleHandler {
4730
+ Sleep : & api.SleepAction {
4731
+ Seconds : 0 ,
4732
+ },
4733
+ },
4734
+ },
4735
+ },
4736
+ },
4737
+ },
4738
+ expectAllowPodLifecycleSleepActionZeroValue : true ,
4739
+ },
4740
+ }
4741
+
4742
+ for _ , tc := range testCases {
4743
+ t .Run (tc .name , func (t * testing.T ) {
4744
+ gotOptions := GetValidationOptionsFromPodSpecAndMeta (& api.PodSpec {}, tc .podSpec , nil , nil )
4745
+ assert .Equal (t , tc .expectAllowPodLifecycleSleepActionZeroValue , gotOptions .AllowPodLifecycleSleepActionZeroValue , "AllowPodLifecycleSleepActionZeroValue" )
4746
+ })
4747
+ }
4748
+ }
0 commit comments