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 Status Updater to be resource agnostic #1814

Merged
merged 10 commits into from
Apr 16, 2024

Conversation

pleshakov
Copy link
Contributor

@pleshakov pleshakov commented Apr 5, 2024

Proposed changes

Problem:
Currently, the status updater is aware of what resource it is updating the status of. This makes it difficult to extend because for each new resource we add support for, we have to modify the status updater.

Solution:

Replace old status updater with two new ones

(1) Regular Updater, to update statuses of multiple resources via UpdateRequest type.

(2) LeaderAwareGroupUpdater to update statuses of groups of resources and save any pending UpdateRequests until the updater is enabled (when pod becomes leader). It uses Regular Updater.

Using groups allow replacing UpdateRequests of subset of resources, without the need to recompute UpdateRequests for all resources.

The new status package is
resource agnostic. This is accomplished by representing status update as a function (Setter).

Other updates:

  • provisioner manager uses regular Updater.
  • static manager uses LeaderAwareGroupUpdater (because it needs to support leader election)
  • framework Status setter were simplified and moved to static/status package
  • status related functions in static package were moved to static/status package.
  • Previous Build* functions were replaced with PrepareRequests functions. Such functions don't create any intermediate status representation (like it was before), but create status UpdateRequests which directly set the resource statuses.
  • static manager handler conditionally updates statuses GatewayClass
    based on manager configuration. Previously, the conditional logic was
    implemented in the Status Updater.

CLOSES -- #1071

Checklist

Before creating a PR, run through this checklist and mark each as complete.

  • I have read the CONTRIBUTING doc
  • I have added tests that prove my fix is effective or that my feature works
  • I have checked that all unit tests pass after adding my changes
  • I have updated necessary documentation
  • I have rebased my branch onto main
  • I will ensure my PR is targeting the main branch and pulling from my branch from my own fork

Release notes

If this PR introduces a change that affects users and needs to be mentioned in the release notes,
please add a brief note that summarizes the change.

NONE

Problem:
Currently, the status updater is aware of what resource it is updating
the status of. This makes it difficult to extend because for each new
resource we add support for, we have to modify the status updater.

Solution:

Replace old status updater with two new ones

(1) Regular Updater, to update statuses of multiple resources via
UpdateRequest type.

(2) LeaderAwareGroupUpdater to update statuses of groups of resources
and save any pending UpdateRequests until the updater is enabled
(when pod becomes leader). It uses Regular Updater.

Using groups allow replacing UpdateRequests of subset of resources,
without the need to recompute UpdateRequests for all resources.

The new status package is
resource agnostic. This is accomplished by representing status update
as a function (Setter).

Other updates:
- provisioner manager uses regular Updater.
- static manager uses LeaderAwareGroupUpdater (because it needs to
  support leader election)
- framework Status setter were simplified and moved to static/status
  package
- status related functions in static package were moved to
  static/status package.
- Previous Build* functions were replaced with PrepareRequests
  functions. Such functions don't create any intermediate status
  representation (like it was before), but create status UpdateRequests
  which directly set the resource statuses.

CLOSES -- nginxinc#1071
@pleshakov pleshakov requested a review from a team as a code owner April 5, 2024 22:31
@github-actions github-actions bot added the tech-debt Short-term pain, long-term benefit label Apr 5, 2024
Copy link

codecov bot commented Apr 5, 2024

Codecov Report

Attention: Patch coverage is 95.18717% with 18 lines in your changes are missing coverage. Please review.

Project coverage is 85.66%. Comparing base (3d180b2) to head (196a991).

Files Patch % Lines
internal/mode/static/manager.go 0.00% 9 Missing ⚠️
internal/mode/static/handler.go 92.85% 2 Missing and 2 partials ⚠️
internal/mode/provisioner/manager.go 0.00% 3 Missing ⚠️
internal/framework/status/updater.go 87.50% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1814      +/-   ##
==========================================
- Coverage   86.18%   85.66%   -0.52%     
==========================================
  Files          87       82       -5     
  Lines        5522     5331     -191     
  Branches       52        0      -52     
==========================================
- Hits         4759     4567     -192     
+ Misses        717      715       -2     
- Partials       46       49       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

internal/framework/helpers/helpers_test.go Outdated Show resolved Hide resolved
internal/mode/static/handler.go Outdated Show resolved Hide resolved
internal/mode/static/handler.go Outdated Show resolved Hide resolved
internal/mode/static/handler.go Outdated Show resolved Hide resolved
internal/mode/static/status/prepare_requests.go Outdated Show resolved Hide resolved
internal/mode/static/handler.go Show resolved Hide resolved
internal/mode/static/manager.go Show resolved Hide resolved
@pleshakov pleshakov requested a review from sjberman April 15, 2024 20:46
@pleshakov pleshakov requested a review from kate-osborn April 16, 2024 17:54
Copy link
Contributor

@kate-osborn kate-osborn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚀 🚀

@pleshakov pleshakov merged commit 2277050 into nginxinc:main Apr 16, 2024
40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tech-debt Short-term pain, long-term benefit
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants