Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import org.apache.spark.deploy.k8s.Config._
import org.apache.spark.deploy.k8s.Constants._
import org.apache.spark.deploy.k8s.SparkKubernetesClientFactory
import org.apache.spark.internal.Logging
import org.apache.spark.internal.LogKeys.{EXECUTOR_ID, MEMORY_SIZE}
import org.apache.spark.internal.LogKeys.{CONFIG, CONFIG2, EXECUTOR_ID, MEMORY_SIZE}
import org.apache.spark.util.{ThreadUtils, Utils}

/**
Expand All @@ -53,6 +53,14 @@ class ExecutorResizeDriverPlugin extends DriverPlugin with Logging {
ThreadUtils.newDaemonSingleThreadScheduledExecutor("executor-resize-plugin")

override def init(sc: SparkContext, ctx: PluginContext): JMap[String, String] = {
val allocator = sc.conf.get(KUBERNETES_ALLOCATION_PODS_ALLOCATOR)
if (allocator != "direct") {
logWarning(log"ExecutorResizePlugin requires the 'direct' pods allocator; " +
log"${MDC(CONFIG, KUBERNETES_ALLOCATION_PODS_ALLOCATOR.key)} is " +
log"${MDC(CONFIG2, allocator)}. Plugin will not start.")
return Map.empty[String, String].asJava
}

val interval = Utils.timeStringAsSeconds(
sc.conf.get(EXECUTOR_RESIZE_INTERVAL.key, "1m"))
val threshold = sc.conf.getDouble(EXECUTOR_RESIZE_THRESHOLD.key, 0.9)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ import org.mockito.Mockito.{mock, never, times, verify, when}
import org.scalatest.BeforeAndAfter
import org.scalatest.PrivateMethodTester

import org.apache.spark.{SparkContext, SparkFunSuite}
import org.apache.spark.{SparkConf, SparkContext, SparkFunSuite}
import org.apache.spark.api.plugin.PluginContext
import org.apache.spark.deploy.k8s.Config.KUBERNETES_ALLOCATION_PODS_ALLOCATOR
import org.apache.spark.deploy.k8s.Constants._
import org.apache.spark.deploy.k8s.Fabric8Aliases._

Expand Down Expand Up @@ -287,4 +289,21 @@ class ExecutorResizePluginSuite

verify(podResource, times(1)).patch(any(), any(classOf[Pod]))
}

Seq("statefulset", "deployment").foreach { allocator =>
test(s"init returns early when pods allocator is '$allocator'") {
val plugin = new ExecutorResizeDriverPlugin()
val sparkConf = new SparkConf().set(KUBERNETES_ALLOCATION_PODS_ALLOCATOR, allocator)
val sc = mock(classOf[SparkContext])
when(sc.conf).thenReturn(sparkConf)
val pluginCtx = mock(classOf[PluginContext])

val result = plugin.init(sc, pluginCtx)

assert(result.isEmpty)
val clientField = plugin.getClass.getDeclaredField("kubernetesClient")
clientField.setAccessible(true)
assert(clientField.get(plugin) == null)
}
}
}