feat(docker, firewall): Add stateful network connection check and optimize NAT rules
continuous-integration/drone/push Build is passing

This adds an IsConnected method to verify if a container is already connected to a network with the expected IP, preventing redundant operations. In reconcileIPs, it skips reconnections if the state is correct. In applyNATRule, MASQUERADE is now applied in the same namespace as DNAT (container or host) for consistent and accurate rule application.
This commit is contained in:
gyurix
2026-06-15 23:39:58 +02:00
parent bf94206849
commit 246346f8b1
4 changed files with 95 additions and 13 deletions
+8
View File
@@ -48,6 +48,9 @@ type MockDockerClient struct {
InspectContainerErr error
RemoveNetworkErr error
DisconnectContainerErr error
IsConnectedCalled bool
IsConnectedResult bool
}
func (m *MockDockerClient) Close() error { return nil }
@@ -106,6 +109,11 @@ func (m *MockDockerClient) FindContainerName(ctx context.Context, name, selector
return name, m.FindContainerNameErr
}
func (m *MockDockerClient) IsConnected(ctx context.Context, containerName, networkName, expectedIP string) bool {
m.IsConnectedCalled = true
return m.IsConnectedResult
}
// MockIPTablesManager implements iptables.IPTablesAPI for testing
type MockIPTablesManager struct {
BinaryResult string