gyogal commented on code in PR #536:
URL: https://github.com/apache/livy/pull/536#discussion_r3730017461
##########
server/src/main/scala/org/apache/livy/utils/SparkKubernetesApp.scala:
##########
@@ -78,25 +78,24 @@ object SparkKubernetesApp extends Logging {
val RefreshServiceAccountTokenThread = new Thread() {
override def run(): Unit = {
- while (true) {
- var currentContext = new Context()
- var currentContextName = new String
- val config = kubernetesClient.getConfiguration
- if (config.getCurrentContext != null) {
- currentContext = config.getCurrentContext.getContext
- currentContextName = config.getCurrentContext.getName
+ while (!Thread.currentThread().isInterrupted) {
+ try {
+ val config = kubernetesClient.getConfiguration
+ val contextName =
Option(config.getCurrentContext).map(_.getName).getOrElse("")
+ val newestConfig = Config.autoConfigure(contextName)
+ config.setOauthToken(newestConfig.getOauthToken)
+ info("Refreshed Kubernetes service account token.")
+
+ // Token will expire 1 hour default, community recommend to update
every 5 minutes
+ Thread.sleep(300000)
+ } catch {
+ case e: InterruptedException =>
+ Thread.currentThread().interrupt()
+ warn("RefreshServiceAccountTokenThread was interrupted, exiting.",
e)
+ return
+ case NonFatal(e) =>
+ warn(s"Failed to refresh Kubernetes service account token, will
retry.", e)
Review Comment:
I was wondering in case there is a NonFatal exception, shouldn't there be a
delay before retrying? If an exception is thrown during token refresh, it may
be spinning in the loop too fast... is this something that can happen?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]