[Refactor] Add common utility functions for working with conditions #806
Labels
area/runtime
Issues or PRs as related to controller runtime, common reconciliation logic, etc
kind/enhancement
Categorizes issue or PR as related to existing feature enhancements.
lifecycle/stale
Denotes an issue or PR has remained open with no activity and has become stale.
Is your feature request related to a problem?
The code to set a condition (specifically
ResourceSynced
) seems to be repeated once per resource. If a pointer to theConditions
array is passed in instead ofko
, then the code could be resource-agnostic and we might only need one function in a common repo.Examples from the ElastiCache controller (with more coming):
Describe the solution you'd like
For the case of setting the
ResourceSynced
condition, each time the process goes:Figure out the status of the condition (this step depends on the resource), i.e. whether the resource can be considered synced.
Create a variable to store a pointer to a condition.
Determine whether a
ResourceSynced
condition already exists in the resource'sConditions
array.If so, populate the variable from step 2 with a pointer to that condition.
If the pointer is still nil, create a new
ResourceSynced
condition and append it to the resource'sConditions
array.Otherwise, set the Status of the existing
ResourceSynced
condition to the value from step 1.where steps 2-4 are resource-agnostic.
Since this happens in custom code, my suggestion is to manually write a single function and place it in the runtime repo, maybe in a
conditions.go
utility file. Then this function can be referenced every time steps 2-4 need to happen (so this wouldn't involve code generation).This could also potentially be used to simplify the generated
updateConditions
code for each resource but I haven't considered that as much.Describe alternatives you've considered
Repeating the same 15-20 lines of code for every resource.
The text was updated successfully, but these errors were encountered: