-
Notifications
You must be signed in to change notification settings - Fork 608
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
Add builtin yq support to lima start command #1359
Conversation
cmd/limactl/start.go
Outdated
@@ -56,6 +60,7 @@ $ cat template.yaml | limactl start --name=local - | |||
// TODO: "survey" does not support using cygwin terminal on windows yet | |||
startCommand.Flags().Bool("tty", isatty.IsTerminal(os.Stdout.Fd()), "enable TUI interactions such as opening an editor, defaults to true when stdout is a terminal") | |||
startCommand.Flags().String("name", "", "override the instance name") | |||
startCommand.Flags().String("yq", "", "modify the template inplace") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe:
startCommand.Flags().String("yq", "", "modify the template inplace") | |
startCommand.Flags().String("set", "", "modify the template inplace, using yq syntax") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- I guess we have to prohibit modifying images?
- Maybe we want to treat this as an experimental?
- Please update
README.md
too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is it not allowed to modified images, from the templates ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Might be ok for new instances, but not allowable for existing instances, obviously
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. But this new tool is not very different, from doing it yourself in the editor...
09b2a29
to
c886757
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
We should add them too, for typechecking, shell completion, etc. (In separate PRs) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, LGTM.
I wish the option would also be added to limactl edit
, but that could be done in a followup PR.
It also makes me a little sad that this little feature increases the size of the limactl
binary by 20% (20MB → 24MB), but I guess that can't be helped, and doesn't really matter when you compare it to the size of QEMU. 😄
To create an instance "default" with modified parameters: | ||
```console | ||
$ limactl start --set='.cpus = 2 | .memory = "2GiB"' | ||
``` | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if we need to include a reference to the yq
documentation, so people can learn to construct more powerful expressions for e.g. scripting:
$ limactl start --set '.env.HOSTPATH=strenv(PATH)' template://alpine
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I expected the same syntax to be available for the limactl edit
command as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess I should have specified: I would expect limactl edit --set ...
to just edit the config, but not to invoke an editor.
It would just be a mechanism to modify the config programmatically without starting the instance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can use something like --eval
, since that is the name of the yq
command being invoked ?
Available Commands:
completion Generate the autocompletion script for the specified shell
eval (default) Apply the expression to each document in each yaml file in sequence
eval-all Loads _all_ yaml documents of _all_ yaml files and runs expression once
help Help about any command
shell-completion Generate completion script
I agree that --set
is somewhat misleading, and that --yq
might be a bit cryptic for lima users...
Adding it to edit
should be straight-forward.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect limactl edit --set ... to just edit the config, but not to invoke an editor.
👍
--eval
sounds much more misleading
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limactl edit --set
can be another PR if complicated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error handling can be a bit tricky to do, so I'd like that.
I noticed that as well. It would be possible to make a more conservative option, either some special-case for cpus/memory/arch/etc. This feature ( |
The binary footprint seems acceptable for me |
No, I think I would prefer to have the expressiveness of Idle curiosity: $ ls -lh /usr/local/Cellar/jq/1.6/bin/jq
-r-xr-xr-x 1 jan admin 296K 2 Jan 18:54 /usr/local/Cellar/jq/1.6/bin/jq
$ ls -lh /usr/local/Cellar/yq/4.30.8/bin/yq
-r-xr-xr-x 1 jan admin 9.0M 14 Jan 16:37 /usr/local/Cellar/yq/4.30.8/bin/yq |
It also does XML and JSON, in addition to just YAML. But I don't think it had any build flags ? |
Of course it does JSON, as JSON is just a subset of YAML; every valid JSON file is also a valid YAML file. I didn't know |
I meant that it links with both encoding/json and encoding/xml libraries:
Sizes in kiB ( |
It is written in C (not Go), so this is normal. |
Needs rebase. Are we ready to merge this after rebasing? |
I'm fine with merging. |
Allows modifying the template inplace for a single instance, if you don't want to change the default or override for all instances. There are currently some quirks with the modified yaml syntax, like removing empty lines or adding indentation on sequences... Signed-off-by: Anders F Björklund <[email protected]>
511ce35
c886757
to
511ce35
Compare
I ran For what it is worth, I made a PR to yq in order to make json and xml optional. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks
Allows modifying the yaml template "inplace" for a single instance,
if you don't want to change the default or override for all instances.
This is similar to running
yq
on the template, from the command-line.Except it does it on a temporary file, and for all different kinds of templates.
$ yq < examples/default.yaml > default.yaml $
Currently it removes empty lines, some quirk with the yaml parser used.
It also seems to change the indentation on some comments (only), but OK:
$ diff -B -w examples/default.yaml default.yaml $
This can be used as a general fallback, similar to
jq
, for modifying templates.Instead of adding the usual
--cpus
--memory
--arch
, or other parameters ?See https://github.com/mikefarah/yq for details
limactl start config.yaml --yq '.arch = "aarch64"'
It is not YAML syntax, but it is rather straightforward.