check-operator: optionally skip not-Ready nodes in the Agent upgrade check #3650
All Vouch review confidence checks passed
Residual risk 0.28 = Change Risk (0.52) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.52 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
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.388
Shallow Review Depth
shallow_review_depth
0.344
Real PR Conversation Timeline
1 comments
"Review active on #3650"
general
weight: 0.35
gabedos
What does this PR do?
Adds opt-in setting to
check-operator upgrade:AGENT_SKIP_NOT_READY_NODES.The check does not count nodes that are not Ready and whose oldest Agent pod is out of date. These nodes (
ReadyconditionFalseorUnknown) usually cannot run the new pod, so today they hold the check until its timeout.Two more settings tune the safety limits:
| Variable | Default | Effect |
|---|---|---|
|
AGENT_SKIP_NOT_READY_MAX_PCT|10| The most % of the scheduled nodes that the check can skip. Above it, the check skips none. ||
AGENT_SKIP_NOT_READY_MAX_NODE_LOOKUPS|300| The most nodes with an out-of-date Agent pod that the check looks up Above it, the check skips none. Values of 0 or less are ignored. |Motivation
The check runs as a Helm post-upgrade hook. On some internal clusters, significant % of the Agent pods sit on nodes that are
Unknown(the kubelet stopped reporting). So the check waits much longer than the rollout of the healthy nodes:kubernetes_state.daemonset.*metrics matches the logs. It also shows that the gap stayed at 45–64 pods for 30 min, close to the number of pods on dead nodes.Evidence: https://app.datadoghq.com/notebook/16020842
How it counts
The check removes nodes from
Current(currentNumberScheduled):Terminatingon a dead node still counts. This is the usual case after the controller deletes an unavailable old pod.pod-template-generationor itscontroller-revision-hashmatches. The check reads the current hash from a pod on the current generation. If there is no such pod yet, or the pod belongs to another Agent DaemonSet with the same selector, the hash is unknown, so the check skips no node of that DaemonSet. Otherwise, after a template revert, it could skip pods that the status counts as updated.nodeShouldRunDaemonPod: itsnodeName, required node affinity andnodeSelector, and itsNoSchedule/NoExecutetaints (template tolerations plus the DaemonSet default tolerations). The pod on the node may come from an older template, for example before a profile label was added to the node. The status does not count these nodes either.node.kubernetes.io/not-ready:NoScheduleandnode.kubernetes.io/unreachable:NoScheduletaints that not-Ready nodes get (for exampleoperator: Exists). Otherwise the status already leaves these nodes out.Safety limits:
AGENT_SKIP_NOT_READY_MAX_PCT(default 10%) of the scheduled nodes would be skipped, the check skips none. A large number of not-Ready nodes is more likely an outage than background churn.AGENT_SKIP_NOT_READY_MAX_PCTof the nodes removed, it makes no API call. Early in a rollout, the out-of-date pod list would return almost every Agent pod.AGENT_SKIP_NOT_READY_MAX_NODE_LOOKUPS(default 300) nodes run an out-of-date Agent pod, the check skips none.observedGenerationis behind itsgeneration.resourceVersion=0). Before Kubernetes 1.31, it would otherwise read every pod of the namespace from etcd.<DaemonSet>/<node>pairs (up to 20) and the adjusted node count.Additional Notes
listonpodsanddaemonsetsin the DatadogAgent namespace, andgetonnodes(a ClusterRole, as nodes are cluster-scoped). The hook RBAC lives in the chart that deploys the check, not in this repo.- A node whose only Agent pod is Pending with no node assigned is not skipped. This is the strict side.
- The check uses the DatadogAgent status, which the operator writes at reconcile time, together with live pods and nodes. Pods on dead nodes stay for a long time, so the risk of a mismatch is low.
Minimum Agent Versions
None.
Describe your test plan
Unit tests.
<details>
<summary>How to reproduce on a 5-node kind cluster</summary>
Goal: prove the upgrade check skips only not-Ready nodes that hold an out-of-date Agent pod, and that
each safety limit (
AGENT_SKIP_NOT_READY_MAX_PCT,AGENT_SKIP_NOT_READY_MAX_NODE_LOOKUPS, missingRBAC, broken rollout) keeps the check strict.
Prerequisites
kind create cluster --name skip-notready).operator-checkimage built from this PR, loaded in kind. SetCHECK_IMAGEto its name (defaultoperator-check:skip-notready).datadog(the Operator itself is unchanged by this PR; any recent version works):Why the threshold settings below: the check runs as a Job like the Helm hook, with
AGENT_COMPLETION_MIN=0(the default10would pass on a 5-node cluster without skipping anything) andCHECK_TIMEOUT_MINUTES=2so failing cases end quickly. With 5 Agent nodes, the default 10% cap allowsint(5 × 0.10) = 0skipped nodes, so the passing cases raiseAGENT_SKIP_NOT_READY_MAX_PCT.Files
dda.yaml:check-rbac.yaml:run-check.sh(runs one check as a Job, prints PASSED/FAILED and its logs):Steps
##### 1. Deploy the Agent
Baseline:
./run-check.sh baseline true 25 300→PASSED, nothing skipped.The first log line must list the settings:
skip not-Ready nodes: true, max node lookups: 300, max skipped pct: 25.##### 2. One dead node during a rollout
Expected state: 4 new pods; the old pod on
worker3staysTerminatingforever (its kubelet is gone).| # | Command | Expected result | Expected log line |
|---|---|---|---|
| 1 |
./run-check.sh 1-skip-off false 25 300|FAILED(timeout) |[Agent] nb pods: 5, nb updated pods: 4on every poll || 2 |
./run-check.sh 2-default-10pct true 10 300|FAILED| No skip line: 10% of 5 nodes is 0, so the check makes no extra API call || 3 |
./run-check.sh 3-pct-25 true 25 300|PASSEDon the first poll |[Agent] skipping 1 not-Ready nodes with an out-of-date Agent pod, counting 4 nodes instead of 5: datadog-agent/skip-notready-worker3, thenreached threshold): 4, nb updated pods: 4|| 4 |
./run-check.sh 4-lookup-cap-0 true 25 0|FAILED|1 nodes have an out-of-date Agent pod, above the 0 node lookups cap: not skipping any|| 5 | Missing node RBAC (below) |
FAILED|unable to count not-Ready nodes, not skipping any: ... cannot get resource "nodes"|Case 5:
##### 3. Two dead nodes: the skip cap
| # | Command | Expected result | Expected log line |
|---|---|---|---|
| 6 |
./run-check.sh 6-two-dead-cap-25 true 25 300 1|FAILED|2 not-Ready nodes have an out-of-date Agent pod, above the 1 cap (25% of scheduled nodes): not skipping any|| 7 |
./run-check.sh 7-two-dead-pct-40 true 40 300|PASSED|skipping 2 not-Ready nodes ... counting 3 nodes instead of 5, thenreached threshold): 3, nb updated pods: 3|(Case 6 passes
AGENT_COMPLETION_MIN=1so the check gets past its pre-check and actually counts the 2 nodes.)##### 4. A broken rollout still blocks the check
| # | Command | Expected result | Expected log line |
|---|---|---|---|
| 8 |
./run-check.sh 8-broken-config-pct-100 true 100 300|FAILED| No skip line, and stillnb updated pods: 1. The live DaemonSet shows 1/5 updated, so even skipping every not-Ready node cannot pass. Ready nodes with old pods are never skipped, even with a 100% cap. |##### 5. A stale DatadogAgent status does not pass a new rollout
Start from the state of step 2 (one dead node, rollout finished on the healthy nodes). Stop the Operator so that the DatadogAgent status stops updating, then start a rollout on the DaemonSet directly:
| # | Command | Expected result | Expected log line |
|---|---|---|---|
| 9 |
./run-check.sh 9-stale-status true 25 300, right after the patch |FAILEDon the first polls, thenPASSEDonly once the live DaemonSet shows the healthy nodes updated |nb updated pods: 4without a skip line while the rollout runs, thenskipping 1 not-Ready nodes ... skip-notready-worker3|Restore the Operator afterwards:
kubectl -n datadog scale deploy datadog-operator --replicas=1.##### Cleanup
Notes for the reviewer
node.kubernetes.io/unreachable:NoScheduletaint (the DDA usesoperator: Exists). Without it, the DaemonSet status already drops the dead node and there is nothing to skip.Error: unable to list DatadogAgentInternals: context deadline exceeded. That is how the existing check reports its timeout, not a new error.Terminatingpod uses onemaxUnavailableslot. If a cluster has more dead nodes thanmaxUnavailable, the DaemonSet rollout itself stalls, and this setting cannot help.Results on kind (2026-10-23)
| # | Scenario | Settings | Result |
|---|---|---|---|
| 0 | Healthy baseline | skip on, 25% | PASSED |
| 1 | 1 dead node, 4/5 updated | skip off | FAILED (timeout) |
| 2 | same | skip on, 10% (0 nodes on 5) | FAILED |
| 3 | same | skip on, 25% | PASSED,
skipping 1|| 4 | same | 25%, lookups 0 | FAILED, lookup cap |
| 5 | same | 25%, no
get nodesRBAC | FAILED, error logged || 6 | 2 dead nodes, 3/5 updated | 25% (cap 1 node), min 1 | FAILED, skip cap |
| 7 | same | 40% | PASSED,
skipping 2|| 8 | broken image rollout, 1/5 updated | 100% | FAILED, only the dead node skipped |
Cases 0–8 ran on
e8cd9e2a. Case 9 ran on041ce437: the check waited 2 polls while the live DaemonSet rolled out (1/5 → 4/5 updated), then skippedworker3. The previous image (ad7bf82f) passed on its first poll with 1/5 updated, reproducing the stale status issue. Cases 1–4 ran again onad7bf82f(affinity, ownership and API-load changes), with the same results, during a template revert: generation-3 pods counted as up to date by their revision hash, and onlyworker3was skipped.</details>
🤖 Generated with Claude Code