Skip to content

Commit 7c9ef3f

Browse files
committed
k8.mjs: copyFrom to handle links that is used by secret volume mounts
Signed-off-by: Jeromy Cannon <[email protected]>
1 parent ddbbd45 commit 7c9ef3f

File tree

1 file changed

+23
-12
lines changed

1 file changed

+23
-12
lines changed

src/core/k8.mjs

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,17 @@ export class K8 {
522522
const namespace = this._getNamespace()
523523

524524
// get stat for source file in the container
525-
const entries = await this.listDir(podName, containerName, srcPath)
525+
let entries = await this.listDir(podName, containerName, srcPath)
526526
if (entries.length !== 1) {
527527
throw new FullstackTestingError(`invalid source path: ${srcPath}`)
528528
}
529+
if (entries[0].name.indexOf(' -> ') > -1) {
530+
const redirectSrcPath = path.join(path.dirname(srcPath), entries[0].name.substring(entries[0].name.indexOf(' -> ') + 4))
531+
entries = await this.listDir(podName, containerName, redirectSrcPath)
532+
if (entries.length !== 1) {
533+
throw new FullstackTestingError(`invalid source path: ${redirectSrcPath}`)
534+
}
535+
}
529536
const srcFileDesc = entries[0] // cache for later comparison after copy
530537

531538
if (!fs.existsSync(destDir)) {
@@ -535,8 +542,8 @@ export class K8 {
535542
try {
536543
const srcFileSize = Number.parseInt(srcFileDesc.size)
537544

538-
const srcFile = path.basename(srcPath)
539-
const srcDir = path.dirname(srcPath)
545+
const srcFile = path.basename(entries[0].name)
546+
const srcDir = path.dirname(entries[0].name)
540547
const destPath = path.join(destDir, srcFile)
541548

542549
// download the tar file to a temp location
@@ -570,17 +577,21 @@ export class K8 {
570577
return reject(new FullstackTestingError(`failed to copy because of error (${code}): ${reason}`))
571578
}
572579

573-
// extract the downloaded file
574-
await tar.x({
575-
file: tmpFile,
576-
cwd: destDir
577-
})
580+
try {
581+
// extract the downloaded file
582+
await tar.x({
583+
file: tmpFile,
584+
cwd: destDir
585+
})
578586

579-
self._deleteTempFile(tmpFile)
587+
self._deleteTempFile(tmpFile)
580588

581-
const stat = fs.statSync(destPath)
582-
if (stat && stat.size === srcFileSize) {
583-
return resolve(true)
589+
const stat = fs.statSync(destPath)
590+
if (stat && stat.size === srcFileSize) {
591+
return resolve(true)
592+
}
593+
} catch (e) {
594+
return reject(new FullstackTestingError(`failed to extract file: ${destPath}`, e))
584595
}
585596

586597
return reject(new FullstackTestingError(`failed to download file completely: ${destPath}`))

0 commit comments

Comments
 (0)