This is an automated email from the ASF dual-hosted git repository.
dongjoon-hyun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/spark-kubernetes-operator.git
The following commit(s) were added to refs/heads/main by this push:
new 27f91c3b [SPARK-60438] Add the name getters of the Services and
NetworkPolicy of SparkCluster
27f91c3b is described below
commit 27f91c3bdb08e5b0d21e165ef11f341e57df2170
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Wed Oct 21 14:36:11 2026 -0700
[SPARK-60438] Add the name getters of the Services and NetworkPolicy of
SparkCluster
### What changes were proposed in this pull request?
This PR aims to add the name getters of the master/worker `Service`s and
the worker `NetworkPolicy` of `SparkCluster` to `SparkClusterResourceSpec`, and
to use them when building these resources.
- `getMasterServiceName` returns `<clusterName>-master-svc`.
- `getWorkerServiceName` returns `<clusterName>-worker-svc`.
- `getWorkerNetworkPolicyName` returns `<clusterName>-worker`.
### Why are the changes needed?
This PR is a preparation step for releasing the resources of a
`SparkCluster` which fails with `SchedulingFailure`. Like the name getters of
the master/worker `StatefulSet`s and the worker
`HorizontalPodAutoscaler`/`PodDisruptionBudget`, which SPARK-59750 added for
`ClusterSuspendStep`, the new getters will be used to delete these resources by
name.
### Does this PR introduce _any_ user-facing change?
No. This is a refactoring and the resource names are unchanged.
### How was this patch tested?
Pass the CIs. The existing `SparkClusterResourceSpecTest` already verifies
these names, e.g., `cluster-name-master-svc`, `cluster-name-worker-svc`, and
`cluster-name-worker`.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Opus 5.5
Closes #979 from dongjoon-hyun/SPARK-60438.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
.../k8s/operator/SparkClusterResourceSpec.java | 36 ++++++++++++++++++++--
1 file changed, 33 insertions(+), 3 deletions(-)
diff --git
a/spark-submission-worker/src/main/java/org/apache/spark/k8s/operator/SparkClusterResourceSpec.java
b/spark-submission-worker/src/main/java/org/apache/spark/k8s/operator/SparkClusterResourceSpec.java
index 9965d709..b0a5509d 100644
---
a/spark-submission-worker/src/main/java/org/apache/spark/k8s/operator/SparkClusterResourceSpec.java
+++
b/spark-submission-worker/src/main/java/org/apache/spark/k8s/operator/SparkClusterResourceSpec.java
@@ -132,7 +132,7 @@ public class SparkClusterResourceSpec {
String name, String namespace, String version, ObjectMeta metadata,
ServiceSpec serviceSpec) {
return new ServiceBuilder()
.withNewMetadataLike(metadata)
- .withName(name + "-master-svc")
+ .withName(getMasterServiceName(name))
.addToLabels(LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_MASTER_VALUE)
.addToLabels(LABEL_SPARK_VERSION_NAME, version)
.withNamespace(namespace)
@@ -175,7 +175,7 @@ public class SparkClusterResourceSpec {
String name, String namespace, String version, ObjectMeta metadata,
ServiceSpec serviceSpec) {
return new ServiceBuilder()
.withNewMetadataLike(metadata)
- .withName(name + "-worker-svc")
+ .withName(getWorkerServiceName(name))
.addToLabels(LABEL_SPARK_ROLE_NAME, LABEL_SPARK_ROLE_WORKER_VALUE)
.addToLabels(LABEL_SPARK_VERSION_NAME, version)
.withNamespace(namespace)
@@ -380,6 +380,36 @@ public class SparkClusterResourceSpec {
return clusterName + "-worker";
}
+ /**
+ * Returns the name of the Service of the Spark master, which does not
depend on the spec.
+ *
+ * @param clusterName The name of the cluster.
+ * @return The name of the master Service.
+ */
+ public static String getMasterServiceName(String clusterName) {
+ return clusterName + "-master-svc";
+ }
+
+ /**
+ * Returns the name of the Service of the Spark workers, which does not
depend on the spec.
+ *
+ * @param clusterName The name of the cluster.
+ * @return The name of the worker Service.
+ */
+ public static String getWorkerServiceName(String clusterName) {
+ return clusterName + "-worker-svc";
+ }
+
+ /**
+ * Returns the name of the NetworkPolicy of the Spark workers, which does
not depend on the spec.
+ *
+ * @param clusterName The name of the cluster.
+ * @return The name of the worker NetworkPolicy.
+ */
+ public static String getWorkerNetworkPolicyName(String clusterName) {
+ return clusterName + "-worker";
+ }
+
/**
* Returns the name of the HorizontalPodAutoscaler of the Spark workers,
which does not depend on
* whether the current spec asks for one.
@@ -520,7 +550,7 @@ public class SparkClusterResourceSpec {
private NetworkPolicy buildWorkerNetworkPolicy(String clusterName, String
namespace) {
return new NetworkPolicyBuilder()
.withNewMetadata()
- .withName(clusterName + "-worker")
+ .withName(getWorkerNetworkPolicyName(clusterName))
.withNamespace(namespace)
.addToLabels(LABEL_SPARK_CLUSTER_NAME, clusterName)
.endMetadata()
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]