Skip to content

Migrate kubectl-datadog autoscaling cluster to client-go pager#2959

Closed
L3n41c wants to merge 1 commit intomainfrom
worktree-use-pager
Closed

Migrate kubectl-datadog autoscaling cluster to client-go pager#2959
L3n41c wants to merge 1 commit intomainfrom
worktree-use-pager

Conversation

@L3n41c
Copy link
Copy Markdown
Member

@L3n41c L3n41c commented Apr 29, 2026

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

  • `go test ./cmd/kubectl-datadog/autoscaling/cluster/...`
  • `make lint`
  • `make kubectl-datadog`
  • Manual smoke test: `kubectl datadog autoscaling cluster install` and `uninstall` on an EKS cluster.

Possible Drawbacks / Trade-offs

  • `detectClusterAutoscaler` no 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

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>
@L3n41c L3n41c closed this Apr 29, 2026
@L3n41c L3n41c deleted the worktree-use-pager branch April 29, 2026 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant