Skip to content

Commit

Permalink
Add pod condition fields (#125)
Browse files Browse the repository at this point in the history
  • Loading branch information
doriordan authored Mar 12, 2018
1 parent 6f2f03f commit 0f576b5
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 14 deletions.
35 changes: 24 additions & 11 deletions client/src/it/scala/skuber/PodSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,31 @@ class PodSpec extends K8SFixture with Eventually with Matchers {
}
}

it should "get the status of newly created pod and container" in { k8s =>
k8s.get[Pod](nginxPodName).map { p =>
val nginxCont = for {
podStatus <- p.status
nginxContainerStatus = podStatus.containerStatuses(0)
nginxContName = nginxContainerStatus.name
nginxContStatus <- nginxContainerStatus.state
} yield (nginxContName, nginxContStatus)
nginxCont.map { case (name, status) =>
println(s"Container ${name} has status ${status}")
it should "check for newly created pod and container to be ready" in { k8s =>
eventually(timeout(100 seconds), interval(3 seconds)) {
val retrievePod=k8s.get[Pod](nginxPodName)
val podRetrieved=Await.ready(retrievePod, 2 seconds).value.get
val podStatus=podRetrieved.get.status.get
val nginxContainerStatus = podStatus.containerStatuses(0)
podStatus.phase should contain(Pod.Phase.Running)
nginxContainerStatus.name should be("nginx")
nginxContainerStatus.state.get shouldBe a[Container.Running]
val isUnschedulable=podStatus.conditions.exists { c =>
c._type=="PodScheduled" && c.status=="False" && c.reason==Some("Unschedulable")
}
assert(nginxCont.isDefined)
val isScheduled=podStatus.conditions.exists { c =>
c._type=="PodScheduled" && c.status=="True"
}
val isInitialised=podStatus.conditions.exists { c =>
c._type=="Initialized" && c.status=="True"
}
val isReady=podStatus.conditions.exists { c =>
c._type=="Ready" && c.status=="True"
}
assert(!isUnschedulable)
assert(isScheduled)
assert(isInitialised)
assert(isReady)
}
}

Expand Down
8 changes: 7 additions & 1 deletion client/src/main/scala/skuber/Pod.scala
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,13 @@ object Pod {
startTime: Option[Timestamp] = None,
containerStatuses: List[Container.Status] = Nil)

case class Condition(_type : String="Ready", status: String)
case class Condition(
_type : String="Ready",
status: String,
reason: Option[String]=None,
message: Option[String]=None,
lastProbeTime: Option[Timestamp]=None,
lastTransitionTime: Option[Timestamp]=None)

case class Template(
val kind: String ="PodTemplate",
Expand Down
7 changes: 5 additions & 2 deletions client/src/main/scala/skuber/json/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -545,9 +545,12 @@ package object format {

implicit val podStatusCondFormat : Format[Pod.Condition] = (
(JsPath \ "type").format[String] and
(JsPath \ "status").format[String]
(JsPath \ "status").formatMaybeEmptyString() and
(JsPath \ "reason").formatNullable[String] and
(JsPath \ "message").formatNullable[String] and
(JsPath \ "lastProbeTime").formatNullable[Timestamp] and
(JsPath \ "lastTransitionTime").formatNullable[Timestamp]
)(Pod.Condition.apply _, unlift(Pod.Condition.unapply))


implicit val podStatusFormat: Format[Pod.Status] = (
(JsPath \ "phase").formatNullableEnum(Pod.Phase) and
Expand Down

0 comments on commit 0f576b5

Please sign in to comment.