-
Notifications
You must be signed in to change notification settings - Fork 117
Restructure the test backends #248
Conversation
mccheah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Mostly minor changes. The overall approach is good.
| import org.apache.spark.deploy.kubernetes.integrationtest.constants.GCE_TEST_BACKEND | ||
|
|
||
| class GCETestBackend extends IntegrationTestBackend { | ||
| val master = System.getProperty("spark.kubernetes.test.master") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: Mark these as private
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the system property through the constructor.
| val defaultClient = new DefaultKubernetesClient(k8ClientConfig) | ||
|
|
||
| override def getKubernetesClient: DefaultKubernetesClient = { | ||
| return defaultClient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for return keyword here. The return value could be on the same line as the function signature, without braces.
|
|
||
| object IntegrationTestBackendFactory { | ||
| def getTestBackend: IntegrationTestBackend = { | ||
| Option(System.getProperty("spark.kubernetes.test.master")).map { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pass the system property's value into the constructor of GCEBackend, and GCEBackend shouldn't look up the system property itself.
|
|
||
| override def afterAll(): Unit = { | ||
| kubernetesTestClient.cleanUp() | ||
| testBackend.cleanUp |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Use empty-paren for non-getter methods.
| return defaultClient | ||
| } | ||
|
|
||
| override def cleanUp: Unit = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Provide empty-paren for methods that aren't getters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cleanup can have a default implementation in the trait that is empty, and then it only has to be overridden in MinikubeTestBackend.
| } | ||
|
|
||
| override def cleanUp: Unit = {} | ||
| override def name: String = GCE_TEST_BACKEND |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Empty-paren.
| import org.apache.spark.deploy.kubernetes.integrationtest.docker.SparkDockerImageBuilder | ||
|
|
||
| class MinikubeTestBackend extends IntegrationTestBackend { | ||
| Minikube.startMinikube() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer if these were not set up in the constructor. Instead, IntegrationTestBackend should have an initialize method that the Minikube variant implements. Then, call initialize in beforeAll().
| import org.apache.spark.deploy.kubernetes.integrationtest.backend.minikube.{Minikube, MinikubeTestBackend} | ||
| import org.apache.spark.deploy.kubernetes.integrationtest.docker.SparkDockerImageBuilder | ||
|
|
||
| abstract class IntegrationTestBackend { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
trait preferred over abstract class.
| var k8ConfBuilder = new ConfigBuilder() | ||
| .withApiVersion("v1") | ||
| .withMasterUrl(resolveK8sMaster(master)) | ||
| val k8ClientConfig = k8ConfBuilder.build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to have a separate var for the builder - simply set the config val inline:
|
|
||
| private[spark] class KubernetesSuite extends SparkFunSuite { | ||
| private var kubernetesTestClient: KubernetesTestClient = _ | ||
| private var testBackend: IntegrationTestBackend = _ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If initialization is done in a separate method and not the constructor, then this can become a val and set inline here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe I'm misunderstanding this. I still need to keep a reference to it to later cleanUp after the tests correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right but this can be a val instead of a var that's set in beforeAll():
private val testBackend = IntegrationTestBackendFactory...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! Got it. Thanks. Fixed.
| val k8ClientConfig = k8ConfBuilder.build | ||
| val defaultClient = new DefaultKubernetesClient(k8ClientConfig) | ||
| private[spark] class GCETestBackend(val master: String) extends IntegrationTestBackend { | ||
| private var defaultClient: DefaultKubernetesClient = _ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the GCE case it's probably fine to initialize in the constructor - create a KubernetesClient should be fairly lightweight. What we wanted to avoid in the Minikube case was to have side effects in the constructor.
mccheah
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks ok to merge into the dependent PR. We can continue reviewing on the downstream.
* Part 1: making test code cluster-agnostic * Final checked * Move all test code into KubernetesTestComponents * Addressed comments * Fixed doc * Restructure the test backends (#248) * Restructured the test backends * Address comments * var -> val * Comments * removed deadcode
* Part 1: making test code cluster-agnostic * Final checked * Move all test code into KubernetesTestComponents * Addressed comments * Fixed doc * Restructure the test backends (#248) * Restructured the test backends * Address comments * var -> val * Comments * removed deadcode
* Part 1: making test code cluster-agnostic * Final checked * Move all test code into KubernetesTestComponents * Addressed comments * Fixed doc * Restructure the test backends (apache-spark-on-k8s#248) * Restructured the test backends * Address comments * var -> val * Comments * removed deadcode (cherry picked from commit 6b489c2)
Resync with apache-spark-on-k8s upstream
* Part 1: making test code cluster-agnostic * Final checked * Move all test code into KubernetesTestComponents * Addressed comments * Fixed doc * Restructure the test backends (apache-spark-on-k8s#248) * Restructured the test backends * Address comments * var -> val * Comments * removed deadcode
@mccheah @ash211
This merges into #243