Skip to content
This repository was archived by the owner on May 25, 2023. It is now read-only.
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 @@ -36,6 +36,7 @@ case class Annotations(
memory: Option[Long],
cpu: Option[Double],
endpoints: Map[String, Endpoint],
managementEndpointName: Option[String],
secrets: Seq[Secret],
annotations: Seq[Annotation] = Seq.empty,
privileged: Boolean,
Expand Down Expand Up @@ -116,6 +117,7 @@ object Annotations extends LazyLogging {
memory = args.memory.orElse(memory(labels)),
cpu = args.cpu.orElse(cpu(labels)),
endpoints = endpoints(selectArrayWithIndex(labels, ns("endpoints")), applicationVersion),
managementEndpointName = managementEndpointName(labels),
secrets = secrets(selectArray(labels, ns("secrets"))),
annotations = annotations(selectArray(labels, ns("annotations"))),
privileged = privileged(labels),
Expand Down Expand Up @@ -211,6 +213,10 @@ object Annotations extends LazyLogging {
value <- annotation.get("value")
} yield Annotation(key, value)

private[annotations] def managementEndpointName(labels: Map[String, String]): Option[String] =
labels
.get(ns("management-endpoint"))

private[annotations] def endpoints(endpoints: Seq[(Int, Map[String, String])], version: Option[String]): Map[String, Endpoint] =
endpoints.flatMap(v => endpoint(v._2, v._1, version)).toMap

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@
package com.lightbend.rp.reactivecli

package object annotations {
val AkkaManagementPortName = "akka-mgmt-http"
val legacyAkkaManagementPortName = "akka-mgmt-http"
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,14 @@ object PodTemplate {
appTypeEnvs(annotations.appType, annotations.modules),
configEnvs(annotations.configResource),
endpointEnvs(annotations.endpoints),
akkaClusterEnvs(annotations.modules, annotations.namespace, serviceResourceName, noOfReplicas, annotations.akkaClusterBootstrapSystemName, akkaClusterJoinExisting),
akkaClusterEnvs(
annotations.modules,
annotations.namespace,
serviceResourceName,
annotations.managementEndpointName.getOrElse(legacyAkkaManagementPortName),
noOfReplicas,
annotations.akkaClusterBootstrapSystemName,
akkaClusterJoinExisting),
externalServicesEnvs(annotations.modules, externalServices))

private[kubernetes] def appNameEnvs(appName: Option[String]): Map[String, EnvironmentVariable] =
Expand All @@ -71,14 +78,22 @@ object PodTemplate {
if (modules.isEmpty) Seq.empty else Seq("RP_MODULES" -> LiteralEnvironmentVariable(modules.toVector.sorted.mkString(","))))
}.toMap

private[kubernetes] def akkaClusterEnvs(modules: Set[String], namespace: Option[String], serviceResourceName: String, noOfReplicas: Int, akkaClusterBootstrapSystemName: Option[String], akkaClusterJoinExisting: Boolean): Map[String, EnvironmentVariable] =
private[kubernetes] def akkaClusterEnvs(
modules: Set[String],
namespace: Option[String],
serviceResourceName: String,
managementEndpointName: String,
noOfReplicas: Int,
akkaClusterBootstrapSystemName: Option[String],
akkaClusterJoinExisting: Boolean): Map[String, EnvironmentVariable] =
if (!modules.contains(Module.AkkaClusterBootstrapping))
Map.empty
else
Map(
"RP_JAVA_OPTS" -> LiteralEnvironmentVariable(
Seq(
s"-Dakka.management.cluster.bootstrap.contact-point-discovery.discovery-method=kubernetes-api",
s"-Dakka.management.cluster.bootstrap.contact-point-discovery.port-name=$managementEndpointName",
s"-Dakka.management.cluster.bootstrap.contact-point-discovery.effective-name=$serviceResourceName",
s"-Dakka.management.cluster.bootstrap.contact-point-discovery.required-contact-point-nr=$noOfReplicas",
akkaClusterBootstrapSystemName.fold("-Dakka.discovery.kubernetes-api.pod-label-selector=appName=%s")(systemName => s"-Dakka.discovery.kubernetes-api.pod-label-selector=actorSystemName=$systemName"),
Expand Down Expand Up @@ -316,13 +331,18 @@ object PodTemplate {
val enableChecks =
annotations.modules.contains(Module.Status) && annotations.modules.contains(Module.AkkaManagement)

lazy val managementPortName =
annotations
.managementEndpointName
.getOrElse(legacyAkkaManagementPortName)

val livenessProbe =
if (enableChecks)
Json("livenessProbe" ->
Json(
"httpGet" -> Json(
"path" -> jString(HealthCheckUrl),
"port" -> jString(AkkaManagementPortName)),
"port" -> jString(managementPortName)),
"periodSeconds" -> jNumber(StatusPeriodSeconds),
"initialDelaySeconds" -> jNumber(LivenessInitialDelaySeconds)))
else
Expand All @@ -334,7 +354,7 @@ object PodTemplate {
Json(
"httpGet" -> Json(
"path" -> jString(ReadyCheckUrl),
"port" -> jString(AkkaManagementPortName)),
"port" -> jString(managementPortName)),
"periodSeconds" -> jNumber(StatusPeriodSeconds)))
else
jEmptyObject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ object RpEnvironmentVariables {
appTypeEnvs(annotations.appType, annotations.modules),
configEnvs(annotations.configResource),
endpointEnvs(annotations.endpoints),
akkaClusterEnvs(annotations.modules, annotations.namespace, serviceResourceName, noOfReplicas, annotations.akkaClusterBootstrapSystemName, akkaClusterJoinExisting),
akkaClusterEnvs(annotations.modules, annotations.namespace, serviceResourceName, annotations.managementEndpointName.getOrElse(legacyAkkaManagementPortName), noOfReplicas, annotations.akkaClusterBootstrapSystemName, akkaClusterJoinExisting),
externalServicesEnvs(annotations.modules, externalServices))

private def appNameEnvs(appName: Option[String]): Map[String, String] =
Expand All @@ -51,13 +51,21 @@ object RpEnvironmentVariables {
if (modules.isEmpty) Seq.empty else Seq("RP_MODULES" -> modules.toVector.sorted.mkString(",")))
}.toMap

private def akkaClusterEnvs(modules: Set[String], namespace: Option[String], serviceResourceName: String, noOfReplicas: Int, akkaClusterBootstrapSystemName: Option[String], akkaClusterJoinExisting: Boolean): Map[String, String] =
private def akkaClusterEnvs(
modules: Set[String],
namespace: Option[String],
serviceResourceName: String,
managementEndpointName: String,
noOfReplicas: Int,
akkaClusterBootstrapSystemName: Option[String],
akkaClusterJoinExisting: Boolean): Map[String, String] =
if (!modules.contains(Module.AkkaClusterBootstrapping))
Map.empty
else
Map(
"RP_JAVA_OPTS" -> Seq(
s"-Dakka.management.cluster.bootstrap.contact-point-discovery.discovery-method=marathon-api",
s"-Dakka.management.cluster.bootstrap.contact-point-discovery.port-name=$managementEndpointName",
s"-Dakka.management.cluster.bootstrap.contact-point-discovery.effective-name=$serviceResourceName",
s"-Dakka.management.cluster.bootstrap.contact-point-discovery.required-contact-point-nr=$noOfReplicas",
akkaClusterBootstrapSystemName.fold("-Dakka.discovery.marathon-api.app-label-query=APP_NAME==%s")(systemName => s"-Dakka.discovery.marathon-api.app-label-query=ACTOR_SYSTEM_NAME==$systemName"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,17 @@ package object marathon {
val enableChecks =
annotations.modules.contains(Module.Status) && annotations.modules.contains(Module.AkkaManagement)

val managementPortName =
annotations
.managementEndpointName
.getOrElse(legacyAkkaManagementPortName)

val checkPortName =
portName(AkkaManagementPortName)
portName(managementPortName)

val checkPortIndex =
sortedEndpoints
.find(_.name == AkkaManagementPortName)
.find(_.name == managementPortName)
.map(_.index)
.getOrElse(0)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ object AnnotationsTest extends TestSuite {
memory = None,
cpu = None,
endpoints = Map.empty,
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map.empty,
Expand Down Expand Up @@ -176,6 +177,8 @@ object AnnotationsTest extends TestSuite {
"com.lightbend.rp.endpoints.2.name" -> "ep3",
"com.lightbend.rp.endpoints.2.protocol" -> "udp",
"com.lightbend.rp.endpoints.2.port" -> "1234",
"com.lightbend.rp.remoting-endpoint" -> "remoting",
"com.lightbend.rp.management-endpoint" -> "management",
"com.lightbend.rp.annotations.0.key" -> "annotationKey0",
"com.lightbend.rp.annotations.0.value" -> "annotationValue0",
"com.lightbend.rp.annotations.1.key" -> "annotationKey1",
Expand All @@ -198,6 +201,7 @@ object AnnotationsTest extends TestSuite {
"ep1" -> HttpEndpoint(0, "ep1", 0, Seq(HttpIngress(Seq(80, 443), Seq("hello.com"), Seq("^/.*")))),
"ep2" -> TcpEndpoint(1, "ep2", 1234),
"ep3" -> UdpEndpoint(2, "ep3", 1234)),
managementEndpointName = Some("management"),
secrets = Seq.empty,
annotations = Vector(
Annotation("annotationKey0", "annotationValue0"),
Expand Down Expand Up @@ -240,6 +244,7 @@ object AnnotationsTest extends TestSuite {
memory = Some(1024),
cpu = Some(0.5),
endpoints = Map.empty,
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map(
Expand All @@ -266,6 +271,7 @@ object AnnotationsTest extends TestSuite {
memory = None,
cpu = None,
endpoints = Map.empty,
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map.empty,
Expand All @@ -288,6 +294,7 @@ object AnnotationsTest extends TestSuite {
memory = None,
cpu = None,
endpoints = Map.empty,
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map.empty,
Expand All @@ -310,6 +317,7 @@ object AnnotationsTest extends TestSuite {
memory = None,
cpu = None,
endpoints = Map.empty,
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map.empty,
Expand Down Expand Up @@ -338,6 +346,7 @@ object AnnotationsTest extends TestSuite {
cpu = None,
endpoints = Map(
"ep2" -> TcpEndpoint(1, "ep2", 1234)),
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map.empty,
Expand All @@ -364,6 +373,7 @@ object AnnotationsTest extends TestSuite {
cpu = None,
endpoints = Map(
"ep2" -> TcpEndpoint(1, "ep2", 1234)),
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ object DeploymentJsonTest extends TestSuite {
memory = Some(8192L),
cpu = Some(0.5D),
endpoints = endpoints,
managementEndpointName = None,
secrets = Seq(Secret("acme.co", "my-secret")),
annotations = Seq(
Annotation("annotationKey0", "annotationValue0"),
Expand Down Expand Up @@ -438,15 +439,15 @@ object DeploymentJsonTest extends TestSuite {
| "readinessProbe": {
| "httpGet": {
| "path": "/platform-tooling/ready",
| "port": "akka-mgmt-http"
| "port": "management"
| },
| "periodSeconds": 10
| },
| "name": "friendimpl",
| "livenessProbe": {
| "httpGet": {
| "path": "/platform-tooling/healthy",
| "port": "akka-mgmt-http"
| "port": "management"
| },
| "periodSeconds": 10,
| "initialDelaySeconds": 60
Expand Down Expand Up @@ -654,7 +655,7 @@ object DeploymentJsonTest extends TestSuite {
| },
| {
| "name": "RP_JAVA_OPTS",
| "value": "-Dconfig.resource=my-config.conf -Dakka.management.cluster.bootstrap.contact-point-discovery.discovery-method=kubernetes-api -Dakka.management.cluster.bootstrap.contact-point-discovery.effective-name=friendimpl -Dakka.management.cluster.bootstrap.contact-point-discovery.required-contact-point-nr=1 -Dakka.discovery.kubernetes-api.pod-label-selector=appName=%s"
| "value": "-Dconfig.resource=my-config.conf -Dakka.management.cluster.bootstrap.contact-point-discovery.discovery-method=kubernetes-api -Dakka.management.cluster.bootstrap.contact-point-discovery.port-name=management -Dakka.management.cluster.bootstrap.contact-point-discovery.effective-name=friendimpl -Dakka.management.cluster.bootstrap.contact-point-discovery.required-contact-point-nr=1 -Dakka.discovery.kubernetes-api.pod-label-selector=appName=%s"
| },
| {
| "name": "RP_KUBERNETES_POD_IP",
Expand Down Expand Up @@ -709,8 +710,8 @@ object DeploymentJsonTest extends TestSuite {
|}
""".stripMargin.parse.right.get
val result = Deployment.generate(annotations.copy(
modules = Set("akka-management", "status", "akka-cluster-bootstrapping")
), "apps/v1beta2", None, imageName,
modules = Set("akka-management", "status", "akka-cluster-bootstrapping"),
managementEndpointName = Some("management")), "apps/v1beta2", None, imageName,
PodTemplate.ImagePullPolicy.Never, PodTemplate.RestartPolicy.Default, noOfReplicas = 1, Map.empty, CanaryDeploymentType, JsonTransform.noop, false).toOption.get
if (result.json != expectedJson) {
println(s"deployment K8 JSON:\n" + PrettyParams.spaces2.copy(colonLeft = "").pretty(result.json))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ object IngressJsonTest extends TestSuite {
HttpIngress(Seq(80, 443), Seq.empty, Seq(urlOne)),
HttpIngress(Seq(80, 443), Seq("hello.com"), Seq.empty),
HttpIngress(Seq(80, 443), Seq("hello.com", "world.io"), Seq(urlOne, urlTwo))))),
managementEndpointName = None,
secrets = Seq.empty,
privileged = true,
environmentVariables = Map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ object JobJsonTest extends TestSuite {
memory = None,
cpu = None,
endpoints = Map.empty,
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ object NamespaceJsonTest extends TestSuite {
memory = None,
cpu = None,
endpoints = Map.empty,
managementEndpointName = None,
secrets = Seq.empty,
privileged = false,
environmentVariables = Map.empty,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ object ServiceJsonTest extends TestSuite {
cpu = Some(0.5D),
endpoints = Map(
"ep1" -> TcpEndpoint(0, "ep1", 1234)),
managementEndpointName = None,
secrets = Seq.empty,
privileged = true,
environmentVariables = Map(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ object RpEnvironmentVariablesTest extends TestSuite {
cpu = Some(0.5D),
endpoints = Map(
"ep1" -> TcpEndpoint(0, "ep1", 1234)),
managementEndpointName = None,
secrets = Seq.empty,
privileged = true,
environmentVariables = Map(
Expand Down Expand Up @@ -89,6 +90,7 @@ object RpEnvironmentVariablesTest extends TestSuite {
cpu = Some(0.5D),
endpoints = Map(
"ep1" -> TcpEndpoint(0, "ep1", 1234)),
managementEndpointName = None,
secrets = Seq.empty,
privileged = true,
environmentVariables = Map(
Expand All @@ -109,7 +111,7 @@ object RpEnvironmentVariablesTest extends TestSuite {
Map(
"RP_ENDPOINT_0_BIND_PORT" -> "$PORT_EP",
"RP_ENDPOINTS" -> "EP1", "RP_APP_VERSION" -> "3.2.1-SNAPSHOT",
"RP_JAVA_OPTS" -> "-Dakka.management.cluster.bootstrap.contact-point-discovery.discovery-method=marathon-api -Dakka.management.cluster.bootstrap.contact-point-discovery.effective-name=friendimpl -Dakka.management.cluster.bootstrap.contact-point-discovery.required-contact-point-nr=3 -Dakka.discovery.marathon-api.app-label-query=APP_NAME==%s",
"RP_JAVA_OPTS" -> "-Dakka.management.cluster.bootstrap.contact-point-discovery.discovery-method=marathon-api -Dakka.management.cluster.bootstrap.contact-point-discovery.port-name=management -Dakka.management.cluster.bootstrap.contact-point-discovery.effective-name=friendimpl -Dakka.management.cluster.bootstrap.contact-point-discovery.required-contact-point-nr=3 -Dakka.discovery.marathon-api.app-label-query=APP_NAME==%s",
"RP_PLATFORM" -> "mesos",
"RP_ENDPOINT_EP1_PORT" -> "$PORT_EP",
"RP_MODULES" -> "akka-cluster-bootstrapping",
Expand Down Expand Up @@ -138,6 +140,7 @@ object RpEnvironmentVariablesTest extends TestSuite {
cpu = Some(0.5D),
endpoints = Map(
"ep1" -> TcpEndpoint(0, "ep1", 1234)),
managementEndpointName = Some("management"),
secrets = Seq.empty,
privileged = true,
environmentVariables = Map(
Expand Down Expand Up @@ -187,6 +190,7 @@ object RpEnvironmentVariablesTest extends TestSuite {
cpu = Some(0.5D),
endpoints = Map(
"ep1" -> TcpEndpoint(0, "ep1", 1234)),
managementEndpointName = None,
secrets = Seq.empty,
privileged = true,
environmentVariables = Map(
Expand Down