Skip to content

Support graceful shutdown of runtime pods. #5283

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,13 @@ trait Container {
transid.failed(this, start, s"initializiation failed with $t")
}
.flatMap { result =>
// if runtime container is shutting down, reschedule the activation message
result.response.right.map { res =>
if (res.shuttingDown) {
throw ContainerHealthError(transid, containerId.asString)
}
}

if (result.ok) {
Future.successful(result.interval)
} else if (result.interval.duration >= timeout) {
Expand Down Expand Up @@ -180,6 +187,13 @@ trait Container {
transid.failed(this, start, s"run failed with $t")
}
.map { result =>
// if runtime container is shutting down, reschedule the activation message
result.response.right.map { res =>
if (res.shuttingDown) {
throw ContainerHealthError(transid, containerId.asString)
}
}

val response = if (result.interval.duration >= timeout) {
ActivationResponse.developerError(Messages.timedoutActivation(timeout, false))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@
package org.apache.openwhisk.core.entity

import scala.util.Try

import akka.http.scaladsl.model.StatusCodes.OK

import akka.http.scaladsl.model.StatusCodes.{OK, ServiceUnavailable}
import spray.json._
import spray.json.DefaultJsonProtocol

import org.apache.openwhisk.common.Logging
import org.apache.openwhisk.http.Messages._

Expand Down Expand Up @@ -139,6 +136,10 @@ protected[core] object ActivationResponse extends DefaultJsonProtocol {
/** true iff status code is OK (HTTP 200 status code), anything else is considered an error. **/
val okStatus = statusCode == OK.intValue
val ok = okStatus && truncated.isEmpty

/** true iff status code is ServiceUnavailable (HTTP 503 status code) */
val shuttingDown = statusCode == ServiceUnavailable.intValue

override def toString = {
val base = if (okStatus) "ok" else "not ok"
val rest = truncated.map(e => s", truncated ${e.toString}").getOrElse("")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,23 @@ class DockerContainerTests
end.deltaToMarkerStart shouldBe Some(interval.duration.toMillis)
}

it should "throw ContainerHealthError if runtime container returns 503 response" in {
implicit val docker = stub[DockerApiWithFileAccess]
implicit val runc = stub[RuncApi]

val interval = intervalOf(1.millisecond)
val result = JsObject.empty
val container = dockerContainer() {
Future.successful(RunResult(interval, Right(ContainerResponse(503, result.compactPrint, None))))
}

val initResult = container.initialize(JsObject.empty, 1.second, 1)
an[ContainerHealthError] should be thrownBy await(initResult)

val runResult = container.run(JsObject.empty, JsObject.empty, 1.second, 1)
an[ContainerHealthError] should be thrownBy await(runResult)
}

it should "properly deal with a timeout during run" in {
implicit val docker = stub[DockerApiWithFileAccess]
implicit val runc = stub[RuncApi]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,22 @@ class KubernetesContainerTests
end.deltaToMarkerStart shouldBe Some(interval.duration.toMillis)
}

it should "throw ContainerHealthError if runtime container returns 503 response" in {
implicit val kubernetes = stub[KubernetesApi]

val interval = intervalOf(1.millisecond)
val result = JsObject.empty
val container = kubernetesContainer() {
Future.successful(RunResult(interval, Right(ContainerResponse(503, result.compactPrint, None))))
}

val initResult = container.initialize(JsObject.empty, 1.second, 1)
an[ContainerHealthError] should be thrownBy await(initResult)

val runResult = container.run(JsObject.empty, JsObject.empty, 1.second, 1)
an[ContainerHealthError] should be thrownBy await(runResult)
}

it should "properly deal with a timeout during run" in {
implicit val kubernetes = stub[KubernetesApi]

Expand Down