Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (kubernetes-client) : Change Pod upload tarball location to target upload directory #5676

Merged
merged 1 commit into from
Jan 2, 2024

Conversation

rohanKanojia
Copy link
Member

@rohanKanojia rohanKanojia commented Dec 28, 2023

Description

Fix #5527

Using /tmp as upload directory can be problematic for scenarios where /tmp is read only. We can directly upload the intermediate upload tarball to the directory where we are uploading the content.

  • In case of uploading a file to a Pod, temporary tarball would be uploaded in the parent directory of that file.

  • In case of uploading a directory to a Pod, temporary tarball would be uploaded in the same directory that's specified for upload path.

Other minor changes:

  • Replace deprecated getNextTarEntry() with getNextEntry() in UploadTest
  • Refactor getDirectoryFromFile method to reuse logic for extracting directory from file path. For consistency we always add a trailing / at the end of file path.

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change
  • Chore (non-breaking change which doesn't affect codebase;
    test, version modification, documentation, etc.)

Checklist

  • Code contributed by me aligns with current project license: Apache 2.0
  • I Added CHANGELOG entry regarding this change
  • I have implemented unit tests to cover my changes
  • I have added/updated the javadocs and other documentation accordingly
  • No new bugs, code smells, etc. in SonarCloud report
  • I tested my code in Kubernetes
  • I tested my code in OpenShift

…load directory

Using `/tmp` as upload directory can be problematic for scenarios where
`/tmp` is read only. We can directly upload the intermediate upload
tarball to the directory where we are uploading the content.

In case of uploading a file to a Pod, temporary tarball would be uploaded in
the parent directory of that file.

In case of uploading a directory to a Pod, temporary tarball would be
uploaded in the same directory that's specified for upload path.

Signed-off-by: Rohan Kumar <[email protected]>
@rohanKanojia rohanKanojia changed the title fix (kubernetes-client) : Change upload tarball location to target upload directory fix (kubernetes-client) : Change Pod upload tarball location to target upload directory Dec 28, 2023
Copy link

@rohanKanojia rohanKanojia marked this pull request as ready for review December 28, 2023 09:30
Copy link
Contributor

@shawkins shawkins left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Member

@manusa manusa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Just to double check, are we deleting the temporary file in all cases?

@manusa manusa added this to the 6.10.0 milestone Jan 2, 2024
@rohanKanojia
Copy link
Member Author

We delete the temporary tarball after extraction:

return String.format("mkdir -p %1$s; tar -C %1$s -xmf %2$s; e=$?; rm %2$s; exit $e", shellQuote(directory), tar);

If tarball upload step fails for some reason, we issue an exec to delete tarball:

// best effort delete of the failed upload
try (ExecWatch rm = operation.writingOutput(new ByteArrayOutputStream()).exec("sh", "-c",
String.format("rm %s", fileName))) {
if (!Utils.waitUntilReady(rm.exitCode(), operation.getRequestConfig().getUploadRequestTimeout(), TimeUnit.MILLISECONDS)

@manusa manusa merged commit a940a4f into fabric8io:main Jan 2, 2024
17 of 19 checks passed
@rohanKanojia rohanKanojia deleted the pr/issue5527 branch January 2, 2024 10:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to transfer file to pod if /tmp of pod is read-only
4 participants