← Back to Pull requests

fix: transform operand manifests from pristine copies #342

Closed
unknown closed this pull request without merging on Sep 10, 2026 09:15 UTC
View on GitHub
unknown unknown commented on Sep 03, 2026 18:13 UTC
Author

The reconciler loads the operand manifests once at start-up, but each install then transformed them and stored the result back into r.resources, so the next reconcile transformed an already-transformed manifest. The transformers only add or overwrite entries, never remove them, so anything deleted from the KedaController spec stayed in the cached desired state and kept being applied. Clearing a field had no effect until the operator process restarted.

This keeps the start-up manifests in new pristine fields and transforms from those on every reconcile. r.resources* still holds the last applied result, which is what the finalizer deletes through.

Two properties of the existing code keep the change small:

  • manifestival.Transform deep-copies (result.resources = m.Resources()), so the pristine manifests cannot be corrupted by a transform and need no defensive copying.

  • Every install already begins its transform list with InjectOwner + ReplaceAllNamespaces, so transforming from pristine still yields a fully namespace-resolved manifest and the finalizer's delete paths are unchanged.
  • It also fixes both failure modes without touching any of the if len(...) > 0 guards. Append-only transforms now only add what is currently in the spec, and guarded total-replacement transforms fall back to the operand manifest's value when the guard skips them, instead of to the previously applied value.

    Affected fields are every spec-driven one, not just env: args, deployment annotations and labels, node selectors, tolerations, affinity, resource requirements, priority class names, and the network policy pod selectors.

    This was reported by CodeRabbit while reviewing the env work in #335, but it is not a regression from that PR — the manifest caching long predates it.

    Testing

    Added envtest removal coverage for all three components. Each spec sets env, waits for the rollout, deletes env, then asserts that the appended variable is gone and that KEDA_HTTP_DEFAULT_TIMEOUT is back to the empty value from resources/keda.yaml. That second assertion is the important one: it proves the desired state really returns to pristine rather than merely stopping at "didn't add anything new".

    The suite's BeforeEach waits for the default KedaController to reach the client cache first, otherwise Apply races the operator creating it at start-up and fails with kedacontrollers.keda.sh "keda" already exists.

    The full functionality suite fails three specs that need a real cluster with running pods (Deploying KedaController manifest and one annotation spec). A baseline run at main in a clean worktree fails the identical specs, so they are pre-existing under envtest.

    Note for reviewers

    The behavior change is that clearing a spec field now actually takes effect. Any cluster relying on a value that was only surviving because of this bug will see it disappear on the first reconcile after upgrade.

    Checklist

  • Commits are signed with Developer Certificate of Origin (DCO)
  • Diff: 385 lines (+288 / -97) across 4 files Reviewer: joelsmith Review duration: 9542m
    All Vouch review confidence checks passed
    Residual risk 0.17 = Change Risk (0.43) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 385 lines diff across 4 files
    0.43
    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.356
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #342"
    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: 43% (MEDIUM) · Higher = larger blast radius
    43%
    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: 17.0% · Safe to merge
    17.0%