Skip to content

Preserve user-supplied service port#3003

Open
nabuskey wants to merge 1 commit into
kubeflow:masterfrom
nabuskey:sc-svc-port
Open

Preserve user-supplied service port#3003
nabuskey wants to merge 1 commit into
kubeflow:masterfrom
nabuskey:sc-svc-port

Conversation

@nabuskey

Copy link
Copy Markdown
Contributor

mutateServerService overwrote the entire Spec.Ports slice on creation,
discarding ports supplied via the Server.Service override.

It now merges instead: user-supplied ports are kept, and any missing required
ports are appended by name. Existing Services are left untouched.

Change Category

  • 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

Checklist

  • 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

Signed-off-by: Manabu McCloskey <manabu.mccloskey@gmail.com>
Copilot AI review requested due to automatic review settings June 23, 2026 17:26
@google-oss-prow google-oss-prow Bot requested review from ImpSy and RobuRishabh June 23, 2026 17:26
@google-oss-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from nabuskey. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes mutateServerService so that, when creating a new SparkConnect server Service, it no longer overwrites spec.ports entirely. Instead, it preserves any user-supplied ports and appends any missing required SparkConnect ports (matched by port name), while continuing to leave existing Services’ ports untouched.

Changes:

  • Update mutateServerService to merge required Service ports into any user-supplied spec.ports during Service creation.
  • Add unit tests covering preservation of custom ports and non-overwrite behavior for user-supplied required ports.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
internal/controller/sparkconnect/reconciler.go Changes Service port mutation logic to merge required ports instead of replacing user-supplied ports on creation.
internal/controller/sparkconnect/reconciler_test.go Adds tests validating port preservation/merge behavior for user-supplied Service port overrides.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread internal/controller/sparkconnect/reconciler.go
Comment thread internal/controller/sparkconnect/reconciler_test.go
@nabuskey nabuskey changed the title Preserve user-supplied server Service port Preserve user-supplied service port Jun 24, 2026

@tariq-hasan tariq-hasan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @nabuskey! I have added a few comments.

Comment on lines +512 to 521
ports := map[string]struct{}{}
for _, port := range svc.Spec.Ports {
ports[port.Name] = struct{}{}
}
for _, port := range requiredPorts {
_, ok := ports[port.Name]
if !ok {
svc.Spec.Ports = append(svc.Spec.Ports, port)
}
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if we want to start with the required ports as the base and only add in user-provided ports which do not conflict on the port name and which do not conflict on the port number and protocol combination.

I mention this because otherwise we might have a user-provided name targeting 15002, for example, and spark-connect-server targeting 15002 as well which would then cause an API server error.

Also the ports are hardcoded either in the operator or natively in Spark. So if a user overrides the port number for web-ui to 4000, for example, then it could be pointing at a port on the driver pod that may not be serving any requests.


return nil
}

@tariq-hasan tariq-hasan Jun 26, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am wondering if webhook validation on the user-provided service would be useful as well.

This would be for the four protected ports as well as other user-provided ports in case the spec for those are invalid as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants