mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
fix(ecs): launch task images for the task definition's runtimePlatform architecture (#6952)
This commit is contained in:
1 parent
a5254bdc0c
commit
4364310b95
19 files changed
+283
-127
No files matched your search
@@ -69,8 +69,11 @@ A task definition round-trips whole. Members Floci acts on are modelled
|
||||
such as `proxyConfiguration`, `ulimits`, `resourceRequirements`,
|
||||
`systemControls` and placement constraints, is kept verbatim and returned as registered. A client
|
||||
that reads back what it wrote (Terraform, or a deploy tool verifying its own
|
||||
`RegisterTaskDefinition`) sees no drift. `runtimePlatform` does not change where a local task
|
||||
runs: Floci launches every task on the host's own architecture. An `AWS::ECS::TaskDefinition` in a
|
||||
`RegisterTaskDefinition`) sees no drift. A task runs its images for the architecture its
|
||||
`runtimePlatform.cpuArchitecture` names (`X86_64` as `linux/amd64`, `ARM64` as `linux/arm64`):
|
||||
a local image built for that platform is used as is, a pull asks the registry for that platform,
|
||||
and the container is created for it, so an `X86_64` task runs under emulation on an arm64 Docker
|
||||
host. Without a `cpuArchitecture` a task runs on the Docker host's own architecture. An `AWS::ECS::TaskDefinition` in a
|
||||
CloudFormation template carries its containers' `LinuxParameters` into the same place, read as the
|
||||
ECS handler reads them (see [CloudFormation](cloudformation.md#ecs-task-definitions)), so they are
|
||||
returned in the API's shape and checked against the Fargate rules below exactly as if the task
|
||||
|
||||
+26
-3
@@ -138,9 +138,29 @@ public class ContainerLifecycleManager {
|
||||
return createAndStart(spec, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a disposable container for a specific Docker platform, reclaiming its anonymous
|
||||
* volumes if startup fails.
|
||||
*
|
||||
* @param platform Docker platform, such as {@code linux/amd64}, or null for the daemon's own
|
||||
*/
|
||||
public ContainerInfo createAndStartEphemeral(ContainerSpec spec, String platform) {
|
||||
return createAndStart(spec, platform, true);
|
||||
}
|
||||
|
||||
private ContainerInfo createAndStart(ContainerSpec spec, boolean removeAnonymousVolumes) {
|
||||
String resolvedImage = imageCacheService.ensureImageExists(spec.image());
|
||||
String containerId = create(spec, resolvedImage, null, removeAnonymousVolumes);
|
||||
return createAndStart(spec, resolvedImage, null, removeAnonymousVolumes);
|
||||
}
|
||||
|
||||
private ContainerInfo createAndStart(ContainerSpec spec, String platform, boolean removeAnonymousVolumes) {
|
||||
String resolvedImage = imageCacheService.ensureImageExists(spec.image(), platform);
|
||||
return createAndStart(spec, resolvedImage, platform, removeAnonymousVolumes);
|
||||
}
|
||||
|
||||
private ContainerInfo createAndStart(ContainerSpec spec, String resolvedImage, String platform,
|
||||
boolean removeAnonymousVolumes) {
|
||||
String containerId = create(spec, resolvedImage, platform, removeAnonymousVolumes);
|
||||
try {
|
||||
return withPublishedHostPorts(startCreated(containerId, spec), spec);
|
||||
} catch (RuntimeException failure) {
|
||||
@@ -165,9 +185,12 @@ public class ContainerLifecycleManager {
|
||||
* Resolves the image a container launch is about to run, pulling it as the ECS agent does
|
||||
* under {@code behavior}. A spec built from the returned image id runs exactly that image,
|
||||
* whatever a later pull of the same reference moves its tag to.
|
||||
*
|
||||
* @param platform the Docker platform the container runs, such as {@code linux/amd64}, or null
|
||||
* for the daemon's own
|
||||
*/
|
||||
public LaunchImage resolveImageForLaunch(String image, ImagePullBehavior behavior) {
|
||||
return imageCacheService.resolveForLaunch(image, behavior);
|
||||
public LaunchImage resolveImageForLaunch(String image, ImagePullBehavior behavior, String platform) {
|
||||
return imageCacheService.resolveForLaunch(image, behavior, platform);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+6
-3
@@ -271,6 +271,9 @@ public class EcsContainerManager {
|
||||
|
||||
List<ContainerDefinition> launchOrder = orderForDependencies(
|
||||
launchOrder(taskDef.getContainerDefinitions(), firelensRouter), firelensRouter);
|
||||
String platform = taskDef.getRuntimePlatform() != null
|
||||
? taskDef.getRuntimePlatform().dockerPlatform()
|
||||
: null;
|
||||
|
||||
// Task-level volumes consumed by per-container mountPoints: host volumes map their
|
||||
// name -> absolute host source path; efsVolumeConfiguration volumes map their
|
||||
@@ -326,7 +329,7 @@ public class EcsContainerManager {
|
||||
// tag again cannot swap the image under this task's reported digest.
|
||||
for (ContainerDefinition def : launchOrder) {
|
||||
LaunchImage launchImage = lifecycleManager.resolveImageForLaunch(imagesByContainer.get(def),
|
||||
config.services().ecs().imagePullBehavior());
|
||||
config.services().ecs().imagePullBehavior(), platform);
|
||||
imagesByContainer.put(def, launchImage.imageId());
|
||||
if (launchImage.manifestDigest() != null) {
|
||||
imageDigestsByContainer.put(def.getName(), launchImage.manifestDigest());
|
||||
@@ -558,7 +561,7 @@ public class EcsContainerManager {
|
||||
|
||||
String dockerId;
|
||||
if (def == firelensRouter) {
|
||||
dockerId = lifecycleManager.create(spec);
|
||||
dockerId = lifecycleManager.create(spec, platform);
|
||||
try {
|
||||
copyFirelensConfig(dockerId, firelensConfig, isFluentdRouter(firelensRouter),
|
||||
firelensExternalConfig, firelensBackoffMillis);
|
||||
@@ -569,7 +572,7 @@ public class EcsContainerManager {
|
||||
}
|
||||
fluentHost = inspectContainerIp(dockerId);
|
||||
} else {
|
||||
ContainerInfo info = lifecycleManager.createAndStartEphemeral(spec);
|
||||
ContainerInfo info = lifecycleManager.createAndStartEphemeral(spec, platform);
|
||||
dockerId = info.containerId();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,25 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
*
|
||||
* <p>Modelled for RegisterTaskDefinition/DescribeTaskDefinition round-trip fidelity — a client that
|
||||
* reads back what it registered (Terraform, or a deploy tool verifying its own write) must see the
|
||||
* platform it asked for. Floci runs every task on the host's own architecture, so the value has no
|
||||
* effect on where a local task is placed.
|
||||
* platform it asked for. A task launch also runs its images for the architecture named here, so an
|
||||
* {@code X86_64} task runs an amd64 image on an arm64 Docker host under emulation, as it would run on
|
||||
* an x86_64 Fargate host.
|
||||
*/
|
||||
@RegisterForReflection
|
||||
public record RuntimePlatform(String cpuArchitecture, String operatingSystemFamily) {
|
||||
|
||||
/**
|
||||
* The Docker platform a task with this runtime platform runs its images for, or null when no
|
||||
* architecture is named and the task runs on the Docker host's own.
|
||||
*/
|
||||
public String dockerPlatform() {
|
||||
if (cpuArchitecture == null) {
|
||||
return null;
|
||||
}
|
||||
return switch (cpuArchitecture) {
|
||||
case "X86_64" -> "linux/amd64";
|
||||
case "ARM64" -> "linux/arm64";
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
}
|
||||
+17
-10
@@ -105,19 +105,26 @@ public class ImageCacheService {
|
||||
* one or anyone else's) is what the next launch runs. The launch creates its container from the
|
||||
* returned image id rather than from the reference, so a pull by an overlapping launch that
|
||||
* moves the tag again cannot change what this one runs.
|
||||
*
|
||||
* @param platform the Docker platform the launch runs, such as {@code linux/amd64}, or null for
|
||||
* the daemon's own. A local image of another platform is never reused for it.
|
||||
*/
|
||||
public LaunchImage resolveForLaunch(String imageUri, ImagePullBehavior behavior) {
|
||||
public LaunchImage resolveForLaunch(String imageUri, ImagePullBehavior behavior, String platform) {
|
||||
if (isImageId(imageUri)) {
|
||||
return new LaunchImage(existingImageId(imageUri), null);
|
||||
}
|
||||
ImageKey imageKey = new ImageKey(imageUri, daemonPlatform());
|
||||
boolean explicitPlatform = platform != null && !platform.isBlank();
|
||||
ImageKey imageKey = new ImageKey(imageUri, explicitPlatform ? platform.trim() : daemonPlatform());
|
||||
String pullPlatform = explicitPlatform ? imageKey.platform() : null;
|
||||
Object lock = locks.computeIfAbsent(imageUri, k -> new Object());
|
||||
synchronized (lock) {
|
||||
LocalImage image = switch (behavior) {
|
||||
case DEFAULT -> pullOrUseCached(imageKey);
|
||||
case ALWAYS -> pull(imageKey, null);
|
||||
case ONCE -> pulledImages.contains(imageKey) ? cachedOrPull(imageKey) : pull(imageKey, null);
|
||||
case PREFER_CACHED -> cachedOrPull(imageKey);
|
||||
case DEFAULT -> pullOrUseCached(imageKey, pullPlatform);
|
||||
case ALWAYS -> pull(imageKey, pullPlatform);
|
||||
case ONCE -> pulledImages.contains(imageKey)
|
||||
? cachedOrPull(imageKey, pullPlatform)
|
||||
: pull(imageKey, pullPlatform);
|
||||
case PREFER_CACHED -> cachedOrPull(imageKey, pullPlatform);
|
||||
};
|
||||
String imageId = resolvedImageReference(imageUri, image.image());
|
||||
resolvedImages.put(imageKey, imageId);
|
||||
@@ -150,9 +157,9 @@ public class ImageCacheService {
|
||||
return resolvedImageReference(imageId, image);
|
||||
}
|
||||
|
||||
private LocalImage pullOrUseCached(ImageKey imageKey) {
|
||||
private LocalImage pullOrUseCached(ImageKey imageKey, String platform) {
|
||||
try {
|
||||
return pull(imageKey, null);
|
||||
return pull(imageKey, platform);
|
||||
} catch (RuntimeException e) {
|
||||
InspectImageResponse cached = Thread.currentThread().isInterrupted() ? null : cachedImage(imageKey);
|
||||
if (cached == null) {
|
||||
@@ -164,9 +171,9 @@ public class ImageCacheService {
|
||||
}
|
||||
}
|
||||
|
||||
private LocalImage cachedOrPull(ImageKey imageKey) {
|
||||
private LocalImage cachedOrPull(ImageKey imageKey, String platform) {
|
||||
InspectImageResponse cached = cachedImage(imageKey);
|
||||
return cached != null ? new LocalImage(cached, null) : pull(imageKey, null);
|
||||
return cached != null ? new LocalImage(cached, null) : pull(imageKey, platform);
|
||||
}
|
||||
|
||||
private InspectImageResponse cachedImage(ImageKey imageKey) {
|
||||
|
||||
+14
-1
@@ -18,6 +18,7 @@ import static org.mockito.Mockito.*;
|
||||
|
||||
class ContainerLifecycleManagerEphemeralTest {
|
||||
private DockerClient docker;
|
||||
private ImageCacheService images;
|
||||
private ContainerLifecycleManager manager;
|
||||
private RemoveContainerCmd remove;
|
||||
private CreateContainerCmd create;
|
||||
@@ -26,7 +27,7 @@ class ContainerLifecycleManagerEphemeralTest {
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
docker = mock(DockerClient.class);
|
||||
ImageCacheService images = mock(ImageCacheService.class);
|
||||
images = mock(ImageCacheService.class);
|
||||
when(images.ensureImageExists(spec.image())).thenReturn("image-id");
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
manager = spy(new ContainerLifecycleManager(docker, images, mock(ContainerDetector.class), config));
|
||||
@@ -74,6 +75,18 @@ class ContainerLifecycleManagerEphemeralTest {
|
||||
verify(docker, never()).removeContainerCmd(anyString());
|
||||
}
|
||||
|
||||
@Test
|
||||
void ephemeralStartForAPlatformCreatesTheContainerForIt() {
|
||||
when(images.ensureImageExists(spec.image(), "linux/amd64")).thenReturn("amd64-id");
|
||||
when(docker.createContainerCmd("amd64-id")).thenReturn(create);
|
||||
ContainerLifecycleManager.ContainerInfo info = new ContainerLifecycleManager.ContainerInfo("owned-id", Map.of());
|
||||
doReturn(info).when(manager).startCreated("owned-id", spec);
|
||||
|
||||
assertSame(info, manager.createAndStartEphemeral(spec, "linux/amd64"));
|
||||
|
||||
verify(create).withPlatform("linux/amd64");
|
||||
}
|
||||
|
||||
@Test
|
||||
void defaultStrictRemovalDoesNotOptIntoVolumeRemoval() {
|
||||
manager.removeIfExistsStrict("owned-id");
|
||||
|
||||
+2
-2
@@ -64,9 +64,9 @@ class EcsContainerManagerAwsBaselineTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
|
||||
ContainerLogStreamer logStreamer = mock(ContainerLogStreamer.class);
|
||||
|
||||
+3
-3
@@ -66,9 +66,9 @@ class EcsContainerManagerEcrRewriteTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
|
||||
ContainerLogStreamer logStreamer = mock(ContainerLogStreamer.class);
|
||||
@@ -145,6 +145,6 @@ class EcsContainerManagerEcrRewriteTest {
|
||||
() -> manager.startTask(task, taskDef, List.of(), "us-east-1"));
|
||||
|
||||
// The earlier "sidecar" container must never have been created.
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
}
|
||||
+22
-22
@@ -97,11 +97,11 @@ class EcsContainerManagerFirelensTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.removeVolume(anyString())).thenReturn(true);
|
||||
when(lifecycleManager.createAndStartEphemeral(any())).thenReturn(new ContainerInfo("app-id", Map.of()));
|
||||
when(lifecycleManager.create(any())).thenReturn("router-id");
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any())).thenReturn(new ContainerInfo("app-id", Map.of()));
|
||||
when(lifecycleManager.create(any(), any())).thenReturn("router-id");
|
||||
when(lifecycleManager.startCreated(anyString(), any())).thenReturn(new ContainerInfo("router-id", Map.of()));
|
||||
|
||||
dockerClient = mock(DockerClient.class, RETURNS_DEEP_STUBS);
|
||||
@@ -167,9 +167,9 @@ class EcsContainerManagerFirelensTest {
|
||||
EcsTaskHandle handle = manager.startTask(task, taskDef, null, "us-east-1");
|
||||
|
||||
InOrder order = inOrder(lifecycleManager);
|
||||
order.verify(lifecycleManager).create(any(ContainerSpec.class));
|
||||
order.verify(lifecycleManager).create(any(ContainerSpec.class), any());
|
||||
order.verify(lifecycleManager).startCreated(anyString(), any());
|
||||
order.verify(lifecycleManager).createAndStartEphemeral(any(ContainerSpec.class));
|
||||
order.verify(lifecycleManager).createAndStartEphemeral(any(ContainerSpec.class), any());
|
||||
|
||||
ArgumentCaptor<LogConfig> logConfig = ArgumentCaptor.forClass(LogConfig.class);
|
||||
verify(builder).withLogConfig(logConfig.capture());
|
||||
@@ -220,9 +220,9 @@ class EcsContainerManagerFirelensTest {
|
||||
manager.startTask(task, taskDef, null, "us-east-1");
|
||||
|
||||
InOrder order = inOrder(lifecycleManager);
|
||||
order.verify(lifecycleManager).create(any(ContainerSpec.class));
|
||||
order.verify(lifecycleManager).create(any(ContainerSpec.class), any());
|
||||
order.verify(lifecycleManager).startCreated(anyString(), any());
|
||||
order.verify(lifecycleManager).createAndStartEphemeral(any(ContainerSpec.class));
|
||||
order.verify(lifecycleManager).createAndStartEphemeral(any(ContainerSpec.class), any());
|
||||
|
||||
ArgumentCaptor<LogConfig> logConfig = ArgumentCaptor.forClass(LogConfig.class);
|
||||
verify(builder).withLogConfig(logConfig.capture());
|
||||
@@ -348,8 +348,8 @@ class EcsContainerManagerFirelensTest {
|
||||
assertEquals("Unable to download firelens s3 config file: unable to download s3 config "
|
||||
+ "missing.conf from bucket firelens-configs: The specified key does not exist.",
|
||||
failure.getMessage());
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class));
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class), any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -365,7 +365,7 @@ class EcsContainerManagerFirelensTest {
|
||||
assertEquals("ClientException", failure.getErrorCode());
|
||||
assertEquals("awsfirelens log driver requires a firelensConfiguration container",
|
||||
failure.getMessage());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -379,8 +379,8 @@ class EcsContainerManagerFirelensTest {
|
||||
|
||||
assertEquals("ClientException", failure.getErrorCode());
|
||||
assertEquals("A task definition can have only one FireLens log router.", failure.getMessage());
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class));
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class), any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -392,7 +392,7 @@ class EcsContainerManagerFirelensTest {
|
||||
|
||||
assertEquals("ClientException", failure.getErrorCode());
|
||||
assertEquals("FireLens port 24224 must not be exposed.", failure.getMessage());
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class));
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -404,7 +404,7 @@ class EcsContainerManagerFirelensTest {
|
||||
|
||||
assertEquals("ClientException", failure.getErrorCode());
|
||||
assertEquals("FireLens configuration type must be fluentbit or fluentd.", failure.getMessage());
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class));
|
||||
verify(lifecycleManager, never()).create(any(ContainerSpec.class), any());
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@@ -464,10 +464,10 @@ class EcsContainerManagerFirelensTest {
|
||||
assertNull(tar.getNextEntry());
|
||||
}
|
||||
InOrder order = inOrder(lifecycleManager, uploads.commands.get(1));
|
||||
order.verify(lifecycleManager).create(any());
|
||||
order.verify(lifecycleManager).create(any(), any());
|
||||
order.verify(uploads.commands.get(1)).exec();
|
||||
order.verify(lifecycleManager).startCreated(eq("router-id"), any());
|
||||
order.verify(lifecycleManager).createAndStartEphemeral(any());
|
||||
order.verify(lifecycleManager).createAndStartEphemeral(any(), any());
|
||||
verify(lifecycleManager, never()).removeIfExists(anyString());
|
||||
if (external) {
|
||||
verify(s3Service).getObject("firelens-configs", "extra.conf");
|
||||
@@ -514,7 +514,7 @@ class EcsContainerManagerFirelensTest {
|
||||
assertEquals(1, uploads.commands.size());
|
||||
assertEquals(1, uploads.completed.size());
|
||||
verify(lifecycleManager).startCreated(eq("router-id"), any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
verify(lifecycleManager).removeIfExists("router-id");
|
||||
verifyFirelensVolumeRemoved();
|
||||
}
|
||||
@@ -545,8 +545,8 @@ class EcsContainerManagerFirelensTest {
|
||||
when(dockerClient.inspectVolumeCmd(anyString()).exec().getMountpoint()).thenReturn(path);
|
||||
assertThrows(AwsException.class, () -> manager.startTask(
|
||||
task(), retryTaskDefinition("fluentbit", false, ""), null, "us-east-1"));
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).create(any(), any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
verifyFirelensVolumeRemoved();
|
||||
}
|
||||
|
||||
@@ -596,7 +596,7 @@ class EcsContainerManagerFirelensTest {
|
||||
} else {
|
||||
assertThrows(AwsException.class, () -> manager.startTask(
|
||||
task(), retryTaskDefinition("fluentbit", false, ""), null, "us-east-1"));
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
verify(lifecycleManager, never()).create(any(), any());
|
||||
verifyFirelensVolumeRemoved();
|
||||
}
|
||||
}
|
||||
@@ -610,9 +610,9 @@ class EcsContainerManagerFirelensTest {
|
||||
}
|
||||
|
||||
private void verifyFailedLaunchCleanup() {
|
||||
verify(lifecycleManager).create(any());
|
||||
verify(lifecycleManager).create(any(), any());
|
||||
verify(lifecycleManager, never()).startCreated(anyString(), any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
verify(lifecycleManager).removeIfExists("router-id");
|
||||
verifyFirelensVolumeRemoved();
|
||||
}
|
||||
|
||||
+47
-14
@@ -14,6 +14,7 @@ import io.github.hectorvent.floci.services.ecr.registry.EcrRegistryManager;
|
||||
import io.github.hectorvent.floci.services.ecs.model.Container;
|
||||
import io.github.hectorvent.floci.services.ecs.model.ContainerDefinition;
|
||||
import io.github.hectorvent.floci.services.ecs.model.EcsTask;
|
||||
import io.github.hectorvent.floci.services.ecs.model.RuntimePlatform;
|
||||
import io.github.hectorvent.floci.services.ecs.model.TaskDefinition;
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService.LaunchImage;
|
||||
import io.github.hectorvent.floci.services.s3.S3Service;
|
||||
@@ -31,11 +32,14 @@ import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
import static org.mockito.Mockito.RETURNS_SELF;
|
||||
import static org.mockito.Mockito.inOrder;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@@ -63,7 +67,7 @@ class EcsContainerManagerImagePullTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.createAndStartEphemeral(any())).thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any())).thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
|
||||
EmulatorConfig config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.services().ecs().imagePullBehavior()).thenReturn(ImagePullBehavior.ALWAYS);
|
||||
@@ -80,18 +84,18 @@ class EcsContainerManagerImagePullTest {
|
||||
|
||||
@Test
|
||||
void everyImageIsPulledWithTheConfiguredBehaviourBeforeAnyContainerIsCreated() {
|
||||
when(lifecycleManager.resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS))
|
||||
when(lifecycleManager.resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS, null))
|
||||
.thenReturn(new LaunchImage(APP_IMAGE_ID, "sha256:new-manifest"));
|
||||
when(lifecycleManager.resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS))
|
||||
when(lifecycleManager.resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS, null))
|
||||
.thenReturn(new LaunchImage(SIDECAR_IMAGE_ID, null));
|
||||
EcsTask task = task();
|
||||
|
||||
manager.startTask(task, taskDefinition(), List.of(), "us-east-1");
|
||||
|
||||
InOrder order = inOrder(lifecycleManager);
|
||||
order.verify(lifecycleManager).resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS);
|
||||
order.verify(lifecycleManager).resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS);
|
||||
order.verify(lifecycleManager).createAndStartEphemeral(any());
|
||||
order.verify(lifecycleManager).resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS, null);
|
||||
order.verify(lifecycleManager).resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS, null);
|
||||
order.verify(lifecycleManager).createAndStartEphemeral(any(), any());
|
||||
List<Container> containers = task.getContainers();
|
||||
assertEquals("sha256:new-manifest", containers.get(0).getImageDigest());
|
||||
assertNull(containers.get(1).getImageDigest(), "a locally built image has no manifest digest");
|
||||
@@ -100,9 +104,9 @@ class EcsContainerManagerImagePullTest {
|
||||
|
||||
@Test
|
||||
void everyContainerIsCreatedFromTheImageIdItsPullResolvedTo() {
|
||||
when(lifecycleManager.resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS))
|
||||
when(lifecycleManager.resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS, null))
|
||||
.thenReturn(new LaunchImage(APP_IMAGE_ID, "sha256:new-manifest"));
|
||||
when(lifecycleManager.resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS))
|
||||
when(lifecycleManager.resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS, null))
|
||||
.thenReturn(new LaunchImage(SIDECAR_IMAGE_ID, null));
|
||||
|
||||
manager.startTask(task(), taskDefinition(), List.of(), "us-east-1");
|
||||
@@ -117,26 +121,55 @@ class EcsContainerManagerImagePullTest {
|
||||
void theImagePulledIsTheOneTheConfiguredRegistryBaseNames() {
|
||||
when(containerBuilder.resolveImage(anyString()))
|
||||
.thenAnswer(invocation -> "mirror.example/" + invocation.getArgument(0));
|
||||
when(lifecycleManager.resolveImageForLaunch(anyString(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(anyString(), any(), any()))
|
||||
.thenReturn(new LaunchImage(APP_IMAGE_ID, null));
|
||||
|
||||
manager.startTask(task(), taskDefinition(), List.of(), "us-east-1");
|
||||
|
||||
verify(lifecycleManager).resolveImageForLaunch("mirror.example/" + APP_IMAGE, ImagePullBehavior.ALWAYS);
|
||||
verify(lifecycleManager).resolveImageForLaunch("mirror.example/" + SIDECAR_IMAGE, ImagePullBehavior.ALWAYS);
|
||||
verify(lifecycleManager).resolveImageForLaunch("mirror.example/" + APP_IMAGE, ImagePullBehavior.ALWAYS, null);
|
||||
verify(lifecycleManager).resolveImageForLaunch("mirror.example/" + SIDECAR_IMAGE, ImagePullBehavior.ALWAYS, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aFailedPullLeavesNoContainerCreated() {
|
||||
when(lifecycleManager.resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS))
|
||||
when(lifecycleManager.resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS, null))
|
||||
.thenReturn(new LaunchImage(APP_IMAGE_ID, "sha256:new-manifest"));
|
||||
when(lifecycleManager.resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS))
|
||||
when(lifecycleManager.resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS, null))
|
||||
.thenThrow(new NotFoundException("pull access denied for sidecar"));
|
||||
|
||||
assertThrows(NotFoundException.class,
|
||||
() -> manager.startTask(task(), taskDefinition(), List.of(), "us-east-1"));
|
||||
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTaskWhoseRuntimePlatformNamesAnArchitecturePullsAndRunsEveryImageForIt() {
|
||||
when(lifecycleManager.resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS, "linux/amd64"))
|
||||
.thenReturn(new LaunchImage(APP_IMAGE_ID, null));
|
||||
when(lifecycleManager.resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS, "linux/amd64"))
|
||||
.thenReturn(new LaunchImage(SIDECAR_IMAGE_ID, null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), eq("linux/amd64")))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
TaskDefinition taskDef = taskDefinition();
|
||||
taskDef.setRuntimePlatform(new RuntimePlatform("X86_64", "LINUX"));
|
||||
|
||||
manager.startTask(task(), taskDef, List.of(), "us-east-1");
|
||||
|
||||
verify(lifecycleManager).resolveImageForLaunch(APP_IMAGE, ImagePullBehavior.ALWAYS, "linux/amd64");
|
||||
verify(lifecycleManager).resolveImageForLaunch(SIDECAR_IMAGE, ImagePullBehavior.ALWAYS, "linux/amd64");
|
||||
verify(lifecycleManager, times(2)).createAndStartEphemeral(any(), eq("linux/amd64"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aTaskWithoutARuntimePlatformRunsOnTheDaemonsOwnPlatform() {
|
||||
when(lifecycleManager.resolveImageForLaunch(anyString(), any(), any()))
|
||||
.thenReturn(new LaunchImage(APP_IMAGE_ID, null));
|
||||
|
||||
manager.startTask(task(), taskDefinition(), List.of(), "us-east-1");
|
||||
|
||||
verify(lifecycleManager, times(2)).resolveImageForLaunch(anyString(), any(), isNull());
|
||||
verify(lifecycleManager, times(2)).createAndStartEphemeral(any(), isNull());
|
||||
}
|
||||
|
||||
private static TaskDefinition taskDefinition() {
|
||||
|
||||
+2
-2
@@ -53,9 +53,9 @@ class EcsContainerManagerLogConfigurationTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
|
||||
logStreamer = mock(ContainerLogStreamer.class);
|
||||
|
||||
+2
-2
@@ -64,9 +64,9 @@ class EcsContainerManagerOverridesTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
|
||||
ContainerLogStreamer logStreamer = mock(ContainerLogStreamer.class);
|
||||
|
||||
+2
-2
@@ -84,9 +84,9 @@ class EcsContainerManagerPortMappingsTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
// resolveNetworkBindings() inspects the container after launch; deep stubs
|
||||
// make the empty-binding readback (Map.get(...) -> null) NPE-free.
|
||||
|
||||
+6
-6
@@ -59,9 +59,9 @@ class EcsContainerManagerSecretsTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
|
||||
ContainerLogStreamer logStreamer = mock(ContainerLogStreamer.class);
|
||||
@@ -187,7 +187,7 @@ class EcsContainerManagerSecretsTest {
|
||||
assertTrue(thrown.getMessage().contains("ResourceInitializationError"));
|
||||
assertTrue(thrown.getMessage().contains("/missing"));
|
||||
verify(containerBuilder, never()).newContainer(anyString());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -207,7 +207,7 @@ class EcsContainerManagerSecretsTest {
|
||||
assertTrue(thrown.getMessage().contains("ResourceInitializationError"));
|
||||
assertTrue(thrown.getMessage().contains(secretArn));
|
||||
verify(containerBuilder, never()).newContainer(anyString());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -273,7 +273,7 @@ class EcsContainerManagerSecretsTest {
|
||||
|
||||
assertTrue(thrown.getMessage().contains("ResourceInitializationError"));
|
||||
assertTrue(thrown.getMessage().contains("did not contain json key token"));
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -305,7 +305,7 @@ class EcsContainerManagerSecretsTest {
|
||||
assertTrue(thrown.getMessage().contains("ResourceInitializationError"));
|
||||
assertTrue(thrown.getMessage().contains(
|
||||
"an invalid ARN format for the AWS Secrets Manager secret was specified"));
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
private static ContainerDefinition containerDef(String name, List<Secret> secrets) {
|
||||
|
||||
+5
-5
@@ -75,9 +75,9 @@ class EcsContainerManagerSecurityGroupTest {
|
||||
when(containerBuilder.resolveImage(anyString())).thenAnswer(invocation -> invocation.getArgument(0));
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any())).thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any())).thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
dockerClient = mock(DockerClient.class, RETURNS_DEEP_STUBS);
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(dockerClient);
|
||||
|
||||
@@ -209,7 +209,7 @@ class EcsContainerManagerSecurityGroupTest {
|
||||
when(ec2Service.describeSecurityGroups(any(), eq(List.of("sg-1")), any(), any()))
|
||||
.thenReturn(List.of(sg));
|
||||
|
||||
when(lifecycleManager.create(any())).thenReturn("router-id");
|
||||
when(lifecycleManager.create(any(), any())).thenReturn("router-id");
|
||||
when(lifecycleManager.startCreated(anyString(), any()))
|
||||
.thenReturn(new ContainerInfo("router-id", Map.of()));
|
||||
InspectVolumeCmd inspectVolumeCmd = mock(InspectVolumeCmd.class);
|
||||
@@ -243,9 +243,9 @@ class EcsContainerManagerSecurityGroupTest {
|
||||
verify(builder, times(2)).withLabels(Map.of("io.floci.security-group.workload", "true"));
|
||||
|
||||
verify(firewallManager).createNamespace(eq("ecs"), eq("abc123"), any(), any(), any(), any(), any(), any());
|
||||
verify(lifecycleManager).create(any());
|
||||
verify(lifecycleManager).create(any(), any());
|
||||
verify(lifecycleManager).startCreated(eq("router-id"), any());
|
||||
verify(lifecycleManager).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
private static EcsTask awsvpcTask() {
|
||||
|
||||
+10
-10
@@ -73,9 +73,9 @@ class EcsContainerManagerTaskRoleCredentialsTest {
|
||||
when(containerBuilder.resolveDockerNetwork(any())).thenReturn(Optional.of(NETWORK));
|
||||
|
||||
ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any())).thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any())).thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
|
||||
config = mock(EmulatorConfig.class, RETURNS_DEEP_STUBS);
|
||||
when(config.services().ecs().taskRoleCredentials().enabled()).thenReturn(true);
|
||||
@@ -188,7 +188,7 @@ class EcsContainerManagerTaskRoleCredentialsTest {
|
||||
@Test
|
||||
void revokesCredentialsEvenWhenAContainerCouldNotBeRemoved() {
|
||||
ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
DockerClient dockerClient = mock(DockerClient.class, RETURNS_DEEP_STUBS);
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(dockerClient);
|
||||
@@ -233,7 +233,7 @@ class EcsContainerManagerTaskRoleCredentialsTest {
|
||||
@Test
|
||||
void keepsAddressesReservedWhenAContainerCouldNotBeRemoved() {
|
||||
ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
DockerClient dockerClient = mock(DockerClient.class, RETURNS_DEEP_STUBS);
|
||||
when(lifecycleManager.getDockerClient()).thenReturn(dockerClient);
|
||||
@@ -257,9 +257,9 @@ class EcsContainerManagerTaskRoleCredentialsTest {
|
||||
@Test
|
||||
void keepsAddressesReservedWhenCleanupCannotRemoveAContainer() {
|
||||
ContainerLifecycleManager lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any())).thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any())).thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
// The reconciler's cleanup path is the other way a task's containers come off, and Docker
|
||||
// can refuse a removal here just as it can on the stop path.
|
||||
doThrow(new IllegalStateException("in use"))
|
||||
@@ -284,11 +284,11 @@ class EcsContainerManagerTaskRoleCredentialsTest {
|
||||
@Test
|
||||
void keepsAddressesReservedWhenAFailedLaunchCannotRemoveAContainer() {
|
||||
ContainerLifecycleManager failing = mock(ContainerLifecycleManager.class);
|
||||
when(failing.resolveImageForLaunch(any(), any()))
|
||||
when(failing.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
// The first container starts and the second does not, so the launch unwinds with one
|
||||
// container already up and holding an address.
|
||||
when(failing.createAndStartEphemeral(any()))
|
||||
when(failing.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()))
|
||||
.thenThrow(new IllegalStateException("no daemon"));
|
||||
doThrow(new IllegalStateException("in use"))
|
||||
@@ -361,9 +361,9 @@ class EcsContainerManagerTaskRoleCredentialsTest {
|
||||
@Test
|
||||
void revokesCredentialsWhenTheLaunchFailsPartWayThrough() {
|
||||
ContainerLifecycleManager failing = mock(ContainerLifecycleManager.class);
|
||||
when(failing.resolveImageForLaunch(any(), any()))
|
||||
when(failing.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(failing.createAndStartEphemeral(any())).thenThrow(new IllegalStateException("no daemon"));
|
||||
when(failing.createAndStartEphemeral(any(), any())).thenThrow(new IllegalStateException("no daemon"));
|
||||
EcsContainerManager failingManager = new EcsContainerManager(containerBuilder, failing,
|
||||
mock(ContainerLogStreamer.class), mock(ContainerDetector.class), config,
|
||||
mock(RegionResolver.class), mock(LaunchedContainerAwsEnv.class), mock(SsmService.class),
|
||||
|
||||
+12
-12
@@ -72,9 +72,9 @@ class EcsContainerManagerVolumesFromTest {
|
||||
when(appBuilder.build()).thenReturn(new ContainerSpec("test-image"));
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("source-id", Map.of()))
|
||||
.thenReturn(new ContainerInfo("app-id", Map.of()));
|
||||
|
||||
@@ -128,7 +128,7 @@ class EcsContainerManagerVolumesFromTest {
|
||||
ContainerBuilder.Builder routerBuilder = mock(ContainerBuilder.Builder.class, RETURNS_SELF);
|
||||
when(containerBuilder.newContainer("router:latest")).thenReturn(routerBuilder);
|
||||
when(routerBuilder.build()).thenReturn(new ContainerSpec("test-image"));
|
||||
when(lifecycleManager.create(any())).thenReturn("router-id");
|
||||
when(lifecycleManager.create(any(), any())).thenReturn("router-id");
|
||||
when(lifecycleManager.startCreated(eq("router-id"), any()))
|
||||
.thenReturn(new ContainerInfo("router-id", Map.of()));
|
||||
DockerClient dockerClient = mock(DockerClient.class, RETURNS_DEEP_STUBS);
|
||||
@@ -160,11 +160,11 @@ class EcsContainerManagerVolumesFromTest {
|
||||
order.verify(containerBuilder).newContainer("router:latest");
|
||||
order.verify(containerBuilder).newContainer("app:latest");
|
||||
InOrder lifecycleOrder = inOrder(lifecycleManager, copyCmd);
|
||||
lifecycleOrder.verify(lifecycleManager).createAndStartEphemeral(any(ContainerSpec.class));
|
||||
lifecycleOrder.verify(lifecycleManager).create(any(ContainerSpec.class));
|
||||
lifecycleOrder.verify(lifecycleManager).createAndStartEphemeral(any(ContainerSpec.class), any());
|
||||
lifecycleOrder.verify(lifecycleManager).create(any(ContainerSpec.class), any());
|
||||
lifecycleOrder.verify(copyCmd).exec();
|
||||
lifecycleOrder.verify(lifecycleManager).startCreated(eq("router-id"), any(ContainerSpec.class));
|
||||
lifecycleOrder.verify(lifecycleManager).createAndStartEphemeral(any(ContainerSpec.class));
|
||||
lifecycleOrder.verify(lifecycleManager).createAndStartEphemeral(any(ContainerSpec.class), any());
|
||||
verify(routerBuilder).withVolumesFrom("source-id", false);
|
||||
verify(appBuilder).withVolumesFrom("source-id", true);
|
||||
verify(lifecycleManager).ensureVolume(eq(handle.getFirelensVolumeName()), any());
|
||||
@@ -205,8 +205,8 @@ class EcsContainerManagerVolumesFromTest {
|
||||
List.of(), "us-east-1"));
|
||||
|
||||
verify(containerBuilder, never()).newContainer(anyString());
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).create(any(), any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
verify(lifecycleManager, never()).ensureVolume(anyString(), any());
|
||||
}
|
||||
|
||||
@@ -234,8 +234,8 @@ class EcsContainerManagerVolumesFromTest {
|
||||
failure.getMessage());
|
||||
verify(s3Service).getObject("firelens-configs", "missing.conf");
|
||||
verify(containerBuilder, never()).newContainer(anyString());
|
||||
verify(lifecycleManager, never()).create(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).create(any(), any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
verify(lifecycleManager, never()).ensureVolume(anyString(), any());
|
||||
}
|
||||
|
||||
@@ -247,7 +247,7 @@ class EcsContainerManagerVolumesFromTest {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> manager.startTask(task(), taskDefinition(List.of(app)), List.of(), "us-east-1"));
|
||||
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -260,7 +260,7 @@ class EcsContainerManagerVolumesFromTest {
|
||||
assertThrows(IllegalArgumentException.class,
|
||||
() -> manager.startTask(task(), taskDefinition(List.of(app, source)), List.of(), "us-east-1"));
|
||||
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
private static ContainerDefinition definition(String name, String image) {
|
||||
|
||||
+6
-6
@@ -139,10 +139,10 @@ class EcsContainerManagerVolumesTest {
|
||||
@ValueSource(booleans = {false, true})
|
||||
void failedLaunchRemovesItsEphemeralVolume(boolean firstContainerStarted) {
|
||||
if (firstContainerStarted) {
|
||||
when(lifecycleManager.createAndStartEphemeral(any())).thenReturn(new ContainerInfo("docker-id", Map.of()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any())).thenReturn(new ContainerInfo("docker-id", Map.of()))
|
||||
.thenThrow(new IllegalStateException("launch failed"));
|
||||
} else {
|
||||
when(lifecycleManager.createAndStartEphemeral(any())).thenThrow(new IllegalStateException("launch failed"));
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any())).thenThrow(new IllegalStateException("launch failed"));
|
||||
}
|
||||
assertThrows(IllegalStateException.class, () -> manager.startTask(task("000000000000", "us-east-1"),
|
||||
ephemeralDefinition(new Volume("shared", null)), List.of(), "us-east-1"));
|
||||
@@ -192,7 +192,7 @@ class EcsContainerManagerVolumesTest {
|
||||
@ParameterizedTest
|
||||
@ValueSource(booleans = {false, true})
|
||||
void failedLaunchPreservesResourcesWhenCleanupFails(boolean containerRemovalFails) {
|
||||
when(lifecycleManager.createAndStartEphemeral(any())).thenReturn(new ContainerInfo("docker-id", Map.of()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any())).thenReturn(new ContainerInfo("docker-id", Map.of()))
|
||||
.thenThrow(new IllegalStateException("launch failed"));
|
||||
if (containerRemovalFails) {
|
||||
doThrow(new IllegalStateException("remove failed")).when(lifecycleManager)
|
||||
@@ -260,9 +260,9 @@ class EcsContainerManagerVolumesTest {
|
||||
|
||||
lifecycleManager = mock(ContainerLifecycleManager.class);
|
||||
when(lifecycleManager.removeVolume(anyString())).thenReturn(true);
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any()))
|
||||
when(lifecycleManager.resolveImageForLaunch(any(), any(), any()))
|
||||
.thenAnswer(invocation -> new LaunchImage(invocation.getArgument(0), null));
|
||||
when(lifecycleManager.createAndStartEphemeral(any()))
|
||||
when(lifecycleManager.createAndStartEphemeral(any(), any()))
|
||||
.thenReturn(new ContainerInfo("docker-id", Map.of()));
|
||||
|
||||
ContainerLogStreamer logStreamer = mock(ContainerLogStreamer.class);
|
||||
@@ -470,7 +470,7 @@ class EcsContainerManagerVolumesTest {
|
||||
() -> managerWithEfs(efsFallbackConfig()).startTask(task("000000000000", "us-east-1"),
|
||||
accessPointDefinition("fsap-test"), List.of(), "us-east-1"));
|
||||
assertEquals("ClientException", failure.getErrorCode());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any());
|
||||
verify(lifecycleManager, never()).createAndStartEphemeral(any(), any());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+78
-20
@@ -18,6 +18,7 @@ import io.github.hectorvent.floci.config.EmulatorConfig.EcsServiceConfig.ImagePu
|
||||
import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService.LaunchImage;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
@@ -427,7 +428,7 @@ class ImageCacheServiceTest {
|
||||
daemon.registry.put(REGISTRY_IMAGE, image("sha256:new", REGISTRY_REPO + "@sha256:new-manifest"));
|
||||
|
||||
assertEquals(new LaunchImage("sha256:new", "sha256:new-manifest"),
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT));
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT, null));
|
||||
assertEquals("sha256:new", service.ensureImageExists(REGISTRY_IMAGE));
|
||||
assertEquals(2, daemon.pulls.get());
|
||||
}
|
||||
@@ -439,7 +440,7 @@ class ImageCacheServiceTest {
|
||||
ImageCacheService service = newService(daemon.client);
|
||||
|
||||
assertEquals(new LaunchImage("sha256:built", null),
|
||||
service.resolveForLaunch(LOCAL_IMAGE, ImagePullBehavior.DEFAULT));
|
||||
service.resolveForLaunch(LOCAL_IMAGE, ImagePullBehavior.DEFAULT, null));
|
||||
assertEquals("sha256:built", service.ensureImageExists(LOCAL_IMAGE));
|
||||
assertEquals(1, daemon.pulls.get());
|
||||
}
|
||||
@@ -449,7 +450,7 @@ class ImageCacheServiceTest {
|
||||
FakeDaemon daemon = new FakeDaemon();
|
||||
|
||||
assertThrows(NotFoundException.class,
|
||||
() -> newService(daemon.client).resolveForLaunch(LOCAL_IMAGE, ImagePullBehavior.DEFAULT));
|
||||
() -> newService(daemon.client).resolveForLaunch(LOCAL_IMAGE, ImagePullBehavior.DEFAULT, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -460,7 +461,7 @@ class ImageCacheServiceTest {
|
||||
daemon.hangingPulls.add(REGISTRY_IMAGE);
|
||||
|
||||
DockerClientException error = assertThrows(DockerClientException.class,
|
||||
() -> newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.ALWAYS));
|
||||
() -> newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.ALWAYS, null));
|
||||
assertTrue(error.getMessage().contains("Timed out pulling image " + REGISTRY_IMAGE), error.getMessage());
|
||||
}
|
||||
|
||||
@@ -470,7 +471,7 @@ class ImageCacheServiceTest {
|
||||
daemon.store(LOCAL_IMAGE, image("sha256:built"));
|
||||
|
||||
assertThrows(NotFoundException.class,
|
||||
() -> newService(daemon.client).resolveForLaunch(LOCAL_IMAGE, ImagePullBehavior.ALWAYS));
|
||||
() -> newService(daemon.client).resolveForLaunch(LOCAL_IMAGE, ImagePullBehavior.ALWAYS, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -483,7 +484,7 @@ class ImageCacheServiceTest {
|
||||
daemon.store(REGISTRY_IMAGE, image("sha256:new", REGISTRY_REPO + "@sha256:new-manifest"));
|
||||
|
||||
assertEquals(new LaunchImage("sha256:new", "sha256:new-manifest"),
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED));
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED, null));
|
||||
assertEquals("sha256:new", service.ensureImageExists(REGISTRY_IMAGE));
|
||||
assertEquals(0, daemon.pulls.get());
|
||||
}
|
||||
@@ -494,7 +495,7 @@ class ImageCacheServiceTest {
|
||||
daemon.registry.put(REGISTRY_IMAGE, image("sha256:new", REGISTRY_REPO + "@sha256:new-manifest"));
|
||||
|
||||
assertEquals(new LaunchImage("sha256:new", "sha256:new-manifest"),
|
||||
newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED));
|
||||
newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED, null));
|
||||
assertEquals(1, daemon.pulls.get());
|
||||
}
|
||||
|
||||
@@ -505,11 +506,11 @@ class ImageCacheServiceTest {
|
||||
daemon.registry.put(REGISTRY_IMAGE, image("sha256:old", REGISTRY_REPO + "@sha256:old-manifest"));
|
||||
ImageCacheService service = newService(daemon.client);
|
||||
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.ONCE);
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.ONCE, null);
|
||||
daemon.registry.put(REGISTRY_IMAGE, image("sha256:new", REGISTRY_REPO + "@sha256:new-manifest"));
|
||||
|
||||
assertEquals(new LaunchImage("sha256:old", "sha256:old-manifest"),
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.ONCE));
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.ONCE, null));
|
||||
assertEquals("sha256:old", service.ensureImageExists(REGISTRY_IMAGE));
|
||||
assertEquals(1, daemon.pulls.get());
|
||||
}
|
||||
@@ -522,9 +523,9 @@ class ImageCacheServiceTest {
|
||||
daemon.registry.put(REGISTRY_IMAGE, image(oldId, REGISTRY_REPO + "@sha256:old-manifest"));
|
||||
ImageCacheService service = newService(daemon.client);
|
||||
|
||||
LaunchImage first = service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT);
|
||||
LaunchImage first = service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT, null);
|
||||
daemon.registry.put(REGISTRY_IMAGE, image(newId, REGISTRY_REPO + "@sha256:new-manifest"));
|
||||
LaunchImage second = service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT);
|
||||
LaunchImage second = service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT, null);
|
||||
|
||||
assertEquals(new LaunchImage(oldId, "sha256:old-manifest"), first);
|
||||
assertEquals(new LaunchImage(newId, "sha256:new-manifest"), second);
|
||||
@@ -551,17 +552,60 @@ class ImageCacheServiceTest {
|
||||
ImageCacheService service = newService(daemon.client);
|
||||
|
||||
for (ImagePullBehavior behavior : ImagePullBehavior.values()) {
|
||||
assertEquals(new LaunchImage(imageId, null), service.resolveForLaunch(imageId, behavior));
|
||||
assertEquals(new LaunchImage(imageId, null), service.resolveForLaunch(imageId, behavior, null));
|
||||
}
|
||||
assertEquals(0, daemon.pulls.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLaunchForAnotherPlatformRunsTheLocalImageBuiltForIt() {
|
||||
FakeDaemon daemon = new FakeDaemon();
|
||||
daemon.store(LOCAL_IMAGE, image("sha256:amd64-build"));
|
||||
ImageCacheService service = newService(daemon.client, "aarch64");
|
||||
|
||||
for (ImagePullBehavior behavior : List.of(ImagePullBehavior.DEFAULT, ImagePullBehavior.PREFER_CACHED)) {
|
||||
assertEquals(new LaunchImage("sha256:amd64-build", null),
|
||||
service.resolveForLaunch(LOCAL_IMAGE, behavior, "linux/amd64"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLaunchOnTheDaemonsPlatformDoesNotReuseALocalImageOfAnother() {
|
||||
FakeDaemon daemon = new FakeDaemon();
|
||||
daemon.store(LOCAL_IMAGE, image("sha256:amd64-build"));
|
||||
|
||||
assertThrows(NotFoundException.class, () -> newService(daemon.client, "aarch64")
|
||||
.resolveForLaunch(LOCAL_IMAGE, ImagePullBehavior.PREFER_CACHED, null));
|
||||
assertEquals(1, daemon.pulls.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLaunchForAnotherPlatformPullsThatPlatform() {
|
||||
FakeDaemon daemon = new FakeDaemon();
|
||||
daemon.registry.put(REGISTRY_IMAGE, image("sha256:amd64", REGISTRY_REPO + "@sha256:amd64-manifest"));
|
||||
|
||||
newService(daemon.client, "aarch64").resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.ALWAYS, "linux/amd64");
|
||||
|
||||
assertEquals(List.of("linux/amd64"), daemon.pullPlatforms);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aLaunchOnTheDaemonsPlatformPullsWithoutNamingOne() {
|
||||
FakeDaemon daemon = new FakeDaemon();
|
||||
daemon.registry.put(REGISTRY_IMAGE, image("sha256:amd64", REGISTRY_REPO + "@sha256:amd64-manifest"));
|
||||
|
||||
newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.ALWAYS, null);
|
||||
|
||||
assertEquals(1, daemon.pulls.get());
|
||||
assertEquals(List.of(), daemon.pullPlatforms);
|
||||
}
|
||||
|
||||
@Test
|
||||
void anImageIdThatIsGoneFailsALaunchWithoutAPull() {
|
||||
FakeDaemon daemon = new FakeDaemon();
|
||||
|
||||
assertThrows(DockerClientException.class, () -> newService(daemon.client)
|
||||
.resolveForLaunch("sha256:" + "e".repeat(64), ImagePullBehavior.ALWAYS));
|
||||
.resolveForLaunch("sha256:" + "e".repeat(64), ImagePullBehavior.ALWAYS, null));
|
||||
assertEquals(0, daemon.pulls.get());
|
||||
}
|
||||
|
||||
@@ -573,7 +617,7 @@ class ImageCacheServiceTest {
|
||||
daemon.registryDigests.put(REGISTRY_IMAGE, "sha256:index");
|
||||
|
||||
assertEquals(new LaunchImage("sha256:config", "sha256:index"),
|
||||
newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT));
|
||||
newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -582,7 +626,7 @@ class ImageCacheServiceTest {
|
||||
daemon.registry.put(REGISTRY_IMAGE, image("sha256:config", REGISTRY_REPO + "@sha256:first-manifest"));
|
||||
daemon.registryDigests.put(REGISTRY_IMAGE, "sha256:first-manifest");
|
||||
ImageCacheService service = newService(daemon.client);
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT);
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT, null);
|
||||
|
||||
// A docker pull outside Floci moves the tag to a second manifest of the same image config,
|
||||
// which the classic image store keeps under the same image id.
|
||||
@@ -590,7 +634,7 @@ class ImageCacheServiceTest {
|
||||
REGISTRY_REPO + "@sha256:first-manifest", REGISTRY_REPO + "@sha256:second-manifest"));
|
||||
|
||||
assertEquals(new LaunchImage("sha256:config", null),
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED));
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -600,7 +644,7 @@ class ImageCacheServiceTest {
|
||||
REGISTRY_REPO + "@sha256:platform-manifest", REGISTRY_REPO + "@sha256:index"));
|
||||
|
||||
assertEquals(new LaunchImage("sha256:index", "sha256:index"),
|
||||
newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED));
|
||||
newService(daemon.client).resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -609,12 +653,12 @@ class ImageCacheServiceTest {
|
||||
daemon.registry.put(REGISTRY_IMAGE, image("sha256:old", REGISTRY_REPO + "@sha256:old-manifest"));
|
||||
daemon.registryDigests.put(REGISTRY_IMAGE, "sha256:old-manifest");
|
||||
ImageCacheService service = newService(daemon.client);
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT);
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.DEFAULT, null);
|
||||
|
||||
daemon.store(REGISTRY_IMAGE, image("sha256:rebuilt"));
|
||||
|
||||
assertEquals(new LaunchImage("sha256:rebuilt", null),
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED));
|
||||
service.resolveForLaunch(REGISTRY_IMAGE, ImagePullBehavior.PREFER_CACHED, null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -671,6 +715,7 @@ class ImageCacheServiceTest {
|
||||
final Map<String, String> registryDigests = new HashMap<>();
|
||||
final Set<String> hangingPulls = new HashSet<>();
|
||||
final AtomicInteger pulls = new AtomicInteger();
|
||||
final List<String> pullPlatforms = new ArrayList<>();
|
||||
|
||||
FakeDaemon() {
|
||||
when(client.inspectImageCmd(anyString())).thenAnswer(invocation -> {
|
||||
@@ -689,6 +734,10 @@ class ImageCacheServiceTest {
|
||||
String reference = invocation.getArgument(0);
|
||||
PullImageCmd pull = mock(PullImageCmd.class);
|
||||
when(pull.withAuthConfig(any())).thenReturn(pull);
|
||||
when(pull.withPlatform(anyString())).thenAnswer(platform -> {
|
||||
pullPlatforms.add(platform.getArgument(0));
|
||||
return pull;
|
||||
});
|
||||
when(pull.exec(any(PullImageResultCallback.class))).thenAnswer(execution -> {
|
||||
pulls.incrementAndGet();
|
||||
if (hangingPulls.contains(reference)) {
|
||||
@@ -727,10 +776,19 @@ class ImageCacheServiceTest {
|
||||
return newService(dockerClient, 300);
|
||||
}
|
||||
|
||||
private static ImageCacheService newService(DockerClient dockerClient, String daemonArchitecture) {
|
||||
return newService(dockerClient, 300, daemonArchitecture);
|
||||
}
|
||||
|
||||
private static ImageCacheService newService(DockerClient dockerClient, int imagePullTimeoutSeconds) {
|
||||
return newService(dockerClient, imagePullTimeoutSeconds, "amd64");
|
||||
}
|
||||
|
||||
private static ImageCacheService newService(DockerClient dockerClient, int imagePullTimeoutSeconds,
|
||||
String daemonArchitecture) {
|
||||
InfoCmd infoCmd = mock(InfoCmd.class);
|
||||
when(dockerClient.infoCmd()).thenReturn(infoCmd);
|
||||
when(infoCmd.exec()).thenReturn(new Info().withOsType("linux").withArchitecture("amd64"));
|
||||
when(infoCmd.exec()).thenReturn(new Info().withOsType("linux").withArchitecture(daemonArchitecture));
|
||||
EmulatorConfig config = mock(EmulatorConfig.class);
|
||||
EmulatorConfig.DockerConfig dockerConfig = mock(EmulatorConfig.DockerConfig.class);
|
||||
when(config.docker()).thenReturn(dockerConfig);
|
||||
|
||||
Reference in new issue
Block a user