Migrate kubectl-datadog autoscaling cluster to client-go pager#2959
Closed
Migrate kubectl-datadog autoscaling cluster to client-go pager#2959
Conversation
Replace the manual metav1.ListOptions{Limit, Continue} pagination loops
with client-go's pager.ListPager.EachListItem in the kubectl-datadog
autoscaling cluster commands. Extend pagination to two sites that
previously fetched everything in one call: detectClusterAutoscaler
(Deployments cluster-wide) and listKarpenterNodes (label-filtered
Nodes).
In GetNodesProperties, decouple the EC2 batch size from the K8s page
size via an explicit ec2DescribeBatchSize, and use a small pendingNode
struct holding only Labels and Taints — the fields downstream needs —
to avoid copying full Node structs and pinning pager page backing
arrays.
Also replace lo.SomeBy / lo.ContainsBy with stdlib slices.ContainsFunc
where the semantics match.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What does this PR do?
Migrates the `kubectl-datadog autoscaling cluster install/uninstall` commands from manual Kubernetes list pagination loops (`metav1.ListOptions{Limit, Continue}`) to `client-go`'s `pager.ListPager.EachListItem`. Replaces several `lo.SomeBy` / `lo.ContainsBy` calls with stdlib `slices.ContainsFunc` where the semantics match.
Motivation
The previous code mixed manual pagination loops at three sites (Node and Deployment listings) with non-paginated `List()` calls at others. Moving to `pager.ListPager.EachListItem` gives a consistent high-level idiom and extends pagination to two sites that previously risked OOM on dense clusters: `detectClusterAutoscaler` (Deployments cluster-wide) and `listKarpenterNodes` (label-filtered Nodes).
In `GetNodesProperties`, the per-batch EC2 work was implicitly tied to the K8s page size. The migration decouples them via an explicit `ec2DescribeBatchSize = 100`, and stores only the Node fields downstream needs (`Labels`, `Taints`) in a small `pendingNode` struct — avoiding both deep `corev1.Node` copies and the pinning of pager page backing arrays through long-lived `*corev1.Node` references.
Describe how to test/QA your changes
Possible Drawbacks / Trade-offs
Additional Notes
None.
🤖 Generated with Claude Code