-
Notifications
You must be signed in to change notification settings - Fork 344
feat: reserve disk space for guest OS during template build #2082
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
Changes from all commits
0ffcec2
4ee0d78
727da33
d8723e1
0596490
deae6fa
3a79aef
69a7044
24893a9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,90 @@ | ||
| package filesystem | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestParseFreeBlocks(t *testing.T) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know it's not the point of this PR, but to get free blocks, instead of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. does stat -fs work on not mounted filesystem in a file?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It works on the underlying filesystem, regardless of where it's mounted:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, but the filesystem is not mounted anywhere (at all), would that work too?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The debugfs allows to execute certain action on not mounted filesystem. If you check the usage, we're passing just a file containing the ext4 fs there |
||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| input string | ||
| expected int64 | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "standard debugfs output", | ||
| input: "Block count: 131072\nFree blocks: 120000\nFirst block: 0\n", | ||
| expected: 120000, | ||
| }, | ||
| { | ||
| name: "large block count", | ||
| input: "Free blocks: 999999999\n", | ||
| expected: 999999999, | ||
| }, | ||
| { | ||
| name: "missing free blocks", | ||
| input: "Block count: 131072\n", | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| result, err := parseFreeBlocks(tc.input) | ||
| if tc.wantErr { | ||
| assert.Error(t, err) | ||
| } else { | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tc.expected, result) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func TestParseReservedBlocks(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| input string | ||
| expected int64 | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "standard debugfs output", | ||
| input: "Block count: 131072\nReserved block count: 6553\nFree blocks: 120000\n", | ||
| expected: 6553, | ||
| }, | ||
| { | ||
| name: "zero reserved blocks", | ||
| input: "Reserved block count: 0\n", | ||
| expected: 0, | ||
| }, | ||
| { | ||
| name: "missing reserved blocks", | ||
| input: "Block count: 131072\nFree blocks: 120000\n", | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tc := range tests { | ||
| t.Run(tc.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| result, err := parseReservedBlocks(tc.input) | ||
| if tc.wantErr { | ||
| assert.Error(t, err) | ||
| } else { | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tc.expected, result) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -219,6 +219,16 @@ func (ppb *PostProcessingBuilder) postProcessingFn(userLogger logger.Logger) lay | |
| return | ||
| } | ||
|
|
||
| // Set reserved disk space for the guest OS before syncing | ||
| if reservedDiskSpaceMB := int64(ppb.featureFlags.IntFlag(ctx, featureflags.BuildReservedDiskSpaceMB)); reservedDiskSpaceMB > 0 { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. it would be better to move this to the place where the envd is updated -> that way old templates would have it already for the build, not only for the sandbox it's just a different place where to put this code
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so in here in
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (it can be done in a follow up)
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. merging as is then making PR for this |
||
| err := sandboxtools.SetReservedBlocksInGuest(ctx, ppb.proxy, userLogger, sbx.Runtime.SandboxID, reservedDiskSpaceMB, ppb.Config.RootfsBlockSize()) | ||
| if err != nil { | ||
| e = fmt.Errorf("error setting reserved disk space: %w", err) | ||
|
|
||
| return | ||
| } | ||
| } | ||
|
|
||
| // Ensure all changes are synchronized to disk so the sandbox can be restarted | ||
| err := sandboxtools.SyncChangesToDisk( | ||
| ctx, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.