Skip to content

[Refactor] Add common utility functions for working with conditions #806

@echen-98

Description

@echen-98

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):

Describe the solution you'd like
For the case of setting the ResourceSynced condition, each time the process goes:

  1. Figure out the status of the condition (this step depends on the resource), i.e. whether the resource can be considered synced.

  2. Create a variable to store a pointer to a condition.

  3. Determine whether a ResourceSynced condition already exists in the resource's Conditions array.
    If so, populate the variable from step 2 with a pointer to that condition.

  4. If the pointer is still nil, create a new ResourceSynced condition and append it to the resource's Conditions 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/runtimeIssues or PRs as related to controller runtime, common reconciliation logic, etckind/enhancementCategorizes issue or PR as related to existing feature enhancements.lifecycle/staleDenotes an issue or PR has remained open with no activity and has become stale.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions