mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(ec2): retain firewall identity during container teardown (#6492)
Capture the primary ENI before asynchronous termination can race with service-side interface release. Cover unregister after the interface list is cleared at the removal boundary. Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
bab7af3a21
commit
73fc6fd0c1
2 files changed
+41
-3
No files matched your search
@@ -12,6 +12,7 @@ import com.github.dockerjava.api.command.InspectExecCmd;
|
||||
import com.github.dockerjava.api.command.InspectExecResponse;
|
||||
import com.github.dockerjava.api.command.ListContainersCmd;
|
||||
import com.github.dockerjava.api.command.PingCmd;
|
||||
import com.github.dockerjava.api.command.RemoveContainerCmd;
|
||||
import com.github.dockerjava.api.command.StartContainerCmd;
|
||||
import com.github.dockerjava.api.command.StopContainerCmd;
|
||||
import com.github.dockerjava.api.exception.DockerException;
|
||||
@@ -100,6 +101,41 @@ import static org.mockito.Mockito.withSettings;
|
||||
|
||||
class Ec2ContainerManagerTest {
|
||||
|
||||
@Test
|
||||
void terminationRetainsFirewallIdentityAfterInterfacesAreReleased() throws Exception {
|
||||
DockerClient docker = mock(DockerClient.class);
|
||||
SecurityGroupFirewallManager firewall = mock(SecurityGroupFirewallManager.class);
|
||||
when(firewall.enabled()).thenReturn(true);
|
||||
Ec2ContainerManager manager = new Ec2ContainerManager(
|
||||
mock(ContainerBuilder.class), mock(ContainerLifecycleManager.class),
|
||||
mock(ContainerLogStreamer.class), mock(ContainerDetector.class),
|
||||
mock(DockerHostResolver.class), docker, mock(PortAllocator.class), mock(EmulatorConfig.class),
|
||||
mock(Ec2MetadataServer.class), mock(Ec2PortForwardManager.class), mock(RegionResolver.class),
|
||||
mock(ContainerNetworkReachability.class), mock(VpcNetworkManager.class),
|
||||
mock(ContainerReachableEndpoint.class), firewall);
|
||||
Instance instance = instance("i-firewall-teardown");
|
||||
instance.setDockerContainerId(TEST_CONTAINER_ID);
|
||||
InstanceNetworkInterface eni = new InstanceNetworkInterface();
|
||||
eni.setNetworkInterfaceId("eni-firewall-teardown");
|
||||
instance.setNetworkInterfaces(new ArrayList<>(List.of(eni)));
|
||||
RemoveContainerCmd remove = mock(RemoveContainerCmd.class, RETURNS_SELF);
|
||||
when(docker.removeContainerCmd(TEST_CONTAINER_ID)).thenReturn(remove);
|
||||
doAnswer(invocation -> {
|
||||
// The service releases ENIs while container teardown is still in progress.
|
||||
instance.getNetworkInterfaces().clear();
|
||||
return null;
|
||||
}).when(remove).exec();
|
||||
CountDownLatch completed = new CountDownLatch(1);
|
||||
try {
|
||||
manager.terminate(instance, completed::countDown);
|
||||
assertTrue(completed.await(5, TimeUnit.SECONDS), "Container teardown must finish");
|
||||
assertEquals("terminated", instance.getState().getName());
|
||||
verify(firewall).unregister("eni-firewall-teardown");
|
||||
} finally {
|
||||
manager.stop();
|
||||
}
|
||||
}
|
||||
|
||||
private static final String TEST_USER_DATA_OUTPUT = "test-output";
|
||||
private static final String TEST_CONTAINER_ID = "container-1";
|
||||
private static final String TEST_LOG_STREAM_NAME = "yyyy/MM/dd/user-data";
|
||||
|
||||
Reference in new issue
Block a user