← Back to Pull requests

Added SparkApp name validator to accept valid DNS-1035 format label names #2697

Closed
unknown closed this pull request without merging on Oct 31, 2025 18:20 UTC
View on GitHub
unknown unknown commented on Oct 31, 2025 06:17 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 adds early validation of SparkApplication metadata.name to ensure it conforms to DNS-1035 label requirements (same as Kubernetes Service names). This prevents applications with invalid names from being accepted and failing later when the controller attempts to create the web UI Service.

Problem:
Currently, SparkApplications with invalid names (e.g., starting with numbers like 28478459-kafka-to-gcs-streaming-6j783x) are accepted by the API server but fail during reconciliation with errors like:

Failed to reconcile SparkApplication: failed to create web UI service: Service "..." is invalid: 
metadata.name: Invalid value: "...": a DNS-1035 label must consist of lower case alphanumeric 
characters or '-', start with an alphabetic character, and end with an alphanumeric character

Solution:
Add webhook validation to reject invalid names at admission time with concise, user-friendly error messages.

Proposed changes:

  • Added validateName() function to check DNS-1035 label compliance

  • Integrated name validation into ValidateCreate() and ValidateUpdate() webhook handlers

  • Improved error messages to be concise and actionable (e.g., "name must start with a letter (not a number)")

  • Prevents late-stage failures by catching invalid names early in the admission webhook
  • 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

    Why this change is needed:
    1. Early Failure Detection: Currently, invalid names are only detected when the controller tries to create Services, resulting in confusing errors long after submission.
    2. Better User Experience: Users get immediate, clear feedback about naming requirements instead of delayed reconciliation errors.
    3. Consistency: Ensures SparkApplication names follow Kubernetes naming conventions from the start, preventing downstream resource creation failures.
    4. Reduced Confusion: The previous error messages were verbose and technical. The new messages are concise and explain the specific issue (e.g., "must start with a letter").

    Impact:

  • ✅ Non-breaking: Only rejects names that would have failed anyway during reconciliation

  • ✅ Backward Compatible: Does not affect existing valid SparkApplications

  • ✅ Clear Errors: Provides actionable error messages for common naming mistakes
  • 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

    <!-- Include any additional notes or context that could be helpful for the reviewers here. -->

    Error Message Examples:

  • Invalid name starting with number: "invalid SparkApplication name \"28478459-kafka-to-gcs-streaming-6j783x\": name must start with a letter (not a number)"

  • Invalid name too long: "invalid SparkApplication name \"...\": name exceeds 63 characters"

  • Invalid name starts with uppercase: "invalid SparkApplication name \"...\": name must start with a lowercase letter"
  • Valid Name Requirements:

  • Must start with a lowercase letter [a-z]

  • Can contain lowercase letters, numbers [0-9], and hyphens [-]

  • Must end with a letter or number (not a hyphen)

  • Maximum 63 characters

  • Examples: my-job, job1, data-pipeline-01, a1
  • Testing:

  • Tested with names starting with numbers (should be rejected)

  • Tested with valid names (should be accepted)

  • Tested with names containing uppercase letters (should be rejected)

  • Tested with names starting/ending with hyphens (should be rejected)

  • Verified error messages are concise and actionable
  • Related:
    This validation prevents the same issue that would occur when creating the web UI Service during reconciliation, but catches it earlier with better error messages.

    Diff: 618 lines (+463 / -155) across 7 files Reviewer: vjanelle Review duration: 723m
    All Vouch review confidence checks passed
    Residual risk 0.20 = Change Risk (0.50) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.50 · 618 lines diff across 7 files
    0.50
    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.385
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #2697"
    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: 50.2% (MEDIUM) · Higher = larger blast radius
    50.2%
    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: 19.8% · Safe to merge
    19.8%