Skip to content

Commit cbbea03

Browse files
RolatZhangleejayweifrearbfishcus
authored
cherry-pick 3.3 commits (apache#616)
* KE-39980 configMap Binds the KE pod * minor fix dockerfile java version and host user (apache#510) * KY-895 Spark driver pod cleanup when application is completed (apache#528) * KY-895, Spark driver pod cleanup when application is completed (apache#358) * KY-895, Spark driver pod cleanup when application is completed * KY-895, release 3.1.1-kylin-4.x-r42-xuanwu * KY-895, add config KUBERNETES_DELETE_DRIVER (apache#376) Co-authored-by: Feng Zhu <[email protected]> --------- Co-authored-by: Jiawei Li <[email protected]> Co-authored-by: Zhiting Guo <[email protected]> Co-authored-by: Feng Zhu <[email protected]>
1 parent 327b6a1 commit cbbea03

File tree

5 files changed

+28
-7
lines changed

5 files changed

+28
-7
lines changed

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/Config.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,14 @@ private[spark] object Config extends Logging {
555555
.checkValue(value => value > 0, "Maximum number of pending pods should be a positive integer")
556556
.createWithDefault(Int.MaxValue)
557557

558+
val KUBERNETES_DELETE_DRIVER =
559+
ConfigBuilder("spark.kubernetes.driver.deleteOnCompleted")
560+
.doc("If set to false then driver pods will not be deleted in case " +
561+
"of completion.")
562+
.version("3.1.1")
563+
.booleanConf
564+
.createWithDefault(true)
565+
558566
val KUBERNETES_DRIVER_LABEL_PREFIX = "spark.kubernetes.driver.label."
559567
val KUBERNETES_DRIVER_ANNOTATION_PREFIX = "spark.kubernetes.driver.annotation."
560568
val KUBERNETES_DRIVER_SERVICE_ANNOTATION_PREFIX = "spark.kubernetes.driver.service.annotation."

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/submit/KubernetesClientApplication.scala

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ private[spark] class KubernetesClientApplication extends SparkApplication {
202202
// The master URL has been checked for validity already in SparkSubmit.
203203
// We just need to get rid of the "k8s://" prefix here.
204204
val master = KubernetesUtils.parseMasterUrl(sparkConf.get("spark.master"))
205-
val watcher = new LoggingPodStatusWatcherImpl(kubernetesConf)
206205

207206
Utils.tryWithResource(SparkKubernetesClientFactory.createKubernetesClient(
208207
master,
@@ -216,7 +215,7 @@ private[spark] class KubernetesClientApplication extends SparkApplication {
216215
kubernetesConf,
217216
new KubernetesDriverBuilder(),
218217
kubernetesClient,
219-
watcher)
218+
new LoggingPodStatusWatcherImpl(kubernetesConf, kubernetesClient))
220219
client.run()
221220
}
222221
}

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/submit/LoggingPodStatusWatcher.scala

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
package org.apache.spark.deploy.k8s.submit
1818

1919
import io.fabric8.kubernetes.api.model.Pod
20-
import io.fabric8.kubernetes.client.{Watcher, WatcherException}
20+
import io.fabric8.kubernetes.client.{KubernetesClient, Watcher, WatcherException}
2121
import io.fabric8.kubernetes.client.Watcher.Action
2222

2323
import org.apache.spark.deploy.k8s.Config._
@@ -36,7 +36,8 @@ private[k8s] trait LoggingPodStatusWatcher extends Watcher[Pod] {
3636
*
3737
* @param conf kubernetes driver conf.
3838
*/
39-
private[k8s] class LoggingPodStatusWatcherImpl(conf: KubernetesDriverConf)
39+
private[k8s] class LoggingPodStatusWatcherImpl(conf: KubernetesDriverConf,
40+
kubernetesClient: KubernetesClient)
4041
extends LoggingPodStatusWatcher with Logging {
4142

4243
private val appId = conf.appId
@@ -110,6 +111,9 @@ private[k8s] class LoggingPodStatusWatcherImpl(conf: KubernetesDriverConf)
110111
pod.map { p => s"Container final statuses:\n\n${containersDescription(p)}" }
111112
.getOrElse("No containers were found in the driver pod."))
112113
logInfo(s"Application ${conf.appName} with submission ID $sId finished")
114+
if (conf.get(KUBERNETES_DELETE_DRIVER)) {
115+
pod.map { p => kubernetesClient.pods().withName(p.getMetadata.getName).delete() }
116+
}
113117
}
114118
podCompleted
115119
} else {

resource-managers/kubernetes/core/src/main/scala/org/apache/spark/scheduler/cluster/k8s/KubernetesClusterSchedulerBackend.scala

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
*/
1717
package org.apache.spark.scheduler.cluster.k8s
1818

19+
import java.net.InetAddress
1920
import java.util.concurrent.{ScheduledExecutorService, TimeUnit}
2021

2122
import scala.concurrent.Future
@@ -76,10 +77,19 @@ private[spark] class KubernetesClusterSchedulerBackend(
7677
val labels =
7778
Map(SPARK_APP_ID_LABEL -> applicationId(), SPARK_ROLE_LABEL -> SPARK_POD_EXECUTOR_ROLE)
7879
val configMap = KubernetesClientUtils.buildConfigMap(configMapName, confFilesMap, labels)
79-
KubernetesUtils.addOwnerReference(driverPod.orNull, Seq(configMap))
80+
KubernetesUtils.addOwnerReference(getDriverPodOrLocalPod(driverPod), Seq(configMap))
8081
kubernetesClient.configMaps().create(configMap)
8182
}
8283

84+
private def getDriverPodOrLocalPod(driverPod: Option[Pod]): Pod = {
85+
if (driverPod.isDefined) {
86+
return driverPod.get
87+
}
88+
val podName = InetAddress.getLocalHost.getHostName
89+
logInfo(s"LocalPod={podName=$podName}")
90+
kubernetesClient.pods().withName(podName).get()
91+
}
92+
8393
/**
8494
* Get an application ID associated with the job.
8595
* This returns the string value of spark.app.id if set, otherwise

resource-managers/kubernetes/docker/src/main/dockerfiles/spark/Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,11 @@
1414
# See the License for the specific language governing permissions and
1515
# limitations under the License.
1616
#
17-
ARG java_image_tag=11-jre-slim
17+
ARG java_image_tag=8-jdk-slim
1818

1919
FROM openjdk:${java_image_tag}
2020

21-
ARG spark_uid=185
21+
ARG spark_uid=root
2222

2323
# Before building the docker image, first build and make a Spark distribution following
2424
# the instructions in http://spark.apache.org/docs/latest/building-spark.html.

0 commit comments

Comments
 (0)