From 1125afd4622e6d3f7f14fca1ebcfebdfba6d9529 Mon Sep 17 00:00:00 2001 From: Kent Yao Date: Sun, 13 Jun 2021 09:11:14 -0700 Subject: [PATCH] [MINOR][K8S] Print the driver pod name instead of Some(name) if absent Print the driver pod name instead of Some(name) if absent ### What changes were proposed in this pull request? ### Why are the changes needed? fix error hint ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? new test Closes #32889 from yaooqinn/minork8s. Authored-by: Kent Yao Signed-off-by: Dongjoon Hyun --- .../cluster/k8s/ExecutorPodsAllocator.scala | 2 +- .../cluster/k8s/ExecutorPodsAllocatorSuite.scala | 14 +++++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) 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 ad489edef6..d6dc13e22e 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 @@ -77,7 +77,7 @@ private[spark] class ExecutorPodsAllocator( .withName(name) .get()) .getOrElse(throw new SparkException( - s"No pod was found named $kubernetesDriverPodName in the cluster in the " + + s"No pod was found named $name in the cluster in the " + s"namespace $namespace (this was supposed to be the driver pod.)."))) // Executor IDs that have been requested from Kubernetes but have not been detected in any diff --git a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocatorSuite.scala b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocatorSuite.scala index 207094ea75..a54f1a105b 100644 --- a/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocatorSuite.scala +++ b/resource-managers/kubernetes/core/src/test/scala/org/apache/spark/scheduler/cluster/k8s/ExecutorPodsAllocatorSuite.scala @@ -32,7 +32,7 @@ import org.mockito.stubbing.Answer import org.scalatest.BeforeAndAfter import org.scalatest.PrivateMethodTester._ -import org.apache.spark.{SecurityManager, SparkConf, SparkFunSuite} +import org.apache.spark.{SecurityManager, SparkConf, SparkException, SparkFunSuite} import org.apache.spark.deploy.k8s.{KubernetesExecutorConf, KubernetesExecutorSpec} import org.apache.spark.deploy.k8s.Config._ import org.apache.spark.deploy.k8s.Constants._ @@ -653,6 +653,18 @@ class ExecutorPodsAllocatorSuite extends SparkFunSuite with BeforeAndAfter { verify(persistentVolumeClaims, never()).create(any()) } + test("print the pod name instead of Some(name) if pod is absent") { + val nonexistentPod = "i-do-not-exist" + val conf = new SparkConf().set(KUBERNETES_DRIVER_POD_NAME, nonexistentPod) + when(kubernetesClient.pods()).thenReturn(podOperations) + when(podOperations.withName(nonexistentPod)).thenReturn(driverPodOperations) + when(driverPodOperations.get()).thenReturn(null) + val e = intercept[SparkException](new ExecutorPodsAllocator( + conf, secMgr, executorBuilder, kubernetesClient, snapshotsStore, waitForExecutorPodsClock)) + assert(e.getMessage.contains("No pod was found named i-do-not-exist in the cluster in the" + + " namespace default")) + } + private def executorPodAnswer(): Answer[KubernetesExecutorSpec] = (invocation: InvocationOnMock) => { val k8sConf: KubernetesExecutorConf = invocation.getArgument(0)