in lease-kubernetes/src/main/scala/org/apache/pekko/coordination/lease/kubernetes/internal/AbstractKubernetesApiImpl.scala [78:109]
protected def createLeaseResource(name: String): Future[Option[LeaseResource]]
protected def getLeaseResource(name: String): Future[Option[LeaseResource]]
protected def pathForLease(name: String): Uri.Path
override def readOrCreateLeaseResource(name: String): Future[LeaseResource] = {
// TODO backoff retry
val maxTries = 5
def loop(tries: Int = 0): Future[LeaseResource] = {
log.debug("Trying to create lease {}", tries)
for {
olr <- getLeaseResource(name)
lr <- olr match {
case Some(found) =>
log.debug("{} already exists. Returning {}", name, found)
Future.successful(found)
case None =>
log.info("lease {} does not exist, creating", name)
createLeaseResource(name).flatMap {
case Some(created) => Future.successful(created)
case None =>
if (tries < maxTries) loop(tries + 1)
else Future.failed(new LeaseException(s"Unable to create or read lease after $maxTries tries"))
}
}
} yield lr
}
loop()
}