-
Notifications
You must be signed in to change notification settings - Fork 706
refactor: decouple driver-specific settings for internal drivers #3901
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,6 +24,7 @@ import ( | |
"github.com/sirupsen/logrus" | ||
|
||
"github.com/lima-vm/lima/v2/pkg/debugutil" | ||
"github.com/lima-vm/lima/v2/pkg/driver" | ||
"github.com/lima-vm/lima/v2/pkg/instance/hostname" | ||
"github.com/lima-vm/lima/v2/pkg/iso9660util" | ||
"github.com/lima-vm/lima/v2/pkg/limatype" | ||
|
@@ -137,14 +138,19 @@ func templateArgs(ctx context.Context, bootScripts bool, instDir, name string, i | |
Containerd: Containerd{System: *instConfig.Containerd.System, User: *instConfig.Containerd.User, Archive: archive}, | ||
SlirpNICName: networks.SlirpNICName, | ||
|
||
RosettaEnabled: *instConfig.Rosetta.Enabled, | ||
RosettaBinFmt: *instConfig.Rosetta.BinFmt, | ||
VMType: *instConfig.VMType, | ||
VSockPort: vsockPort, | ||
VirtioPort: virtioPort, | ||
Plain: *instConfig.Plain, | ||
TimeZone: *instConfig.TimeZone, | ||
Param: instConfig.Param, | ||
VMType: *instConfig.VMType, | ||
VSockPort: vsockPort, | ||
VirtioPort: virtioPort, | ||
Plain: *instConfig.Plain, | ||
TimeZone: *instConfig.TimeZone, | ||
Param: instConfig.Param, | ||
} | ||
|
||
if instConfig.VMOpts.VZ.Rosetta.Enabled != nil { | ||
args.RosettaEnabled = *instConfig.VMOpts.VZ.Rosetta.Enabled | ||
} | ||
if instConfig.VMOpts.VZ.Rosetta.BinFmt != nil { | ||
args.RosettaEnabled = *instConfig.VMOpts.VZ.Rosetta.BinFmt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. - args.RosettaEnabled = *instConfig.VMOpts.VZ.Rosetta.BinFmt
+ args.RosettaBinFmt = *instConfig.VMOpts.VZ.Rosetta.BinFmt There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. opened #3921 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks |
||
} | ||
|
||
firstUsernetIndex := limayaml.FirstUsernetIndex(instConfig) | ||
|
@@ -357,7 +363,7 @@ func GenerateCloudConfig(ctx context.Context, instDir, name string, instConfig * | |
return os.WriteFile(filepath.Join(instDir, filenames.CloudConfig), config, 0o444) | ||
} | ||
|
||
func GenerateISO9660(ctx context.Context, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string) error { | ||
func GenerateISO9660(ctx context.Context, drv driver.Driver, instDir, name string, instConfig *limatype.LimaYAML, udpDNSLocalPort, tcpDNSLocalPort int, guestAgentBinary, nerdctlArchive string, vsockPort int, virtioPort string) error { | ||
args, err := templateArgs(ctx, true, instDir, name, instConfig, udpDNSLocalPort, tcpDNSLocalPort, vsockPort, virtioPort) | ||
if err != nil { | ||
return err | ||
|
@@ -372,6 +378,18 @@ func GenerateISO9660(ctx context.Context, instDir, name string, instConfig *lima | |
return err | ||
} | ||
|
||
driverScripts, err := drv.BootScripts() | ||
if err != nil { | ||
return fmt.Errorf("failed to get boot scripts: %w", err) | ||
} | ||
|
||
for filename, content := range driverScripts { | ||
layout = append(layout, iso9660util.Entry{ | ||
Path: fmt.Sprintf("boot/%s", filename), | ||
Reader: strings.NewReader(string(content)), | ||
}) | ||
} | ||
|
||
for i, f := range instConfig.Provision { | ||
switch f.Mode { | ||
case limatype.ProvisionModeSystem, limatype.ProvisionModeUser, limatype.ProvisionModeDependency: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,13 +15,13 @@ type Lifecycle interface { | |
// Validate returns error if the current driver isn't support for given config | ||
Validate(_ context.Context) error | ||
|
||
// Initialize is called on creating the instance for initialization. | ||
// Create is called on creating the instance for the first time. | ||
// (e.g., creating "vz-identifier" file) | ||
// | ||
// Initialize MUST return nil when it is called against an existing instance. | ||
// Create MUST return nil when it is called against an existing instance. | ||
// | ||
// Initialize does not create the disks. | ||
Initialize(_ context.Context) error | ||
// Create does not create the disks. | ||
Create(_ context.Context) error | ||
|
||
// CreateDisk returns error if the current driver fails in creating disk | ||
CreateDisk(_ context.Context) error | ||
|
@@ -34,6 +34,12 @@ type Lifecycle interface { | |
// Stop will terminate the running vm instance. | ||
// It returns error if there are any errors during Stop | ||
Stop(_ context.Context) error | ||
|
||
Delete(_ context.Context) error | ||
|
||
InspectStatus(_ context.Context, inst *limatype.Instance) string | ||
|
||
BootScripts() (map[string][]byte, error) | ||
} | ||
|
||
// GUI defines GUI-related operations. | ||
|
@@ -54,12 +60,6 @@ type SnapshotManager interface { | |
ListSnapshots(ctx context.Context) (string, error) | ||
} | ||
|
||
// Registration defines operations for registering and unregistering the driver instance. | ||
type Registration interface { | ||
Register(ctx context.Context) error | ||
Unregister(ctx context.Context) error | ||
} | ||
|
||
// GuestAgent defines operations for the guest agent. | ||
type GuestAgent interface { | ||
// ForwardGuestAgent returns if the guest agent sock needs forwarding by host agent. | ||
|
@@ -74,23 +74,33 @@ type Driver interface { | |
Lifecycle | ||
GUI | ||
SnapshotManager | ||
Registration | ||
GuestAgent | ||
|
||
Info() Info | ||
|
||
// SetConfig sets the configuration for the instance. | ||
// Configure sets the configuration for the instance. | ||
Configure(inst *limatype.Instance) *ConfiguredDriver | ||
|
||
AcceptConfig(cfg *limatype.LimaYAML, filePath string) error | ||
FillConfig(cfg *limatype.LimaYAML, filePath string) error | ||
|
||
SSHAddress(ctx context.Context) (string, error) | ||
} | ||
|
||
type ConfiguredDriver struct { | ||
Driver | ||
} | ||
|
||
type Info struct { | ||
DriverName string `json:"driverName"` | ||
CanRunGUI bool `json:"canRunGui,omitempty"` | ||
VsockPort int `json:"vsockPort"` | ||
VirtioPort string `json:"virtioPort"` | ||
InstanceDir string `json:"instanceDir,omitempty"` | ||
DriverName string `json:"driverName"` | ||
CanRunGUI bool `json:"canRunGui,omitempty"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't this be in a "DriverFeatures" ? Can be fixed later |
||
VsockPort int `json:"vsockPort"` | ||
VirtioPort string `json:"virtioPort"` | ||
InstanceDir string `json:"instanceDir,omitempty"` | ||
Features DriverFeatures `json:"features"` | ||
} | ||
|
||
type DriverFeatures struct { | ||
DynamicSSHAddress bool `json:"dynamicSSHAddress"` | ||
SkipSocketForwarding bool `json:"skipSocketForwarding"` | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
--vm-type
is not guaranteed to work as an edit flag.e.g., this will probably not work
Probably we need a warning when
--vm-type
is specified as an edit flag for an existing instance, but it can be worked out later.