From 137f9c02feacf2b7ff673c05a7d872050c5b0405 Mon Sep 17 00:00:00 2001 From: Julien Pepy Date: Wed, 13 Sep 2023 00:52:26 +0200 Subject: [PATCH] Automatically detect criteo IP address for checks This should remove the constraint on Mesos to configure `criteo` network in a specific order (last element). With patch, the effective address of the current task should be assign the criteo network's (first) IP address (if it is defined), otherwise we will fall back to the previous heuristic (extract the first IP address provided by Mesos). JIRA: MESOS-5907 --- .../marathon/core/task/state/NetworkInfo.scala | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/main/scala/mesosphere/marathon/core/task/state/NetworkInfo.scala b/src/main/scala/mesosphere/marathon/core/task/state/NetworkInfo.scala index d4ca6a4ac61..f431f27a8e8 100644 --- a/src/main/scala/mesosphere/marathon/core/task/state/NetworkInfo.scala +++ b/src/main/scala/mesosphere/marathon/core/task/state/NetworkInfo.scala @@ -28,7 +28,9 @@ case class NetworkInfo( */ def effectiveIpAddress(runSpec: RunSpec): Option[String] = { if (!ipAddresses.isEmpty) { - pickFirstIpAddressFrom(ipAddresses) + findCriteoIpAddress().getOrElse( + pickFirstIpAddressFrom(ipAddresses) + ) } else { Some(hostName) } @@ -91,6 +93,18 @@ object NetworkInfo extends StrictLogging { } } + def findCriteoIpAddress(mesosStatus: mesos.Protos.TaskStatus): Option[mesos.Protos.NetworkInfo.IPAddress] = { + if (mesosStatus.hasContainerStatus && mesosStatus.getContainerStatus.getNetworkInfosCount > 0) { + mesosStatus.getContainerStatus.getNetworkInfosList + .find(_.getName == "criteo") + .map(_.getIpAddressesList) + .headOption + .map(_.getIpAddress) + } else { + None + } + } + private def computePortAssignments( app: AppDefinition, hostName: String,