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

Batch tagging controller create/delete tags calls #1120

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

Conversation

shiv-amz
Copy link
Contributor

@shiv-amz shiv-amz commented Mar 21, 2025

/kind feature

What this PR does / why we need it:

  • Tagging controller runs in single threaded loop which can create backlog in clusters with large number of nodes. Added worker count of 10, which can make progress in parallel.
  • Added createTag/deleteTag batcher which batches multiple api calls into a single call with multiple instances.
  • Batching is behind option tagging-controller-enable-batching flag.

Special notes for your reviewer:
We have a similar batching for other EC2 calls in Karpenter

Sample logs, tagging multiple instances. 
createTags.go:61] Batched create tags {
  Resources: [
    "i-09c32e7b40efd2a37",
    "i-0b8387fdf8ffb4e21",
    "i-035ccfa88750fc37e",
    "i-0f1f9fd038b4a8953",
    "i-0c97fbe1fb9ad5823"
  ],
  Tags: [{
      Key: "k8s.io/cloud-provider-aws",
      Value: "test-cluster"
    }]
}

deleteTags.go:76] Batched delete tags {
  Resources: [
    "i-01288200c4829f248",
    "i-0dfc2e29029a8d5ce",
    "i-026eb630a8ad49f7b",
    "i-0b4e6e3ef3612c4f5"
  ],
  Tags: [{
      Key: "k8s.io/cloud-provider-aws"
      Value: "test-cluster"
    }]
}

Does this PR introduce a user-facing change?:
NONE

@k8s-ci-robot
Copy link
Contributor

Adding the "do-not-merge/release-note-label-needed" label because no release-note block was detected, please follow our release note process to remove it.

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 kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 21, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign mmerkes 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

@k8s-ci-robot k8s-ci-robot requested review from dims and olemarkus March 21, 2025 22:54
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If cloud-provider-aws contributors determine 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 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 Mar 21, 2025
@k8s-ci-robot
Copy link
Contributor

Hi @shiv-amz. 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 the size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. label Mar 21, 2025
@shiv-amz shiv-amz marked this pull request as draft March 21, 2025 22:58
@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 Mar 21, 2025
@shiv-amz shiv-amz marked this pull request as ready for review March 22, 2025 00:55
@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 Mar 22, 2025
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

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 the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 25, 2025
Resources []string
RateLimit float64
BurstLimit int
EnableBatching bool
Copy link
Contributor

Choose a reason for hiding this comment

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

What's the rationale for making this configurable? If it's useful, a BatchSize config option seems more flexible for tuning.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, we don't need the enable batching flag. I added this for my load testing, to easily compare results between batching versus single calls. I'll remove this in next rev.

@@ -64,6 +65,7 @@ const (
taggingControllerLabelKey = "k8s.io/cloud-provider-aws"

maxRequeuingCount = 9
workerQueueCount = 10
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems like a useful config option, similar to --concurrent-node-syncs, --concurrent-service-syncs, etc.

Comment on lines +202 to +204
for i := int32(0); i < workerQueueCount; i++ {
go wait.Until(tc.work, tc.nodeMonitorPeriod, stopCh)
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why is parallelism of API calls gated by the batching-per-call option? these seem like 2 different concerns

Copy link
Contributor Author

@shiv-amz shiv-amz Mar 25, 2025

Choose a reason for hiding this comment

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

They are related since, with single concurrent thread, batching api calls does not work. If all calls are made by single thread, they won't ever get batched. So to enable batching, parallel threads consuming from workqueue is required.

As pointed above, will make workerQueueCount as configurable, and remove the batching flag.

Copy link
Contributor

Choose a reason for hiding this comment

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

There's a lot going on here :)

Is there a simpler way we could implement this? Could a goroutine in the tagging controller poll multiple items off the queue (if they're available) and fire off the request? In Karpenter, it makes sense why we'd need a decoupled "batcher" because controller-runtime doesn't expose the underlying work queue to Reconcile, but we have some more flexibility in this controller

@cartermckinnon
Copy link
Contributor

cartermckinnon commented Mar 25, 2025

Chatted offline -- we'll split this up into 2 PR's, one that adds a simple parallelism mechanism (with a worker pool), and we'll keep iterating on the batching approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. kind/feature Categorizes issue or PR as related to a new feature. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants