Skip to content
This repository was archived by the owner on Jan 9, 2020. It is now read-only.

Use a separate class to track components that need to be cleaned up #122

Merged
merged 12 commits into from
Feb 23, 2017

Conversation

mccheah
Copy link

@mccheah mccheah commented Feb 16, 2017

Instead of trying to handle try-catch blocks and keep in mind when objects are edited - instead store the things we want to clean up in a separate place, update the things to clean up whenever we edit them, and remove them if we deem that the component should be persisted beyond the lifetime of the spark-submit process.

Part of #109

@mccheah
Copy link
Author

mccheah commented Feb 16, 2017

This refactor is not strictly dependent on #116 but I based this branch off of that for ease of avoiding merge conflicts later.

@mccheah mccheah changed the title Refactor submit cleanup Use a separate class to track components that need to be cleaned up Feb 16, 2017
Copy link

@ash211 ash211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Like the approach -- only minor comments on logging and method naming

registeredIngresses.remove(ingress.getMetadata.getName)
}

def purgeAllRegisteredComponentsFromKubernetes(): Unit = LOCK.synchronized {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

purge -> delete (use k8s terminology)

registeredSecrets.remove(secret.getMetadata.getName)
}

def registerOrUpdateIngress(ingress: Ingress): Unit = LOCK.synchronized {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we have to have this separate LOCK object? We could have a more granular locking and lock on each map when updating that map, rather than the instance-wide LOCK

registeredIngresses.remove(ingress.getMetadata.getName)
}

def purgeAllRegisteredComponentsFromKubernetes(): Unit = LOCK.synchronized {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

put an info log line here that we're deleting registered kubernetes components plus the counts of each resource type

@mccheah mccheah force-pushed the refactor-submit-cleanup branch from dd599d4 to 8c69aa9 Compare February 16, 2017 22:46
@mccheah
Copy link
Author

mccheah commented Feb 16, 2017

This also should make #119 a little easier. We could probably cover it with a unit test, actually.

@mccheah mccheah force-pushed the refactor-submit-cleanup branch from 8c69aa9 to d1d76b0 Compare February 17, 2017 01:25
@mccheah
Copy link
Author

mccheah commented Feb 18, 2017

@aash - I believe this would cover #94 as well.

Create a KubernetesComponentsCleaner which can register arbitrary pods,
services, secrets, and ingresses. When an exception is thrown or the JVM
shuts down, the cleaner automatically purges any of its registered
components from Kubernetes. The components can be unregistered when the
driver successfully begins running, so that the application persists
beyond the lifetime of the spark-submit process.
@mccheah mccheah force-pushed the refactor-submit-cleanup branch from d1d76b0 to 693d1ec Compare February 22, 2017 23:15
…te-incremental' into refactor-submit-cleanup-rebased-2
@mccheah mccheah changed the base branch from ingress-support to k8s-support-alternate-incremental February 22, 2017 23:18
@mccheah
Copy link
Author

mccheah commented Feb 22, 2017

I changed the base branch fo k8s-support-alternate-incremental since the Ingress support PR won't be merged immediately. I will also target the other refactor PRs to merge into the base.

@@ -107,99 +107,80 @@ private[spark] class Client(

val k8ClientConfig = k8ConfBuilder.build
Utils.tryWithResource(new DefaultKubernetesClient(k8ClientConfig)) { kubernetesClient =>
val kubernetesComponentCleaner = new KubernetesComponentCleaner(kubernetesClient)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there's a lot of passing around of this local variable. I wonder if it makes more sense to make this instance local, add to it throughout the run and other methods and then at the end of the run method (probably in a finally block) clean everything up. That approach reminds me a lot of a Haskell Monad accumulating state for later processing

@ash211
Copy link

ash211 commented Feb 22, 2017

Totally agree with separating this from the Ingress PR -- let's get the refactoring PRs in separately since they're much less controversial

(Array[EnvVar], Array[Volume], Array[VolumeMount], Array[Secret]) = {
private def configureSsl(
kubernetesClient: KubernetesClient,
kubernetesComponentCleaner: KubernetesComponentCleaner,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we still need this as a parameter vs using the instance variable?

Copy link

@ash211 ash211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm comfortable merging when the build is green

@mccheah
Copy link
Author

mccheah commented Feb 23, 2017

@erikerlandson @foxish @iyanuobidele - anyone have any more comments about this?

Copy link

@ash211 ash211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still looks good after the last two changes

registeredPods.synchronized {
registeredPods.values.foreach { pod =>
Utils.tryLogNonFatalError {
kubernetesClient.pods().delete(pod)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if all of these can be accomplished using the kubernetesClient.resource(obj).delete(...) call?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would simplify the logic here to instead just track each of them as resources, rather than pods/secrets/services.

@mccheah
Copy link
Author

mccheah commented Feb 23, 2017

@foxish addressed your comments, thanks for the review. @ash211

Copy link

@ash211 ash211 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a nice change to clean resources generically. I'm comfortable now -- will merge when the build is green

@foxish
Copy link
Member

foxish commented Feb 23, 2017

LGTM. Thanks!

@ash211 ash211 merged commit 452f8f1 into k8s-support-alternate-incremental Feb 23, 2017
@mccheah mccheah deleted the refactor-submit-cleanup branch February 24, 2017 02:32
ash211 pushed a commit that referenced this pull request Mar 8, 2017
…122)

* Refactor the cleaning up of Kubernetes components.

Create a KubernetesComponentsCleaner which can register arbitrary pods,
services, secrets, and ingresses. When an exception is thrown or the JVM
shuts down, the cleaner automatically purges any of its registered
components from Kubernetes. The components can be unregistered when the
driver successfully begins running, so that the application persists
beyond the lifetime of the spark-submit process.

* Fix spacing

* Address comments

* Fix compiler error

* Pull KubernetesComponentCleaner into instance variable

* Remove a parameter

* Remove redundant registerOrUpdateSecret for SSL

* Remove Ingresses from component cleaner

* Clear resources generically as opposed to specifying each type

* Remove incorrect test assertion

* Rename variable
foxish pushed a commit that referenced this pull request Jul 24, 2017
…122)

* Refactor the cleaning up of Kubernetes components.

Create a KubernetesComponentsCleaner which can register arbitrary pods,
services, secrets, and ingresses. When an exception is thrown or the JVM
shuts down, the cleaner automatically purges any of its registered
components from Kubernetes. The components can be unregistered when the
driver successfully begins running, so that the application persists
beyond the lifetime of the spark-submit process.

* Fix spacing

* Address comments

* Fix compiler error

* Pull KubernetesComponentCleaner into instance variable

* Remove a parameter

* Remove redundant registerOrUpdateSecret for SSL

* Remove Ingresses from component cleaner

* Clear resources generically as opposed to specifying each type

* Remove incorrect test assertion

* Rename variable
ifilonenko pushed a commit to ifilonenko/spark that referenced this pull request Feb 25, 2019
…pache-spark-on-k8s#122)

* Refactor the cleaning up of Kubernetes components.

Create a KubernetesComponentsCleaner which can register arbitrary pods,
services, secrets, and ingresses. When an exception is thrown or the JVM
shuts down, the cleaner automatically purges any of its registered
components from Kubernetes. The components can be unregistered when the
driver successfully begins running, so that the application persists
beyond the lifetime of the spark-submit process.

* Fix spacing

* Address comments

* Fix compiler error

* Pull KubernetesComponentCleaner into instance variable

* Remove a parameter

* Remove redundant registerOrUpdateSecret for SSL

* Remove Ingresses from component cleaner

* Clear resources generically as opposed to specifying each type

* Remove incorrect test assertion

* Rename variable

(cherry picked from commit 452f8f1)
ifilonenko pushed a commit to ifilonenko/spark that referenced this pull request Feb 25, 2019
puneetloya pushed a commit to puneetloya/spark that referenced this pull request Mar 11, 2019
…pache-spark-on-k8s#122)

* Refactor the cleaning up of Kubernetes components.

Create a KubernetesComponentsCleaner which can register arbitrary pods,
services, secrets, and ingresses. When an exception is thrown or the JVM
shuts down, the cleaner automatically purges any of its registered
components from Kubernetes. The components can be unregistered when the
driver successfully begins running, so that the application persists
beyond the lifetime of the spark-submit process.

* Fix spacing

* Address comments

* Fix compiler error

* Pull KubernetesComponentCleaner into instance variable

* Remove a parameter

* Remove redundant registerOrUpdateSecret for SSL

* Remove Ingresses from component cleaner

* Clear resources generically as opposed to specifying each type

* Remove incorrect test assertion

* Rename variable
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants