Commit a4693c48 authored by Mathieu's avatar Mathieu
Browse files

Fix openmole pod creation

parent 3766448a
......@@ -13,6 +13,8 @@ import skuber.ext.{Deployment, Ingress, IngressList}
import scala.concurrent.duration._
import scala.concurrent.{Await, Future}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.{Failure, Success}
object K8sService {
......@@ -101,89 +103,58 @@ object K8sService {
}
}
// def withK8sToResult(k8Action: String)(kubeAction: KubernetesClient => Future[_ <: ObjectResource]): K8ActionResult = {
//
// implicit val system = ActorSystem()
// implicit val materializer = ActorMaterializer()
// implicit val dispatcher = system.dispatcher
// val k8s = k8sInit(K8SConfiguration.useLocalProxyDefault)
//
// Try {
// Await.result({
// kubeAction(k8s)
// }, Duration.Inf)
// } match {
// case Success(o: ObjectResource) => K8Success(s"$k8Action successfully completed " + o.name + " // " + o.metadata.generateName)
// case Failure(t: Throwable) => K8Failure(t.getMessage, t.toStackTrace)
// }
// }
// implicit class OResourceToK8ActionResult[OR <: ObjectResource](o: OR) {
// def toK8ActionResult = o match {
// case Success(o: ObjectResource) => K8Success(s"$k8Action successfully completed " + o.name + " // " + o.metadata.generateName)
// case Failure(t: Throwable) => K8Failure(t.getMessage, t.toStackTrace)
// }
//}
def deployOpenMOLE(uuid: UUID) = {
withK8s { k8s =>
val openmoleLabel = "app" -> "openmole"
val openmoleContainer = Container(name = "openmole", image = "openmole/openmole", command = List("bin/bash", "-c", "openmole --port 80 --password password --http --remote")).exposePort(80)
val openmoleTemplate = Pod.Template.Spec(ObjectMeta(name = uuid.value, namespace = "default"))
.addContainer(openmoleContainer)
.addLabel(openmoleLabel)
//.named("openmole")
val desiredCount = 1
val openmoleDeployment = Deployment(uuid.value)
.withReplicas(desiredCount)
.withTemplate(openmoleTemplate)
println("\nCreating openmole deployment")
k8s create openmoleDeployment
}
def deployOpenMOLE(uuid: UUID) = {
withK8s { k8s =>
val podName = s"${uuid.value}"
}
val openmoleContainer = Container(
name = "openmole",
image = "openmole/openmole",
command = List("bin/bash", "-c", "openmole --port 80 --password password --http --remote --mem 1G")).exposePort(80)
def deployIfNotDeployedYet(uuid: UUID) = {
if (!isDeploymentExists(uuid))
deployOpenMOLE(uuid)
val openmolePod = Pod(spec = Some(Pod.Spec().addContainer(openmoleContainer)), metadata = ObjectMeta(name = podName, namespace = "openmole"))
}
private def podInfo(uuid: UUID)
=
{
k8s create openmolePod
}
}
// import monix.execution.Scheduler.Implicits.global
val lp = listPods
println("pods " + lp)
lp.find {
_.name.contains(uuid.value)
}
}
def deployIfNotDeployedYet(uuid: UUID) = {
if (!isDeploymentExists(uuid))
deployOpenMOLE(uuid)
}
def isServiceUp(uuid: UUID): Boolean = {
podInfo(uuid).map {
_.status
} == Some(Running)
}
private def podInfo(uuid: UUID) = {
// import monix.execution.Scheduler.Implicits.global
val lp = listPods
println("pods " + lp)
lp.find {
_.name.contains(uuid.value)
}
}
def isDeploymentExists(uuid: UUID) = podInfo(uuid).isDefined
def podInfos: Seq[PodInfo] = {
def isServiceUp(uuid: UUID): Boolean = {
podInfo(uuid).map {
_.status
} == Some(Running)
}
for {
uuid <- DB.uuids
podInfo <- podInfo(uuid)
} yield (podInfo)
}
def isDeploymentExists(uuid: UUID) = podInfo(uuid).isDefined
def hostIP(uuid: UUID) = {
podInfo(uuid).map {
_.podIP
}
}
}
\ No newline at end of file
def podInfos: Seq[PodInfo] = {
for {
uuid <- DB.uuids
podInfo <- podInfo(uuid)
} yield (podInfo)
}
def hostIP(uuid: UUID) = {
podInfo(uuid).map {
_.podIP
}
}
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment