-
Notifications
You must be signed in to change notification settings - Fork 118
Use a separate class to track components that need to be cleaned up #122
Use a separate class to track components that need to be cleaned up #122
Conversation
This refactor is not strictly dependent on #116 but I based this branch off of that for ease of avoiding merge conflicts later. |
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.
Like the approach -- only minor comments on logging and method naming
registeredIngresses.remove(ingress.getMetadata.getName) | ||
} | ||
|
||
def purgeAllRegisteredComponentsFromKubernetes(): Unit = LOCK.synchronized { |
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.
purge -> delete (use k8s terminology)
registeredSecrets.remove(secret.getMetadata.getName) | ||
} | ||
|
||
def registerOrUpdateIngress(ingress: Ingress): Unit = LOCK.synchronized { |
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.
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 { |
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.
put an info log line here that we're deleting registered kubernetes components plus the counts of each resource type
dd599d4
to
8c69aa9
Compare
This also should make #119 a little easier. We could probably cover it with a unit test, actually. |
8c69aa9
to
d1d76b0
Compare
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.
d1d76b0
to
693d1ec
Compare
…te-incremental' into refactor-submit-cleanup-rebased-2
I changed the base branch fo |
@@ -107,99 +107,80 @@ private[spark] class Client( | |||
|
|||
val k8ClientConfig = k8ConfBuilder.build | |||
Utils.tryWithResource(new DefaultKubernetesClient(k8ClientConfig)) { kubernetesClient => | |||
val kubernetesComponentCleaner = new KubernetesComponentCleaner(kubernetesClient) |
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.
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
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, |
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.
do we still need this as a parameter vs using the instance variable?
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.
I'm comfortable merging when the build is green
@erikerlandson @foxish @iyanuobidele - anyone have any more comments about this? |
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.
Still looks good after the last two changes
registeredPods.synchronized { | ||
registeredPods.values.foreach { pod => | ||
Utils.tryLogNonFatalError { | ||
kubernetesClient.pods().delete(pod) |
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.
I'm wondering if all of these can be accomplished using the kubernetesClient.resource(obj).delete(...)
call?
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.
It would simplify the logic here to instead just track each of them as resources
, rather than pods/secrets/services.
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.
That's a nice change to clean resources generically. I'm comfortable now -- will merge when the build is green
LGTM. Thanks! |
…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
…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
…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)
…-palantir4-k8s-release Resync with k8s
…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
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