@@ -40,7 +40,7 @@ import (
40
40
)
41
41
42
42
type HostAgent struct {
43
- y * limayaml.LimaYAML
43
+ instConfig * limayaml.LimaYAML
44
44
sshLocalPort int
45
45
udpDNSLocalPort int
46
46
tcpDNSLocalPort int
@@ -97,22 +97,22 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
97
97
return nil , err
98
98
}
99
99
100
- y , err := inst .LoadYAML ()
100
+ instConfig , err := inst .LoadYAML ()
101
101
if err != nil {
102
102
return nil , err
103
103
}
104
104
// y is loaded with FillDefault() already, so no need to care about nil pointers.
105
105
106
- sshLocalPort , err := determineSSHLocalPort (y , instName )
106
+ sshLocalPort , err := determineSSHLocalPort (instConfig , instName )
107
107
if err != nil {
108
108
return nil , err
109
109
}
110
- if * y .VMType == limayaml .WSL2 {
110
+ if * instConfig .VMType == limayaml .WSL2 {
111
111
sshLocalPort = inst .SSHLocalPort
112
112
}
113
113
114
114
var udpDNSLocalPort , tcpDNSLocalPort int
115
- if * y .HostResolver .Enabled {
115
+ if * instConfig .HostResolver .Enabled {
116
116
udpDNSLocalPort , err = findFreeUDPLocalPort ()
117
117
if err != nil {
118
118
return nil , err
@@ -125,24 +125,24 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
125
125
126
126
vSockPort := 0
127
127
virtioPort := ""
128
- if * y .VMType == limayaml .VZ {
128
+ if * instConfig .VMType == limayaml .VZ {
129
129
vSockPort = 2222
130
- } else if * y .VMType == limayaml .WSL2 {
130
+ } else if * instConfig .VMType == limayaml .WSL2 {
131
131
port , err := getFreeVSockPort ()
132
132
if err != nil {
133
133
logrus .WithError (err ).Error ("failed to get free VSock port" )
134
134
}
135
135
vSockPort = port
136
- } else if * y .VMType == limayaml .QEMU {
136
+ } else if * instConfig .VMType == limayaml .QEMU {
137
137
// virtserialport doesn't seem to work reliably: https://github.com/lima-vm/lima/issues/2064
138
138
virtioPort = "" // filenames.VirtioPort
139
139
}
140
140
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 {
142
142
return nil , err
143
143
}
144
144
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 )
146
146
if err != nil {
147
147
return nil , err
148
148
}
@@ -155,7 +155,7 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
155
155
156
156
ignoreTCP := false
157
157
ignoreUDP := false
158
- for _ , rule := range y .PortForwards {
158
+ for _ , rule := range instConfig .PortForwards {
159
159
if rule .Ignore && rule .GuestPortRange [0 ] == 1 && rule .GuestPortRange [1 ] == 65535 {
160
160
switch rule .Proto {
161
161
case limayaml .TCP :
@@ -169,14 +169,14 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
169
169
break
170
170
}
171
171
}
172
- rules := make ([]limayaml.PortForward , 0 , 3 + len (y .PortForwards ))
172
+ rules := make ([]limayaml.PortForward , 0 , 3 + len (instConfig .PortForwards ))
173
173
// Block ports 22 and sshLocalPort on all IPs
174
174
for _ , port := range []int {sshGuestPort , sshLocalPort } {
175
175
rule := limayaml.PortForward {GuestIP : net .IPv4zero , GuestPort : port , Ignore : true }
176
176
limayaml .FillPortForwardDefaults (& rule , inst .Dir , inst .Param )
177
177
rules = append (rules , rule )
178
178
}
179
- rules = append (rules , y .PortForwards ... )
179
+ rules = append (rules , instConfig .PortForwards ... )
180
180
// Default forwards for all non-privileged ports from "127.0.0.1" and "::1"
181
181
rule := limayaml.PortForward {}
182
182
limayaml .FillPortForwardDefaults (& rule , inst .Dir , inst .Param )
@@ -189,14 +189,14 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
189
189
190
190
limaDriver := driverutil .CreateTargetDriverInstance (& driver.BaseDriver {
191
191
Instance : inst ,
192
- Yaml : y ,
192
+ InstConfig : instConfig ,
193
193
SSHLocalPort : sshLocalPort ,
194
194
VSockPort : vSockPort ,
195
195
VirtioPort : virtioPort ,
196
196
})
197
197
198
198
a := & HostAgent {
199
- y : y ,
199
+ instConfig : instConfig ,
200
200
sshLocalPort : sshLocalPort ,
201
201
udpDNSLocalPort : udpDNSLocalPort ,
202
202
tcpDNSLocalPort : tcpDNSLocalPort ,
@@ -329,16 +329,16 @@ func (a *HostAgent) Run(ctx context.Context) error {
329
329
}()
330
330
adjustNofileRlimit ()
331
331
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
334
334
hosts ["host.lima.internal" ] = networks .SlirpGateway
335
335
hosts [fmt .Sprintf ("lima-%s" , a .instName )] = networks .SlirpIPAddress
336
336
srvOpts := dns.ServerOptions {
337
337
UDPPort : a .udpDNSLocalPort ,
338
338
TCPPort : a .tcpDNSLocalPort ,
339
339
Address : "127.0.0.1" ,
340
340
HandlerOptions : dns.HandlerOptions {
341
- IPv6 : * a .y .HostResolver .IPv6 ,
341
+ IPv6 : * a .instConfig .HostResolver .IPv6 ,
342
342
StaticHosts : hosts ,
343
343
},
344
344
}
@@ -355,16 +355,16 @@ func (a *HostAgent) Run(ctx context.Context) error {
355
355
}
356
356
357
357
// 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 {
359
359
sshAddr , err := store .GetSSHAddress (a .instName )
360
360
if err != nil {
361
361
return err
362
362
}
363
363
a .instSSHAddress = sshAddr
364
364
}
365
365
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 , "," )
368
368
vnchost , vncnum , err := net .SplitHostPort (vncdisplay )
369
369
if err != nil {
370
370
return err
@@ -465,7 +465,7 @@ func (a *HostAgent) Info(_ context.Context) (*hostagentapi.Info, error) {
465
465
}
466
466
467
467
func (a * HostAgent ) startHostAgentRoutines (ctx context.Context ) error {
468
- if * a .y .Plain {
468
+ if * a .instConfig .Plain {
469
469
logrus .Info ("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running." )
470
470
}
471
471
a .onClose = append (a .onClose , func () error {
@@ -479,7 +479,7 @@ func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
479
479
if err := a .waitForRequirements ("essential" , a .essentialRequirements ()); err != nil {
480
480
errs = append (errs , err )
481
481
}
482
- if * a .y .SSH .ForwardAgent {
482
+ if * a .instConfig .SSH .ForwardAgent {
483
483
faScript := `#!/bin/bash
484
484
set -eux -o pipefail
485
485
sudo mkdir -p -m 700 /run/host-services
@@ -492,7 +492,7 @@ sudo chown -R "${USER}" /run/host-services`
492
492
errs = append (errs , fmt .Errorf ("stdout=%q, stderr=%q: %w" , stdout , stderr , err ))
493
493
}
494
494
}
495
- if * a .y .MountType == limayaml .REVSSHFS && ! * a .y .Plain {
495
+ if * a .instConfig .MountType == limayaml .REVSSHFS && ! * a .instConfig .Plain {
496
496
mounts , err := a .setupMounts ()
497
497
if err != nil {
498
498
errs = append (errs , err )
@@ -507,10 +507,10 @@ sudo chown -R "${USER}" /run/host-services`
507
507
return errors .Join (unmountErrs ... )
508
508
})
509
509
}
510
- if len (a .y .AdditionalDisks ) > 0 {
510
+ if len (a .instConfig .AdditionalDisks ) > 0 {
511
511
a .onClose = append (a .onClose , func () error {
512
512
var unlockErrs []error
513
- for _ , d := range a .y .AdditionalDisks {
513
+ for _ , d := range a .instConfig .AdditionalDisks {
514
514
disk , inspectErr := store .InspectDisk (d .Name )
515
515
if inspectErr != nil {
516
516
unlockErrs = append (unlockErrs , inspectErr )
@@ -524,13 +524,13 @@ sudo chown -R "${USER}" /run/host-services`
524
524
return errors .Join (unlockErrs ... )
525
525
})
526
526
}
527
- if ! * a .y .Plain {
527
+ if ! * a .instConfig .Plain {
528
528
go a .watchGuestAgentEvents (ctx )
529
529
}
530
530
if err := a .waitForRequirements ("optional" , a .optionalRequirements ()); err != nil {
531
531
errs = append (errs , err )
532
532
}
533
- if ! * a .y .Plain {
533
+ if ! * a .instConfig .Plain {
534
534
logrus .Info ("Waiting for the guest agent to be running" )
535
535
select {
536
536
case <- a .guestAgentAliveCh :
@@ -543,14 +543,14 @@ sudo chown -R "${USER}" /run/host-services`
543
543
errs = append (errs , err )
544
544
}
545
545
// Copy all config files _after_ the requirements are done
546
- for _ , rule := range a .y .CopyToHost {
546
+ for _ , rule := range a .instConfig .CopyToHost {
547
547
if err := copyToHost (ctx , a .sshConfig , a .sshLocalPort , rule .HostFile , rule .GuestFile ); err != nil {
548
548
errs = append (errs , err )
549
549
}
550
550
}
551
551
a .onClose = append (a .onClose , func () error {
552
552
var rmErrs []error
553
- for _ , rule := range a .y .CopyToHost {
553
+ for _ , rule := range a .instConfig .CopyToHost {
554
554
if rule .DeleteOnStop {
555
555
logrus .Infof ("Deleting %s" , rule .HostFile )
556
556
if err := os .RemoveAll (rule .HostFile ); err != nil {
@@ -579,9 +579,9 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
579
579
// TODO: use vSock (when QEMU for macOS gets support for vSock)
580
580
581
581
// Setup all socket forwards and defer their teardown
582
- if * a .y .VMType != limayaml .WSL2 {
582
+ if * a .instConfig .VMType != limayaml .WSL2 {
583
583
logrus .Debugf ("Forwarding unix sockets" )
584
- for _ , rule := range a .y .PortForwards {
584
+ for _ , rule := range a .instConfig .PortForwards {
585
585
if rule .GuestSocket != "" {
586
586
local := hostAddress (rule , & guestagentapi.IPPort {})
587
587
_ = forwardSSH (ctx , a .sshConfig , a .sshLocalPort , local , rule .GuestSocket , verbForward , rule .Reverse )
@@ -595,7 +595,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
595
595
a .onClose = append (a .onClose , func () error {
596
596
logrus .Debugf ("Stop forwarding unix sockets" )
597
597
var errs []error
598
- for _ , rule := range a .y .PortForwards {
598
+ for _ , rule := range a .instConfig .PortForwards {
599
599
if rule .GuestSocket != "" {
600
600
local := hostAddress (rule , & guestagentapi.IPPort {})
601
601
// using ctx.Background() because ctx has already been cancelled
@@ -613,7 +613,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
613
613
})
614
614
615
615
go func () {
616
- if a .y .MountInotify != nil && * a .y .MountInotify {
616
+ if a .instConfig .MountInotify != nil && * a .instConfig .MountInotify {
617
617
if a .client == nil || ! isGuestAgentSocketAccessible (ctx , a .client ) {
618
618
if a .driver .ForwardGuestAgent () {
619
619
_ = forwardSSH (ctx , a .sshConfig , a .sshLocalPort , localUnix , remoteUnix , verbForward , false )
0 commit comments