Github user ifilonenko commented on a diff in the pull request:

    https://github.com/apache/spark/pull/22911#discussion_r233542062
  
    --- Diff: 
resource-managers/kubernetes/core/src/main/scala/org/apache/spark/deploy/k8s/SparkPod.scala
 ---
    @@ -18,7 +18,30 @@ package org.apache.spark.deploy.k8s
     
     import io.fabric8.kubernetes.api.model.{Container, ContainerBuilder, Pod, 
PodBuilder}
     
    -private[spark] case class SparkPod(pod: Pod, container: Container)
    +private[spark] case class SparkPod(pod: Pod, container: Container) {
    +
    +  /**
    +   * Convenience method to apply a series of chained transformations to a 
pod.
    +   *
    +   * Use it like:
    +   *
    +   *     original.modify { case pod =>
    +   *       // update pod and return new one
    +   *     }.modify { case pod =>
    +   *       // more changes that create a new pod
    +   *     }.modify {
    +   *       case pod if someCondition => // new pod
    +   *     }
    +   *
    +   * This makes it cleaner to apply multiple transformations, avoiding 
having to create
    +   * a bunch of awkwardly-named local variables. Since the argument is a 
partial function,
    +   * it can do matching without needing to exhaust all the possibilities. 
If the function
    +   * is not applied, then the original pod will be kept.
    +   */
    +  def transform(fn: PartialFunction[SparkPod, SparkPod]): SparkPod = 
fn.lift(this).getOrElse(this)
    --- End diff --
    
    I would think that this change is out of the scope of this PR, but I do 
love the use of a PartialFunction here. Thanks for this! 


---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscr...@spark.apache.org
For additional commands, e-mail: reviews-h...@spark.apache.org

Reply via email to