← Back to Pull requests

feat(webhook): sort map iterations in webhook plugins and application injectors for deterministic mutation #6262

Open
unknown opened this pull request with 355 lines diff across 4 files
View on GitHub
unknown unknown commented on Nov 17, 2026 10:25 UTC
Author

Ⅰ. Describe what this PR does

This PR ensures deterministic pod mutations across webhook plugins and FUSE application injectors by replacing unordered Go map iterations with utils.OrderedKeys:

1. pkg/application/inject/fuse/mount_point_script.go:
- In assembleMountInfos, sort path2RuntimeTypeMap keys so colon-separated mountPathStr and mountTypeStr injected into container lifecycle.postStart commands are always deterministic.
- Deterministically pick first valid runtime info namespace when multiple runtime infos exist (utils.OrderedKeys(runtimeInfos)) with nil checks.
- Update mount_point_script_test.go with strict equality assertions and stress test loops (50 iterations over fresh fake client instances).

2. pkg/webhook/plugins/fileprefetcher/file_prefetcher.go:
- Sort runtimeInfos keys when building default fileList (pvc://...).
- Sort config.VolumeMountPaths keys when assembling sidecar container volume mounts.
- Sort config.ExtraEnvs keys when injecting extra environment variables into the prefetcher container.
- Update file_prefetcher_test.go to assert exact deterministic ordering on volume mounts, fileList env, and extra envs.

3. pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector.go:
- Defensively sort runtimeInfos keys when collecting datasetNames for deterministic debug logging.
- Add unit test coverage for multiple runtimeInfos.

4. pkg/webhook/plugins/datasetusageinjector/dataset_usage_injector.go:
- Use utils.OrderedKeys directly for datasetsInUse slice generation.

Ⅱ. Does this pull request fix one or more issues?


Follow-up to #6217 and #6234 to guarantee deterministic pod spec mutations and eliminate webhook mutation diffs / test flakiness across all injection sites.

Ⅲ. List the added test cases (unit test/integration test)


  • pkg/application/inject/fuse/mount_point_script_test.go:

  • - Context("when given multiple paths in random map order"): 50 iterations asserting exact sorted colon-separated output.
    - Context("when multiple runtime infos are provided"): 50 iterations with fresh fake clients asserting deterministic namespace selection.
  • pkg/webhook/plugins/fileprefetcher/file_prefetcher_test.go:

  • - Exact equality assertion on fileListEnv.Value.
    - Exact equality assertion on volumeNames.
    - Added It("should append extraEnvs in deterministic key-sorted order").
  • pkg/webhook/plugins/mountpropagationinjector/mount_propagation_injector_test.go:

  • - Added It("should mutate pod with multiple runtimeInfos").

    Ⅳ. Describe how to verify it


    go test -count=1 -v ./pkg/application/inject/fuse/... ./pkg/webhook/plugins/...
    

    Ⅴ. Special notes for reviews


    None. All existing unit tests pass cleanly with zero API or CRD changes.

    Diff: 355 lines (+266 / -89) across 4 files Reviewer: cheyang Review duration: 7759m
    All Vouch review confidence checks passed
    Residual risk 0.23 = Change Risk (0.43) × (1 − Review Confidence (0.47)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.43 · 355 lines diff across 4 files
    0.43
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    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.351
    Shallow Review Depth shallow_review_depth
    0.344
    Real PR Conversation Timeline
    1 comments
    "Review active on #6262"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% 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: 42.5% (MEDIUM) · Higher = larger blast radius
    42.5%
    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: 46.7% · Lower = rushed or shallow review
    46.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: 22.7% · Safe to merge
    22.7%