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: site/content/en/docs/user/stages-configuration.md
+41Lines changed: 41 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -88,6 +88,7 @@ Please note that `weight` only takes effect among stages with same `resourceRef`
88
88
Additionally, the `delay` field in a Stage resource allows users to specify a delay before the stage is applied,
89
89
and introduce jitter to the delay to specify the latest delay time to make the simulation more realistic.
90
90
This can be useful for simulating real-world scenarios where events do not always happen at the same time.
91
+
Please refer to [How Delay is Calculated] for more details.
91
92
92
93
By configuring the `delay`, `selector`, and `next` fields in a Stage, you can control when and how the stage is applied,
93
94
providing a flexible and scalable way to simulate real-world scenarios in your Kubernetes cluster.
@@ -152,6 +153,45 @@ if a "Change Stage" is matched. The update action itself consequently causes a n
152
153
However, this event-driven approach to applying Stages has a limitation: `kwok`won’t apply a Stage until a new event associated with that resource is received. To address the limitation,
153
154
users can utilize the `immediateNextStage` field to make the controller apply Stages immediately rather than waiting for an event pushed from the apiserver.
154
155
156
+
## How Delay is Calculated
157
+
158
+
The delay time of applying a Stage is obtained by adding a constant time period and a randomized interval,
159
+
which will be denoted by *duration* and *jitter* respectively in the following.
160
+
161
+
- `durationMilliseconds`: provides *duration*.
162
+
- `jitterDurationMilliseconds`: calculates *jitter* by *random*(`jitterDurationMilliseconds`-*duration*).
163
+
It shall be larger than `durationMilliseconds` if you want to inject jitter to the delay.
164
+
Otherwise, it will be used directly as the delay time without any randomization.
165
+
166
+
`kwok`also provides other fields to flexibly handle more situations. They are used to extract
167
+
and parse a RFC3339 timestamp field of a resource to help determine the delay time dynamically.
168
+
169
+
- `durationFrom`: calculates *duration* by `durationFrom`-*now*
170
+
- `jitterDurationFrom`: calculates *jitter* by *random*(`jitterDurationFrom`-*now*-*duration*),
171
+
where *now* is the timestamp when the delay starts.
172
+
173
+
{{< hint "info" >}}
174
+
`durationFrom`and `jitterDurationFrom` have a higher priority than `durationMilliseconds`
175
+
and `jitterDurationMilliseconds` if both are set.
176
+
{{< /hint >}}
177
+
178
+
Let’s explain a little bit about the motivation behind these two advanced fields.
179
+
But before that, for a better understanding, we briefly describe how kubelet "delete" a pod from a node.
180
+
181
+
Here are the steps to remove a pod in Kubernetes:
182
+
183
+
1. Execute the command `kubectl delete pod`. The apiserver receives the deletion request but does not immediately remove the corresponding pod resource from etcd.
184
+
2. The apiserver sets the `metadata.deletionTimestamp` field to the time the request was issued plus a short period, defined by `metadata.deletionGracePeriodSeconds` (default 30s).
185
+
3. The kubelet detects a non-null `metadata.deletionTimestamp` for a pod and starts to send a `TERM` signal to the main process of the container.
186
+
4. If the `metadata.deletionTimestamp` expires before the process stops by itself, the main process is then terminated using the `KILL` signal.
187
+
5. After all the containers in the pod have stopped running, the kubelet sends a force deletion request to the apiserver.
188
+
6. The apiserver removes the pod object from etcd.
189
+
190
+
To simulate this situation, you can set `jitterDurationFrom` of a "Delete Stage" (`next.delete: true`) to point to `metadata.deletionTimestamp`.
191
+
This will cause the deletion operation to occur at a random moment before `metadata.deletionTimestamp` expires.
192
+
You can also let `kwok` perform the deletion in a deterministic way by pointing `durationFrom` to `metadata.deletionTimple`,
193
+
making the deletion happen exactly at `metadata.deletionTimple`.
194
+
155
195
## Examples
156
196
157
197
### Node Stages
@@ -216,3 +256,4 @@ This example shows how to configure the simplest and fastest stages of Pod resou
216
256
[General Pod Stages]: https://github.com/kubernetes-sigs/kwok/tree/main/kustomize/stage/pod/general
0 commit comments