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
Refactor blob copying and compression #1579
Commits on Jun 15, 2022
-
Move imageCopier.copyBlobFromStream into a new copy/blob.go
The over-300-line-long function would benefit from splitting up, and copy/copy.go has grown entirely too long. As a first step, move it to a new copy/blob.go. Only moves unmodified code, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
... so that the file reads from top-level callers down to implementation details. Only moves unchanged code, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Rename the srcStream parameter to srcReader
We will use srcStream for another purpose. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Introduce sourceStream, use it for the first pipeline stage
The purpose of sourceStream is to make it a bit easier to split the blob copy pipeline stages into separate functions; they will update a *sourceStream, which we can pass a single parameter. For now, build it and use it to initialize a digestingReader; then update other code that should consume the current pipeline data. NOTE: That is a judgement call, it is not always obvious what data was intended to be used and what is a bug. As a geneeral principle, use srcInfo (the original unmodified data) in user-visible error reports, notably using the original digest. Otherwise, lean towards using srcStream.info. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Use stream.reader instead of destStream
One part of moving to use stream throughout the pipeline. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Use stream.info throughout. Should not change behavior. (In some cases that's dubious, we are currently losing data like annotations compression/decompression. This commit doesn't change that, only adds a FIXME? to eventually review.) Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Move the OCI blob decryption pipeline step into copier.blobPipelineDe…
…cryptionStep Only moves the code with minimal necessary adjustments, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Beautify blobPipelineDecryptionStep a bit
Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
This smaller function can use simpler identifiers. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Beautify the DecryptLayer usage a bit
Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Move the OCI blob encryption pipeline step into copier.blobPipelineEn…
…cryptionStep Only moves the code with minimal necessary adjustments, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Simplify blobPipelineEncryptionStep
Make the "not encrypting" case truly special, and then we don't need extra variables across the function. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Exit from updateCryptoOperationAndAnnotations early if not encrypting
Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Beautify blobPipelineEncryptionStep
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Rename copy/encrypt.go to copy/encryption.go
It contains decompression code as well. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Move the compression detection step into blobPipelineDetectCompressio…
…nStep Only moves the code with minimal necessary adjustments, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Beautify blobPipelineDetectCompressionStep
We can use shorter variable names in this short function now. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Move the compression annotation update closer to the other compressio…
…n edits Only moves code, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Move copier.compressGoroutine to compression.go
Only moves unchanged code, should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Move the compression/decompression step to blobPipelineCompressionStep
Only moves the code with minimal necessary adjustments, should not change behavior. Those adjustments are not completely trivial in this case: we could just do a "defer stream.Close()" in copyBlobFromStream, now we need a separate closers field in blobPipelineCompressionStepData. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Rename detectedCompession to detected
The compression meaning is clear in context here. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Rename compresisonOperation to operation
Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Rename uploadCompressionFormat to uploadedAlgorithm
Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Rename uploadCompressorName to uploadedCompressorName
Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Rename compressionMetadata to uploadedAnnotations.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Compute srcCompressorName already in blobPipelineDetectCompressionStep
Except for the encrypted content case, we already have the data available, and this will allow us to just pass around a *blobPipelineDetectCompressionStepData without an extra parameter for srcCompressorName. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Return a fresh &bpCompressionStepData in each case
That's actually shorter because in most cases we just use a field initializer instead of setting a variable; and we don't need that variable in the first place. For now, do just the minimal edit, we will clean this up a bit later. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Move uploadedAnnotations inside the individual cases.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Move uploadedAlgorithm inside the individual cases.
Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Clean up the control flow of blobPipelineCompressionStep
Don't use else after each step that returns early. The function nows looks like a set of ~special cases, with the general fallback of doing nothing. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Rename s to decompressed in the re-compress case
to avoid ambiguity. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Factor out copier.compressedStream from copier.blobPipelineCompressio…
…nStep ... so that we only implement the pipe handling once. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Split blobPipelineCompressionStep into individual functions
The logic is a simple sequence of condition + decision, which is fairly regullar, and doesn't have to be in a single function. So, split it up. Eliminate the recently-introduced closers array again, in most cases. Should not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Eliminate the closers array in bpcRecompressCompressed
... now that it only could effectively apply to a single element. Shoud not change behavior. Signed-off-by: Miloslav Trmač <mitr@redhat.com>
-
Use a loop for the alternatives in blobPipelineCompressionStep
The alternatives are, mostly, things to _try_; we can typically fall back to just using the original. So, just use a loop to take advantage of the regular structure. Signed-off-by: Miloslav Trmač <mitr@redhat.com>