← Back to Pull requests

[CASCL-338] Add kubectl datadog autoscaling dpa commands #3558

Merged
clamoriniere merged 30 files (2789 lines) on Oct 28, 2026 12:38 UTC
View on GitHub
clamoriniere clamoriniere commented on Oct 06, 2026 11:28 UTC
Author

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:

  • Explicit selection only: names, -l/--label-selector, or --all. -A/--all-namespaces widens a selection and is rejected on its own.

  • Confirmation prompt when more than one object is selected (--yes to skip); --dry-run prints namespace/name: current → new.

  • Values are validated client-side, because the Cluster Agent silently ignores invalid ones.

  • After patching, waits (--timeout, default 30s; --wait=false to skip) for the Cluster Agent to report the override in the status:

  • - pause: Active=False, reason LocallyPaused
    - force-replicas: HorizontalScalingLimited, "replica count pinned to N …"
    - force-resources: VerticalScalingLimited, reason ForcedByAnnotation
    - force-fallback enable: status.horizontal.target.source=Local. Only a warning if not confirmed, since the local recommender may not have fresh values yet.
  • Ctrl-C aborts cleanly at the prompt, during patching, and during the wait.
  • 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

  • Annotation keys and status strings match datadog-agent pkg/clusteragent/autoscaling/workload (DataDog/datadog-agent#56984, #56985, #56988). TestContractStrings pins them.

  • force-resources only applies while the DPA has a vertical recommendation; forced values are overlaid on it.

  • force-fallback disable only stops forcing the fallback; it does not disable spec.fallback.horizontal.enabled.
  • Minimum Agent Versions

    Agent: N/A
    Cluster Agent: v7.85.0

    Describe your test plan

  • Unit tests: go test -race ./cmd/kubectl-datadog/autoscaling/dpa/...

  • On a cluster running Cluster Agent 7.85.0 or later:

  • 1. kubectl datadog autoscaling dpa pause enable <dpa> → waits, prints "Confirmed by the Cluster Agent"; kubectl describe dpa shows Active=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; unset releases it.
    4. force-resources set -c app --requests cpu=500m <dpa> then unset -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

  • PR has at least one valid label: bug, enhancement, refactoring, documentation, tooling, and/or dependencies

  • PR has a milestone or the qa/skip-qa label

  • All commits are signed (see: [signing commits][1])
  • [1]: https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits

    🤖 PR description and code assisted by Claude:claude-opus-5-5

    Diff: 2789 lines (+2781 / -8) across 30 files Reviewer: maycmlee Review duration: 31749m
    All Vouch review confidence checks passed
    Residual risk 0.39 = Change Risk (0.95) × (1 − Review Confidence (0.59)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.95 · 2789 lines diff across 30 files
    0.95
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.22 · 3 substantive comment(s)
    0.22
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 50%
    58%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.400
    Shallow Review Depth shallow_review_depth
    0.274
    Sensitive Paths sensitive_paths
    0.095
    Mass File Touch mass_file_touch
    0.080
    Real PR Conversation Timeline
    7 items
    datadog-prod-us1-3[bot] datadog-prod-us1-3[bot] commented on Oct 06, 2026 11:33 UTC
    Bot

    <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> &nbsp;<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&amp;buildId=AwAAAaGCN5CQuYAQfAAAABhBYUdDTjVDUUFBQkh0Z3ZidHZkQVc1UU4AAAAkMDFhMTgyM2EtY2Y5OS00NGI2LWIwOTMtNGQzMzhhOWY1NTQ5AAAp5w&amp;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&amp;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>

    chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Oct 06, 2026 19:43 UTC
    Bot

    <!-- 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

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review" or "@codex security review".
  • Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

    </details>

    maycmlee maycmlee approved these changes on Oct 06, 2026 20:26 UTC
    Approved Reviewer

    Approved these changes.

    clamoriniere clamoriniere commented on Oct 06, 2026 22:45 UTC
    Author

    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.
    

    Mathew-Estafanous Mathew-Estafanous approved these changes on Oct 07, 2026 19:35 UTC
    Approved Reviewer

    Approved these changes.

    NoelM NoelM approved these changes on Oct 28, 2026 10:17 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    clamoriniere clamoriniere
    Labels
    risk: medium confidence: 58.7% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 94.7% (HIGH) · Higher = larger blast radius
    94.7%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 58.7% · Lower = rushed or shallow review
    58.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 39.1% · Moderate risk
    39.1%