mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 06:00:46 -05:00
feat(core): make the image pull timeout configurable (#6521)
ImageCacheService gave each attempt at pulling an image a hard-coded five minutes, and a pull three attempts. An EMR Serverless runtime is 3.5 to 4.3 GB, so on an ordinary connection the first run of a release Docker did not have yet failed with "Could not pull image" before the pull could finish. floci.docker.image-pull-timeout-seconds, or FLOCI_DOCKER_IMAGE_PULL_TIMEOUT_SECONDS, now sets the limit for each attempt. Its default, 300, keeps today's five minutes, and it must be at least 1, checked with the other Docker timeouts in DockerClientProducer. Follow-up to #6469.
This commit is contained in:
1 parent
1ea49d9432
commit
b66ee9ecf0
8 files changed
+89
-8
No files matched your search
@@ -92,6 +92,16 @@ floci:
|
||||
|
||||
Environment variable: `FLOCI_DOCKER_API_TIMEOUT_SECONDS`
|
||||
|
||||
An image pull has a limit of its own: each attempt may take up to `image-pull-timeout-seconds`, 300 seconds (5 minutes) by default. A pull still downloading when the limit passes fails that attempt with "Could not pull image: Downloading" and is tried again, three attempts in all, so a launch that needs an image Docker does not have yet can wait up to about three times the limit before it fails; a pull that has reported no progress at all within the limit fails at once with "Timed out pulling image". A large image, such as an EMR Serverless runtime of 3.5 to 4.3 GB, can need longer on a slow connection: raise the limit, or pull the image with `docker pull` before the first launch. It must be at least 1:
|
||||
|
||||
```yaml
|
||||
floci:
|
||||
docker:
|
||||
image-pull-timeout-seconds: 300
|
||||
```
|
||||
|
||||
Environment variable: `FLOCI_DOCKER_IMAGE_PULL_TIMEOUT_SECONDS`
|
||||
|
||||
## Private Registry Authentication
|
||||
|
||||
Any service that pulls a container image from a private registry (Lambda image functions, custom OpenSearch images, private Postgres images, etc.) needs Docker credentials. Two approaches are supported and can be combined.
|
||||
|
||||
@@ -107,9 +107,10 @@ publishes for customizing EMR Serverless images (`public.ecr.aws/emr-serverless/
|
||||
`spark-submit` in local mode in it: the container holds the driver and its executors.
|
||||
|
||||
* **States**: a run is `SCHEDULED` while its image is pulled and its container starts (the first run
|
||||
of a release pulls its image, 3.5 to 4.3 GB unpacked; Floci gives a pull three attempts of five
|
||||
minutes, so on a slow connection run `docker pull` on the image first, or the run is `FAILED` with
|
||||
"Could not pull image"), and `RUNNING` once the Spark driver runs, which sets `startedAt`. It
|
||||
of a release pulls its image, 3.5 to 4.3 GB unpacked; a pull still downloading after
|
||||
[`floci.docker.image-pull-timeout-seconds`](../configuration/docker.md), five minutes by default,
|
||||
is tried again, three attempts in all, so on a slow connection raise it or run `docker pull` on the
|
||||
image first, or the run is `FAILED` with "Could not pull image"), and `RUNNING` once the Spark driver runs, which sets `startedAt`. It
|
||||
is `SUCCESS` when the driver exits with code 0 and `FAILED` otherwise, with the exit code in
|
||||
`stateDetails`. `CancelJobRun`, or a `BATCH` run passing its `executionTimeoutMinutes`, makes it
|
||||
`CANCELLING` until the driver is stopped, then `CANCELLED`, as the job run states describe. A run
|
||||
|
||||
@@ -3880,6 +3880,15 @@ public interface EmulatorConfig {
|
||||
@WithDefault("300")
|
||||
int apiTimeoutSeconds();
|
||||
|
||||
/**
|
||||
* How long each attempt at pulling an image may take before it is given up, in seconds. A pull
|
||||
* still downloading when the limit passes is tried again, three attempts in all, so a launch that
|
||||
* needs an image can wait up to about three times this before it fails. A large image, such as an EMR Serverless runtime of 3.5 to 4.3 GB, can need longer
|
||||
* on a slow connection.
|
||||
*/
|
||||
@WithDefault("300")
|
||||
int imagePullTimeoutSeconds();
|
||||
|
||||
/**
|
||||
* Optional namespace inserted into Floci-managed child container and volume names.
|
||||
* Useful when multiple Floci processes share one Docker daemon.
|
||||
|
||||
@@ -407,6 +407,12 @@ public class DockerClientProducer {
|
||||
return requireAtLeastOne(seconds, "floci.docker.api-timeout-seconds", "FLOCI_DOCKER_API_TIMEOUT_SECONDS");
|
||||
}
|
||||
|
||||
/** At 0 every pull would be given up at once, so a launch that needs an image could never start. */
|
||||
public static int validateImagePullTimeoutSeconds(int seconds) {
|
||||
return requireAtLeastOne(seconds, "floci.docker.image-pull-timeout-seconds",
|
||||
"FLOCI_DOCKER_IMAGE_PULL_TIMEOUT_SECONDS");
|
||||
}
|
||||
|
||||
private static int requireAtLeastOne(int value, String setting, String envVar) {
|
||||
if (value < 1) {
|
||||
throw new IllegalArgumentException(setting + " (" + envVar + ") must be at least 1, got: " + value);
|
||||
|
||||
+9
-2
@@ -11,6 +11,7 @@ import com.github.dockerjava.api.model.Info;
|
||||
import com.github.dockerjava.api.model.PullResponseItem;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig.EcsServiceConfig.ImagePullBehavior;
|
||||
import io.github.hectorvent.floci.core.common.docker.DockerClientProducer;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -44,6 +45,8 @@ public class ImageCacheService {
|
||||
|
||||
private final DockerClient dockerClient;
|
||||
private final List<EmulatorConfig.DockerConfig.RegistryCredential> registryCredentials;
|
||||
// floci.docker.image-pull-timeout-seconds: how long each pull attempt may take.
|
||||
private final int pullTimeoutSeconds;
|
||||
private final Map<ImageKey, String> resolvedImages = new ConcurrentHashMap<>();
|
||||
private final Set<ImageKey> pulledImages = ConcurrentHashMap.newKeySet();
|
||||
private final ConcurrentHashMap<String, Object> locks = new ConcurrentHashMap<>();
|
||||
@@ -53,6 +56,8 @@ public class ImageCacheService {
|
||||
public ImageCacheService(DockerClient dockerClient, EmulatorConfig config) {
|
||||
this.dockerClient = dockerClient;
|
||||
this.registryCredentials = config.docker().registryCredentials();
|
||||
this.pullTimeoutSeconds = DockerClientProducer.validateImagePullTimeoutSeconds(
|
||||
config.docker().imagePullTimeoutSeconds());
|
||||
}
|
||||
|
||||
public String ensureImageExists(String imageUri) {
|
||||
@@ -186,8 +191,10 @@ public class ImageCacheService {
|
||||
}
|
||||
ManifestDigestCallback callback = new ManifestDigestCallback();
|
||||
lastAttempt.set(callback);
|
||||
if (!pullImage.<PullImageResultCallback>exec(callback).awaitCompletion(5, TimeUnit.MINUTES)) {
|
||||
throw new DockerClientException("Timed out pulling image " + imageUri + " after 5 minutes");
|
||||
if (!pullImage.<PullImageResultCallback>exec(callback)
|
||||
.awaitCompletion(pullTimeoutSeconds, TimeUnit.SECONDS)) {
|
||||
throw new DockerClientException("Timed out pulling image " + imageUri + " after "
|
||||
+ pullTimeoutSeconds + " seconds");
|
||||
}
|
||||
});
|
||||
} catch (InterruptedException e) {
|
||||
|
||||
@@ -377,6 +377,11 @@ floci:
|
||||
# attempt: a control-plane request that is safe to repeat is tried up to six times. Keep in step with
|
||||
# the @WithDefault on EmulatorConfig.DockerConfig.apiTimeoutSeconds: a value set here WINS over the annotation.
|
||||
api-timeout-seconds: 300
|
||||
# FLOCI_DOCKER_IMAGE_PULL_TIMEOUT_SECONDS: how long each attempt at an image pull may take; a pull
|
||||
# still downloading when it passes is tried again, three attempts in all.
|
||||
# Keep in step with the @WithDefault on EmulatorConfig.DockerConfig.imagePullTimeoutSeconds: a value
|
||||
# set here WINS over the annotation.
|
||||
image-pull-timeout-seconds: 300
|
||||
resource-namespace: "" # FLOCI_DOCKER_RESOURCE_NAMESPACE; scopes child container/volume names
|
||||
docker-config-path: ""
|
||||
# extra-labels: # Extra Docker labels applied to every Floci-created container and volume
|
||||
|
||||
+16
@@ -692,6 +692,22 @@ class DockerClientProducerTest {
|
||||
assertEquals(300, DockerClientProducer.validateApiTimeoutSeconds(300));
|
||||
}
|
||||
|
||||
// Catches: a zero pull timeout, which would give up on every pull at once.
|
||||
@ParameterizedTest
|
||||
@ValueSource(ints = {0, -1})
|
||||
void validateImagePullTimeoutSeconds_belowOne_throwsNamingTheSetting(int seconds) {
|
||||
IllegalArgumentException e = assertThrows(IllegalArgumentException.class,
|
||||
() -> DockerClientProducer.validateImagePullTimeoutSeconds(seconds));
|
||||
|
||||
assertThat(e.getMessage(), containsString("floci.docker.image-pull-timeout-seconds"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void validateImagePullTimeoutSeconds_positive_returnsItUnchanged() {
|
||||
assertEquals(1, DockerClientProducer.validateImagePullTimeoutSeconds(1));
|
||||
assertEquals(1800, DockerClientProducer.validateImagePullTimeoutSeconds(1800));
|
||||
}
|
||||
|
||||
/**
|
||||
* The pool size comes from {@code floci.docker.max-connections}. A followed log stream holds
|
||||
* its connection until the container exits, and this fake daemon never answers, so with a
|
||||
|
||||
+30
-3
@@ -32,6 +32,7 @@ import static org.junit.jupiter.api.Assertions.assertSame;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -67,7 +68,28 @@ class ImageCacheServiceTest {
|
||||
|
||||
verify(pullImage).exec(any(PullImageResultCallback.class));
|
||||
verify(pullImage, never()).withPlatform(nullable(String.class));
|
||||
verify(callback).awaitCompletion(5, TimeUnit.MINUTES);
|
||||
verify(callback).awaitCompletion(300, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
void eachPullAttemptWaitsAsLongAsTheConfiguredImagePullTimeout() throws Exception {
|
||||
DockerClient dockerClient = mock(DockerClient.class);
|
||||
InspectImageCmd inspectImage = mock(InspectImageCmd.class);
|
||||
PullImageCmd pullImage = mock(PullImageCmd.class);
|
||||
PullImageResultCallback callback = completedPull();
|
||||
when(dockerClient.inspectImageCmd(IMAGE)).thenReturn(inspectImage);
|
||||
when(inspectImage.exec()).thenThrow(new NotFoundException("image not found"))
|
||||
.thenReturn(new InspectImageResponse()
|
||||
.withId("sha256:native")
|
||||
.withOs("linux")
|
||||
.withArch("amd64"));
|
||||
when(dockerClient.pullImageCmd(IMAGE)).thenReturn(pullImage);
|
||||
when(pullImage.withAuthConfig(any())).thenReturn(pullImage);
|
||||
when(pullImage.exec(any(PullImageResultCallback.class))).thenReturn(callback);
|
||||
|
||||
newService(dockerClient, 1800).ensureImageExists(IMAGE);
|
||||
|
||||
verify(callback).awaitCompletion(1800, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -105,7 +127,7 @@ class ImageCacheServiceTest {
|
||||
|
||||
assertEquals("sha256:arm64", resolvedImage);
|
||||
verify(pullImage).withPlatform("linux/arm64");
|
||||
verify(callback).awaitCompletion(5, TimeUnit.MINUTES);
|
||||
verify(callback).awaitCompletion(300, TimeUnit.SECONDS);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -697,11 +719,15 @@ class ImageCacheServiceTest {
|
||||
|
||||
private static PullImageResultCallback completedPull() throws InterruptedException {
|
||||
PullImageResultCallback callback = mock(PullImageResultCallback.class);
|
||||
when(callback.awaitCompletion(5, TimeUnit.MINUTES)).thenReturn(true);
|
||||
when(callback.awaitCompletion(anyLong(), any(TimeUnit.class))).thenReturn(true);
|
||||
return callback;
|
||||
}
|
||||
|
||||
private static ImageCacheService newService(DockerClient dockerClient) {
|
||||
return newService(dockerClient, 300);
|
||||
}
|
||||
|
||||
private static ImageCacheService newService(DockerClient dockerClient, int imagePullTimeoutSeconds) {
|
||||
InfoCmd infoCmd = mock(InfoCmd.class);
|
||||
when(dockerClient.infoCmd()).thenReturn(infoCmd);
|
||||
when(infoCmd.exec()).thenReturn(new Info().withOsType("linux").withArchitecture("amd64"));
|
||||
@@ -709,6 +735,7 @@ class ImageCacheServiceTest {
|
||||
EmulatorConfig.DockerConfig dockerConfig = mock(EmulatorConfig.DockerConfig.class);
|
||||
when(config.docker()).thenReturn(dockerConfig);
|
||||
when(dockerConfig.registryCredentials()).thenReturn(List.of());
|
||||
when(dockerConfig.imagePullTimeoutSeconds()).thenReturn(imagePullTimeoutSeconds);
|
||||
return new ImageCacheService(dockerClient, config);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user