This is an automated email from the ASF dual-hosted git repository. apupier pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4fff2b00c4046636cd61d7ee9ee37e018eb12f76 Author: Aurélien Pupier <[email protected]> AuthorDate: Tue Nov 24 10:08:01 2026 +0100 CAMEL-26387: retry on HTTP 429 and mention skipTests.<arch> in HostArchitectureImagePullPolicy Address the review of the pull request: - docker-java maps the HTTP codes it does not know, like 429, to a plain DockerException: check the quota/rate-limit failure on every runtime exception of the pull, not only on DockerClientException - mention skipTests.<arch> (unit tests) in addition to skipITs.<arch> (integration tests) in the message of a permanent pull failure Co-authored-by: IBM Bob 2.2.1 Signed-off-by: Aurélien Pupier <[email protected]> --- .../infra/common/HostArchitectureImagePullPolicy.java | 16 ++++++++++------ .../common/HostArchitectureImagePullPolicyTest.java | 13 +++++++++++++ 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/HostArchitectureImagePullPolicy.java b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/HostArchitectureImagePullPolicy.java index f611637d65aa..2597ca7c8092 100644 --- a/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/HostArchitectureImagePullPolicy.java +++ b/test-infra/camel-test-infra-common/src/main/java/org/apache/camel/test/infra/common/HostArchitectureImagePullPolicy.java @@ -21,7 +21,7 @@ import java.time.Instant; import java.util.Locale; import com.github.dockerjava.api.DockerClient; -import com.github.dockerjava.api.exception.DockerClientException; +import com.github.dockerjava.api.exception.DockerException; import com.github.dockerjava.api.exception.InternalServerErrorException; import com.github.dockerjava.api.exception.NotFoundException; import org.slf4j.Logger; @@ -84,6 +84,7 @@ public class HostArchitectureImagePullPolicy implements ImagePullPolicy { private static final Logger LOG = LoggerFactory.getLogger(HostArchitectureImagePullPolicy.class); + private static final int HTTP_TOO_MANY_REQUESTS = 429; private static final Duration INITIAL_RETRY_DELAY = Duration.ofSeconds(1); private static final Duration MAX_RETRY_DELAY = Duration.ofSeconds(15); @@ -187,13 +188,13 @@ public class HostArchitectureImagePullPolicy implements ImagePullPolicy { transientFailure = new ContainerFetchException("Pull of image " + name + " made no progress", e); } catch (InternalServerErrorException e) { transientFailure = e; - } catch (DockerClientException e) { + } catch (RuntimeException e) { + // docker-java reports a failed pull as a DockerClientException, and maps the HTTP codes it does not know, + // like 429, to a plain DockerException if (!isQuotaExceeded(e)) { throw permanentFailure(name, platform, e); } transientFailure = e; - } catch (RuntimeException e) { - throw permanentFailure(name, platform, e); } if (Instant.now().plus(delay).isAfter(deadline)) { @@ -236,8 +237,8 @@ public class HostArchitectureImagePullPolicy implements ImagePullPolicy { // Do not let Testcontainers fall back to linux/amd64, this would leave an image that cannot run on this host String arch = platform.substring("linux/".length()); String skipHint = isCheckedByDefault(arch) - ? ", the tests needing it can be skipped with the skipITs." + arch - + " Maven property" + ? ", the tests needing it can be skipped with the skipTests." + arch + " (unit tests) or skipITs." + arch + + " (integration tests) Maven properties" : ""; return new ContainerFetchException( "Failed to pull image " + name + " for platform " + platform @@ -248,6 +249,9 @@ public class HostArchitectureImagePullPolicy implements ImagePullPolicy { } private static boolean isQuotaExceeded(Exception e) { + if (e instanceof DockerException && ((DockerException) e).getHttpStatus() == HTTP_TOO_MANY_REQUESTS) { + return true; + } String message = e.getMessage(); if (message == null) { return false; diff --git a/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/HostArchitectureImagePullPolicyTest.java b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/HostArchitectureImagePullPolicyTest.java index fbbbd374a1dd..3c84b585294f 100644 --- a/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/HostArchitectureImagePullPolicyTest.java +++ b/test-infra/camel-test-infra-common/src/test/java/org/apache/camel/test/infra/common/HostArchitectureImagePullPolicyTest.java @@ -23,6 +23,7 @@ import java.util.List; import java.util.Queue; import com.github.dockerjava.api.exception.DockerClientException; +import com.github.dockerjava.api.exception.DockerException; import com.github.dockerjava.api.exception.InternalServerErrorException; import com.github.dockerjava.api.exception.NotFoundException; import org.junit.jupiter.api.Test; @@ -138,6 +139,17 @@ class HostArchitectureImagePullPolicyTest { assertEquals("ppc64le", operations.localArch); } + @Test + void retriesWhenTheRegistryRepliesTooManyRequests() { + StubOperations operations = new StubOperations("ppc64le"); + // docker-java maps the HTTP codes it does not know to a plain DockerException + operations.failures.add(new DockerException("rate limited", 429)); + + assertFalse(policy(operations, "ppc64le", true).shouldPull(IMAGE)); + + assertEquals(2, operations.pulls.size()); + } + @Test void retriesWhenThePullMadeNoProgress() { StubOperations operations = new StubOperations("ppc64le"); @@ -171,6 +183,7 @@ class HostArchitectureImagePullPolicyTest { assertEquals(1, operations.pulls.size()); assertTrue(e.getMessage().contains("skipITs.ppc64le"), e.getMessage()); + assertTrue(e.getMessage().contains("skipTests.ppc64le"), e.getMessage()); assertNull(operations.localArch); }
