fix(docker): retry core and EKS archive uploads (#5916)

* fix(docker): retry core and EKS archive uploads

* fix(docker): fail fast on local host archive errors

* test(docker): skip backoff in archive retry regressions

Allow package-private caller entry points to select the archive backoff while production retains the shared defaults. Remove the unused user-data tar builder requested in review.

* test(resourceexplorer2): isolate empty-query count assertions

The shared integration fixture can contain exactly 1000 resources, where a capped total does not imply incomplete results. Search a tracked single-resource view and cover 999, 1000 and 1001 matches with deterministic service tests.
This commit is contained in:
Aniket Shukla authored and GitHub committed 2026-10-18 11:53:50 -04:00
1 parent f5811c3a07
commit d951fd532c
12 files changed
+803 -106

No files matched your search

@@ -30,12 +30,8 @@ import io.github.hectorvent.floci.services.lambda.launcher.ImageCacheService.Lau
import io.quarkus.runtime.annotations.RegisterForReflection;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.jboss.logging.Logger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.nio.file.Files;
import java.nio.file.Path;
@@ -91,6 +87,7 @@ public class ContainerLifecycleManager {
private final ImageCacheService imageCacheService;
private final ContainerDetector containerDetector;
private final EmulatorConfig config;
private final long archiveRetryBackoffMillis;
/** Volumes whose shared-ownership root has already been initialised this process (run-once guard). */
private final ConcurrentHashMap<String, Boolean> initializedSharedVolumes = new ConcurrentHashMap<>();
@@ -103,10 +100,20 @@ public class ContainerLifecycleManager {
ImageCacheService imageCacheService,
ContainerDetector containerDetector,
EmulatorConfig config) {
this(dockerClient, imageCacheService, containerDetector, config,
RetryingTarCopier.DEFAULT_BACKOFF_MS);
}
ContainerLifecycleManager(DockerClient dockerClient,
ImageCacheService imageCacheService,
ContainerDetector containerDetector,
EmulatorConfig config,
long archiveRetryBackoffMillis) {
this.dockerClient = dockerClient;
this.imageCacheService = imageCacheService;
this.containerDetector = containerDetector;
this.config = config;
this.archiveRetryBackoffMillis = archiveRetryBackoffMillis;
}
/**
@@ -331,18 +338,9 @@ public class ContainerLifecycleManager {
private boolean copyCaBundle(String containerId, Path bundle) {
try {
byte[] content = Files.readAllBytes(bundle);
ByteArrayOutputStream archive = new ByteArrayOutputStream(content.length + 1024);
try (TarArchiveOutputStream tar = new TarArchiveOutputStream(archive)) {
TarArchiveEntry entry = new TarArchiveEntry(ContainerCaBundle.FILE_NAME);
entry.setSize(content.length);
tar.putArchiveEntry(entry);
tar.write(content);
tar.closeArchiveEntry();
}
dockerClient.copyArchiveToContainerCmd(containerId)
.withRemotePath(ContainerCaBundle.CONTAINER_DIR)
.withTarInputStream(new ByteArrayInputStream(archive.toByteArray()))
.exec();
RetryingTarCopier.copyBytes(dockerClient, containerId, ContainerCaBundle.CONTAINER_DIR,
ContainerCaBundle.FILE_NAME, content, 0644,
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
LOG.debugv("Copied the CA bundle into container {0} at {1}", containerId, ContainerCaBundle.CONTAINER_PATH);
return true;
} catch (Exception e) {
@@ -1,6 +1,7 @@
package io.github.hectorvent.floci.core.common.docker;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.exception.DockerClientException;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.jboss.logging.Logger;
@@ -30,8 +31,8 @@ public final class RetryingTarCopier {
private static final Logger LOG = Logger.getLogger(RetryingTarCopier.class);
static final int DEFAULT_MAX_ATTEMPTS = 6;
static final long DEFAULT_BACKOFF_MS = 500L;
public static final int DEFAULT_MAX_ATTEMPTS = 6;
public static final long DEFAULT_BACKOFF_MS = 500L;
/**
* Buffer for the tar-streaming pipe. The default {@link PipedInputStream} buffer is only 1KB,
@@ -154,11 +155,22 @@ public final class RetryingTarCopier {
public static void copyHostResource(DockerClient docker, String containerId, String remotePath,
String hostPath, int maxAttempts, long backoffMillis) {
retry(hostPath, containerId, maxAttempts, backoffMillis, () ->
retry(hostPath, containerId, maxAttempts, backoffMillis, () -> {
try {
docker.copyArchiveToContainerCmd(containerId)
.withHostResource(hostPath)
.withRemotePath(remotePath)
.exec());
.exec();
} catch (DockerClientException e) {
// These docker-java wrappers identify local archive preparation and temporary-file I/O.
String message = e.getMessage();
if (message != null && (message.startsWith("Unable to perform tar on host resource ")
|| message.startsWith("Unable to read temp file "))) {
throw new DockerRetry.LocalFailure(message, e);
}
throw e;
}
});
}
/** Single-entry tar bytes, reusable across attempts and callers. */
@@ -3,8 +3,6 @@ package io.github.hectorvent.floci.core.common.docker;
import com.github.dockerjava.api.DockerClient;
import com.github.dockerjava.api.async.ResultCallback;
import com.github.dockerjava.api.model.Frame;
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.jboss.logging.Logger;
import java.io.ByteArrayInputStream;
@@ -203,20 +201,6 @@ public final class UserDataPipeline {
return false;
}
public static byte[] buildSingleFileTar(String filename, byte[] content, int mode) throws IOException {
ByteArrayOutputStream bos = new ByteArrayOutputStream();
try (TarArchiveOutputStream tar = new TarArchiveOutputStream(bos)) {
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU);
TarArchiveEntry entry = new TarArchiveEntry(filename);
entry.setSize(content.length);
entry.setMode(mode);
tar.putArchiveEntry(entry);
tar.write(content);
tar.closeArchiveEntry();
}
return bos.toByteArray();
}
public static String summarizeUserDataOutput(BoundedOutput output) {
if (output == null) {
return "(no output)";
@@ -239,6 +223,20 @@ public final class UserDataPipeline {
Duration timeout,
Consumer<String> outputLineConsumer,
Set<ResultCallback<Frame>> activeCallbacks
) {
return executeUserData(dockerClient, containerId, contextDescription, userData, timeout,
outputLineConsumer, activeCallbacks, RetryingTarCopier.DEFAULT_BACKOFF_MS);
}
static ExecutionResult executeUserData(
DockerClient dockerClient,
String containerId,
String contextDescription,
String userData,
Duration timeout,
Consumer<String> outputLineConsumer,
Set<ResultCallback<Frame>> activeCallbacks,
long archiveRetryBackoffMillis
) {
if (dockerClient == null || containerId == null || containerId.isBlank()) {
return ExecutionResult.skipped("No container available");
@@ -255,7 +253,7 @@ public final class UserDataPipeline {
String scriptContent = shellScripts.get(i);
ExecutionResult partResult = executeSingleScript(
dockerClient, containerId, contextDescription, scriptContent, partNumber, partCount,
effectiveTimeout, outputLineConsumer, activeCallbacks);
effectiveTimeout, outputLineConsumer, activeCallbacks, archiveRetryBackoffMillis);
if (!partResult.isSuccess()) {
return partResult;
}
@@ -272,15 +270,13 @@ public final class UserDataPipeline {
int partCount,
Duration timeout,
Consumer<String> outputLineConsumer,
Set<ResultCallback<Frame>> activeCallbacks
Set<ResultCallback<Frame>> activeCallbacks,
long archiveRetryBackoffMillis
) {
byte[] script = scriptContent.getBytes(StandardCharsets.UTF_8);
try {
byte[] tar = buildSingleFileTar("user-data.sh", script, 0755);
dockerClient.copyArchiveToContainerCmd(containerId)
.withRemotePath("/var/lib")
.withTarInputStream(new ByteArrayInputStream(tar))
.exec();
RetryingTarCopier.copyBytes(dockerClient, containerId, "/var/lib", "user-data.sh", script, 0755,
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
String execId = dockerClient.execCreateCmd(containerId)
.withCmd(USER_DATA_SCRIPT_PATH)
@@ -62,7 +62,6 @@ import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
import org.jboss.logging.Logger;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.Closeable;
import java.io.File;
@@ -158,6 +157,7 @@ public class EksClusterManager
private final ContainerBuilder containerBuilder;
private final ContainerLifecycleManager lifecycleManager;
private final long archiveRetryBackoffMillis;
private final ContainerDetector containerDetector;
private final PortAllocator portAllocator;
private final DockerHostResolver dockerHostResolver;
@@ -424,6 +424,26 @@ public class EksClusterManager
FlociCertificateAuthority certificateAuthority,
ContainerLogStreamer logStreamer,
StorageBackend<String, Nodegroup> nodeGroupStorage) {
this(containerBuilder, lifecycleManager, containerDetector, portAllocator,
dockerHostResolver, ecrRegistryManager, config, regionResolver, metadataServer,
oidcService, certificateAuthority, logStreamer, nodeGroupStorage,
RetryingTarCopier.DEFAULT_BACKOFF_MS);
}
EksClusterManager(ContainerBuilder containerBuilder,
ContainerLifecycleManager lifecycleManager,
ContainerDetector containerDetector,
PortAllocator portAllocator,
DockerHostResolver dockerHostResolver,
EcrRegistryManager ecrRegistryManager,
EmulatorConfig config,
RegionResolver regionResolver,
Ec2MetadataServer metadataServer,
EksOidcService oidcService,
FlociCertificateAuthority certificateAuthority,
ContainerLogStreamer logStreamer,
StorageBackend<String, Nodegroup> nodeGroupStorage,
long archiveRetryBackoffMillis) {
this.containerBuilder = containerBuilder;
this.lifecycleManager = lifecycleManager;
this.containerDetector = containerDetector;
@@ -437,6 +457,7 @@ public class EksClusterManager
this.certificateAuthority = certificateAuthority;
this.logStreamer = logStreamer;
this.nodeGroupStorage = nodeGroupStorage;
this.archiveRetryBackoffMillis = archiveRetryBackoffMillis;
}
@Inject
@@ -1554,7 +1575,8 @@ public class EksClusterManager
private void copyWebhookIntoContainer(String containerId, String localFile, String clusterName) {
try {
RetryingTarCopier.copyHostResource(lifecycleManager.getDockerClient(), containerId,
WEBHOOK_CONFIG_DIR, localFile);
WEBHOOK_CONFIG_DIR, localFile,
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
} catch (Exception e) {
LOG.warnv("EKS token-webhook may not authenticate for cluster {0}: could not copy kubeconfig "
+ "into the k3s container: {1}", clusterName, e.getMessage());
@@ -1592,10 +1614,8 @@ public class EksClusterManager
try {
DockerClient dockerClient = lifecycleManager.getDockerClient();
if (dockerClient != null) {
dockerClient.copyArchiveToContainerCmd(containerId)
.withHostResource(localFile)
.withRemotePath(AUDIT_POLICY_DIR)
.exec();
RetryingTarCopier.copyHostResource(dockerClient, containerId, AUDIT_POLICY_DIR, localFile,
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
LOG.debugv("Injected audit policy file into k3s container {0} for cluster {1}",
containerId, clusterName);
}
@@ -1919,16 +1939,12 @@ public class EksClusterManager
*/
void copySigningKeysIntoContainer(String containerId, SigningKeyFiles keyFiles, String clusterName) {
try {
lifecycleManager.getDockerClient()
.copyArchiveToContainerCmd(containerId)
.withHostResource(keyFiles.signingKeyPath().toString())
.withRemotePath(WEBHOOK_CONFIG_DIR)
.exec();
lifecycleManager.getDockerClient()
.copyArchiveToContainerCmd(containerId)
.withHostResource(keyFiles.publicKeyPath().toString())
.withRemotePath(WEBHOOK_CONFIG_DIR)
.exec();
RetryingTarCopier.copyHostResource(lifecycleManager.getDockerClient(), containerId,
WEBHOOK_CONFIG_DIR, keyFiles.signingKeyPath().toString(),
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
RetryingTarCopier.copyHostResource(lifecycleManager.getDockerClient(), containerId,
WEBHOOK_CONFIG_DIR, keyFiles.publicKeyPath().toString(),
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
LOG.debugv("Injected IRSA OIDC signing keypair into k3s container {0} for cluster {1}",
containerId, clusterName);
} catch (Exception e) {
@@ -1983,7 +1999,8 @@ public class EksClusterManager
"registries.yaml"), content, clusterName);
try {
RetryingTarCopier.copyBytes(lifecycleManager.getDockerClient(), containerId, "/etc",
REGISTRIES_TAR_ENTRY, content.getBytes(StandardCharsets.UTF_8), 0644);
REGISTRIES_TAR_ENTRY, content.getBytes(StandardCharsets.UTF_8), 0644,
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
LOG.infov("Injected ECR registry mirror ({0}) into k3s cluster {1}", endpoint, clusterName);
} catch (Exception e) {
LOG.warnv("EKS cluster {0} gets no ECR registry mirror: could not copy registries.yaml "
@@ -2001,11 +2018,10 @@ public class EksClusterManager
*/
void linkContainerdCertsDir(String containerId, String clusterName) {
try {
lifecycleManager.getDockerClient()
.copyArchiveToContainerCmd(containerId)
.withTarInputStream(new ByteArrayInputStream(buildContainerdCertsLinkTar()))
.withRemotePath("/")
.exec();
byte[] tar = buildContainerdCertsLinkTar();
RetryingTarCopier.copyStreamed(lifecycleManager.getDockerClient(), containerId, "/",
"containerd-certs-link", out -> out.write(tar),
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
} catch (Exception e) {
LOG.warnv("EKS cluster {0}: could not link containerd certs.d directory: {1}",
clusterName, e.getMessage());
@@ -2071,12 +2087,10 @@ public class EksClusterManager
writeLocalCopy(Paths.get(config.services().eks().dataPath(), "webhook", clusterName,
POD_IDENTITY_MANIFEST_FILE), manifest, clusterName);
try {
lifecycleManager.getDockerClient()
.copyArchiveToContainerCmd(containerId)
.withTarInputStream(new ByteArrayInputStream(
tarSingleFile(POD_IDENTITY_MANIFEST_TAR_ENTRY, manifest)))
.withRemotePath(K3S_DATA_DIR)
.exec();
byte[] tar = tarSingleFile(POD_IDENTITY_MANIFEST_TAR_ENTRY, manifest);
RetryingTarCopier.copyStreamed(lifecycleManager.getDockerClient(), containerId, K3S_DATA_DIR,
POD_IDENTITY_MANIFEST_FILE, out -> out.write(tar),
RetryingTarCopier.DEFAULT_MAX_ATTEMPTS, archiveRetryBackoffMillis);
LOG.infov("Registered the EKS Pod Identity mutating webhook ({0}) for cluster {1}", url, clusterName);
} catch (Exception e) {
LOG.warnv("EKS cluster {0} gets no pod identity injection: could not copy {1} into the k3s "