fix: only add 'networks' key if 'network_mode' is absent

This commit is contained in:
Matt 2024-02-11 09:22:09 -06:00
parent 059748ad3b
commit e6ca8cd167

View File

@ -527,28 +527,32 @@ function getTopLevelNetworks(Service|Application $resource)
$definedNetwork = collect([$resource->uuid]); $definedNetwork = collect([$resource->uuid]);
$services = collect($services)->map(function ($service, $_) use ($topLevelNetworks, $definedNetwork) { $services = collect($services)->map(function ($service, $_) use ($topLevelNetworks, $definedNetwork) {
$serviceNetworks = collect(data_get($service, 'networks', [])); $serviceNetworks = collect(data_get($service, 'networks', []));
$hasNetworkMode = data_get($service, 'network_mode');
// Collect/create/update networks // Only add 'networks' key if 'network_mode' is absent
if ($serviceNetworks->count() > 0) { if (!$hasNetworkMode) {
foreach ($serviceNetworks as $networkName => $networkDetails) { // Collect/create/update networks
$networkExists = $topLevelNetworks->contains(function ($value, $key) use ($networkName) { if ($serviceNetworks->count() > 0) {
return $value == $networkName || $key == $networkName; foreach ($serviceNetworks as $networkName => $networkDetails) {
}); $networkExists = $topLevelNetworks->contains(function ($value, $key) use ($networkName) {
if (!$networkExists) { return $value == $networkName || $key == $networkName;
$topLevelNetworks->put($networkDetails, null); });
if (!$networkExists) {
$topLevelNetworks->put($networkDetails, null);
}
} }
} }
}
$definedNetworkExists = $topLevelNetworks->contains(function ($value, $_) use ($definedNetwork) { $definedNetworkExists = $topLevelNetworks->contains(function ($value, $_) use ($definedNetwork) {
return $value == $definedNetwork; return $value == $definedNetwork;
}); });
if (!$definedNetworkExists) { if (!$definedNetworkExists) {
foreach ($definedNetwork as $network) { foreach ($definedNetwork as $network) {
$topLevelNetworks->put($network, [ $topLevelNetworks->put($network, [
'name' => $network, 'name' => $network,
'external' => true 'external' => true
]); ]);
}
} }
} }