Skip to content

Conversation

@schmaxXximilian
Copy link
Contributor

@schmaxXximilian schmaxXximilian commented Jul 29, 2025

What changes were proposed in this pull request?

Updated the podSelector for master and worker services to include both clusterRole and name labels.

Why are the changes needed?

Using only clusterRole caused service misrouting when multiple Spark clusters were deployed in the same namespace. Adding name ensures correct pod targeting.

Does this PR introduce any user-facing change?

No, this is an internal fix to service selectors.

How was this patch tested?

Tested with multiple clusters in the same namespace. Verified each service only matched its own pods via kubectl describe service.
Also adapted unit tests to reflect new behaviour

Was this patch authored or co-authored using generative AI tooling?

Yes, PR metadata was assisted by AI, but code changes were made manually.

@schmaxXximilian schmaxXximilian changed the title Fixes wrong worker assignment if multiple clusters are deployed to the namespace [SPARK-52997] Fixes wrong worker assignment if multiple clusters are deployed to the same namespace Jul 29, 2025
@schmaxXximilian schmaxXximilian force-pushed the main branch 2 times, most recently from a373739 to 62a3b2d Compare July 29, 2025 14:51
@schmaxXximilian schmaxXximilian marked this pull request as draft July 29, 2025 15:04
@schmaxXximilian schmaxXximilian marked this pull request as ready for review July 30, 2025 07:22
@schmaxXximilian
Copy link
Contributor Author

Hey @dongjoon-hyun, would be great if you could have a look at this. Our team is using the operator and we are grateful to the great work you folks have been doing.
Alas, the issue described in the PR is a pretty big problem to it. It would be amazing if we could get it resolved for the next release of the operator.

@dongjoon-hyun
Copy link
Member

Thank you for making a PR, @schmaxXximilian .

cc @peter-toth

.withClusterIP("None")
.withSelector(
Collections.singletonMap(LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_MASTER_VALUE))
Map.of(
Copy link
Member

Choose a reason for hiding this comment

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

May I ask why we need to use Map.of instead of Collections.singletonMap?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @dongjoon-hyun, I'm afraid, I'm not quire sure what you are suggesting. Collections.singletonMap only creates a map with a single element.
I changed my initial commit to below approach. Do you think it would be more suitable?

        .addToSelector(Collections.singletonMap(LABEL_SPARK_CLUSTER_NAME, name))
        .addToSelector(
            Collections.singletonMap(LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_MASTER_VALUE))

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

I left a few comments including https://github.com/apache/spark-kubernetes-operator/pull/291/files#r2243410142 .

In general, I understand your requirements although this is not recommended for HPA-enabled Spark Clusters. Let me play with this for a while.

Copy link
Member

@dongjoon-hyun dongjoon-hyun left a comment

Choose a reason for hiding this comment

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

+1, LGTM. Thank you, @schmaxXximilian . Sorry for being delayed.

Merged to main.

@dongjoon-hyun
Copy link
Member

I added you to the Apache Spark contributor group (of ASF JIRA) and assigned SPARK-52997 to you.

Welcome to the Apache Spark community.

songgane pushed a commit to songgane/spark-kubernetes-operator that referenced this pull request Oct 2, 2025
…deployed to the same namespace

### What changes were proposed in this pull request?
Updated the podSelector for master and worker services to include both clusterRole and name labels.

### Why are the changes needed?
Using only clusterRole caused service misrouting when multiple Spark clusters were deployed in the same namespace. Adding name ensures correct pod targeting.

### Does this PR introduce any user-facing change?
No, this is an internal fix to service selectors.

### How was this patch tested?
Tested with multiple clusters in the same namespace. Verified each service only matched its own pods via kubectl describe service.
Also adapted unit tests to reflect new behaviour

### Was this patch authored or co-authored using generative AI tooling?
Yes, PR metadata was assisted by AI, but code changes were made manually.

Closes apache#291 from schmaxXximilian/main.

Authored-by: Schmöller Maximilian <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
(cherry picked from commit 7915164)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants