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 support for kernel/initrd/cmdline options #242
Conversation
libvirt/disk_def_test.go
Outdated
b := newDefDisk() | ||
b := newDefDisk(0) | ||
prettyB := spew.Sdump(b) | ||
t.Logf("Parsed default disk:\n%s", prettyB) |
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 like to propose that we don't print to much log details.
It becomes really difficult to have 3/5 tests that are printing so much info, and then to filter what is passing and what is not, if a test is failing.
Imho we should just print debug info when a test is failing for debugging purpose.
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.
Did I added that, or did it come from the rebase?
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.
dunno 🙄 🤣 . we removed it from the codebase, but in this case donno if it comes from your addition or maybe a missing conflict
a217650
to
cd64e6c
Compare
libvirt/resource_libvirt_domain.go
Outdated
} | ||
|
||
cmdlinesCount := d.Get("cmdline.#").(int) | ||
cmdlineArgs := make([]string, 0) |
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.
nitpick
: i would use here
var cmdlineArgs []string
https://stackoverflow.com/questions/29164375/golang-correct-way-to-initialize-empty-slice
I have reviewed all relevant observations and tests are passing now (included tests with a real kernel/initrd fixture). Still pending to read the values back. |
cd64e6c
to
088b965
Compare
libvirt/utils_domain_def_test.go
Outdated
t.Errorf("Expected error for parsing '%s'", v) | ||
} | ||
func TestSplitKernelInvalidCmdLine(t *testing.T) { | ||
v := "foo=barfoo=bar" |
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.
nitpick
can we use more expressive name then v
, e
, r
? i know that is testsdata, but still in sake for mantainabilty
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.
Sorry, but golang uses t
for tests. I am following the same convention/thinking ("expected", "result", "value"). Not hard to guess. The function is small, you will not get lost with it's meaning.
libvirt/utils_domain_def_test.go
Outdated
t.Error(err) | ||
} | ||
e := []map[string]string{{"foo": "bar"}, {"foo": "bar", "key": "val"}} | ||
r, err := splitKernelCmdLine("foo=bar foo=bar key=val") |
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.
same comments as above
Everything is implemented now. I think this should be ready to be merged. For the reviewer: please have a look how I implemented cmdline, as a list of maps, to allow duplicate keys (kernel supports them). I think this way it is simple to define simple command line while still allowing duplicate keys. You need to know to separate them in that case, but I can't think of a simpler and ergonomic way. |
libvirt/resource_libvirt_domain.go
Outdated
@@ -170,6 +171,27 @@ func resourceLibvirtDomain() *schema.Resource { | |||
Default: "/usr/bin/qemu-system-x86_64", | |||
Optional: true, | |||
}, | |||
"kernel": &schema.Schema{ |
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.
nitpick
we can remove this &schema.Schema
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.
lgtm from my pov. a part from the small nitpick comment
@@ -267,6 +289,25 @@ func resourceLibvirtDomainCreate(d *schema.ResourceData, meta interface{}) error | |||
} | |||
} | |||
|
|||
if kernel, ok := d.GetOk("kernel"); ok { |
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 could wrap this new code in a function. because the DomainCreate is a really big function.
website/docs/r/domain.html.markdown
Outdated
|
||
You can use it in the same way as the kernel. | ||
|
||
* `cmdlin` - (Optional) Arguments to the kernel |
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.
Typo? cmdline
maybe?
libvirt/resource_libvirt_domain.go
Outdated
|
||
cmdlinesCount := d.Get("cmdline.#").(int) | ||
var cmdlineArgs []string | ||
for i := 0; i < cmdlinesCount; i++ { |
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.
You can just do
for i := 0; i < d.Get("cmdline.#").(int); i++ {
and get rid of line 299.
libvirt/resource_libvirt_domain.go
Outdated
for i := 0; i < cmdlinesCount; i++ { | ||
cmdlineKey := fmt.Sprintf("cmdline.%d", i) | ||
cmdlineMap := d.Get(cmdlineKey).(map[string]interface{}) | ||
for k, v := range cmdlineMap { |
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.
You could also shorten this if you wanted to. The variables are only used once anyway.
for k, v := range d.Get(fmt.Sprintf("cmdline.%d", i)).(map[string]interface{}) {
IMHO the code is still pretty clear.
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.
good
website/docs/r/domain.html.markdown
Outdated
|
||
* `cmdlin` - (Optional) Arguments to the kernel | ||
|
||
resource "libvirt_domain" "domain-suse" { |
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.
Missing "```hcl"
website/docs/r/domain.html.markdown
Outdated
@@ -73,7 +166,7 @@ read-only. | |||
domain. However, `libvirt` can manage this automatically (and this is the recommended solution) | |||
if a mapping for the firmware to a _variables file_ exists in `/etc/libvirt/qemu.conf:nvram`. | |||
In that case, `libvirt` will copy that variables file into a file specific for this domain. | |||
* `template` - (Optional) path to the file used to override variables from the master NVRAM | |||
s * `template` - (Optional) path to the file used to override variables from the master NVRAM |
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 's' does not belong here.
83db59c
to
cc74c04
Compare
This fix is with the cmd "gofmt -w -s *"
cc74c04
to
9f7f025
Compare
@dmacvicar https://serverfault.com/questions/740694/how-to-set-kvm-kernel-boot-only-once actually i experimented this, since we are using the direct kernel boot, we end up in a infinite loop. We might need some research how to do it properly without the loop for a network installation, e.g find out something similar as |
Are there any news on this? I just stay at this problem with the infinite loop, when I try to create a vm with k3os. My plan is this:
Any help is welcome :-) |
This allows you to specify kernel, initrd, cmdline, which combined with volumes open the way for booting directly from a repository.
Originally I planned to implement AutoYaST and booting from repos in a similar way to
cloud-init
andignition
, replicating some code present invirt-install
, and doing all the ISO creation, etc. I decided to start laying a foundation that at the beginning requires more work on the.tf
file, but it reuses most of the existing infrastructure, and then start making it easier from there (eg. in the future may be allow to create an ISO to be uploaded, from local terraform files).