nileshrathi345 commented on code in PR #536:
URL: https://github.com/apache/livy/pull/536#discussion_r3733253708
##########
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:
Valid point — without a delay, a persistent failure would retry in a tight
loop. I've added a 5-minute sleep in the NonFatal path, same as the normal
refresh interval, before retrying.
--
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]