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

prepare stage: introduce --no-auto-prune command-line flag #42

Merged
merged 3 commits into from
Nov 6, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,13 @@ that required paid sponsorship upon exceeding a free limit.

### `prepare` stage

| Argument | Default | Description |
|-----------------|-------------|--------------------------------------------------------------------------------------|
| `--concurrency` | 1 | Maximum number of concurrently running Tart VMs to calculate the `auto` resources |
| `--cpu` | no override | Override default image CPU configuration (number of CPUs or `auto`<sup>1</sup>) |
| `--memory` | no override | Override default image memory configuration (size in megabytes or `auto`<sup>1</sup>) |
| `--dir` | | `--dir` arguments to pass to `tart run`, can be specified multiple times |
| Argument | Default | Description |
|-------------------|-------------|----------------------------------------------------------------------------------------------------------------------|
| `--concurrency` | 1 | Maximum number of concurrently running Tart VMs to calculate the `auto` resources |
| `--cpu` | no override | Override default image CPU configuration (number of CPUs or `auto`<sup>1</sup>) |
| `--memory` | no override | Override default image memory configuration (size in megabytes or `auto`<sup>1</sup>) |
| `--dir` | | `--dir` arguments to pass to `tart run`, can be specified multiple times |
| `--no-auto-prune` | false | set `TART_NO_AUTO_PRUNE=true` environment variable for Tart invocations to disable the Tart's auto-pruning mechanism |

<sup>1</sup>: automatically distributes all host resources according to the concurrency level (for example, VM gets all of the host CPU and RAM assigned when `--concurrency` is 1, and half of that when `--concurrency` is 2)

Expand Down
10 changes: 10 additions & 0 deletions internal/commands/prepare/prepare.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ var concurrency uint64
var cpuOverrideRaw string
var memoryOverrideRaw string
var customDirectoryMounts []string
var noAutoPrune bool

func NewCommand() *cobra.Command {
command := &cobra.Command{
Expand All @@ -40,6 +41,9 @@ func NewCommand() *cobra.Command {
"Override default image memory configuration (size in megabytes or \"auto\")")
command.PersistentFlags().StringArrayVar(&customDirectoryMounts, "dir", []string{},
"\"--dir\" arguments to pass to \"tart run\", can be specified multiple times")
command.PersistentFlags().BoolVar(&noAutoPrune, "no-auto-prune", false,
Copy link
Contributor

Choose a reason for hiding this comment

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

Doesn't it automatically support --no prefix for bool flags? Maybe invert it and default to true to always pool?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Doesn't it automatically support --no prefix for bool flags?

I don't think so: spf13/pflag#214.

Copy link
Contributor

Choose a reason for hiding this comment

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

What do you think of --auto-prune flag with a a default to true? Potential usage like --no-auto-prune=false looks weird to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

See bebf869.

"set \"TART_NO_AUTO_PRUNE=true\" environment variable for Tart invocations"+
"to disable the Tart's auto-pruning mechanism")

return command
}
Expand All @@ -55,6 +59,12 @@ func runPrepareVM(cmd *cobra.Command, args []string) error {
return err
}

if noAutoPrune {
if err := os.Setenv("TART_NO_AUTO_PRUNE", "true"); err != nil {
return err
}
}

gitLabEnv, err := gitlab.InitEnv()
if err != nil {
return err
Expand Down