Repository: mesos Updated Branches: refs/heads/master c05eab4f4 -> 5324b5999
Modified CNI isolator to treat "__MESOST_TEST__*" as a test network. Currently the CNI isolator identifies the "__MESOS_TEST__" as a test network. However, there are cases where we might need multiple test networks to test against. To support this use case we now do a substring match on the network name and treat any network with name of the form "*__MESOS_TEST__*" as a test network. Review: https://reviews.apache.org/r/57627/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/02b9cd05 Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/02b9cd05 Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/02b9cd05 Branch: refs/heads/master Commit: 02b9cd055adf826d1fbc6c5e91f1a55f8ddb2114 Parents: c05eab4 Author: Avinash sridharan <[email protected]> Authored: Sun Mar 19 09:09:07 2017 -0700 Committer: Jie Yu <[email protected]> Committed: Sun Mar 19 09:09:07 2017 -0700 ---------------------------------------------------------------------- .../mesos/isolators/network/cni/cni.cpp | 35 +++++++++++++------- 1 file changed, 23 insertions(+), 12 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/02b9cd05/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp ---------------------------------------------------------------------- diff --git a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp index fdb9ce5..6e95315 100644 --- a/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp +++ b/src/slave/containerizer/mesos/isolators/network/cni/cni.cpp @@ -695,18 +695,29 @@ Future<Option<ContainerLaunchInfo>> NetworkCniIsolatorProcess::prepare( env->set_value("0.0.0.0"); if (!containerId.has_parent()) { - if (containerNetworks.contains("__MESOS_TEST__")) { - // This is only for test. For testing 'network/cni' isolator, - // we will use a mock CNI plugin and a mock CNI network - // configuration file which has "__MESOS_TEST__" as network - // name. The mock plugin will not create a new network - // namespace for the container. The container will be launched - // in the host's network namespace. The mock plugin will - // return the host's IP address for this test container. - // - // NOTE: There is an implicit assumption here that when used - // for testing, '__MESOS_TEST__' is the only network the - // container is going to join. + auto mesosTestNetwork = [=]() { + foreachkey (const string& networkName, containerNetworks) { + // We can specify test networks to the `network/cni` isolator + // with a name of the form "__MESOS_TEST__*". For these test + // networks we will use a mock CNI plugin and a mock CNI + // network configuration file which has "__MESOS_TEST__*" as + // network name. The mock plugin will not create a new network + // namespace for the container. The container will be launched + // in the host's network namespace. The mock plugin will + // return the host's IP address for this test container. + // + // NOTE: There is an implicit assumption here that when used + // for testing, '__MESOS_TEST__*' are the only networks the + // container is going to join. + if (strings::contains(networkName, "__MESOS_TEST__")) { + return true; + } + } + + return false; + }; + + if (mesosTestNetwork()) { launchInfo.add_clone_namespaces(CLONE_NEWNS); launchInfo.add_clone_namespaces(CLONE_NEWUTS); } else {
