← Back to Pull requests

fix: Patch memory resources being duplicated #2866

Closed
unknown closed this pull request without merging on Aug 20, 2026 00:14 UTC
View on GitHub
unknown unknown commented on Mar 05, 2026 03:24 UTC
Author

<!-- Thanks for sending a pull request! Here are some tips for you:
1. If this is your first time, check our contributor guidelines: https://www.kubeflow.org/docs/about/contributing
2. To know more about how to develop with the Spark operator, check the developer guide: https://www.kubeflow.org/docs/components/spark-operator/developer-guide/
3. If you want faster PR reviews, check how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
4. Please open an issue to discuss significant work before you start. We appreciate your contributions and don't want your efforts to go to waste!
-->

Purpose of this PR

This PR is to fix an error where memory requests are doubled for spark applications when quota enforcement is enabled. The changes added are in two main categories listed below.

IMPORTANT NOTE: Before merge, I will add some additional tests to validate this logic. Putting up the PR now for some early feedback.

Proposed changes:

1. Fix the memory resource validation
2. Add more information when resources are rejected
3. Other misc things
- Add a default for when no memory is set here

Change Category

<!-- Indicate the type of change by marking the applicable boxes. -->

  • Bugfix (non-breaking change which fixes an issue)

  • Feature (non-breaking change which adds functionality)

  • Breaking change (fix or feature that could affect existing functionality)

  • Documentation update
  • Rationale

    For the changes respectively:
    1. Resource quotas for memory do not seem to be evaluated correctly.
    2. Add more informative information so a user can know which resource they are exceeding.

    Checklist

    <!-- Before submitting your PR, please review the following: -->

  • I have conducted a self-review of my own code.

  • I have updated documentation accordingly.

  • I have added tests that prove my changes are effective or that my feature works.

  • Existing unit tests pass locally with my changes.
  • Additional Notes

    Change 2 - Add more information when resources are rejected.

    First I will explain the new error message because that is simple. With a change to validateResourceQuota and validateResourceUsage the new error message looks like:

    Error from server (Forbidden): error when creating "examples/spark-pi.yaml": admission webhook "validate-sparkoperator-k8s-io-v1beta2-sparkapplication.sparkoperator.k8s.io" denied the request: failed to validate resource quota "default/compute-quota" with error "Exceeded 'memory' quota: requested=3584Mi, used=0, limit=2Gi (new total would be: 3584Mi)
    

    This matches the native Spark K8 integration more closely and removes guess work.

    Change 1 - Fix the memory resource validation.

    At a high level, because

  • getSparkPodMemoryRequests was setting memory and requests.memory here

  • getMemoryLimits reused this function here
  • Then this SumResourceList will double memory and requests.memory.

    This can be seen while running the examples/spark-pi.yaml after enabling --enable-resource-quota-enforcement=true and with the following resource quota:

    apiVersion: v1
    kind: ResourceQuota
    metadata:
      name: compute-quota
    spec:
      hard:
        pods: "10"
        cpu: "2"
        memory: 2Gi
    

    This is what produced the error message shown above.
    Error from server (Forbidden): error when creating "examples/spark-pi.yaml": admission webhook "validate-sparkoperator-k8s-io-v1beta2-sparkapplication.sparkoperator.k8s.io" denied the request: failed to validate resource quota "default/compute-quota" with error "Exceeded 'memory' quota: requested=3584Mi, used=0, limit=2Gi (new total would be: 3584Mi)
    

    As this error message states, the calculated requested memory is 3584Mi. However this spark job only requests 512m for the driver and a single executor (see here). This plus the default overhead should give us a total application request of:
    (512 + 384) * 2 = 1792
    

    However due to the reasons shown above we are getting:
    ((512 + 384) * 2) * 2 = 3584
    

    This PR changes getSparkPodMemoryRequests (renamed getSparkPodMemory) and getMemoryRequests (renamed getMemory) to return a simple int64. Then getMemoryRequests and getMemoryLimits set the specific resource name here.

    Because this will now produce memory, requests.memory and limits.memory without any key duplicated, then the doubling is removed.

    Another note: This is my first commit to the spark-operator side of kubeflow so if there is any convention which I should be following and I have neglected, please let me know and I will make changes :+1:

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: vjanelle Review duration: 241730m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). 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%
    56%
    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 #2866"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% 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: 56.8% · Lower = rushed or shallow review
    56.8%
    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.5% · Safe to merge
    22.5%