-
Notifications
You must be signed in to change notification settings - Fork 1
Add configurable /tmp tmpfs size for guest VMs #44
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
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| //go:build linux | ||
|
|
||
| package mount | ||
|
|
||
| // EssentialMountsForTest exposes essentialMounts for testing. | ||
| var EssentialMountsForTest = essentialMounts |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| // Package vmconfig reads the VM configuration file written by the host into | ||
| // the rootfs before boot. Guest init binaries use this to apply host-side | ||
| // configuration (e.g. /tmp size) before the SSH server starts. | ||
| package vmconfig |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package vmconfig | ||
|
|
||
| // ReadFromForTest exposes readFrom for testing. | ||
| var ReadFromForTest = readFrom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package vmconfig | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "errors" | ||
| "fmt" | ||
| "os" | ||
| ) | ||
|
|
||
| // GuestPath is the guest path where the host writes the VM config. | ||
| const GuestPath = "/etc/propolis-vm.json" | ||
|
|
||
| // Config holds settings written by the host and read by the guest init. | ||
| // Zero values mean "use the built-in default" for each field. | ||
| type Config struct { | ||
| // TmpSizeMiB is the size of the /tmp tmpfs in MiB. Zero means use the | ||
| // mount package default (256 MiB). | ||
| TmpSizeMiB uint32 `json:"tmp_size_mib,omitempty"` | ||
| } | ||
|
|
||
| // Read loads the VM config from /etc/propolis-vm.json. | ||
| // Returns a zero-value Config (all defaults) if the file does not exist, | ||
| // ensuring backward compatibility with hosts that do not write the file. | ||
| func Read() (Config, error) { | ||
| return readFrom(GuestPath) | ||
| } | ||
|
|
||
| // readFrom loads the VM config from the given path. | ||
| func readFrom(path string) (Config, error) { | ||
| data, err := os.ReadFile(path) | ||
| if err != nil { | ||
| if errors.Is(err, os.ErrNotExist) { | ||
| return Config{}, nil | ||
| } | ||
| return Config{}, fmt.Errorf("reading vm config: %w", err) | ||
| } | ||
| var cfg Config | ||
| if err := json.Unmarshal(data, &cfg); err != nil { | ||
| return Config{}, fmt.Errorf("parsing vm config: %w", err) | ||
| } | ||
| return cfg, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| // SPDX-FileCopyrightText: Copyright 2025 Stacklok, Inc. | ||
| // SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| package vmconfig | ||
|
|
||
| import ( | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/assert" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestReadFrom(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| tests := []struct { | ||
| name string | ||
| content *string // nil = file does not exist | ||
| want Config | ||
| wantErr bool | ||
| }{ | ||
| { | ||
| name: "file does not exist", | ||
| content: nil, | ||
| want: Config{}, | ||
| }, | ||
| { | ||
| name: "valid JSON with TmpSizeMiB", | ||
| content: strPtr(`{"tmp_size_mib":512}`), | ||
| want: Config{TmpSizeMiB: 512}, | ||
| }, | ||
| { | ||
| name: "empty JSON object", | ||
| content: strPtr(`{}`), | ||
| want: Config{}, | ||
| }, | ||
| { | ||
| name: "malformed JSON", | ||
| content: strPtr(`{not json`), | ||
| wantErr: true, | ||
| }, | ||
| } | ||
|
|
||
| for _, tt := range tests { | ||
| t.Run(tt.name, func(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| dir := t.TempDir() | ||
| path := filepath.Join(dir, "vm.json") | ||
|
|
||
| if tt.content != nil { | ||
| require.NoError(t, os.WriteFile(path, []byte(*tt.content), 0o644)) | ||
| } | ||
|
|
||
| got, err := ReadFromForTest(path) | ||
| if tt.wantErr { | ||
| assert.Error(t, err) | ||
| return | ||
| } | ||
| require.NoError(t, err) | ||
| assert.Equal(t, tt.want, got) | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| func strPtr(s string) *string { return &s } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.