Skip to content

WIP: feat(ccm): watch-based route controller reconciliation #131220

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

lukasmetzner
Copy link

@lukasmetzner lukasmetzner commented Apr 9, 2025

What type of PR is this?

/kind feature

What this PR does / why we need it:

The route controller in the cloud-controller-manager currently operates with a static reconciliation interval. Depending on the scale of the cluster, this can quickly lead to exceeding the rate limits set by cloud providers.

This PR introduces a new watch-based route controller that triggers reconciliation only when a node is added, deleted, or when there are updates to the Status.Addresses or PodCIDR fields.

Additionally, a new feature gate, CloudControllerManagerWatchBasedRoutesReconciliation, is introduced, which is disabled by default.

Which issue(s) this PR fixes:

Fixes #60646

Special notes for your reviewer:

KEP 5237 is currently in progress, but is looking good so far.

Does this PR introduce a user-facing change?

Add cloud-controller-manager feature gate CloudControllerManagerWatchBasedRoutesReconciliation

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 9, 2025
@k8s-ci-robot
Copy link
Contributor

Please note that we're already in Test Freeze for the release-1.33 branch. This means every merged PR will be automatically fast-forwarded via the periodic ci-fast-forward job to the release branch of the upcoming v1.33.0 release.

Fast forwards are scheduled to happen every 6 hours, whereas the most recent run was: Wed Apr 9 13:32:32 UTC 2025.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 9, 2025
@k8s-ci-robot
Copy link
Contributor

Welcome @lukasmetzner!

It looks like this is your first PR to kubernetes/kubernetes 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/kubernetes has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot k8s-ci-robot added needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 9, 2025
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If a SIG or subproject determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot
Copy link
Contributor

Hi @lukasmetzner. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository.

@k8s-ci-robot k8s-ci-robot added needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/cloudprovider sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Apr 9, 2025
@lukasmetzner lukasmetzner changed the title feat(ccm): watch-based route controller reconciliation WIP: feat(ccm): watch-based route controller reconciliation Apr 9, 2025
@lukasmetzner lukasmetzner changed the title WIP: feat(ccm): watch-based route controller reconciliation WIP: feat(ccm): event-based route controller reconciliation Apr 10, 2025
@lukasmetzner lukasmetzner changed the title WIP: feat(ccm): event-based route controller reconciliation WIP: feat(ccm): watch-based route controller reconciliation Apr 10, 2025
@aojea
Copy link
Member

aojea commented Apr 10, 2025

/ok-to-test
/assign @aojea

I do not think we need a KEP for this change, commented in the linked issue

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Apr 10, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: lukasmetzner
Once this PR has been reviewed and has the lgtm label, please assign dims for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@lukasmetzner
Copy link
Author

/retest

Comment on lines 106 to 110
// It is only necessary to reconcile the routes for any events that have the potential to impact them:
// - Node is added
// - Node is removed
// - Node .Status.Addresses is changed
// TODO: is this a reasonable assumption or are there other values that can impact the Routes?
// - Node .Spec.PodCIDRs is changed
Copy link
Member

Choose a reason for hiding this comment

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

why do we need to filter, just reconcile the node as we did before

Copy link
Author

Choose a reason for hiding this comment

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

The current situation is a reconcile every 10s and no event-based reconciliation.

Our goal is to reduce the rate of requests to cloudprovider.Routes.ListRoutes and subsequently to the cloud provider API. As node updates can happen for a number of reasons and are reasonably frequent, running the reconcile without filter, causes even more requests to the cloud provider.

Comment on lines 182 to 186
// We should still regularly run the reconcile, even if no events come in. Usually controllers use the
// `syncPeriod` for this, but for the route controller the default period is very low (5s) and not useful for
// watch-based reconciliation.
// Because of our event filters the usual resync period from the informer does not trigger reconciles.
// TODO: What time should we use?
Copy link
Member

Choose a reason for hiding this comment

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

if we do not filter on the event handlers, is not possible to use the resync period then? doing watch based and periodic at the same time is racy and we are worse than before

Copy link
Author

Choose a reason for hiding this comment

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

if we do not filter on the event handlers, is not possible to use the resync period then?

This is possible, but for the reasons mentioned in #131220 (comment) we would like to introduce filtering.

doing watch based and periodic at the same time is racy and we are worse than before

To mitigate this issue we use the workqueue with a single key (rc.workqueue.Add("routes")). This makes sure, that only a single reconcile runs at the same time.

err := func(key string) error {
defer rc.workqueue.Done(key)

// Run the route reconciliation
if err := rc.reconcileNodeRoutes(ctx); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

the point is to reconcile just the node that has changed, not all the nodes

Copy link
Author

@lukasmetzner lukasmetzner Apr 23, 2025

Choose a reason for hiding this comment

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

In our understanding the route controller is responsible for two main topics.

  1. If nodes are added, deleted or updated the corresponding routes need to created, deleted or updated.
  2. Regular reconciliation to cleanup any leftover routes, that were not processed as events, because the CCM was not running for example. In addition, this avoids exceeding limits on the cloud provider side.

1. Event-based reconciliation of single nodes

Although this is possible, we think that this might cause more requests to the cloud provider than the current implementation.

The method ListRoutes from the cloudprovider.Routes interface is the only option we have to get information from the cloud provider about existing routes. As this will always include all routes it makes sense to utilize this information directly for a full reconciliation. Otherwise, each node event will cause a full fetch of all routes from the cloud provider, which in larger clusters is worse than the current full fetch every 10s (default). In this PR we use the workqueue with a single key (rc.workqueue.Add("routes")) to deduplicate multiple node events and do a single reconcile for all nodes.

2. Regular cleanup

Events can't be used here because we need to clean up routes for nodes that have left the cluster without emitting an event (e.g. ccm outage). To do that, we need the full list of routes and nodes.

Conclusion

As we anyway need to do the cleanup regularly, and we might cause a larger overhead with respect to API requests to the cloud provider, we propose to do a full reconcile in the event handler.

@lukasmetzner lukasmetzner marked this pull request as ready for review June 11, 2025 09:59
@lukasmetzner lukasmetzner changed the title WIP: feat(ccm): watch-based route controller reconciliation feat(ccm): watch-based route controller reconciliation Jun 11, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 11, 2025
@k8s-ci-robot k8s-ci-robot requested a review from jiahuif June 11, 2025 09:59
@lukasmetzner lukasmetzner changed the title feat(ccm): watch-based route controller reconciliation WIP: feat(ccm): watch-based route controller reconciliation Jun 11, 2025
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 11, 2025
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jun 28, 2025
Introduces a new watch based route controller for the cloud-controller-manager. This prevents the exhaustion of API rate limits through an overagressive routes controller. This is further described in kubernetes#60646. The corresponding feature gate is called "CloudControllerManagerWatchBasedRoutesReconciliation".
@lukasmetzner lukasmetzner force-pushed the feat-ccm-watch-based-route-controller branch from 8f86a33 to c1bb6c8 Compare July 1, 2025 06:20
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Jul 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cloudprovider cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Overaggressive Routes Controller
3 participants