← Back to Pull requests

check-operator: optionally skip not-Ready nodes in the Agent upgrade check #3686

Closed
unknown closed this pull request without merging on Nov 19, 2026 18:33 UTC
View on GitHub
unknown unknown commented on Oct 28, 2026 21:19 UTC
Author

What does this PR do?

Adds an opt-in setting to check-operator upgrade, AGENT_SKIP_NOT_READY_NODES (default false). When the Agent threshold is not reached, the check stops counting not-Ready nodes whose Agent pod is out of date.

On some clusters a few % of nodes go Unknown (dead kubelet). Their old Agent pod stays Terminating forever, so today the check waits until its 2h timeout. On mudkip-d it ran 46 min for this reason (evidence).

Alternative to #3650, with the same goal and a simpler structure.

| Variable | Default | Effect |
|---|---|---|
| AGENT_SKIP_NOT_READY_NODES | false | Turns the discount on. |
| AGENT_SKIP_NOT_READY_MAX_PCT | 10 | The most % of the Agent nodes that can be skipped. Above it, nothing is skipped (more likely an outage). |

New permissions, only with the setting on: list on pods and daemonsets in the DatadogAgent namespace, and list on nodes (ClusterRole). The hook RBAC lives in the chart, not in this repo.

Review guide

All logic is in cmd/check-operator/upgrade/upgrade.go. Read in this order:

1. isAgentDoneSkippingNotReadyNodes: entry point. It runs the plain check first, then the discount. Errors wrapping errNoDiscount are normal "not skipping" outcomes, logged as one line. Other errors are logged as errors. Both fall back to the plain threshold.
2. getNotReadyNodeDiscount: one call per step.
- getSkipBounds on the DatadogAgent status: no API call while skipping cannot help.
- getAgentDaemonSets: sums the live DaemonSet status. The DatadogAgent status can lag behind it.
- getSkipBounds again, on the live numbers.
- getAgentPods, getNodes: two Lists from the API server cache.
3. computeNotReadyNodeDiscount: pure function, holds the counting rules.

A node is skipped only if all of these hold:

| Rule | Why |
|---|---|
| Node not Ready | The target case |
| Exactly one Agent pod of that DaemonSet on it, out of date (generation and revision hash) | The status judges a node by its oldest pod. With maxSurge: 0 there is one pod, and nodes with several pods are never skipped (safe side) |
| The DaemonSet's current revision hash is known | Otherwise a reverted pod that the status counts as updated could be skipped |
| No DaemonSet is deleting or has observedGeneration behind | The live status must match the pods |
| Each DaemonSet's discount is reduced by its numberMisscheduled (not below 0) | Misscheduled nodes (e.g. after a DAP change) are not in Current, so they must not be subtracted again |
| The skipped count is between the fewest needed to pass and the MAX_PCT cap | No discount that would not change the result, and none during an outage |

Known limits: surge rollouts do not benefit. Skipping only helps if the Agent tolerates the not-ready/unreachable NoSchedule taints (production Agents use operator: Exists); otherwise the status already leaves these nodes out. With the defaults, the check can pass with up to about 14.5% of nodes out of date: 10% skipped, plus 5% of the rest.

Describe your test plan

  • Unit tests: the counting rules (pure function), early polls make no API call, API errors fall back, and Run end to end (setting off, setting on, a DaemonSet status behind its spec, live status behind the DatadogAgent status, a misscheduled node). Removing any single rule makes a test fail.

  • kind, 5 nodes, kubelet stopped on 1–2 nodes: details below.
  • <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, missing RBAC, broken rollout, stale status)
    keeps the check strict.

    Prerequisites

  • A kind cluster with 1 control-plane and 4 worker nodes (names below assume kind create cluster --name skip-notready).

  • The operator-check image built from this PR, loaded in kind. Set CHECK_IMAGE to its name (default operator-check:skip-notready).

  • The Datadog Operator installed with Helm in namespace datadog (the Operator itself is unchanged by this PR; any recent version works):

  •   kubectl create namespace datadog
      kubectl -n datadog create secret generic datadog-secret --from-literal=api-key=00000000000000000000000000000000
      helm install datadog-operator datadog/datadog-operator -n datadog --wait
      

    Why the threshold settings below: the check runs as a Job like the Helm hook, with
    AGENT_COMPLETION_MIN=0 (the default 10 would pass on a 5-node cluster without skipping anything) and
    CHECK_TIMEOUT_MINUTES=2 so failing cases end quickly. With 5 Agent nodes, the default 10% cap allows
    int(5 × 0.10) = 0 skipped nodes, so the passing cases raise AGENT_SKIP_NOT_READY_MAX_PCT.

    Files

    dda.yaml:

    apiVersion: datadoghq.com/v2alpha1
    kind: DatadogAgent
    metadata:
      name: datadog
      namespace: datadog
    spec:
      global:
        clusterName: skip-notready-qa
        kubelet:
          tlsVerify: false
        credentials:
          apiSecret:
            secretName: datadog-secret
            keyName: api-key
      override:
        nodeAgent:
          # Tolerate every taint, like production Agent DaemonSets. Without it, the DaemonSet status
          # drops the dead node (unreachable:NoSchedule taint) and there is nothing to skip.
          tolerations:
            - operator: Exists
          # The stuck Terminating pod on the dead node uses one unavailable slot. Production clusters get
          # more slots (10% of the nodes); on 5 nodes, allow 2 so the healthy nodes keep rolling.
          updateStrategy:
            type: RollingUpdate
            rollingUpdate:
              maxUnavailable: 2
    

    check-rbac.yaml:

    apiVersion: v1
    kind: ServiceAccount
    metadata:
      name: check-operator
      namespace: datadog
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: Role
    metadata:
      name: check-operator
      namespace: datadog
    rules:
      - apiGroups: ["datadoghq.com"]
        resources: ["datadogagents"]
        verbs: ["get"]
      - apiGroups: ["datadoghq.com"]
        resources: ["datadogagentinternals"]
        verbs: ["list"]
      # Only needed with AGENT_SKIP_NOT_READY_NODES=true.
      - apiGroups: [""]
        resources: ["pods"]
        verbs: ["list"]
      - apiGroups: ["apps"]
        resources: ["daemonsets"]
        verbs: ["list"]
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: RoleBinding
    metadata:
      name: check-operator
      namespace: datadog
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: Role
      name: check-operator
    subjects:
      - kind: ServiceAccount
        name: check-operator
        namespace: datadog
    ---
    # Only needed with AGENT_SKIP_NOT_READY_NODES=true.
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRole
    metadata:
      name: check-operator-nodes
    rules:
      - apiGroups: [""]
        resources: ["nodes"]
        verbs: ["list"]
    ---
    apiVersion: rbac.authorization.k8s.io/v1
    kind: ClusterRoleBinding
    metadata:
      name: check-operator-nodes
    roleRef:
      apiGroup: rbac.authorization.k8s.io
      kind: ClusterRole
      name: check-operator-nodes
    subjects:
      - kind: ServiceAccount
        name: check-operator
        namespace: datadog
    

    run-check.sh (runs one check as a Job, prints PASSED/FAILED and its logs):

    #!/usr/bin/env bash
    # Usage: ./run-check.sh <case> <skip true|false> <max pct> [completion min, default 0]
    set -euo pipefail
    NAME=$1 SKIP=$2 PCT=$3 MIN=${4:-0}
    IMAGE=${CHECK_IMAGE:-operator-check:skip-notready}
    kubectl -n datadog delete job "check-$NAME" --ignore-not-found >/dev/null
    cat <<YAML | kubectl apply -f - >/dev/null
    apiVersion: batch/v1
    kind: Job
    metadata:
      name: check-$NAME
      namespace: datadog
    spec:
      backoffLimit: 0
      template:
        spec:
          serviceAccountName: check-operator
          restartPolicy: Never
          containers:
            - name: check
              image: $IMAGE
              imagePullPolicy: IfNotPresent
              args: ["upgrade", "datadog"]
              env:
                - {name: CHECK_TIMEOUT_MINUTES, value: "2"}
                - {name: AGENT_COMPLETION_PCT, value: "95"}
                - {name: AGENT_COMPLETION_MIN, value: "$MIN"}
                - {name: AGENT_SKIP_NOT_READY_NODES, value: "$SKIP"}
                - {name: AGENT_SKIP_NOT_READY_MAX_PCT, value: "$PCT"}
    YAML
    # Wait for either outcome; the check times out after 2 minutes.
    for _ in $(seq 1 100); do
      RESULT=$(kubectl -n datadog get job "check-$NAME" -o jsonpath='{.status.succeeded}/{.status.failed}')
      [[ $RESULT == 1/ ]] && { echo "=== $NAME: PASSED"; break; }
      [[ $RESULT == /1 ]] && { echo "=== $NAME: FAILED"; break; }
      sleep 3
    done
    kubectl -n datadog logs "job/check-$NAME" | grep -v "v2alpha1 is available"
    

    Steps

    ##### 1. Deploy the Agent

    chmod +x run-check.sh
    kubectl apply -f dda.yaml -f check-rbac.yaml
    kubectl -n datadog rollout status ds/datadog-agent --timeout=5m
    kubectl -n datadog get pods -l agent.datadoghq.com/component=agent -o wide   # 5 pods, one per node
    

    Baseline: ./run-check.sh baseline true 25 → PASSED, nothing skipped.
    The first log line must list the settings: skip not-Ready nodes: true, max skipped pct: 25.

    ##### 2. One dead node during a rollout

    docker exec skip-notready-worker3 systemctl stop kubelet
    # Wait ~40s until the node is Unknown with the unreachable:NoSchedule taint
    kubectl get node skip-notready-worker3 -o jsonpath='{.status.conditions[?(@.type=="Ready")].status} {.spec.taints}{"\n"}'
    kubectl -n datadog patch datadogagent datadog --type merge \
      -p '{"spec":{"override":{"nodeAgent":{"env":[{"name":"QA_ROLLOUT","value":"1"}]}}}}'
    # Wait until the DDA status shows upToDate 4 / current 5
    kubectl -n datadog get datadogagent datadog -o jsonpath='{.status.agent.upToDate}/{.status.agent.current}{"\n"}'
    

    Expected state: 4 new pods; the old pod on worker3 stays Terminating forever (its kubelet is gone).

    | # | Command | Expected result | Expected log line |
    |---|---|---|---|
    | 1 | ./run-check.sh 1-skip-off false 25 | FAILED (timeout) | [Agent] nb pods: 5, nb updated pods: 4 on every poll |
    | 2 | ./run-check.sh 2-default-10pct true 10 | FAILED | [Agent] not skipping not-Ready nodes: 4/5 nodes up to date, not enough even with 0 nodes skipped (10% of 5 nodes is 0, so no API call) |
    | 3 | ./run-check.sh 3-pct-25 true 25 | PASSED on the first poll | [Agent] skipping 1 not-Ready nodes with an out-of-date Agent pod, counting 4 nodes instead of 5, then reached threshold): 4, nb updated pods: 4 |
    | 5 | Missing node RBAC (below) | FAILED | unable to count not-Ready nodes, not skipping any: unable to list nodes: ... cannot list resource "nodes" |

    Case 5:

    kubectl delete clusterrolebinding check-operator-nodes
    ./run-check.sh 5-no-node-rbac true 25
    kubectl apply -f check-rbac.yaml   # restore
    

    ##### 3. Two dead nodes: the skip cap

    docker exec skip-notready-worker systemctl stop kubelet   # wait until Unknown
    kubectl -n datadog patch datadogagent datadog --type merge -p '{"spec":{"override":{"nodeAgent":{
      "env":[{"name":"QA_ROLLOUT","value":"2"}],
      "updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":3}}}}}}'
    # Wait until upToDate 3 / current 5, with 2 Terminating pods on worker and worker3
    

    | # | Command | Expected result | Expected log line |
    |---|---|---|---|
    | 6 | ./run-check.sh 6-two-dead-cap-25 true 25 1 | FAILED | [Agent] not skipping not-Ready nodes: 2 not-Ready nodes with an out-of-date Agent pod, above the 1 cap |
    | 7 | ./run-check.sh 7-two-dead-pct-40 true 40 | PASSED | skipping 2 not-Ready nodes ... counting 3 nodes instead of 5, then reached threshold): 3, nb updated pods: 3 |

    (Case 6 passes AGENT_COMPLETION_MIN=1 so the check gets past its pre-check and actually counts the 2 nodes.)

    ##### 4. A broken rollout still blocks the check

    docker exec skip-notready-worker systemctl start kubelet   # worker recovers; wait for upToDate 4 / current 5
    kubectl -n datadog patch datadogagent datadog --type merge -p '{"spec":{"override":{"nodeAgent":{
      "image":{"name":"gcr.io/datadoghq/agent","tag":"0.0.0-does-not-exist"},
      "updateStrategy":{"type":"RollingUpdate","rollingUpdate":{"maxUnavailable":2}}}}}}'
    # Wait ~1 min: one pod in ErrImagePull, rollout stalled at upToDate 1 / current 5
    

    | # | Command | Expected result | Expected log line |
    |---|---|---|---|
    | 8 | ./run-check.sh 8-broken-config-pct-100 true 100 | FAILED | A not skipping not-Ready nodes: ... line, and still nb 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:

    kubectl -n datadog scale deploy datadog-operator --replicas=0
    kubectl -n datadog patch ds datadog-agent --type json -p '[{"op":"add","path":"/spec/template/metadata/annotations/qa-stale","value":"1"}]'
    kubectl -n datadog get ds datadog-agent -o jsonpath='{.status.currentNumberScheduled}/{.status.updatedNumberScheduled}{"\n"}'   # e.g. 5/1
    kubectl -n datadog get datadogagent datadog -o jsonpath='{.status.agent.current}/{.status.agent.upToDate}{"\n"}'          # still 5/4
    

    | # | Command | Expected result | Expected log line |
    |---|---|---|---|
    | 9 | ./run-check.sh 9-stale-status true 25, right after the patch | FAILED on the first polls, then PASSED only once the live DaemonSet shows the healthy nodes updated | not skipping not-Ready nodes: 2/5 nodes up to date, ... while the live DaemonSet rolls out, then skipping 1 not-Ready nodes ..., counting 4 nodes instead of 5 |

    Restore the Operator afterwards: kubectl -n datadog scale deploy datadog-operator --replicas=1.

    ##### Cleanup

    kind delete cluster --name skip-notready
    

    Notes for the reviewer

  • The Agent must tolerate the node.kubernetes.io/unreachable:NoSchedule taint (the DDA uses operator: Exists). Without it, the DaemonSet status already drops the dead node and there is nothing to skip.

  • Every failing case ends with Error: unable to list DatadogAgentInternals: context deadline exceeded. That is how the existing check reports its timeout, not a new error.

  • The stuck Terminating pod uses one maxUnavailable slot. If a cluster has more dead nodes than maxUnavailable, the DaemonSet rollout itself stalls, and this setting cannot help.
  • Results on kind (2026-10-28, e84e05c7)

    | # | Scenario | Settings | Result |
    |---|---|---|---|
    | 1 | 1 dead node, 4/5 updated | skip off | FAILED (timeout) |
    | 2 | same | skip on, 10% (0 nodes on 5) | FAILED, not skipping ... not enough even with 0 nodes skipped |
    | 3 | same | skip on, 25% | PASSED, skipping 1 not-Ready nodes ..., counting 4 nodes instead of 5 |
    | 5 | same | 25%, no list nodes RBAC | FAILED, cannot list resource "nodes" logged |
    | 9 | Operator stopped, DaemonSet patched: live 1/5 updated, DDA status still 5/4 | 25% | Waited while the live DaemonSet rolled out (2/5, 3/5 logged), then PASSED at 4/5 skipping worker3 |

    Cases 6–8 ran on #3650 (same counting rules) and were not rerun on this branch. Since these runs, the branch was rebased on main, the skip log no longer names the nodes, and the taint and affinity checks were replaced by subtracting numberMisscheduled from each DaemonSet's discount. On the same kind cluster, removing the Agent tolerations made the dead worker3 leave currentNumberScheduled (5 → 3, with the control-plane) and show up as numberMisscheduled=1, which is what the check subtracts.

    </details>

    Checklist

  • PR has at least one valid label

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

  • All commits are signed
  • 🤖 Generated with Claude Code

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: levan-m Review duration: 31513m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #3686"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 20.5% · Safe to merge
    20.5%