Skip to content

Commit 41102b6

Browse files
committed
pkg: improve field and variable names
Signed-off-by: Oleksandr Redko <[email protected]>
1 parent b5b5600 commit 41102b6

File tree

17 files changed

+153
-153
lines changed

17 files changed

+153
-153
lines changed

pkg/driver/driver.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ type Driver interface {
7272
}
7373

7474
type BaseDriver struct {
75-
Instance *store.Instance
76-
Yaml *limayaml.LimaYAML
75+
Instance *store.Instance
76+
InstConfig *limayaml.LimaYAML
7777

7878
SSHLocalPort int
7979
VSockPort int

pkg/driverutil/instance.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func CreateTargetDriverInstance(base *driver.BaseDriver) driver.Driver {
12-
limaDriver := base.Yaml.VMType
12+
limaDriver := base.InstConfig.VMType
1313
if *limaDriver == limayaml.VZ {
1414
return vz.New(base)
1515
}

pkg/hostagent/hostagent.go

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ import (
4040
)
4141

4242
type HostAgent struct {
43-
y *limayaml.LimaYAML
43+
instConfig *limayaml.LimaYAML
4444
sshLocalPort int
4545
udpDNSLocalPort int
4646
tcpDNSLocalPort int
@@ -97,22 +97,22 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
9797
return nil, err
9898
}
9999

100-
y, err := inst.LoadYAML()
100+
instConfig, err := inst.LoadYAML()
101101
if err != nil {
102102
return nil, err
103103
}
104104
// y is loaded with FillDefault() already, so no need to care about nil pointers.
105105

106-
sshLocalPort, err := determineSSHLocalPort(y, instName)
106+
sshLocalPort, err := determineSSHLocalPort(instConfig, instName)
107107
if err != nil {
108108
return nil, err
109109
}
110-
if *y.VMType == limayaml.WSL2 {
110+
if *instConfig.VMType == limayaml.WSL2 {
111111
sshLocalPort = inst.SSHLocalPort
112112
}
113113

114114
var udpDNSLocalPort, tcpDNSLocalPort int
115-
if *y.HostResolver.Enabled {
115+
if *instConfig.HostResolver.Enabled {
116116
udpDNSLocalPort, err = findFreeUDPLocalPort()
117117
if err != nil {
118118
return nil, err
@@ -125,24 +125,24 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
125125

126126
vSockPort := 0
127127
virtioPort := ""
128-
if *y.VMType == limayaml.VZ {
128+
if *instConfig.VMType == limayaml.VZ {
129129
vSockPort = 2222
130-
} else if *y.VMType == limayaml.WSL2 {
130+
} else if *instConfig.VMType == limayaml.WSL2 {
131131
port, err := getFreeVSockPort()
132132
if err != nil {
133133
logrus.WithError(err).Error("failed to get free VSock port")
134134
}
135135
vSockPort = port
136-
} else if *y.VMType == limayaml.QEMU {
136+
} else if *instConfig.VMType == limayaml.QEMU {
137137
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
138138
virtioPort = "" // filenames.VirtioPort
139139
}
140140

141-
if err := cidata.GenerateISO9660(inst.Dir, instName, y, udpDNSLocalPort, tcpDNSLocalPort, o.nerdctlArchive, vSockPort, virtioPort); err != nil {
141+
if err := cidata.GenerateISO9660(inst.Dir, instName, instConfig, udpDNSLocalPort, tcpDNSLocalPort, o.nerdctlArchive, vSockPort, virtioPort); err != nil {
142142
return nil, err
143143
}
144144

145-
sshOpts, err := sshutil.SSHOpts(inst.Dir, *y.SSH.LoadDotSSHPubKeys, *y.SSH.ForwardAgent, *y.SSH.ForwardX11, *y.SSH.ForwardX11Trusted)
145+
sshOpts, err := sshutil.SSHOpts(inst.Dir, *instConfig.SSH.LoadDotSSHPubKeys, *instConfig.SSH.ForwardAgent, *instConfig.SSH.ForwardX11, *instConfig.SSH.ForwardX11Trusted)
146146
if err != nil {
147147
return nil, err
148148
}
@@ -155,7 +155,7 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
155155

156156
ignoreTCP := false
157157
ignoreUDP := false
158-
for _, rule := range y.PortForwards {
158+
for _, rule := range instConfig.PortForwards {
159159
if rule.Ignore && rule.GuestPortRange[0] == 1 && rule.GuestPortRange[1] == 65535 {
160160
switch rule.Proto {
161161
case limayaml.TCP:
@@ -169,14 +169,14 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
169169
break
170170
}
171171
}
172-
rules := make([]limayaml.PortForward, 0, 3+len(y.PortForwards))
172+
rules := make([]limayaml.PortForward, 0, 3+len(instConfig.PortForwards))
173173
// Block ports 22 and sshLocalPort on all IPs
174174
for _, port := range []int{sshGuestPort, sshLocalPort} {
175175
rule := limayaml.PortForward{GuestIP: net.IPv4zero, GuestPort: port, Ignore: true}
176176
limayaml.FillPortForwardDefaults(&rule, inst.Dir, inst.Param)
177177
rules = append(rules, rule)
178178
}
179-
rules = append(rules, y.PortForwards...)
179+
rules = append(rules, instConfig.PortForwards...)
180180
// Default forwards for all non-privileged ports from "127.0.0.1" and "::1"
181181
rule := limayaml.PortForward{}
182182
limayaml.FillPortForwardDefaults(&rule, inst.Dir, inst.Param)
@@ -189,14 +189,14 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
189189

190190
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
191191
Instance: inst,
192-
Yaml: y,
192+
InstConfig: instConfig,
193193
SSHLocalPort: sshLocalPort,
194194
VSockPort: vSockPort,
195195
VirtioPort: virtioPort,
196196
})
197197

198198
a := &HostAgent{
199-
y: y,
199+
instConfig: instConfig,
200200
sshLocalPort: sshLocalPort,
201201
udpDNSLocalPort: udpDNSLocalPort,
202202
tcpDNSLocalPort: tcpDNSLocalPort,
@@ -329,16 +329,16 @@ func (a *HostAgent) Run(ctx context.Context) error {
329329
}()
330330
adjustNofileRlimit()
331331

332-
if limayaml.FirstUsernetIndex(a.y) == -1 && *a.y.HostResolver.Enabled {
333-
hosts := a.y.HostResolver.Hosts
332+
if limayaml.FirstUsernetIndex(a.instConfig) == -1 && *a.instConfig.HostResolver.Enabled {
333+
hosts := a.instConfig.HostResolver.Hosts
334334
hosts["host.lima.internal"] = networks.SlirpGateway
335335
hosts[fmt.Sprintf("lima-%s", a.instName)] = networks.SlirpIPAddress
336336
srvOpts := dns.ServerOptions{
337337
UDPPort: a.udpDNSLocalPort,
338338
TCPPort: a.tcpDNSLocalPort,
339339
Address: "127.0.0.1",
340340
HandlerOptions: dns.HandlerOptions{
341-
IPv6: *a.y.HostResolver.IPv6,
341+
IPv6: *a.instConfig.HostResolver.IPv6,
342342
StaticHosts: hosts,
343343
},
344344
}
@@ -355,16 +355,16 @@ func (a *HostAgent) Run(ctx context.Context) error {
355355
}
356356

357357
// WSL instance SSH address isn't known until after VM start
358-
if *a.y.VMType == limayaml.WSL2 {
358+
if *a.instConfig.VMType == limayaml.WSL2 {
359359
sshAddr, err := store.GetSSHAddress(a.instName)
360360
if err != nil {
361361
return err
362362
}
363363
a.instSSHAddress = sshAddr
364364
}
365365

366-
if a.y.Video.Display != nil && *a.y.Video.Display == "vnc" {
367-
vncdisplay, vncoptions, _ := strings.Cut(*a.y.Video.VNC.Display, ",")
366+
if a.instConfig.Video.Display != nil && *a.instConfig.Video.Display == "vnc" {
367+
vncdisplay, vncoptions, _ := strings.Cut(*a.instConfig.Video.VNC.Display, ",")
368368
vnchost, vncnum, err := net.SplitHostPort(vncdisplay)
369369
if err != nil {
370370
return err
@@ -465,7 +465,7 @@ func (a *HostAgent) Info(_ context.Context) (*hostagentapi.Info, error) {
465465
}
466466

467467
func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
468-
if *a.y.Plain {
468+
if *a.instConfig.Plain {
469469
logrus.Info("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running.")
470470
}
471471
a.onClose = append(a.onClose, func() error {
@@ -479,7 +479,7 @@ func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
479479
if err := a.waitForRequirements("essential", a.essentialRequirements()); err != nil {
480480
errs = append(errs, err)
481481
}
482-
if *a.y.SSH.ForwardAgent {
482+
if *a.instConfig.SSH.ForwardAgent {
483483
faScript := `#!/bin/bash
484484
set -eux -o pipefail
485485
sudo mkdir -p -m 700 /run/host-services
@@ -492,7 +492,7 @@ sudo chown -R "${USER}" /run/host-services`
492492
errs = append(errs, fmt.Errorf("stdout=%q, stderr=%q: %w", stdout, stderr, err))
493493
}
494494
}
495-
if *a.y.MountType == limayaml.REVSSHFS && !*a.y.Plain {
495+
if *a.instConfig.MountType == limayaml.REVSSHFS && !*a.instConfig.Plain {
496496
mounts, err := a.setupMounts()
497497
if err != nil {
498498
errs = append(errs, err)
@@ -507,10 +507,10 @@ sudo chown -R "${USER}" /run/host-services`
507507
return errors.Join(unmountErrs...)
508508
})
509509
}
510-
if len(a.y.AdditionalDisks) > 0 {
510+
if len(a.instConfig.AdditionalDisks) > 0 {
511511
a.onClose = append(a.onClose, func() error {
512512
var unlockErrs []error
513-
for _, d := range a.y.AdditionalDisks {
513+
for _, d := range a.instConfig.AdditionalDisks {
514514
disk, inspectErr := store.InspectDisk(d.Name)
515515
if inspectErr != nil {
516516
unlockErrs = append(unlockErrs, inspectErr)
@@ -524,13 +524,13 @@ sudo chown -R "${USER}" /run/host-services`
524524
return errors.Join(unlockErrs...)
525525
})
526526
}
527-
if !*a.y.Plain {
527+
if !*a.instConfig.Plain {
528528
go a.watchGuestAgentEvents(ctx)
529529
}
530530
if err := a.waitForRequirements("optional", a.optionalRequirements()); err != nil {
531531
errs = append(errs, err)
532532
}
533-
if !*a.y.Plain {
533+
if !*a.instConfig.Plain {
534534
logrus.Info("Waiting for the guest agent to be running")
535535
select {
536536
case <-a.guestAgentAliveCh:
@@ -543,14 +543,14 @@ sudo chown -R "${USER}" /run/host-services`
543543
errs = append(errs, err)
544544
}
545545
// Copy all config files _after_ the requirements are done
546-
for _, rule := range a.y.CopyToHost {
546+
for _, rule := range a.instConfig.CopyToHost {
547547
if err := copyToHost(ctx, a.sshConfig, a.sshLocalPort, rule.HostFile, rule.GuestFile); err != nil {
548548
errs = append(errs, err)
549549
}
550550
}
551551
a.onClose = append(a.onClose, func() error {
552552
var rmErrs []error
553-
for _, rule := range a.y.CopyToHost {
553+
for _, rule := range a.instConfig.CopyToHost {
554554
if rule.DeleteOnStop {
555555
logrus.Infof("Deleting %s", rule.HostFile)
556556
if err := os.RemoveAll(rule.HostFile); err != nil {
@@ -579,9 +579,9 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
579579
// TODO: use vSock (when QEMU for macOS gets support for vSock)
580580

581581
// Setup all socket forwards and defer their teardown
582-
if *a.y.VMType != limayaml.WSL2 {
582+
if *a.instConfig.VMType != limayaml.WSL2 {
583583
logrus.Debugf("Forwarding unix sockets")
584-
for _, rule := range a.y.PortForwards {
584+
for _, rule := range a.instConfig.PortForwards {
585585
if rule.GuestSocket != "" {
586586
local := hostAddress(rule, &guestagentapi.IPPort{})
587587
_ = forwardSSH(ctx, a.sshConfig, a.sshLocalPort, local, rule.GuestSocket, verbForward, rule.Reverse)
@@ -595,7 +595,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
595595
a.onClose = append(a.onClose, func() error {
596596
logrus.Debugf("Stop forwarding unix sockets")
597597
var errs []error
598-
for _, rule := range a.y.PortForwards {
598+
for _, rule := range a.instConfig.PortForwards {
599599
if rule.GuestSocket != "" {
600600
local := hostAddress(rule, &guestagentapi.IPPort{})
601601
// using ctx.Background() because ctx has already been cancelled
@@ -613,7 +613,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
613613
})
614614

615615
go func() {
616-
if a.y.MountInotify != nil && *a.y.MountInotify {
616+
if a.instConfig.MountInotify != nil && *a.instConfig.MountInotify {
617617
if a.client == nil || !isGuestAgentSocketAccessible(ctx, a.client) {
618618
if a.driver.ForwardGuestAgent() {
619619
_ = forwardSSH(ctx, a.sshConfig, a.sshLocalPort, localUnix, remoteUnix, verbForward, false)

pkg/hostagent/inotify.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ func (a *HostAgent) startInotify(ctx context.Context) error {
6767
}
6868

6969
func (a *HostAgent) setupWatchers(events chan notify.EventInfo) error {
70-
for _, m := range a.y.Mounts {
70+
for _, m := range a.instConfig.Mounts {
7171
if !*m.Writable {
7272
continue
7373
}

pkg/hostagent/mount.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func (a *HostAgent) setupMounts() ([]*mount, error) {
2020
res []*mount
2121
errs []error
2222
)
23-
for _, f := range a.y.Mounts {
23+
for _, f := range a.instConfig.Mounts {
2424
m, err := a.setupMount(f)
2525
if err != nil {
2626
errs = append(errs, err)

pkg/hostagent/requirements.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ Make sure that the YAML field "ssh.localPort" is not used by other processes on
114114
If any private key under ~/.ssh is protected with a passphrase, you need to have ssh-agent to be running.
115115
`,
116116
})
117-
if *a.y.Plain {
117+
if *a.instConfig.Plain {
118118
return req
119119
}
120120
req = append(req,
@@ -134,7 +134,7 @@ it must not be created until the session reset is done.
134134
`,
135135
})
136136

137-
if *a.y.MountType == limayaml.REVSSHFS && len(a.y.Mounts) > 0 {
137+
if *a.instConfig.MountType == limayaml.REVSSHFS && len(a.instConfig.Mounts) > 0 {
138138
req = append(req, requirement{
139139
description: "sshfs binary to be installed",
140140
script: `#!/bin/bash
@@ -167,7 +167,7 @@ fi
167167

168168
func (a *HostAgent) optionalRequirements() []requirement {
169169
req := make([]requirement, 0)
170-
if (*a.y.Containerd.System || *a.y.Containerd.User) && !*a.y.Plain {
170+
if (*a.instConfig.Containerd.System || *a.instConfig.Containerd.User) && !*a.instConfig.Plain {
171171
req = append(req,
172172
requirement{
173173
description: "systemd must be available",
@@ -189,7 +189,7 @@ are set to 'false' in the config file.
189189
description: "containerd binaries to be installed",
190190
script: `#!/bin/bash
191191
set -eux -o pipefail
192-
if ! timeout 30s bash -c "until command -v nerdctl || test -x ` + *a.y.GuestInstallPrefix + `/bin/nerdctl; do sleep 3; done"; then
192+
if ! timeout 30s bash -c "until command -v nerdctl || test -x ` + *a.instConfig.GuestInstallPrefix + `/bin/nerdctl; do sleep 3; done"; then
193193
echo >&2 "nerdctl is not installed yet"
194194
exit 1
195195
fi
@@ -200,7 +200,7 @@ Also see "/var/log/cloud-init-output.log" in the guest.
200200
`,
201201
})
202202
}
203-
for _, probe := range a.y.Probes {
203+
for _, probe := range a.instConfig.Probes {
204204
if probe.Mode == limayaml.ProbeModeReadiness {
205205
req = append(req, requirement{
206206
description: probe.Description,

pkg/instance/create.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ import (
1616
"github.com/lima-vm/lima/pkg/version"
1717
)
1818

19-
func Create(ctx context.Context, instName string, yBytes []byte, saveBrokenYAML bool) (*store.Instance, error) {
19+
func Create(ctx context.Context, instName string, instConfig []byte, saveBrokenYAML bool) (*store.Instance, error) {
2020
if instName == "" {
2121
return nil, errors.New("got empty instName")
2222
}
23-
if len(yBytes) == 0 {
24-
return nil, errors.New("got empty yBytes")
23+
if len(instConfig) == 0 {
24+
return nil, errors.New("got empty instConfig")
2525
}
2626

2727
instDir, err := store.InstanceDir(instName)
@@ -40,24 +40,24 @@ func Create(ctx context.Context, instName string, yBytes []byte, saveBrokenYAML
4040
}
4141
// limayaml.Load() needs to pass the store file path to limayaml.FillDefault() to calculate default MAC addresses
4242
filePath := filepath.Join(instDir, filenames.LimaYAML)
43-
y, err := limayaml.Load(yBytes, filePath)
43+
loadedInstConfig, err := limayaml.Load(instConfig, filePath)
4444
if err != nil {
4545
return nil, err
4646
}
47-
if err := limayaml.Validate(y, true); err != nil {
47+
if err := limayaml.Validate(loadedInstConfig, true); err != nil {
4848
if !saveBrokenYAML {
4949
return nil, err
5050
}
5151
rejectedYAML := "lima.REJECTED.yaml"
52-
if writeErr := os.WriteFile(rejectedYAML, yBytes, 0o644); writeErr != nil {
52+
if writeErr := os.WriteFile(rejectedYAML, instConfig, 0o644); writeErr != nil {
5353
return nil, fmt.Errorf("the YAML is invalid, attempted to save the buffer as %q but failed: %w: %w", rejectedYAML, writeErr, err)
5454
}
5555
return nil, fmt.Errorf("the YAML is invalid, saved the buffer as %q: %w", rejectedYAML, err)
5656
}
5757
if err := os.MkdirAll(instDir, 0o700); err != nil {
5858
return nil, err
5959
}
60-
if err := os.WriteFile(filePath, yBytes, 0o644); err != nil {
60+
if err := os.WriteFile(filePath, instConfig, 0o644); err != nil {
6161
return nil, err
6262
}
6363
if err := os.WriteFile(filepath.Join(instDir, filenames.LimaVersion), []byte(version.Version), 0o444); err != nil {
@@ -70,8 +70,8 @@ func Create(ctx context.Context, instName string, yBytes []byte, saveBrokenYAML
7070
}
7171

7272
limaDriver := driverutil.CreateTargetDriverInstance(&driver.BaseDriver{
73-
Instance: inst,
74-
Yaml: y,
73+
Instance: inst,
74+
InstConfig: loadedInstConfig,
7575
})
7676

7777
if err := limaDriver.Register(ctx); err != nil {

0 commit comments

Comments
 (0)