Skip to content

Commit f7861fb

Browse files
authored
Merge pull request #3910 from unsuman/refactor/support-external-drivers
refactor: support external drivers for the recent changes
2 parents 87a61f9 + d4dc0a5 commit f7861fb

File tree

27 files changed

+693
-326
lines changed

27 files changed

+693
-326
lines changed

cmd/limactl/clone.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ func cloneAction(cmd *cobra.Command, args []string) error {
8080
if err != nil {
8181
return err
8282
}
83-
if err := driverutil.ResolveVMType(y, filePath); err != nil {
84-
return fmt.Errorf("failed to accept config for %q: %w", filePath, err)
83+
if err := driverutil.ResolveVMType(ctx, y, filePath); err != nil {
84+
return fmt.Errorf("failed to resolve vm for %q: %w", filePath, err)
8585
}
8686
if err := limayaml.Validate(y, true); err != nil {
8787
return saveRejectedYAML(yBytes, err)

cmd/limactl/edit.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func editAction(cmd *cobra.Command, args []string) error {
121121
if err != nil {
122122
return err
123123
}
124-
if err := driverutil.ResolveVMType(y, filePath); err != nil {
125-
return fmt.Errorf("failed to accept config for %q: %w", filePath, err)
124+
if err := driverutil.ResolveVMType(ctx, y, filePath); err != nil {
125+
return fmt.Errorf("failed to resolve vm for %q: %w", filePath, err)
126126
}
127127
if err := limayaml.Validate(y, true); err != nil {
128128
return saveRejectedYAML(yBytes, err)

cmd/limactl/prune.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,8 +97,8 @@ func knownLocations(ctx context.Context) (map[string]limatype.File, error) {
9797
if err != nil {
9898
return nil, err
9999
}
100-
if err := driverutil.ResolveVMType(y, t.Name); err != nil {
101-
return nil, fmt.Errorf("failed to accept config for %q: %w", t.Name, err)
100+
if err := driverutil.ResolveVMType(ctx, y, t.Name); err != nil {
101+
return nil, fmt.Errorf("failed to resolve vm for %q: %w", t.Name, err)
102102
}
103103
maps.Copy(locations, locationsFromLimaYAML(y))
104104
}

cmd/limactl/start.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -363,8 +363,8 @@ func applyYQExpressionToExistingInstance(ctx context.Context, inst *limatype.Ins
363363
if err != nil {
364364
return nil, err
365365
}
366-
if err := driverutil.ResolveVMType(y, filePath); err != nil {
367-
return nil, fmt.Errorf("failed to accept config for %q: %w", filePath, err)
366+
if err := driverutil.ResolveVMType(ctx, y, filePath); err != nil {
367+
return nil, fmt.Errorf("failed to resolve vm for %q: %w", filePath, err)
368368
}
369369
if err := limayaml.Validate(y, true); err != nil {
370370
rejectedYAML := "lima.REJECTED.yaml"

cmd/limactl/template.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func fillDefaults(ctx context.Context, tmpl *limatmpl.Template) error {
8888
if err == nil {
8989
tmpl.Bytes, err = limayaml.Marshal(tmpl.Config, false)
9090
}
91-
if err := driverutil.ResolveVMType(tmpl.Config, filePath); err != nil {
91+
if err := driverutil.ResolveVMType(ctx, tmpl.Config, filePath); err != nil {
9292
logrus.Warnf("failed to resolve VM type for %q: %v", filePath, err)
9393
return nil
9494
}
@@ -251,7 +251,7 @@ func templateValidateAction(cmd *cobra.Command, args []string) error {
251251
if err != nil {
252252
return err
253253
}
254-
if err := driverutil.ResolveVMType(y, filePath); err != nil {
254+
if err := driverutil.ResolveVMType(ctx, y, filePath); err != nil {
255255
logrus.Warnf("failed to resolve VM type for %q: %v", filePath, err)
256256
return nil
257257
}

pkg/cidata/cidata.TEMPLATE.d/boot/05-rosetta-volume.sh

Lines changed: 0 additions & 33 deletions
This file was deleted.

pkg/driver/driver.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,15 @@ type ConfiguredDriver struct {
9292
}
9393

9494
type Info struct {
95-
DriverName string `json:"driverName"`
96-
CanRunGUI bool `json:"canRunGui,omitempty"`
9795
VsockPort int `json:"vsockPort"`
9896
VirtioPort string `json:"virtioPort"`
9997
InstanceDir string `json:"instanceDir,omitempty"`
10098
Features DriverFeatures `json:"features"`
10199
}
102100

103101
type DriverFeatures struct {
104-
DynamicSSHAddress bool `json:"dynamicSSHAddress"`
105-
SkipSocketForwarding bool `json:"skipSocketForwarding"`
102+
DriverName string `json:"driverName"`
103+
CanRunGUI bool `json:"canRunGui,omitempty"`
104+
DynamicSSHAddress bool `json:"dynamicSSHAddress"`
105+
SkipSocketForwarding bool `json:"skipSocketForwarding"`
106106
}

pkg/driver/external/client/methods.go

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ func (d *DriverClient) Validate(ctx context.Context) error {
3232
return nil
3333
}
3434

35-
func (d *DriverClient) Create(_ context.Context) error {
36-
return errors.New("create not implemented for external drivers")
35+
func (d *DriverClient) Create(ctx context.Context) error {
36+
d.logger.Debug("Initializing driver instance")
37+
38+
_, err := d.DriverSvc.Create(ctx, &emptypb.Empty{})
39+
if err != nil {
40+
d.logger.Errorf("Initialization failed: %v", err)
41+
return err
42+
}
43+
44+
d.logger.Debug("Driver instance initialized successfully")
45+
return nil
3746
}
3847

3948
func (d *DriverClient) CreateDisk(ctx context.Context) error {
@@ -93,8 +102,17 @@ func (d *DriverClient) Stop(ctx context.Context) error {
93102
return nil
94103
}
95104

96-
func (d *DriverClient) Delete(_ context.Context) error {
97-
return errors.New("delete not implemented for external drivers")
105+
func (d *DriverClient) Delete(ctx context.Context) error {
106+
d.logger.Debug("Deleting driver instance")
107+
108+
_, err := d.DriverSvc.Delete(ctx, &emptypb.Empty{})
109+
if err != nil {
110+
d.logger.Errorf("Failed to delete driver instance: %v", err)
111+
return err
112+
}
113+
114+
d.logger.Debug("Driver instance deleted successfully")
115+
return nil
98116
}
99117

100118
func (d *DriverClient) AcceptConfig(_ *limatype.LimaYAML, _ string) error {
@@ -239,7 +257,7 @@ func (d *DriverClient) Info() driver.Info {
239257
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
240258
defer cancel()
241259

242-
resp, err := d.DriverSvc.GetInfo(ctx, &emptypb.Empty{})
260+
resp, err := d.DriverSvc.Info(ctx, &emptypb.Empty{})
243261
if err != nil {
244262
d.logger.Errorf("Failed to get driver info: %v", err)
245263
return driver.Info{}
@@ -267,7 +285,7 @@ func (d *DriverClient) Configure(inst *limatype.Instance) *driver.ConfiguredDriv
267285
ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second)
268286
defer cancel()
269287

270-
_, err = d.DriverSvc.SetConfig(ctx, &pb.SetConfigRequest{
288+
_, err = d.DriverSvc.Configure(ctx, &pb.SetConfigRequest{
271289
InstanceConfigJson: instJSON,
272290
})
273291
if err != nil {
@@ -285,10 +303,27 @@ func (d *DriverClient) InspectStatus(_ context.Context, _ *limatype.Instance) st
285303
return ""
286304
}
287305

288-
func (d *DriverClient) SSHAddress(_ context.Context) (string, error) {
289-
return "", errors.New("sshAddress not implemented for external drivers")
306+
func (d *DriverClient) SSHAddress(ctx context.Context) (string, error) {
307+
d.logger.Debug("Getting SSH address for the driver instance")
308+
309+
resp, err := d.DriverSvc.SSHAddress(ctx, &emptypb.Empty{})
310+
if err != nil {
311+
d.logger.Errorf("Failed to get SSH address: %v", err)
312+
return "", err
313+
}
314+
315+
d.logger.Debugf("SSH address retrieved: %s", resp.Address)
316+
return resp.Address, nil
290317
}
291318

292319
func (d *DriverClient) BootScripts() (map[string][]byte, error) {
293-
return nil, errors.New("bootScripts not implemented for external drivers")
320+
d.logger.Debug("Getting boot scripts for the driver instance")
321+
resp, err := d.DriverSvc.BootScripts(context.Background(), &emptypb.Empty{})
322+
if err != nil {
323+
d.logger.Errorf("Failed to get boot scripts: %v", err)
324+
return nil, err
325+
}
326+
327+
d.logger.Debugf("Boot scripts retrieved successfully: %d scripts", len(resp.Scripts))
328+
return resp.Scripts, nil
294329
}

0 commit comments

Comments
 (0)