dongjoon-hyun commented on code in PR #837:
URL: 
https://github.com/apache/spark-kubernetes-operator/pull/837#discussion_r4035516627


##########
spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppCleanUpStep.java:
##########
@@ -163,6 +165,10 @@ public ReconcileProgress reconcile(
     for (HasMetadata resource : resourcesToRemove) {
       ReconcilerUtils.deleteResourceIfExists(context.getClient(), resource, 
forceDelete);
     }
+    if (KueueWorkloadFactory.hasQueueName(application)) {

Review Comment:
   Thank you for the careful analysis, @peter-toth. You're right. I moved the 
release above `resourcesToRemove` and added 
`cleanupReleasesKueueWorkloadWhenSpecBuildFails` as a regression test. It fails 
before this change and passes after it.



##########
spark-operator/src/test/java/org/apache/spark/k8s/operator/reconciler/reconcilesteps/AppCleanUpStepTest.java:
##########
@@ -115,6 +118,50 @@ class AppCleanUpStepTest {
           notExceedRetainDuration,
           notExceedTtl);
 
+  @Test
+  void cleanupReleasesKueueWorkload() {
+    SparkAppStatusRecorder mockRecorder = mock(SparkAppStatusRecorder.class);
+    AppCleanUpStep cleanUpWithReason = new 
AppCleanUpStep(SparkAppStatusUtils::appCancelled);
+    SparkApplication app = new SparkApplication();
+    app.setMetadata(
+        new ObjectMetaBuilder()
+            .withName("app1")
+            .withNamespace("default")
+            .withLabels(Map.of(Constants.LABEL_QUEUE_NAME, "test-queue"))
+            .build());
+    
app.setStatus(prepareApplicationStatus(ApplicationStateSummary.RunningHealthy));
+    SparkAppContext mockAppContext = mock(SparkAppContext.class);
+    when(mockAppContext.getResource()).thenReturn(app);
+    KubernetesClient mockClient = mock(KubernetesClient.class);
+    when(mockAppContext.getClient()).thenReturn(mockClient);
+    when(mockAppContext.getDriverPod()).thenReturn(Optional.empty());
+    when(mockRecorder.appendNewStateAndPersist(eq(mockAppContext), 
any())).thenReturn(true);
+
+    try (MockedStatic<KueueWorkloadUtils> kueue = 
Mockito.mockStatic(KueueWorkloadUtils.class)) {
+      cleanUpWithReason.reconcile(mockAppContext, mockRecorder);
+      kueue.verify(() -> KueueWorkloadUtils.releaseWorkload(mockClient, app));
+    }
+  }
+
+  @Test
+  void cleanupWithoutQueueNameDoesNotReleaseKueueWorkload() {
+    SparkAppStatusRecorder mockRecorder = mock(SparkAppStatusRecorder.class);
+    AppCleanUpStep cleanUpWithReason = new 
AppCleanUpStep(SparkAppStatusUtils::appCancelled);
+    SparkApplication app = new SparkApplication();
+    app.setMetadata(new 
ObjectMetaBuilder().withName("app1").withNamespace("default").build());
+    
app.setStatus(prepareApplicationStatus(ApplicationStateSummary.RunningHealthy));
+    SparkAppContext mockAppContext = mock(SparkAppContext.class);
+    when(mockAppContext.getResource()).thenReturn(app);
+    when(mockAppContext.getClient()).thenReturn(mock(KubernetesClient.class));
+    when(mockAppContext.getDriverPod()).thenReturn(Optional.empty());
+    when(mockRecorder.appendNewStateAndPersist(eq(mockAppContext), 
any())).thenReturn(true);
+
+    try (MockedStatic<KueueWorkloadUtils> kueue = 
Mockito.mockStatic(KueueWorkloadUtils.class)) {
+      cleanUpWithReason.reconcile(mockAppContext, mockRecorder);
+      kueue.verifyNoInteractions();

Review Comment:
   Agreed. I added `cleanupWithRetainPolicyKeepsKueueWorkload` to pin that the 
retain path keeps the `Workload` and ends in 
`TerminatedWithoutReleaseResources`.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to