From ec7fddb378598191458dff24e3e5a745b9f0900e 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 | 8 ++++---- 2 files changed, 5 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..810439b7144 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,7 @@ 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 $?"); } }