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: avoid errors when --max-package-size differs between create runs #3398

Merged
merged 8 commits into from
Jan 27, 2025

Conversation

AustinAbro321
Copy link
Contributor

Description

As seen explained in #3266 the existing split file logic doesn't replace files it writes over leading to errors with create is run with different --max-package-size values. Additionally, if the package is split and there are more files than Zarf is expecting (likely leftovers from a previous run) Zarf will give the below error

     ERROR:  failed to deploy package: unable to load the package: package is missing parts, expected 15, found
             29

Related Issue

Fixes #3266

Checklist before merging

Signed-off-by: Austin Abro <[email protected]>
@AustinAbro321 AustinAbro321 requested review from a team as code owners January 13, 2025 17:23
Copy link

netlify bot commented Jan 13, 2025

Deploy Preview for zarf-docs canceled.

Name Link
🔨 Latest commit 2920864
🔍 Latest deploy log https://app.netlify.com/sites/zarf-docs/deploys/6793d09b382c1600087a0d32

Signed-off-by: Austin Abro <[email protected]>
Copy link

codecov bot commented Jan 13, 2025

Codecov Report

Attention: Patch coverage is 53.33333% with 7 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/internal/packager2/layout/create.go 57.14% 4 Missing and 2 partials ⚠️
src/internal/packager2/layout/package.go 0.00% 1 Missing ⚠️
Files with missing lines Coverage Δ
src/internal/packager2/layout/package.go 39.03% <0.00%> (ø)
src/internal/packager2/layout/create.go 31.47% <57.14%> (+6.63%) ⬆️

... and 64 files with indirect coverage changes

@AustinAbro321 AustinAbro321 changed the title fix: avoid errors when --max-package-size differs between runs fix: avoid errors when --max-package-size differs between create runs Jan 13, 2025
@AustinAbro321 AustinAbro321 marked this pull request as draft January 16, 2025 14:52
Signed-off-by: Austin Abro <[email protected]>
Signed-off-by: Austin Abro <[email protected]>
Signed-off-by: Austin Abro <[email protected]>
@AustinAbro321 AustinAbro321 marked this pull request as ready for review January 16, 2025 16:54
Signed-off-by: Austin Abro <[email protected]>
Copy link
Contributor

@mkcp mkcp left a comment

Choose a reason for hiding this comment

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

LGTM

func TestSplitFile(t *testing.T) {
t.Parallel()

tests := []struct {
Copy link
Contributor

Choose a reason for hiding this comment

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

Great test cases 👍

t.Run(tt.name, func(t *testing.T) {
t.Parallel()

dir := t.TempDir()
Copy link
Contributor

Choose a reason for hiding this comment

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

Nonblocking: this is more of a style thing, but usually I add some small intent comment (example below) on a series of logically similar operations. There's tradeoffs here with just making self-documenting code, so I'm curious where your opinions are at there.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it's a reasonable thing to do. I try to break up my tests with indentation and the arrange-act-assert methodology. I don't think comments are always necessary, but when code is non intuitive I do think it helps to provide additional context.

In this case, this test case was actually from packager1 so I just copied it over, going forward I'll try to air on the side of more clarity.

err = splitFile(context.Background(), p, tt.chunkSize)
require.NoError(t, err)

_, err = os.Stat(p)
Copy link
Contributor

Choose a reason for hiding this comment

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

e.g.

// Ensure content exists

data := make([]byte, 50)
err := os.WriteFile(inputFilename, data, 0644)
require.NoError(t, err)
// Create many fake split files
Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@AustinAbro321 AustinAbro321 added this pull request to the merge queue Jan 27, 2025
Merged via the queue into main with commit e09ed2c Jan 27, 2025
26 checks passed
@AustinAbro321 AustinAbro321 deleted the fix-split-file branch January 27, 2025 13:41
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.

Rerunning package create with --max-package-size leaves old files around
2 participants