mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Merge pull request #130496 from sreeram-venkitesh/automated-cherry-pick-of-#129946-upstream-release-1.32
Automated cherry pick of #129946: fix(pod/util): fix typo in getting pod validation options
This commit is contained in:
commit
b245ae997e
@ -415,7 +415,7 @@ func GetValidationOptionsFromPodSpecAndMeta(podSpec, oldPodSpec *api.PodSpec, po
|
||||
}
|
||||
}
|
||||
|
||||
opts.AllowPodLifecycleSleepActionZeroValue = opts.AllowPodLifecycleSleepActionZeroValue || podLifecycleSleepActionZeroValueInUse(podSpec)
|
||||
opts.AllowPodLifecycleSleepActionZeroValue = opts.AllowPodLifecycleSleepActionZeroValue || podLifecycleSleepActionZeroValueInUse(oldPodSpec)
|
||||
// If oldPod has resize policy set on the restartable init container, we must allow it
|
||||
opts.AllowSidecarResizePolicy = hasRestartableInitContainerResizePolicy(oldPodSpec)
|
||||
}
|
||||
@ -772,7 +772,7 @@ func podLifecycleSleepActionZeroValueInUse(podSpec *api.PodSpec) bool {
|
||||
inUse = true
|
||||
return false
|
||||
}
|
||||
if c.Lifecycle.PostStart != nil && c.Lifecycle.PostStart.Sleep != nil && c.Lifecycle.PreStop.Sleep.Seconds == 0 {
|
||||
if c.Lifecycle.PostStart != nil && c.Lifecycle.PostStart.Sleep != nil && c.Lifecycle.PostStart.Sleep.Seconds == 0 {
|
||||
inUse = true
|
||||
return false
|
||||
}
|
||||
|
@ -4204,3 +4204,92 @@ func TestValidateAllowSidecarResizePolicy(t *testing.T) {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func TestValidateAllowPodLifecycleSleepActionZeroValue(t *testing.T) {
|
||||
testCases := []struct {
|
||||
name string
|
||||
podSpec *api.PodSpec
|
||||
expectAllowPodLifecycleSleepActionZeroValue bool
|
||||
}{
|
||||
{
|
||||
name: "no lifecycle hooks",
|
||||
podSpec: &api.PodSpec{},
|
||||
expectAllowPodLifecycleSleepActionZeroValue: false,
|
||||
},
|
||||
{
|
||||
name: "Prestop with non-zero second duration",
|
||||
podSpec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Lifecycle: &api.Lifecycle{
|
||||
PreStop: &api.LifecycleHandler{
|
||||
Sleep: &api.SleepAction{
|
||||
Seconds: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectAllowPodLifecycleSleepActionZeroValue: false,
|
||||
},
|
||||
{
|
||||
name: "PostStart with non-zero second duration",
|
||||
podSpec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Lifecycle: &api.Lifecycle{
|
||||
PostStart: &api.LifecycleHandler{
|
||||
Sleep: &api.SleepAction{
|
||||
Seconds: 1,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectAllowPodLifecycleSleepActionZeroValue: false,
|
||||
},
|
||||
{
|
||||
name: "PreStop with zero seconds",
|
||||
podSpec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Lifecycle: &api.Lifecycle{
|
||||
PreStop: &api.LifecycleHandler{
|
||||
Sleep: &api.SleepAction{
|
||||
Seconds: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectAllowPodLifecycleSleepActionZeroValue: true,
|
||||
},
|
||||
{
|
||||
name: "PostStart with zero seconds",
|
||||
podSpec: &api.PodSpec{
|
||||
Containers: []api.Container{
|
||||
{
|
||||
Lifecycle: &api.Lifecycle{
|
||||
PostStart: &api.LifecycleHandler{
|
||||
Sleep: &api.SleepAction{
|
||||
Seconds: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expectAllowPodLifecycleSleepActionZeroValue: true,
|
||||
},
|
||||
}
|
||||
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
gotOptions := GetValidationOptionsFromPodSpecAndMeta(&api.PodSpec{}, tc.podSpec, nil, nil)
|
||||
assert.Equal(t, tc.expectAllowPodLifecycleSleepActionZeroValue, gotOptions.AllowPodLifecycleSleepActionZeroValue, "AllowPodLifecycleSleepActionZeroValue")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user