@@ -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 .ProtoTCP :
@@ -173,14 +173,14 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
173
173
break
174
174
}
175
175
}
176
- rules := make ([]limayaml.PortForward , 0 , 3 + len (y .PortForwards ))
176
+ rules := make ([]limayaml.PortForward , 0 , 3 + len (instConfig .PortForwards ))
177
177
// Block ports 22 and sshLocalPort on all IPs
178
178
for _ , port := range []int {sshGuestPort , sshLocalPort } {
179
179
rule := limayaml.PortForward {GuestIP : net .IPv4zero , GuestPort : port , Ignore : true }
180
180
limayaml .FillPortForwardDefaults (& rule , inst .Dir , inst .Param )
181
181
rules = append (rules , rule )
182
182
}
183
- rules = append (rules , y .PortForwards ... )
183
+ rules = append (rules , instConfig .PortForwards ... )
184
184
// Default forwards for all non-privileged ports from "127.0.0.1" and "::1"
185
185
rule := limayaml.PortForward {}
186
186
limayaml .FillPortForwardDefaults (& rule , inst .Dir , inst .Param )
@@ -193,14 +193,14 @@ func New(instName string, stdout io.Writer, signalCh chan os.Signal, opts ...Opt
193
193
194
194
limaDriver := driverutil .CreateTargetDriverInstance (& driver.BaseDriver {
195
195
Instance : inst ,
196
- Yaml : y ,
196
+ InstConfig : instConfig ,
197
197
SSHLocalPort : sshLocalPort ,
198
198
VSockPort : vSockPort ,
199
199
VirtioPort : virtioPort ,
200
200
})
201
201
202
202
a := & HostAgent {
203
- y : y ,
203
+ instConfig : instConfig ,
204
204
sshLocalPort : sshLocalPort ,
205
205
udpDNSLocalPort : udpDNSLocalPort ,
206
206
tcpDNSLocalPort : tcpDNSLocalPort ,
@@ -333,16 +333,16 @@ func (a *HostAgent) Run(ctx context.Context) error {
333
333
}()
334
334
adjustNofileRlimit ()
335
335
336
- if limayaml .FirstUsernetIndex (a .y ) == - 1 && * a .y .HostResolver .Enabled {
337
- hosts := a .y .HostResolver .Hosts
336
+ if limayaml .FirstUsernetIndex (a .instConfig ) == - 1 && * a .instConfig .HostResolver .Enabled {
337
+ hosts := a .instConfig .HostResolver .Hosts
338
338
hosts ["host.lima.internal" ] = networks .SlirpGateway
339
339
hosts [fmt .Sprintf ("lima-%s" , a .instName )] = networks .SlirpIPAddress
340
340
srvOpts := dns.ServerOptions {
341
341
UDPPort : a .udpDNSLocalPort ,
342
342
TCPPort : a .tcpDNSLocalPort ,
343
343
Address : "127.0.0.1" ,
344
344
HandlerOptions : dns.HandlerOptions {
345
- IPv6 : * a .y .HostResolver .IPv6 ,
345
+ IPv6 : * a .instConfig .HostResolver .IPv6 ,
346
346
StaticHosts : hosts ,
347
347
},
348
348
}
@@ -359,16 +359,16 @@ func (a *HostAgent) Run(ctx context.Context) error {
359
359
}
360
360
361
361
// WSL instance SSH address isn't known until after VM start
362
- if * a .y .VMType == limayaml .WSL2 {
362
+ if * a .instConfig .VMType == limayaml .WSL2 {
363
363
sshAddr , err := store .GetSSHAddress (a .instName )
364
364
if err != nil {
365
365
return err
366
366
}
367
367
a .instSSHAddress = sshAddr
368
368
}
369
369
370
- if a .y .Video .Display != nil && * a .y .Video .Display == "vnc" {
371
- vncdisplay , vncoptions , _ := strings .Cut (* a .y .Video .VNC .Display , "," )
370
+ if a .instConfig .Video .Display != nil && * a .instConfig .Video .Display == "vnc" {
371
+ vncdisplay , vncoptions , _ := strings .Cut (* a .instConfig .Video .VNC .Display , "," )
372
372
vnchost , vncnum , err := net .SplitHostPort (vncdisplay )
373
373
if err != nil {
374
374
return err
@@ -469,7 +469,7 @@ func (a *HostAgent) Info(_ context.Context) (*hostagentapi.Info, error) {
469
469
}
470
470
471
471
func (a * HostAgent ) startHostAgentRoutines (ctx context.Context ) error {
472
- if * a .y .Plain {
472
+ if * a .instConfig .Plain {
473
473
logrus .Info ("Running in plain mode. Mounts, port forwarding, containerd, etc. will be ignored. Guest agent will not be running." )
474
474
}
475
475
a .onClose = append (a .onClose , func () error {
@@ -483,7 +483,7 @@ func (a *HostAgent) startHostAgentRoutines(ctx context.Context) error {
483
483
if err := a .waitForRequirements ("essential" , a .essentialRequirements ()); err != nil {
484
484
errs = append (errs , err )
485
485
}
486
- if * a .y .SSH .ForwardAgent {
486
+ if * a .instConfig .SSH .ForwardAgent {
487
487
faScript := `#!/bin/bash
488
488
set -eux -o pipefail
489
489
sudo mkdir -p -m 700 /run/host-services
@@ -496,7 +496,7 @@ sudo chown -R "${USER}" /run/host-services`
496
496
errs = append (errs , fmt .Errorf ("stdout=%q, stderr=%q: %w" , stdout , stderr , err ))
497
497
}
498
498
}
499
- if * a .y .MountType == limayaml .REVSSHFS && ! * a .y .Plain {
499
+ if * a .instConfig .MountType == limayaml .REVSSHFS && ! * a .instConfig .Plain {
500
500
mounts , err := a .setupMounts ()
501
501
if err != nil {
502
502
errs = append (errs , err )
@@ -511,10 +511,10 @@ sudo chown -R "${USER}" /run/host-services`
511
511
return errors .Join (unmountErrs ... )
512
512
})
513
513
}
514
- if len (a .y .AdditionalDisks ) > 0 {
514
+ if len (a .instConfig .AdditionalDisks ) > 0 {
515
515
a .onClose = append (a .onClose , func () error {
516
516
var unlockErrs []error
517
- for _ , d := range a .y .AdditionalDisks {
517
+ for _ , d := range a .instConfig .AdditionalDisks {
518
518
disk , inspectErr := store .InspectDisk (d .Name )
519
519
if inspectErr != nil {
520
520
unlockErrs = append (unlockErrs , inspectErr )
@@ -528,13 +528,13 @@ sudo chown -R "${USER}" /run/host-services`
528
528
return errors .Join (unlockErrs ... )
529
529
})
530
530
}
531
- if ! * a .y .Plain {
531
+ if ! * a .instConfig .Plain {
532
532
go a .watchGuestAgentEvents (ctx )
533
533
}
534
534
if err := a .waitForRequirements ("optional" , a .optionalRequirements ()); err != nil {
535
535
errs = append (errs , err )
536
536
}
537
- if ! * a .y .Plain {
537
+ if ! * a .instConfig .Plain {
538
538
logrus .Info ("Waiting for the guest agent to be running" )
539
539
select {
540
540
case <- a .guestAgentAliveCh :
@@ -547,14 +547,14 @@ sudo chown -R "${USER}" /run/host-services`
547
547
errs = append (errs , err )
548
548
}
549
549
// Copy all config files _after_ the requirements are done
550
- for _ , rule := range a .y .CopyToHost {
550
+ for _ , rule := range a .instConfig .CopyToHost {
551
551
if err := copyToHost (ctx , a .sshConfig , a .sshLocalPort , rule .HostFile , rule .GuestFile ); err != nil {
552
552
errs = append (errs , err )
553
553
}
554
554
}
555
555
a .onClose = append (a .onClose , func () error {
556
556
var rmErrs []error
557
- for _ , rule := range a .y .CopyToHost {
557
+ for _ , rule := range a .instConfig .CopyToHost {
558
558
if rule .DeleteOnStop {
559
559
logrus .Infof ("Deleting %s" , rule .HostFile )
560
560
if err := os .RemoveAll (rule .HostFile ); err != nil {
@@ -583,9 +583,9 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
583
583
// TODO: use vSock (when QEMU for macOS gets support for vSock)
584
584
585
585
// Setup all socket forwards and defer their teardown
586
- if * a .y .VMType != limayaml .WSL2 {
586
+ if * a .instConfig .VMType != limayaml .WSL2 {
587
587
logrus .Debugf ("Forwarding unix sockets" )
588
- for _ , rule := range a .y .PortForwards {
588
+ for _ , rule := range a .instConfig .PortForwards {
589
589
if rule .GuestSocket != "" {
590
590
local := hostAddress (rule , & guestagentapi.IPPort {})
591
591
_ = forwardSSH (ctx , a .sshConfig , a .sshLocalPort , local , rule .GuestSocket , verbForward , rule .Reverse )
@@ -599,7 +599,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
599
599
a .onClose = append (a .onClose , func () error {
600
600
logrus .Debugf ("Stop forwarding unix sockets" )
601
601
var errs []error
602
- for _ , rule := range a .y .PortForwards {
602
+ for _ , rule := range a .instConfig .PortForwards {
603
603
if rule .GuestSocket != "" {
604
604
local := hostAddress (rule , & guestagentapi.IPPort {})
605
605
// using ctx.Background() because ctx has already been cancelled
@@ -617,7 +617,7 @@ func (a *HostAgent) watchGuestAgentEvents(ctx context.Context) {
617
617
})
618
618
619
619
go func () {
620
- if a .y .MountInotify != nil && * a .y .MountInotify {
620
+ if a .instConfig .MountInotify != nil && * a .instConfig .MountInotify {
621
621
if a .client == nil || ! isGuestAgentSocketAccessible (ctx , a .client ) {
622
622
if a .driver .ForwardGuestAgent () {
623
623
_ = forwardSSH (ctx , a .sshConfig , a .sshLocalPort , localUnix , remoteUnix , verbForward , false )
0 commit comments