You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by do...@apache.org on 2026/03/30 21:43:24 UTC

(spark-kubernetes-operator) branch main updated: [SPARK-56294] Apply exhaustive `switch` for `ResourceRetainPolicy` and `ClusterStateSummary`

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 c86cad0  [SPARK-56294] Apply exhaustive `switch` for `ResourceRetainPolicy` and `ClusterStateSummary`
c86cad0 is described below

commit c86cad0cf66a53330324bf7866dea000256a9cb9
Author: Dongjoon Hyun <do...@apache.org>
AuthorDate: Mon Mar 30 14:43:17 2026 -0700

    [SPARK-56294] Apply exhaustive `switch` for `ResourceRetainPolicy` and `ClusterStateSummary`
    
    ### What changes were proposed in this pull request?
    
    This PR removes `default` branches from switch statements on `ResourceRetainPolicy` and `ClusterStateSummary` enums by explicitly listing all enum constants, leveraging Java's exhaustive switch feature.
    
    ### Why are the changes needed?
    
    With exhaustive switch, the compiler will flag any unhandled enum constant at compile time when a new value is added in the future. This improves type safety compared to silently falling through a `default` branch.
    
    ### Does this PR introduce _any_ user-facing change?
    
    No.
    
    ### How was this patch tested?
    
    Pass the CIs with the existing tests.
    
    ### Was this patch authored or co-authored using generative AI tooling?
    
    Generated-by: Claude Code (claude-opus-4-6)
    
    Closes #608 from dongjoon-hyun/SPARK-56294.
    
    Authored-by: Dongjoon Hyun <do...@apache.org>
    Signed-off-by: Dongjoon Hyun <do...@apache.org>
---
 .../apache/spark/k8s/operator/reconciler/SparkClusterReconciler.java   | 3 ++-
 .../spark/k8s/operator/reconciler/reconcilesteps/AppCleanUpStep.java   | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkClusterReconciler.java b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkClusterReconciler.java
index 6dc1b21..02022b6 100644
--- a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkClusterReconciler.java
+++ b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkClusterReconciler.java
@@ -163,7 +163,8 @@ public class SparkClusterReconciler implements Reconciler<SparkCluster>, Cleaner
       case RunningHealthy -> {
         // There is nothing to do because Spark Cluster is supposed to run infinitely.
       }
-      default -> steps.add(new ClusterUnknownStateStep());
+      case SchedulingFailure, Failed, ResourceReleased ->
+          steps.add(new ClusterUnknownStateStep());
     }
     return steps;
   }
diff --git a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppCleanUpStep.java b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppCleanUpStep.java
index 57e48c6..e0dc065 100644
--- a/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppCleanUpStep.java
+++ b/spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppCleanUpStep.java
@@ -331,9 +331,9 @@ public final class AppCleanUpStep extends AppReconcileStep {
   protected boolean retainReleaseResourceForPolicyAndState(
       ResourceRetainPolicy resourceRetainPolicy, ApplicationState currentState) {
     return switch (resourceRetainPolicy) {
+      case Always -> true;
       case Never -> false;
       case OnFailure -> currentState.getCurrentStateSummary().isFailure();
-      default -> true;
     };
   }
 


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org