Skip to content

Commit

Permalink
fix(client): improve reliability of file upload to pod (#6212)
Browse files Browse the repository at this point in the history
Fix: #6212

Signed-off-by: Florian Hussonnois <florian.hussonnois@gmail.com>
(cherry picked from commit f3ec2cd)
  • Loading branch information
fhussonnois authored and manusa committed Aug 9, 2024
1 parent 01f1cfd commit 76596c8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Fix #6066: Added support for missing `v1.APIVersions` in KubernetesClient
* Fix #6110: VolumeSource (and other file mode fields) in Octal are correctly interpreted
* Fix #6215: Suppressing rejected execution exception for port forwarder
* Fix #6212: Improved reliability of file upload to Pod

### 6.13.1 (2024-07-02)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ 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
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 $?");
}

//
Expand All @@ -66,15 +66,16 @@ 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
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 $?");
}
}

Expand Down

0 comments on commit 76596c8

Please sign in to comment.