Skip to content

Adopt network to running instance - #635

Merged
MykolaSuperman merged 6 commits into
aosedge:developfrom
MykolaSuperman:adopt_network_to_running_instance
Aug 3, 2026
Merged

Adopt network to running instance#635
MykolaSuperman merged 6 commits into
aosedge:developfrom
MykolaSuperman:adopt_network_to_running_instance

Conversation

@MykolaSuperman

Copy link
Copy Markdown

No description provided.

@mlohvynenko mlohvynenko left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>

@mykola-kobets-epam mykola-kobets-epam left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Mykola Kobets <mykola_kobets@epam.com>

/**
* Bridge link kind.
*/
static constexpr auto cLinkKindBridge = "bridge";

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably better to make it as Aos Enum?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Error AddInstanceToCache(const String& instanceID, const String& networkID);
RetWithError<bool> IsInstanceInterfaceAlive(
const String& instanceID, const String& hostIfName, const String& bridgeIfName) const;
Error AdoptInstance(const String& instanceID, const String& networkID);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Init, or update?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

InitInstance

}
}

if (auto errDNS = AdoptDNSServer(entry.mNetworkID); !errDNS.IsNone()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use err =

and in the following condition

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


auto cleanupMonitoring = DeferRelease(&instanceID, [this, &err](const String* id) {
if (!err.IsNone()) {
if (auto errStop = mNetMonitor->StopInstanceMonitoring(*id); !errStop.IsNone()) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err =

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no, assigning to err here would disarm the other defers: they all guard on !err.IsNone() and are destroyed after this one, so a successful StopInstanceMonitoring would reset err and silently skip the remaining rollbacks.

@MykolaSuperman
MykolaSuperman force-pushed the adopt_network_to_running_instance branch from 9ffe3e6 to cb3a210 Compare August 2, 2026 08:21

@al1img al1img left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>

Mykola Solianko added 6 commits August 3, 2026 11:18
InterfaceManagerItf exposed only mutating operations, so there was no way
to tell an interface that must be created from one that is already on the
system and can be adopted as is. Same for network namespaces.

Add InterfaceManagerItf::GetLink returning link kind, master, vlan ID and
admin state (eNotFound when the link is absent) and
NamespaceManagerItf::IsNetworkNamespaceExist.

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
Reviewed-by: Mykola Kobets <mykola_kobets@epam.com>
Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Reviewed-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>
After a crash SM restarts with an empty mPhysicalNetworks, so the first
StartInstanceNetwork ran CreateNetwork over links that are still up.
Recreating them is not a no-op: rtnl_link_add is issued without
NLM_F_EXCL, so the kernel treats it as a modify request and CreateVlan
pushes a freshly generated MAC onto the live vlan, breaking traffic of the
instances still running on it.

Probe each link with the new InterfaceManagerItf::GetLink and create only
what is missing. Rollback deletes a link only when this call created it, so
a failure midway no longer tears down an adopted one.

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
Reviewed-by: Mykola Kobets <mykola_kobets@epam.com>
Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Reviewed-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>
CleanupLeftoverInstances tore down every instance recorded in storage on
Start: it detached the host veth and deleted the network namespace even
when the instance was alive and correctly wired, so an SM crash cut the
network of containers that kept running.

Replace it with ReconcileInstances, which checks the system before acting.
An instance whose host veth is up, is a veth and is enslaved to its own
bridge, and whose network namespace still exists, is adopted: nothing on
the system is touched, only the runtime cache is restored. Everything else
keeps the previous teardown path.

Adopting into the runtime cache also makes the launcher restart flow work:
StartInstanceNetwork now short-circuits with eAlreadyExist, which the
launcher already tolerates.

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
Reviewed-by: Mykola Kobets <mykola_kobets@epam.com>
Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Reviewed-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>
DeleteInstanceNetworkConfig removes the DNS record through the handle in
mDNSServers, which is runtime state and is empty after a restart. Without
a handle a dead leftover instance kept its addnhosts record.

Adopt the handle before the cleanup again, now that DNSServer::Init loads
the existing records instead of truncating them and so no longer drops the
records of instances adopted on the same network.

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
Reviewed-by: Mykola Kobets <mykola_kobets@epam.com>
Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Reviewed-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>
FirewallItf gains RemoveOrphans so that the firewall no longer has to wipe
its whole table on start to get rid of what a crashed SM left behind.

Call it from Start with the instances and networks known from storage, so
artifacts of anything gone are removed while the rules protecting the
instances that kept running stay in place.

Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
Reviewed-by: Mykola Kobets <mykola_kobets@epam.com>
Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Reviewed-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>
Signed-off-by: Mykola Solianko <mykola_solianko@epam.com>
Reviewed-by: Mykola Kobets <mykola_kobets@epam.com>
Reviewed-by: Oleksandr Grytsov <oleksandr_grytsov@epam.com>
Reviewed-by: Mykhailo Lohvynenko <mykhailo_lohvynenko@epam.com>
@MykolaSuperman
MykolaSuperman force-pushed the adopt_network_to_running_instance branch from cb3a210 to beaa5b2 Compare August 3, 2026 08:19
@sonarqubecloud

sonarqubecloud Bot commented Aug 3, 2026

Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
44.7% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@MykolaSuperman
MykolaSuperman merged commit 20eb0a8 into aosedge:develop Aug 3, 2026
4 of 5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants