Skip to content

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 tags/untags a single instance at a time. Added createTag/deleteTag batcher which can batche 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?:

Improve tagging controller performance by batching tag creation and deletion API calls. Batching can be enabled using the `--tagging-controller-enable-batching` flag.

@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 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 added needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. labels Mar 22, 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.

@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 18, 2025
@cartermckinnon
Copy link
Contributor

/ok-to-test

@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 18, 2025
@shiv-amz
Copy link
Contributor Author

/ok-to-test

@k8s-ci-robot k8s-ci-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Apr 18, 2025
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. label Apr 18, 2025
@shiv-amz shiv-amz force-pushed the batcher branch 2 times, most recently from 82c48ea to c3da800 Compare April 18, 2025 23:05
@cartermckinnon
Copy link
Contributor

/lgtm
/approve

@shiv-amz can you remove the usage of controller-runtime's logging framework in a followup? We should use the same logger used in the rest of the project

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 22, 2025
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cartermckinnon

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

The pull request process is described 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 added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 22, 2025
@k8s-ci-robot k8s-ci-robot merged commit 8ab6997 into kubernetes:master Apr 22, 2025
11 checks passed
k8s-ci-robot added a commit that referenced this pull request Apr 25, 2025
…1120-#1126-upstream-release-1.32

Automated cherry pick of #1116: feat: add tagging controller delays and work queue size
#1120: Batch tagging controller create/delete tags calls
#1126: Enable concurrent worker syncs for tagging controller
k8s-ci-robot added a commit that referenced this pull request Apr 29, 2025
…1120-upstream-release-1.33

Automated cherry pick of #1116: feat: add tagging controller delays and work queue size
#1120: Batch tagging controller create/delete tags calls
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. 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. 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