diff --git a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala index 5fc81a6d84273..033e2da70ea80 100644 --- a/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala +++ b/resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocator.scala @@ -198,8 +198,8 @@ private[spark] class ExecutorPodsAllocator( } var totalPendingCount = 0 - // The order we request executors for each ResourceProfile is not guaranteed. - totalExpectedExecutorsPerResourceProfileId.asScala.foreach { case (rpId, targetNum) => + totalExpectedExecutorsPerResourceProfileId.asScala.toSeq.sortBy(_._1) + .foreach { case (rpId, targetNum) => val podsForRpId = rpIdToExecsAndPodState.getOrElse(rpId, mutable.HashMap.empty) val currentRunningCount = podsForRpId.values.count {