[CASCL-338] Add kubectl datadog autoscaling dpa commands #3558
<a target='_blank' href='https://app.datadoghq.com/ci/pipeline-executions?query=ci_level%3Ajob+%40ci.status%3Aerror+%40git.commit.sha%3A43736646c24e64ed1d7ea3f76b6499b0f37ede71&referrer=pr-comment&start=1793180844000'><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/pipelines-warning.svg"/><img src="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/pipelines-warning-light.svg" alt="Pipelines" align="center" /></picture></a> <a target='_blank' href='https://app.datadoghq.com/ci/code-coverage/github.com%2Fdatadog%2Fdatadog-operator/pull-requests/3558'><picture><source media="(prefers-color-scheme: dark)" srcset="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/code-coverage-ok.svg"/><img src="https://static.datadoghq.com/static/images/pr_comments/software_delivery/badges_header/code-coverage-ok-light.svg" alt="Code Coverage" align="center" /></picture></a>
⚠️ Warnings
Your PR has warnings. Please review the issues below.
🚦 1 Pipeline job failed
<blockquote>
<div>
<details open>
<summary>DDCI - DataDog/datadog-operator | build_operator_image_arm64 — 🔄 Retry may pass, looks flaky</summary>
<a href="https://app.datadoghq.com/ci/pull-request/Z2l0aHViLmNvbS9kYXRhZG9nL2RhdGFkb2ctb3BlcmF0b3IvMzU1OA==?referrer=pr-comment&buildId=AwAAAaGCN5CQuYAQfAAAABhBYUdDTjVDUUFBQkh0Z3ZidHZkQVc1UU4AAAAkMDFhMTgyM2EtY2Y5OS00NGI2LWIwOTMtNGQzMzhhOWY1NTQ5AAAp5w&ciFailurePanel=job">View more details</a> · <a href="https://mosaic.us1.ddbuild.io/change-request/repository/DataDog/datadog-operator/pull/3558/request/8518132441015643425?taskExecutionId=2184758231&taskId=gitlab">View in DDCI</a>
</details>
</div>
</blockquote>
ℹ️ Info
🎯 Code Coverage (<a target='_blank' href='https://app.datadoghq.com/ci/code-coverage/github.com%2Fdatadog%2Fdatadog-operator/pull-requests/3558'>details</a>)<br>• <strong><span title="Percentage of modified executable lines covered by tests in this PR">Patch Coverage</span></strong>: 95.31%<br>• <strong><span title="Percentage of all executable lines covered by tests in the entire codebase">Overall Coverage</span></strong>: 56.92% <span title="Change in overall coverage compared to the base branch">(+0.60%)</span><br>
Useful? React with 👍 / 👎
<sub>
This comment will be updated automatically if new data arrives. <br />
🔗 Commit SHA: 4373664 | <a href="https://docs.datadoghq.com/integrations/guide/source-code-integration/#pr-comments">Docs</a> | <a href="https://app.datadoghq.com/ci/pull-request/Z2l0aHViLmNvbS9kYXRhZG9nL2RhdGFkb2ctb3BlcmF0b3IvMzU1OA==?referrer=pr-comment">View more details</a> | Give us <a href="https://dd.enterprise.slack.com/archives/C07E3U2QRMM">feedback</a>!
</sub>
<!-- codex-pull-request-review-summary -->
Codex Review Summary
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ⚠️ Failed <relative-time datetime="2026-10-06T19:48:20.787170Z">2026-10-06T19:48:20.787170Z</relative-time> | e4f1a80 | Draft marked ready |
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.
</details>
Approved these changes.
e2e tests done with last 7.85.0-rc cluster-agent version
All 45 checks pass with the latest binary, run straight from bin/darwin-arm64. It runs fine from there, with no macOS kill.
┌─────────────────┬───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┬─────────┐
│ Area │ Checks │ Result │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│ pause │ enable confirmed (Active=False/LocallyPaused), already-paused skip, disable confirmed, annotation removed │ ✅ 5/5 │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│ force-fallback │ enable warns and exits 0 (local recommender never becomes the source here), disable, annotation set then removed │ ✅ 4/4 │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│ force-replicas │ set 7 confirmed (above maxReplicas 4), set 5; set 3 while paused not applied (exit 1 with explanation); applied after │ ✅ │
│ │ unpause; unset; --replicas 0 rejected │ 11/11 │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│ force-resources │ list format, merging main then sidecar, unset -c sidecar (dry-run and real), invalid cpu=abc and gpu rejected, full unset │ ✅ │
│ │ confirmed │ 10/10 │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│ Wait robustness │ 0 rate-limiter errors in 6 timeout runs. Service account without list permission: exit 1, Forbidden shown, no rate-limiter │ ✅ 5/5 │
│ │ error, no Cluster Agent version hint │ │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│ Selection │ no selector and -A on its own rejected, --all -A dry-run then 2 DPAs paused and confirmed, no terminal without --yes │ ✅ 8/8 │
│ │ rejected, --all -n team-b, -A by name, unknown name │ │
├─────────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┼─────────┤
│ Cleanup │ no override annotations left on either DPA │ ✅ 2/2 │
└─────────────────┴───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┴─────────┘
As before, setting force-resources is never confirmed on this cluster because there's no vertical recommendation. The command explains that in its message. Actual pod changes from force-resources are still untested; that needs a cluster with real recommendations and the admission controller on.
Approved these changes.
Approved these changes.
maycmlee
clamoriniere
What does this PR do?
Adds
kubectl datadog autoscaling dpa, a set of break-glass commands that set the DatadogPodAutoscaler operational annotations without touching the spec:| Command | Annotation | Effect |
|---|---|---|
|
pause enable\|disable|autoscaling.datadoghq.com/pause| Stop / resume applying any change to the workload ||
force-fallback enable\|disable|autoscaling.datadoghq.com/force-fallback| Force the local recommender as the horizontal source ||
force-replicas set\|unset|autoscaling.datadoghq.com/force-replicas| Pin the replica count ||
force-resources set\|unset|autoscaling.datadoghq.com/force-resources| Override container cpu/memory requests and limits (merged into the current value) |Common behaviour:
-l/--label-selector, or--all.-A/--all-namespaceswidens a selection and is rejected on its own.--yesto skip);--dry-runprintsnamespace/name: current → new.--timeout, default 30s;--wait=falseto skip) for the Cluster Agent to report the override in the status:-
pause:Active=False, reasonLocallyPaused-
force-replicas:HorizontalScalingLimited, "replica count pinned to N …"-
force-resources:VerticalScalingLimited, reasonForcedByAnnotation-
force-fallback enable:status.horizontal.target.source=Local. Only a warning if not confirmed, since the local recommender may not have fresh values yet.Also fixes a typo in
pkg/plugin/common/client.go("unable to register").Motivation
Give on-call engineers a safe, auditable way to pause or override DPA autoscaling during an incident, without editing the DPA spec by hand or remembering annotation formats.
Additional Notes
pkg/clusteragent/autoscaling/workload(DataDog/datadog-agent#56984, #56985, #56988).TestContractStringspins them.force-resourcesonly applies while the DPA has a vertical recommendation; forced values are overlaid on it.force-fallback disableonly stops forcing the fallback; it does not disablespec.fallback.horizontal.enabled.Minimum Agent Versions
Agent: N/A
Cluster Agent: v7.85.0
Describe your test plan
go test -race ./cmd/kubectl-datadog/autoscaling/dpa/...1.
kubectl datadog autoscaling dpa pause enable <dpa>→ waits, prints "Confirmed by the Cluster Agent";kubectl describe dpashowsActive=False/LocallyPaused.2.
pause enable -A→ rejected;pause enable --all -A --dry-run→ lists objects.3.
force-replicas set --replicas 5 <dpa>→ workload scales to 5;unsetreleases it.4.
force-resources set -c app --requests cpu=500m <dpa>thenunset -c app.5.
force-fallback enable <dpa>without fresh local values → warning, exit 0.6. Ctrl-C at the confirmation prompt (with
--all) → aborts, nothing patched.Checklist
bug,enhancement,refactoring,documentation,tooling, and/ordependenciesqa/skip-qalabel[1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits
🤖 PR description and code assisted by Claude:claude-opus-5-5