This is an automated email from the ASF dual-hosted git repository.
dongjoon 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 98de4d3 [SPARK-55911] Improve `ModelUtils` to support `isClientMode`
method
98de4d3 is described below
commit 98de4d32af4d5fd6d83a6e984f0e26cd2891a4b8
Author: Dongjoon Hyun <[email protected]>
AuthorDate: Mon Mar 9 21:50:21 2026 -0700
[SPARK-55911] Improve `ModelUtils` to support `isClientMode` method
### What changes were proposed in this pull request?
This PR adds `ModelUtils.isClientMode` utility method and uses it in
`AppValidateStep` to improve code readability.
### Why are the changes needed?
The inline deployment mode check `ClientMode ==
context.getResource().getSpec().getDeploymentMode()` is verbose and may be
needed in multiple places. Extracting it into a reusable `isClientMode` utility
method in `ModelUtils` improves readability and consistency, following the same
pattern as `isValidApplicationStatus` in `SparkAppStatusUtils`.
### Does this PR introduce _any_ user-facing change?
No.
### How was this patch tested?
A new unit test `testIsClientMode` was added in `ModelUtilsTest` to verify
both `ClientMode` and `ClusterMode` cases.
### Was this patch authored or co-authored using generative AI tooling?
Generated-by: Claude Code (claude-opus-4-6)
Closes #544 from dongjoon-hyun/SPARK-55911.
Authored-by: Dongjoon Hyun <[email protected]>
Signed-off-by: Dongjoon Hyun <[email protected]>
---
.../org/apache/spark/k8s/operator/utils/ModelUtils.java | 11 +++++++++++
.../apache/spark/k8s/operator/utils/ModelUtilsTest.java | 16 ++++++++++++++++
.../reconciler/reconcilesteps/AppValidateStep.java | 4 ++--
3 files changed, 29 insertions(+), 2 deletions(-)
diff --git
a/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java
b/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java
index 24190cc..022a9bb 100644
---
a/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java
+++
b/spark-operator-api/src/main/java/org/apache/spark/k8s/operator/utils/ModelUtils.java
@@ -20,6 +20,7 @@
package org.apache.spark.k8s.operator.utils;
import static
org.apache.spark.k8s.operator.Constants.DRIVER_SPARK_CONTAINER_PROP_KEY;
+import static org.apache.spark.k8s.operator.spec.DeploymentMode.ClientMode;
import java.util.List;
import java.util.Map;
@@ -155,4 +156,14 @@ public final class ModelUtils {
}
return attemptId;
}
+
+ /**
+ * Checks if the application is in client mode.
+ *
+ * @param app The SparkApplication to check.
+ * @return True if the application is in client mode, false otherwise.
+ */
+ public static boolean isClientMode(SparkApplication app) {
+ return ClientMode == app.getSpec().getDeploymentMode();
+ }
}
diff --git
a/spark-operator-api/src/test/java/org/apache/spark/k8s/operator/utils/ModelUtilsTest.java
b/spark-operator-api/src/test/java/org/apache/spark/k8s/operator/utils/ModelUtilsTest.java
index 87170be..0f73c8e 100644
---
a/spark-operator-api/src/test/java/org/apache/spark/k8s/operator/utils/ModelUtilsTest.java
+++
b/spark-operator-api/src/test/java/org/apache/spark/k8s/operator/utils/ModelUtilsTest.java
@@ -34,8 +34,10 @@ import
io.fabric8.kubernetes.api.model.PodTemplateSpecBuilder;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.apache.spark.k8s.operator.SparkApplication;
import org.apache.spark.k8s.operator.spec.ApplicationSpec;
import org.apache.spark.k8s.operator.spec.BaseApplicationTemplateSpec;
+import org.apache.spark.k8s.operator.spec.DeploymentMode;
class ModelUtilsTest {
@@ -124,4 +126,18 @@ class ModelUtilsTest {
applicationSpec.setDriverSpec(executorSpec);
assertTrue(ModelUtils.overrideDriverTemplateEnabled(applicationSpec));
}
+
+ @Test
+ void testIsClientMode() {
+ SparkApplication app = new SparkApplication();
+ ApplicationSpec spec = new ApplicationSpec();
+
+ spec.setDeploymentMode(DeploymentMode.ClientMode);
+ app.setSpec(spec);
+ assertTrue(ModelUtils.isClientMode(app));
+
+ spec.setDeploymentMode(DeploymentMode.ClusterMode);
+ app.setSpec(spec);
+ assertFalse(ModelUtils.isClientMode(app));
+ }
}
diff --git
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppValidateStep.java
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppValidateStep.java
index 9cefd67..ca88233 100644
---
a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppValidateStep.java
+++
b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppValidateStep.java
@@ -21,7 +21,7 @@ package
org.apache.spark.k8s.operator.reconciler.reconcilesteps;
import static
org.apache.spark.k8s.operator.reconciler.ReconcileProgress.completeAndImmediateRequeue;
import static
org.apache.spark.k8s.operator.reconciler.ReconcileProgress.proceed;
-import static org.apache.spark.k8s.operator.spec.DeploymentMode.ClientMode;
+import static org.apache.spark.k8s.operator.utils.ModelUtils.isClientMode;
import static
org.apache.spark.k8s.operator.utils.SparkAppStatusUtils.isValidApplicationStatus;
import lombok.extern.slf4j.Slf4j;
@@ -50,7 +50,7 @@ public class AppValidateStep extends AppReconcileStep {
log.warn("Spark application found with empty status. Resetting to
initial state.");
return attemptStatusUpdate(context, statusRecorder, new
ApplicationStatus(), proceed());
}
- if (ClientMode == context.getResource().getSpec().getDeploymentMode()) {
+ if (isClientMode(context.getResource())) {
ApplicationState failure =
new ApplicationState(ApplicationStateSummary.Failed, "Client mode is
not supported yet.");
return attemptStatusUpdate(
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]