-
Notifications
You must be signed in to change notification settings - Fork 5
/
Boot.scala
executable file
·46 lines (36 loc) · 1.93 KB
/
Boot.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package ie.zalando.fabric.gateway
import akka.actor.ActorSystem
import akka.http.scaladsl.Http
import akka.http.scaladsl.server.Route
import akka.http.scaladsl.server.RouteConcatenation._
import akka.stream.ActorMaterializer
import ie.zalando.fabric.gateway.features.{TlsEndpointSupport, VersionedHostsEnabled}
import ie.zalando.fabric.gateway.service.{IngressDerivationChain, StackSetOperations, ZeroDowntimeIngressTransitions}
import ie.zalando.fabric.gateway.web.{GatewayWebhookRoutes, HttpsContext, OperationalRoutes}
import skuber.k8sInit
import scala.concurrent.ExecutionContext
object Boot extends App with GatewayWebhookRoutes with OperationalRoutes with HttpsContext {
implicit val system: ActorSystem = ActorSystem("Fabric-Gateway-Operator")
implicit val materializer: ActorMaterializer = ActorMaterializer()
implicit val dispatcher: ExecutionContext = system.dispatcher
val versionedHostsBaseDomain = VersionedHostsEnabled.runIfEnabled { () =>
sys.env
.get(VersionedHostsEnabled.baseDomainEnvName)
.map(_.toLowerCase.trim)
.getOrElse {
throw new IllegalStateException(
s"ENV Var '${VersionedHostsEnabled.baseDomainEnvName}' needs to be set if '${VersionedHostsEnabled.envName}' is enabled")
}
}
val k8s = k8sInit
val ssOps = new StackSetOperations(k8s)
val ingDerivations = new IngressDerivationChain(ssOps, versionedHostsBaseDomain)
val zeroDowntimeIngressSwitcher = new ZeroDowntimeIngressTransitions(ingDerivations)
lazy val routes: Route = createRoutesFromDerivations(zeroDowntimeIngressSwitcher) ~ operationalRoutes
Http().bindAndHandle(routes, "0.0.0.0", 8080)
TlsEndpointSupport.runIfEnabled { () =>
system.log.info("TLS endpoint is enabled")
Http().bindAndHandle(routes, "0.0.0.0", 8443, connectionContext = httpsCtxt)
}
system.log.info("Now accepting requests for fabric gateway operator")
}