Skip to content

Commit ae8b70d

Browse files
committed
adapt documentation
1 parent 245188c commit ae8b70d

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

docs/libs/status.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,26 @@ For simplicity, all commands can be chained:
2929
updatedCons, changed := conditions.ConditionUpdater(oldCons, false).UpdateCondition("myCondition", conditions.FromBool(true), myObj.Generation, "newReason", "newMessage").Conditions()
3030
```
3131

32+
### Event Recording for Conditions
33+
34+
The condition updater can optionally record events for changed conditions. To enable event recording, call first `WithEventRecorder` and later `Record` on the `ConditionUpdater`:
35+
```go
36+
updatedCons, changed := conditions.ConditionUpdater(...).WithEventRecorder(recorder, conditions.EventIfChanged).UpdateCondition(...).Record(myObj).Conditions()
37+
```
38+
Note that `Record` records all changes (`UpdateCondition` and `RemoveCondition` calls) that happened between construction of the condition updater and the `Record` call. Changes that are done after the `Record` call will not result in events. It is therefore recommended to call this method only after all conditions have been updated. Calling `Record` multiple times will lead to duplicate events.
39+
40+
`Record` is a no-op, if either the event recorder is `nil` (most likely because `WithEventRecorder` has not been called before) or the given object is `nil`.
41+
42+
The `WithEventRecorder` method takes a verbosity as second argument. There are three known verbosity values, each of which is stored in a corresponding constant in the `conditions` package:
43+
- `perChange` (constant: `EventPerChange`)
44+
- This is the most verbose option which creates a single event for each condition that was added, removed, or changed its status. It also displays the new and/or previous status of the condition, if applicable.
45+
- `perNewStatus` (constant: `EventPerNewStatus`)
46+
- This verbosity bundles all changes to the same status in a single event. This means that it will at most record four events per conditions update: one for all conditions that became `True`, one for all that became `False`, one for all that became `Unknown`, and one for all conditions that were removed. The condition types are listed in the events, their respective previous status is not.
47+
- `ifChanged` (constant: `EventIfChanged`)
48+
- This is the least verbose option. It will always log only a single event that bundles all changes. The condition types are listed, but the event does not allow to differentiate between added, removed, or changed conditions and does not contain any information about any condition's previous or current status.
49+
50+
Setting the verbosity to any other than these values results in no events being recorded.
51+
3252
## Status Updater
3353

3454
The status updater is based on the idea that many of our resources use a status similar to this:
@@ -140,6 +160,7 @@ You can then `Build()` the status updater and run `UpdateStatus()` to do the act
140160
- The package contains constants with the field keys that are required by most of these methods. `STATUS_FIELD` refers to the `Status` field itself, the other field keys are prefixed with `STATUS_FIELD_`.
141161
- The `AllStatusFields()` function returns a list containing all status field keys, _except the one for the status field itself_, for convenience.
142162
- The `WithCustomUpdateFunc` method can be used to inject a function that performs custom logic on the resource's status. Note that while the function gets the complete object as an argument, only changes to its status will be updated by the status updater.
163+
- `WithConditionEvents` can be used to enable event recording for changed conditions. The events are automatically connected to the resource from the `ReconcileResult`'s `Object` field, no events will be recorded if that field is `nil`.
143164

144165
### The ReconcileResult
145166

0 commit comments

Comments
 (0)