Skip to content

Commit eb6a351

Browse files
committed
- Fix for kubernetes-client#1826: Updated WebSocketStreamHandler.write() to calculate 'remaining' bytes using bufferSize from the current loop iteration instead of the cummulative bytesWritten.
- Related to kubernetes-client#1822: Removed the base64 encode/decode steps/streams per comment kubernetes-client#1822 (comment) - Unit test fix - Added path normalization to convert potential windows path delimiters to linux deliniters.
1 parent dbea66f commit eb6a351

3 files changed

Lines changed: 7 additions & 8 deletions

File tree

util/src/main/java/io/kubernetes/client/Copy.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@
3434
import java.util.concurrent.Future;
3535
import java.util.concurrent.TimeUnit;
3636
import org.apache.commons.codec.binary.Base64InputStream;
37-
import org.apache.commons.codec.binary.Base64OutputStream;
3837
import org.apache.commons.compress.archivers.ArchiveEntry;
3938
import org.apache.commons.compress.archivers.ArchiveInputStream;
4039
import org.apache.commons.compress.archivers.ArchiveOutputStream;
@@ -365,8 +364,7 @@ public Future<Integer> copyFileToPodAsync(
365364
// Send encoded archive output stream
366365
File srcFile = new File(srcPath.toUri());
367366
try (ArchiveOutputStream archiveOutputStream =
368-
new TarArchiveOutputStream(
369-
new Base64OutputStream(proc.getOutputStream(), true, 0, null));
367+
new TarArchiveOutputStream(proc.getOutputStream());
370368
FileInputStream input = new FileInputStream(srcFile)) {
371369
ArchiveEntry tarEntry = new TarArchiveEntry(srcFile, destPath.getFileName().toString());
372370

@@ -398,7 +396,7 @@ public Future<Integer> copyFileToPodAsync(
398396
final Process proc = execCopyToPod(namespace, pod, container, destPath);
399397

400398
try (ArchiveOutputStream archiveOutputStream =
401-
new TarArchiveOutputStream(new Base64OutputStream(proc.getOutputStream(), true, 0, null))) {
399+
new TarArchiveOutputStream(proc.getOutputStream())) {
402400

403401
ArchiveEntry tarEntry = new TarArchiveEntry(new File(destPath.getFileName().toString()));
404402
((TarArchiveEntry) tarEntry).setSize(src.length);
@@ -414,10 +412,11 @@ public Future<Integer> copyFileToPodAsync(
414412
private Process execCopyToPod(String namespace, String pod, String container, Path destPath)
415413
throws ApiException, IOException {
416414
String parentPath = destPath.getParent() != null ? destPath.getParent().toString() : ".";
415+
parentPath = parentPath.replace("\\", "/");
417416
return this.exec(
418417
namespace,
419418
pod,
420-
new String[] {"sh", "-c", "base64 -d | tar -xmf - -C " + parentPath},
419+
new String[] {"sh", "-c", "tar -xmf - -C " + parentPath},
421420
container,
422421
true,
423422
false);

util/src/main/java/io/kubernetes/client/util/WebSocketStreamHandler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ public void write(byte[] b, int offset, int length) throws IOException {
270270
throw new IOException("WebSocket has closed.");
271271
}
272272
bytesWritten += bufferSize;
273-
remaining -= bytesWritten;
273+
remaining -= bufferSize;
274274
}
275275
}
276276
}

util/src/test/java/io/kubernetes/client/CopyTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void run() {
130130
.withQueryParam("tty", equalTo("false"))
131131
.withQueryParam("command", equalTo("sh"))
132132
.withQueryParam("command", equalTo("-c"))
133-
.withQueryParam("command", equalTo("base64 -d | tar -xmf - -C /")));
133+
.withQueryParam("command", equalTo("tar -xmf - -C /")));
134134
}
135135

136136
@Test
@@ -176,7 +176,7 @@ public void run() {
176176
.withQueryParam("tty", equalTo("false"))
177177
.withQueryParam("command", equalTo("sh"))
178178
.withQueryParam("command", equalTo("-c"))
179-
.withQueryParam("command", equalTo("base64 -d | tar -xmf - -C /")));
179+
.withQueryParam("command", equalTo("tar -xmf - -C /")));
180180
}
181181

182182
public void testCopyDirectoryFromPod() throws IOException, ApiException, InterruptedException {

0 commit comments

Comments
 (0)