Skip to content

Commit 0ea2b0a

Browse files
committed
Use driver feature instead of the name
Other container drivers with dynamic addresses and static ports also want to set the port after start. Signed-off-by: Anders F Björklund <anders.f.bjorklund@gmail.com>
1 parent c71bc48 commit 0ea2b0a

File tree

4 files changed

+9
-4
lines changed

4 files changed

+9
-4
lines changed

pkg/driver/driver.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ type Info struct {
105105
type DriverFeatures struct {
106106
CanRunGUI bool `json:"canRunGui,omitempty"`
107107
DynamicSSHAddress bool `json:"dynamicSSHAddress"`
108+
StaticSSHPort bool `json:"staticSSHPort"`
108109
SkipSocketForwarding bool `json:"skipSocketForwarding"`
109110
NoCloudInit bool `json:"noCloudInit"`
110111
RosettaEnabled bool `json:"rosettaEnabled"`

pkg/driver/wsl2/wsl_driver_windows.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -309,6 +309,7 @@ func (l *LimaWslDriver) Info() driver.Info {
309309

310310
info.Features = driver.DriverFeatures{
311311
DynamicSSHAddress: true,
312+
StaticSSHPort: true,
312313
SkipSocketForwarding: true,
313314
NoCloudInit: true,
314315
CanRunGUI: l.canRunGUI(),

pkg/driverutil/instance.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ func CreateConfiguredDriver(inst *limatype.Instance, sshLocalPort int) (*driver.
2222
return nil, fmt.Errorf("unknown or unsupported VM type: %s", *limaDriver)
2323
}
2424

25-
inst.SSHLocalPort = sshLocalPort
2625
if extDriver != nil {
2726
extDriver.Logger.Debugf("Using external driver %q", extDriver.Name)
2827
if extDriver.Client == nil || extDriver.Command == nil {
@@ -36,9 +35,15 @@ func CreateConfiguredDriver(inst *limatype.Instance, sshLocalPort int) (*driver.
3635
extDriver.InstanceName = inst.Name
3736
}
3837

38+
if !extDriver.Client.Info().Features.StaticSSHPort {
39+
inst.SSHLocalPort = sshLocalPort
40+
}
3941
return extDriver.Client.Configure(inst), nil
4042
}
4143

4244
logrus.Debugf("Using internal driver %q", intDriver.Info().Name)
45+
if !intDriver.Info().Features.StaticSSHPort {
46+
inst.SSHLocalPort = sshLocalPort
47+
}
4348
return intDriver.Configure(inst), nil
4449
}

pkg/hostagent/hostagent.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,6 @@ func New(ctx context.Context, instName string, stdout io.Writer, signalCh chan o
140140
if err != nil {
141141
return nil, err
142142
}
143-
if *inst.Config.VMType == limatype.WSL2 {
144-
sshLocalPort = inst.SSHLocalPort
145-
}
146143

147144
var udpDNSLocalPort, tcpDNSLocalPort int
148145
if *inst.Config.HostResolver.Enabled {
@@ -160,6 +157,7 @@ func New(ctx context.Context, instName string, stdout io.Writer, signalCh chan o
160157
if err != nil {
161158
return nil, fmt.Errorf("failed to create driver instance: %w", err)
162159
}
160+
sshLocalPort = inst.SSHLocalPort
163161

164162
vSockPort := limaDriver.Info().VsockPort
165163
virtioPort := limaDriver.Info().VirtioPort

0 commit comments

Comments
 (0)