Skip to content
Open
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 @@ -16,8 +16,9 @@
*/
package org.apache.spark.deploy.k8s

import io.fabric8.kubernetes.api.model.{Pod, PodBuilder}
import io.fabric8.kubernetes.api.model.PodBuilder
import io.fabric8.kubernetes.client.KubernetesClient
import io.fabric8.kubernetes.client.dsl.base.{PatchContext, PatchType}
import org.apache.hadoop.util.StringUtils

import org.apache.spark.{SparkConf, SparkMasterRegex}
Expand Down Expand Up @@ -52,6 +53,7 @@ private[spark] class SparkKubernetesDiagnosticsSetter(clientProvider: Kubernetes
extends SparkDiagnosticsSetter with Logging {

private val KUBERNETES_EXIT_EXCEPTION_MESSAGE_LIMIT_BYTES = 64 * 1024 // 64 KiB
private val PATCH_CONTEXT = PatchContext.of(PatchType.STRATEGIC_MERGE)

def this() = {
this(new DefaultKubernetesClientProvider)
Expand All @@ -65,8 +67,8 @@ private[spark] class SparkKubernetesDiagnosticsSetter(clientProvider: Kubernetes
client.pods()
.inNamespace(conf.get(KUBERNETES_NAMESPACE))
.withName(podName)
.edit((p: Pod) => new PodBuilder(p)
.editOrNewMetadata()
.patch(PATCH_CONTEXT, new PodBuilder()
.withNewMetadata()
.addToAnnotations(EXIT_EXCEPTION_ANNOTATION, diagnostics)
.endMetadata()
.build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
*/
package org.apache.spark.deploy.k8s

import java.util.function.UnaryOperator

import io.fabric8.kubernetes.api.model.Pod
import io.fabric8.kubernetes.client.KubernetesClient
import io.fabric8.kubernetes.client.dsl.PodResource
import io.fabric8.kubernetes.client.dsl.base.PatchContext
import org.apache.hadoop.util.StringUtils
import org.mockito.{ArgumentCaptor, Mock, MockitoAnnotations}
import org.mockito.ArgumentMatchers.any
Expand Down Expand Up @@ -75,15 +74,10 @@ class SparkKubernetesDiagnosticsSetterSuite extends SparkFunSuite

setter.setDiagnostics(diagnostics, conf)

val captor: ArgumentCaptor[UnaryOperator[Pod]] =
ArgumentCaptor.forClass(classOf[UnaryOperator[Pod]])
verify(driverPodOperations).edit(captor.capture())

val fn = captor.getValue
val initialPod = SparkPod.initialPod().pod
val editedPod = fn.apply(initialPod)
val podCaptor: ArgumentCaptor[Pod] = ArgumentCaptor.forClass(classOf[Pod])
verify(driverPodOperations).patch(any(classOf[PatchContext]), podCaptor.capture())

assert(editedPod.getMetadata.getAnnotations.get(EXIT_EXCEPTION_ANNOTATION)
assert(podCaptor.getValue.getMetadata.getAnnotations.get(EXIT_EXCEPTION_ANNOTATION)
== StringUtils.stringifyException(diagnostics))
}
}