You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: keps/sig-node/4818-allow-zero-value-for-sleep-action-of-prestop-hook/README.md
+21-7Lines changed: 21 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -175,20 +175,19 @@ A potential use case for this behaviour is when you need a PreStop hook to be de
175
175
176
176
### Non-Goals
177
177
178
-
N/A
178
+
- This KEP does not support adding negative values for the sleep duration.
179
+
- This KEP does not aim to provide a way to pause or delay pod termination indefinitely.
179
180
180
181
## Proposal
181
182
182
183
Introduce a `PodLifecycleSleepActionAllowZero` feature gate which is disabled by default. When the feature gate is enabled, the `validateSleepAction` method would allow values greater than or equal to zero as a valid sleep duration.
183
184
184
-
185
185
Since this update to the validation allows previously invalid values, care must be taken to support cluster downgrades safely. To accomplish this, the validation will distinguish between new resources and updates to existing resources:
186
186
187
-
188
187
- When the feature gate is disabled:
189
188
- (a) New resources will no longer allow setting zero as the sleep duration second for the PreStop hook. (no change to current validation)
190
189
- (b) Existing resources cannot be updated to have a sleep duration of zero seconds
191
-
- (c) Existing resources with a PreStop sleep duration set to zero will continue to run and use a sleep duration of zero seconds. These resources however cannot be updated without also updating the sleep duration to a non-zero value, since the validation would now fail.
190
+
- (c) Existing resources with a PreStop sleep duration set to zero will continue to run and use a sleep duration of zero seconds. These can be updated and the zero sleep duration would continue to work.
192
191
- When the feature gate is enabled:
193
192
- (c) New resources allow zero as a valid sleep duration.
194
193
- (d) Updates to existing resources will allow zero as a valid sleep duration.
@@ -220,7 +219,7 @@ The proposed change adds another layer to the `validateSleepAction` function to
220
219
}
221
220
```
222
221
223
-
If the feature gate must be turned off after it was turned on initially, users should take care to update all their resources with a PreStop sleep duration of zero seconds to a non-zero value. This can be done after the feature gate is disabled too.
222
+
Currently, the kubelet accepts `0` as a valid duration. There is no validation done at the kubelet level. All the validation for the duration itself is done at the kube-apiserver. The [runSleepHandler](https://github.com/AxeZhan/kubernetes/blob/3a96afdfefdf329c637623ae31a61d20dbdb0393/pkg/kubelet/lifecycle/handlers.go#L129-L141) in the kubelet uses the `time.After()` function from the [time](https://pkg.go.dev/time) package, which supports a `0` duration input. `time.After` also accepts negative values which are also returned immediately similar to zero. We don't support negative values however.
224
223
225
224
See the entire code changes in the WIP PR: [https://github.com/kubernetes/kubernetes/pull/127094](https://github.com/kubernetes/kubernetes/pull/127094)
226
225
@@ -294,6 +293,16 @@ extending the production code to implement this enhancement.
294
293
295
294
-`<package>`: `<date>` - `<test coverage>`
296
295
296
+
Alpha:
297
+
298
+
- Test that the runSleepHandler function returns immediately when given a duration of zero.
299
+
- Test that the validation returns an error when given an invalid duration value (e.g., a negative value).
0 commit comments