-
Notifications
You must be signed in to change notification settings - Fork 272
Description
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 the Conditions
array is passed in instead of ko
, 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):
- https://github.com/aws-controllers-k8s/elasticache-controller/blob/main/pkg/resource/cache_parameter_group/custom_api.go#L302-L326
- https://github.com/aws-controllers-k8s/elasticache-controller/blob/main/pkg/resource/replication_group/custom_set_output.go#L113-L128
- https://github.com/aws-controllers-k8s/elasticache-controller/blob/main/pkg/resource/snapshot/custom_set_output.go#L88-L103
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 existingResourceSynced
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.