in spark-operator/src/main/java/org/apache/spark/k8s/operator/reconciler/SparkAppReconciler.java [196:224]
public DeleteControl cleanup(
SparkApplication sparkApplication, Context<SparkApplication> context) {
LoggingUtils.TrackedMDC trackedMDC = new LoggingUtils.TrackedMDC();
try {
trackedMDC.set(sparkApplication);
log.info("Cleaning up resources for SparkApp.");
SparkAppContext ctx = new SparkAppContext(sparkApplication, context, submissionWorker);
List<AppReconcileStep> cleanupSteps = new ArrayList<>();
cleanupSteps.add(new AppValidateStep());
cleanupSteps.add(new AppTerminatedStep());
cleanupSteps.add(new AppCleanUpStep(SparkAppStatusUtils::appCancelled));
for (AppReconcileStep step : cleanupSteps) {
ReconcileProgress progress = step.reconcile(ctx, sparkAppStatusRecorder);
if (progress.isCompleted()) {
if (progress.isRequeue()) {
return DeleteControl.noFinalizerRemoval()
.rescheduleAfter(progress.getRequeueAfterDuration());
} else {
break;
}
}
}
} finally {
log.info("Cleanup completed");
trackedMDC.reset();
}
sparkAppStatusRecorder.removeCachedStatus(sparkApplication);
return DeleteControl.defaultDelete();
}