← Back to Pull requests

fix(kube-applier): compare ReadDesire kubeContent semantically to stop no-op Cosmos writes #7078

Closed
unknown closed this pull request without merging on Sep 25, 2026 14:21 UTC
View on GitHub
unknown unknown commented on Sep 22, 2026 13:21 UTC
Author

ARO-29788

Relates to #7071 (improve_NeedsUpdate_number_handling, ARO-29803): the no-op guard here relies on NeedsUpdate's precision-preserving JSON comparison - which is still OK in the present implementation (integer precision up to 2^53) - can be merged independently.

What

  • Replace the bytes.Equal no-op guard with internalcontrollerutils.NeedsUpdate, which compares *runtime.RawExtension via canonical JSON — key-order- and formatting-agnostic, with integer precision preserved via UseNumber (landed separately on main).

  • A no-op reconcile now only re-affirms Successful=True, which is idempotent through meta.SetStatusCondition, so the writer's equality.Semantic.DeepEqual sees no change and performs no Cosmos write / no instanceVersion bump.

  • Genuine content changes still publish the observed payload verbatim; object-absent (nil) handling is unchanged.
  • Expected effect: backupschedule ReadDesires drop from ~278 writes to ~5 (the real changes); other reflectors unaffected.

    Why

    The ReadDesireKubernetesController re-wrote its Cosmos document on nearly every 60s resync (at least for backupschedule CRs), even when the observed kube object had not changed. Each write bumps instanceVersion, producing a new Cosmos snapshot and — downstream — a new must-gather git commit.

    Root cause is a serialization asymmetry. The no-op guard compared:

  • newRaw = a fresh Go json.Marshal of the observed object, against

  • existingRaw = the same value after a Cosmos JSON round-trip (different key order / whitespace / number formatting).
  • bytes.Equal(newRaw, existingRaw) therefore returned false on every resync, so each 60s tick issued a Replace. The freshly-written bytes went through the same round-trip, so the mismatch is permanent, not transient.

    Measured on one hourly Velero backupschedule ReadDesire (must-gather-20260921-155039): 278 Cosmos writes but only ~5 distinct resourceVersion transitions → ~273 no-op writes. The three backupschedule cadences (hourly/daily/weekly) alone were ~72% of all commits in that gather. Cleanly round-tripping objects (e.g. the hostedcluster reflector, writes ≈ real changes) were unaffected, because for them semantic-equal already equals byte-equal.

    Testing

    go test ./pkg/controllers/read_desire_kubernetes/... — green.

    Manual tryout with personal dev env: verified, that each cosmos instanceVersion references a dedicated kubernetes resourceVersion:

    ADX

    ``
    let clusterId = "/subscriptions/1d3378d3-5a3f-4712-85a1-2485495dfc4b/resourceGroups/autoscaling-cluster-qhg8snsz7swx/providers/Microsoft.RedHatOpenshift/hcpOpenShiftClusters/autoscaling-hcp-cluster";
    cosmosResourceSnapshots
    | where timestamp > ago(2h)
    | where resourceID startswith clusterId
    | where resourceType == "microsoft.redhatopenshift/hcpopenshiftclusters/readdesires"
    | where resourceName startswith "backupschedule-ocm-arohcppers-2t1acm9jq83nib8eiab3jhbfnl5mj223-hourly"
    | project iv = tostring(content.properties.cosmosMetadata.instanceVersion), rv = tostring(content.properties.status.kubeContent.metadata.resourceVersion), content = content
    ``

    🤖 Generated with Claude Code

    Diff: 501 lines (+375 / -126) across 6 files Reviewer: tmstff Review duration: 4380m
    All Vouch review confidence checks passed
    Residual risk 0.28 = Change Risk (0.71) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.71 · 501 lines diff across 6 files
    0.71
    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.372
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.071
    Real PR Conversation Timeline
    1 comments
    "Review active on #7078"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 70.7% (HIGH) · Higher = larger blast radius
    70.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: 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: 27.9% · Safe to merge
    27.9%
    Repository