in lease-kubernetes/src/main/scala/org/apache/pekko/coordination/lease/kubernetes/internal/NativeKubernetesApiImpl.scala [108:137]
override def getLeaseResource(name: String): Future[Option[LeaseResource]] = {
val fResponse = makeRequest(requestForPath(pathForLease(name)), s"Timed out reading lease $name")
for {
response <- fResponse
entity <- response.entity.toStrict(settings.bodyReadTimeout)
lr <- response.status match {
case StatusCodes.OK =>
// it exists, parse it
log.debug("Resource {} exists: {}", name, entity)
Unmarshal(entity)
.to[NativeLeaseResource]
.map(lcr => {
Some(toLeaseResource(lcr))
})
case StatusCodes.NotFound =>
response.discardEntityBytes()
log.debug("Resource does not exist: {}", name)
Future.successful(None)
case StatusCodes.Unauthorized =>
handleUnauthorized(response)
case unexpected =>
Unmarshal(response.entity)
.to[String]
.flatMap(body => {
Future.failed(new LeaseException(
s"Unexpected response from API server when retrieving lease StatusCode: $unexpected. Body: $body"))
})
}
} yield lr
}