calculate sha256 file checksum by streaming #2036
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
/kind feature
change file checksum method to stream calculation in order to run on limited memory machine.
What this PR does / why we need it:
When I initiate the Harbor registry using the kubekey command tool like this:
It fails with error message "Killed". After debugging step by step, I found the root cause in file
cmd/kk/pkg/files/file.go
functionsha256sum
:In function
sha256sum
, it read all file content into memory to calculate file checksum. because of that, when running on machine with low memory(only 2GB), process be killed by system because of the memory exhausted.So I changed it into stream calculation, like this:
It works fine on my server machine.