Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
echen-98 opened this issue May 27, 2021 · 3 comments
Closed
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.

Comments

@echen-98
Copy link
Contributor

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.

@echen-98 echen-98 added kind/enhancement Categorizes issue or PR as related to existing feature enhancements. area/runtime Issues or PRs as related to controller runtime, common reconciliation logic, etc labels May 27, 2021
@surajkota
Copy link
Member

aws-controllers-k8s/mq-controller#10

@ack-bot
Copy link
Collaborator

ack-bot commented Sep 2, 2021

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.
If this issue is safe to close now please do so with /close.
Provide feedback via https://github.com/aws-controllers-k8s/community.
/lifecycle stale

@ack-bot ack-bot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Sep 2, 2021
@RedbackThomson
Copy link
Contributor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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.
Projects
None yet
Development

No branches or pull requests

4 participants