Skip to content

Commit

Permalink
fix: upload can failed silently and need to be retry
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Dec 15, 2023
1 parent 60baedb commit 1de0760
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 14 deletions.
57 changes: 45 additions & 12 deletions src/main/java/io/kestra/plugin/kubernetes/AbstractPod.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.kestra.plugin.kubernetes;

import io.fabric8.kubernetes.api.model.*;
import io.fabric8.kubernetes.client.dsl.CopyOrReadable;
import io.fabric8.kubernetes.client.dsl.PodResource;
import io.kestra.core.exceptions.IllegalVariableEvaluationException;
import io.kestra.core.models.annotations.PluginProperty;
import io.kestra.core.runners.RunContext;
import io.kestra.core.tasks.PluginUtilsService;
import io.kestra.core.utils.RetryUtils;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;
import lombok.experimental.SuperBuilder;
Expand Down Expand Up @@ -82,19 +84,27 @@ protected Path tempDir(RunContext runContext) throws IOException {
}

protected void uploadInputFiles(RunContext runContext, PodResource podResource, Logger logger) throws IOException {
podResource
.inContainer(INIT_FILES_CONTAINER_NAME)
.dir("/kestra/working-dir")
.upload(tempDir(runContext));
withRetries(
logger,
"uploadInputFiles",
() -> podResource
.inContainer(INIT_FILES_CONTAINER_NAME)
.dir("/kestra/working-dir")
.upload(tempDir(runContext))
);

this.uploadMarker(runContext, podResource, logger, false);
}

protected Map<String, URI> downloadOutputFiles(RunContext runContext, PodResource podResource, Logger logger) throws Exception {
podResource
.inContainer(SIDECAR_FILES_CONTAINER_NAME)
.dir("/kestra/working-dir/")
.copy(tempDir(runContext));
withRetries(
logger,
"downloadOutputFiles",
() -> podResource
.inContainer(SIDECAR_FILES_CONTAINER_NAME)
.dir("/kestra/working-dir/")
.copy(tempDir(runContext))
);

this.uploadMarker(runContext, podResource, logger, true);

Expand Down Expand Up @@ -123,14 +133,37 @@ protected void uploadMarker(RunContext runContext, PodResource podResource, Logg
File marker = tempDir(runContext).resolve(s).toFile();
marker.createNewFile();

podResource
.inContainer(finished ? SIDECAR_FILES_CONTAINER_NAME : INIT_FILES_CONTAINER_NAME)
.file("/kestra/" + s)
.upload(marker.toPath());
withRetries(
logger,
"uploadMarker",
() -> podResource
.inContainer(finished ? SIDECAR_FILES_CONTAINER_NAME : INIT_FILES_CONTAINER_NAME)
.file("/kestra/" + s)
.upload(marker.toPath())
);

logger.debug(s + " marker uploaded");
}

protected static Boolean withRetries(Logger logger, String where, RetryUtils.CheckedSupplier<Boolean> call) throws IOException {
Boolean upload = new RetryUtils().<Boolean, IOException>of().run(
object -> !object,
() -> {
var bool = call.get();

logger.debug("Failed to call '{}'", where);

return bool;
}
);

if (!upload) {
throw new IOException("Failed to call '" + where + "'");
}

return upload;
}

protected void handleFiles(RunContext runContext, ObjectMeta metadata, PodSpec spec) throws IOException, IllegalVariableEvaluationException, URISyntaxException {
VolumeMount volumeMount = new VolumeMountBuilder()
.withMountPath("/kestra")
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/io/kestra/plugin/kubernetes/PodCreateTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import jakarta.inject.Named;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.RetryingTest;
import org.slf4j.event.Level;

import java.io.InputStream;
Expand Down Expand Up @@ -219,7 +218,7 @@ void resume() throws Exception {
assertThat(logs.stream().filter(logEntry -> logEntry.getLevel() == Level.INFO).filter(logEntry -> logEntry.getMessage().equals("10")).count(), greaterThan(0L));
}

@RetryingTest(5)
@Test
void inputOutputFiles() throws Exception {
PodCreate task = PodCreate.builder()
.id(PodCreate.class.getSimpleName())
Expand Down

0 comments on commit 1de0760

Please sign in to comment.