-
Notifications
You must be signed in to change notification settings - Fork 612
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
Move template locator and reader code into new limatmpl package #3009
Conversation
@@ -0,0 +1,166 @@ | |||
package limatmpl |
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:
package limatmpl | |
package templatelocator |
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.
It may not make sense right now, but there will be a limatmpl/assemble.go
in the future that contains all methods on a limatmpl.Template
receiver, and then the package name templatelocator
doesn't make sense anymore.
And while I haven't written it yet, the new FillDefaults()
will also have to move to the limatmpl
package (to avoid a circular dependency with usrlocalsharelima
, which indirectly needs limayaml
).
So for now at least I would like to keep the limatmpl
package name.
This is interesting, a possible use case is creating new yaml from template, and then creating one or move vms from the yaml. Can be done today by copying a template from source, or from Not sure that template is a good name since we repeat "template":
Maybe it should work with edit?
If this may be confusing since edit is used for instances, maybe:
|
As @AkihiroSuda already pointed out, we will need additional subcommands under
I'm not sure about the Maybe we need to have 2 different subcommands for that. I find it challenging to come up with meaningful names. I will make the I still think I'm more concerned about the confusion with "text templates" inside Just for clarification, I consider |
Just for illustration (and I guess as a teaser), here is an example of $ cat my.yaml
basedOn: template://fedora
mountTypesUnsupported: [virtiofs]
provision:
# Hello world!
- file: my.sh # Hi there
$ cat my.sh
#!/bin/sh
echo "Hello world!"
$ limactl template assemble my.yaml
# 9p is broken in Linux v6.9, v6.10, and v6.11 (used by Fedora 41).
# The issue was fixed in Linux v6.12-rc5 (https://github.com/torvalds/linux/commit/be2ca38).
mountTypesUnsupported: [virtiofs, "9p"]
provision:
# Hello world!
- script: | # Hi there
#!/bin/sh
echo "Hello world!"
# This template requires Lima v0.7.0 or later.
images:
- location: "https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-41-1.4.x86_64.qcow2"
arch: "x86_64"
digest: "sha256:6205ae0c524b4d1816dbd3573ce29b5c44ed26c9fbc874fbe48c41c89dd0bac2"
- location: "https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/aarch64/images/Fedora-Cloud-Base-Generic-41-1.4.aarch64.qcow2"
arch: "aarch64"
digest: "sha256:085883b42c7e3b980e366a1fe006cd0ff15877f7e6e984426f3c6c67c7cc2faa"
- location: "https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/x86_64/images/Fedora-Cloud-Base-Generic-41-1.4.x86_64.qcow2"
arch: "x86_64"
digest: "sha256:6205ae0c524b4d1816dbd3573ce29b5c44ed26c9fbc874fbe48c41c89dd0bac2"
- location: "https://download.fedoraproject.org/pub/fedora/linux/releases/41/Cloud/aarch64/images/Fedora-Cloud-Base-Generic-41-1.4.aarch64.qcow2"
arch: "aarch64"
digest: "sha256:085883b42c7e3b980e366a1fe006cd0ff15877f7e6e984426f3c6c67c7cc2faa"
mounts:
- location: "~"
- location: "/tmp/lima"
writable: true You can see how both And you can see how Footnotes
|
Tanks for the example, it is very helpful. |
We can bike-shed the names later. I went through several already, and used To me |
I've realized that The difference comes in with the Assume you have basedOn: fedora.yaml
provision:
- file: my.sh You can reference it as
This means the copy will continue to reference the same base I'll rename the Footnotes
|
Sounds confusing. |
Side topic:
This has to support specifying sha256 digest |
Not sure what that means. Digest for what? For the template content? That seems impractical. If you need to fetch a digest, you can just fetch the template instead and load it locally because the templates are small. How do you specify a digest for
If you want to have an immutable reference, maybe store your templates in an OCI registry and reference the data by hash? |
The I'm not sure how important the The part I dislike about It may all make more sense once the actual implementation is merged (which isn't even part of this PR). I've made the |
The digest of the source template. base:
location: "https://example.com/a.yaml"
digest: "sha256:deadbeef" As a side topic, |
I expect any command named "copy" to take two (or more) arguments: SRC and DST |
That totally makes sense. I was already thinking about adding an Maybe most of the other planned subcommands, like
Practically speaking
Maybe we can allow the user to override, like |
Maybe |
Actually, I'm not sure about this; currently filling defaults and evaluating text templates is intermingled, and may need to continue to be so. So we may just have |
A side topic to the side note... 😄 I've moved this to a discussion topic at #3019. |
I've renamed So @AkihiroSuda I don't plan to make any other changes; do you have more feedback? |
cmd/limactl/validate.go
Outdated
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.
This should now invoke limactl template validate
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.
Ok, limactl validate
now invokes templateValidateAction
.
cmd/limactl/template.go
Outdated
SilenceUsage: true, | ||
SilenceErrors: true, | ||
GroupID: advancedCommand, | ||
Hidden: true, |
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 reason should be explained in a comment or --help
3e18003
to
ae1664a
Compare
It was part of cmd/limactl/start.go but should be generally reusable code. Moved related cmd/limactl/guessarg into limatmpl as well. Also created a new `limactl template` command. It takes a single template locator argument, loads the template, and writes it to STDOUT. This is currently not very interesting; it is in preparation of implementing composable (multi-file) templates. Signed-off-by: Jan Dubois <[email protected]>
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
It was part of cmd/limactl/start.go but should be generally reusable code. Moved related cmd/limactl/guessarg into limatmpl as well.
Also created a new
limactl template
command.It takes a single template locator argument, loads the template, and writes it to STDOUT.
This is currently not very interesting; it is in preparation of implementing composable (multi-file) templates.