Migrate kubectl-datadog autoscaling cluster to client-go pager#2960
Migrate kubectl-datadog autoscaling cluster to client-go pager#2960
kubectl-datadog autoscaling cluster to client-go pager#2960Conversation
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>
kubectl-datadog autoscaling cluster to client-go pager
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #2960 +/- ##
==========================================
- Coverage 41.38% 41.37% -0.02%
==========================================
Files 327 327
Lines 28952 28960 +8
==========================================
- Hits 11982 11981 -1
- Misses 16109 16120 +11
+ Partials 861 859 -2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
|
@codex review |
|
Codex Review: Didn't find any major issues. 👍 ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
Fold the predicate into the slices.ContainsFunc lambda inside
hasKarpenterControllerContainer (its only caller), and collapse
"if a { return true } return b" into "return a || b" — both branches
were structurally equivalent.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
What does this PR do?
Migrates the
kubectl-datadog autoscaling cluster install/uninstallcommands from manual Kubernetes list pagination loops (metav1.ListOptions{Limit, Continue}) toclient-go'spager.ListPager.EachListItem. Replaces severallo.SomeBy/lo.ContainsBycalls with stdlibslices.ContainsFuncwhere 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 topager.ListPager.EachListItemgives a consistent high-level idiom and extends pagination to two sites that previously risked OOM on dense clusters:detectClusterAutoscaler(Deployments cluster-wide) andlistKarpenterNodes(label-filtered Nodes).In
GetNodesProperties, the per-batch EC2 work was implicitly tied to the K8s page size. The migration decouples them via an explicitec2DescribeBatchSize = 100, and stores only the Node fields downstream needs (Labels,Taints) in a smallpendingNodestruct — avoiding both deepcorev1.Nodecopies and the pinning of pager page backing arrays through long-lived*corev1.Nodereferences.Describe how to test/QA your changes
go test ./cmd/kubectl-datadog/autoscaling/cluster/...make lintmake kubectl-datadogkubectl datadog autoscaling cluster installanduninstallon an EKS cluster.Possible Drawbacks / Trade-offs
detectClusterAutoscalerno longer warns when several Cluster Autoscaler Deployments coexist on the same cluster. The cluster-wide enumeration order is unspecified, so when multiple matches coexist (a configuration we don't expect in practice), which one wins is non-deterministic. We accept that to keep the scan short-circuited and avoid materialising every Deployment in memory.Additional Notes
None.
🤖 Generated with Claude Code