From c9e22e713ba9835ab59e531d579a467bb8ce257d Mon Sep 17 00:00:00 2001 From: Florian Hussonnois Date: Wed, 31 Jul 2024 20:20:33 +0200 Subject: [PATCH] fix(client): improve reliability of file upload to pod (#6212) Fix: #6212 Signed-off-by: Florian Hussonnois --- .../client/dsl/internal/uploadable/PodUpload.java | 2 +- .../client/dsl/internal/uploadable/PodUploadTest.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/uploadable/PodUpload.java b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/uploadable/PodUpload.java index 2c08c064e2f..c105023c736 100644 --- a/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/uploadable/PodUpload.java +++ b/kubernetes-client/src/main/java/io/fabric8/kubernetes/client/dsl/internal/uploadable/PodUpload.java @@ -184,7 +184,7 @@ private static void addFileToTar(String fileName, File file, TarArchiveOutputStr static String createExecCommandForUpload(String file) { return String.format( - "mkdir -p %s && cat - > %s", shellQuote(getDirectoryFromFile(file)), shellQuote(file)); + "mkdir -p %s && cat - > %s && echo $?", shellQuote(getDirectoryFromFile(file)), shellQuote(file)); } private static String ensureEndsWithSlash(String path) { diff --git a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/dsl/internal/uploadable/PodUploadTest.java b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/dsl/internal/uploadable/PodUploadTest.java index 0e3ad7716d4..9509c2e2880 100644 --- a/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/dsl/internal/uploadable/PodUploadTest.java +++ b/kubernetes-client/src/test/java/io/fabric8/kubernetes/client/dsl/internal/uploadable/PodUploadTest.java @@ -49,7 +49,7 @@ void withFileInRootPath_shouldCreateValidExecCommandForUpload() { // When String result = PodUpload.createExecCommandForUpload("/cp.log"); // Then - assertThat(result).isEqualTo("mkdir -p '/' && cat - > '/cp.log'"); + assertThat(result).isEqualTo("mkdir -p '/' && cat - > '/cp.log' && echo $?"); } @Test @@ -57,7 +57,7 @@ void withNormalFile_shouldCreateValidExecCommandForUpload() { // When String result = PodUpload.createExecCommandForUpload("/tmp/foo/cp.log"); // Then - assertThat(result).isEqualTo("mkdir -p '/tmp/foo/' && cat - > '/tmp/foo/cp.log'"); + assertThat(result).isEqualTo("mkdir -p '/tmp/foo/' && cat - > '/tmp/foo/cp.log' && echo $?"); } // @@ -66,7 +66,7 @@ void withSingleQuoteInPath() { // When String result = PodUpload.createExecCommandForUpload("/tmp/fo'o/cp.log"); // Then - assertThat(result).isEqualTo("mkdir -p '/tmp/fo\'\\'\'o/' && cat - > '/tmp/fo\'\\'\'o/cp.log'"); + assertThat(result).isEqualTo("mkdir -p '/tmp/fo\'\\'\'o/' && cat - > '/tmp/fo\'\\'\'o/cp.log' && echo $?"); } @Test @@ -74,7 +74,8 @@ void withMultipleSingleQuotesInPath() { // When String result = PodUpload.createExecCommandForUpload("/tmp/f'o'o/c'p.log"); // Then - assertThat(result).isEqualTo("mkdir -p '/tmp/f\'\\'\'o\'\\'\'o/' && cat - > '/tmp/f\'\\'\'o\'\\'\'o/c\'\\'\'p.log'"); + assertThat(result) + .isEqualTo("mkdir -p '/tmp/f\'\\'\'o\'\\'\'o/' && cat - > '/tmp/f\'\\'\'o\'\\'\'o/c\'\\'\'p.log' && echo $?"); } }