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

simplify FillDefault() using reflects #1069

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

AkihiroSuda
Copy link
Member

@AkihiroSuda AkihiroSuda commented Sep 27, 2022

The type of CPUType map[Arch]string is now changed to map[Arch]*string, as pkg/reflectutil.Merge() is designed to distinguish "empty" from "nil".

@AkihiroSuda AkihiroSuda added this to the v0.12.1 milestone Sep 27, 2022
@AkihiroSuda AkihiroSuda changed the title pkg/limayaml: remove deprecated network and useHostResolver ; simplify FillDefault()` using reflects pkg/limayaml: remove deprecated network and useHostResolver ; simplify FillDefault() using reflects Sep 27, 2022
- `network`: deprecated in Lima v0.7.0 (Oct 2021), in favor of `networks`:
   lima-vm@07e6823
- `useHostResolver`: deprecated in Lima v0.8.1 (Jan 2022), in favor of `hostResolver.enabled`:
   lima-vm@eaeee31

The deprecated support for VDE is not removed in this commit.

Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
var err error
x, err = Merge(x, v)
if err != nil {
return x, err
Copy link
Member

Choose a reason for hiding this comment

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

Don't return incompletely merged result in case of error:

Suggested change
return x, err
return nil, err

Comment on lines +149 to +154
func logX(t testing.TB, x interface{}, format string, args ...interface{}) {
// Print in JSON for human readability
j, err := json.Marshal(x)
assert.NilError(t, err)
t.Logf(format+": %s", append(args, string(j))...)
}
Copy link
Member

Choose a reason for hiding this comment

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

args is never used; format is really just a name:

Suggested change
func logX(t testing.TB, x interface{}, format string, args ...interface{}) {
// Print in JSON for human readability
j, err := json.Marshal(x)
assert.NilError(t, err)
t.Logf(format+": %s", append(args, string(j))...)
}
func logX(t testing.TB, x interface{}, name string) {
// Print in JSON for human readability
j, err := json.Marshal(x)
assert.NilError(t, err)
t.Logf("%s: %s", name, string(j))
}

Personally I would also swap the order of x and name, but it doesn't really matter.

}
}
// *EXCEPTION*: Mounts are appended in d, y, o order, but "merged" when the Location matches a previous entry;
// the highest priority Writable setting wins.
Copy link
Member

@jandubois jandubois Oct 9, 2022

Choose a reason for hiding this comment

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

Just below is this block:

	mounts := make([]Mount, 0, len(d.Mounts)+len(y.Mounts)+len(o.Mounts))
	location := make(map[string]int)
	for _, mount := range append(append(d.Mounts, y.Mounts...), o.Mounts...) {
		if i, ok := location[mount.Location]; ok {

It should have been updated to no longer use d, y, and o, but just x.

	mounts := make([]Mount, 0, len(x.Mounts))
	location := make(map[string]int)
	for _, mount := range x.Mounts {
        mount.Location = filepath.Clean(mount.Location)
		if i, ok := location[mount.Location]; ok {

Update: I also added a call to filepath.Clean() to normalize paths before matching. Could be in a separate commit or even PR.

Copy link
Member

Choose a reason for hiding this comment

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

Same thing again further down for networks.

Comment on lines +222 to +224
networks := make([]Network, 0, len(d.Networks)+len(y.Networks)+len(o.Networks))
iface := make(map[string]int)
for _, nw := range append(append(d.Networks, y.Networks...), o.Networks...) {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
networks := make([]Network, 0, len(d.Networks)+len(y.Networks)+len(o.Networks))
iface := make(map[string]int)
for _, nw := range append(append(d.Networks, y.Networks...), o.Networks...) {
networks := make([]Network, 0, len(x.Networks))
iface := make(map[string]int)
for _, nw := range x.Networks {

@AkihiroSuda AkihiroSuda modified the milestones: v1.0 (tentative), v0.13 Oct 12, 2022
@AkihiroSuda AkihiroSuda marked this pull request as draft November 25, 2022 04:14
@AkihiroSuda AkihiroSuda modified the milestones: v0.14, v0.15 (tentative) Nov 30, 2022
@AkihiroSuda AkihiroSuda changed the title pkg/limayaml: remove deprecated network and useHostResolver ; simplify FillDefault() using reflects simplify FillDefault() using reflects Dec 14, 2022
@AkihiroSuda AkihiroSuda removed this from the v0.15 (tentative) milestone Jan 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants