fix(ecr): follow the registry when deleting the last repository replaces it (#7224)

In memory mode, or with prune-volumes-on-delete, deleting the last repository
removes the backing registry container and the next CreateRepository starts a
new one. Floci running in Docker reached the registry by container name, so
when the new container got a different IP the JVM's cached lookup kept
answering with the old address. Until it expired, DeleteRepository returned
500 and CreateRepository could wait long enough for the SDK to time out and
retry, which then failed with RepositoryAlreadyExistsException.

Use the address Docker reports for the container just started or adopted,
and only fall back to the name when none is known. EcrTest no longer needs to
keep a repository to avoid this.

Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-11-01 12:45:46 -04:00
1 parent b38fe7d96d
commit 38eb938f22
3 files changed
+63 -9

No files matched your search

@@ -324,6 +324,49 @@ class EcrRegistryManagerTest {
assertEquals("http://" + REGISTRY_NAME + ":5000", manager.httpClient().baseUrl());
}
@Test
void httpClient_usesTheStartedRegistrysAddressInsideDocker() {
when(containerDetector.isRunningInContainer()).thenReturn(true);
when(lifecycleManager.createAndStart(any())).thenReturn(containerAt("container-id", "172.18.0.3"));
manager.ensureStarted();
assertEquals("http://172.18.0.3:5000", manager.httpClient().baseUrl());
}
@Test
void httpClient_followsTheRegistryWhenDeletingTheLastRepositoryReplacesIt() {
when(containerDetector.isRunningInContainer()).thenReturn(true);
when(storage.pruneVolumesOnDelete()).thenReturn(true);
when(lifecycleManager.createAndStart(any())).thenReturn(
containerAt("old-container", "172.18.0.3"), containerAt("new-container", "172.18.0.9"));
manager.ensureStarted();
manager.pruneStorage();
assertEquals("http://" + REGISTRY_NAME + ":5000", manager.httpClient().baseUrl());
manager.ensureStarted();
assertEquals("http://172.18.0.9:5000", manager.httpClient().baseUrl());
}
@Test
void httpClient_forgetsTheAddressOfARegistryThatDisappeared() {
when(containerDetector.isRunningInContainer()).thenReturn(true);
when(lifecycleManager.createAndStart(any())).thenReturn(
containerAt("old-container", "172.18.0.3"), containerAt("new-container", "172.18.0.9"));
manager.ensureStarted();
when(lifecycleManager.presenceOf("old-container")).thenReturn(ContainerPresence.ABSENT);
manager.ensureStarted();
assertEquals("http://172.18.0.9:5000", manager.httpClient().baseUrl());
}
private static ContainerLifecycleManager.ContainerInfo containerAt(String containerId, String ip) {
return new ContainerLifecycleManager.ContainerInfo(containerId,
Map.of(5000, new ContainerLifecycleManager.EndpointInfo(ip, 5000)));
}
@Test
void freshlyCreatedRegistryStreamsItsCompleteLog() {
when(lifecycleManager.createAndStart(any())).thenReturn(