Skip to content

Commit fbf186d

Browse files
committed
pkg/driver/qemu: Avoid calling checkBinarySignature() from FillConfig().
This change separates `checkBinarySignature()` from `validateConfig()` to prevent calling them from `FillConfig()`. fixes #4142 Signed-off-by: Norio Nomura <norio.nomura@gmail.com>
1 parent c71bc48 commit fbf186d

File tree

1 file changed

+21
-13
lines changed

1 file changed

+21
-13
lines changed

pkg/driver/qemu/qemu_driver.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,16 @@ func (l *LimaQemuDriver) Configure(inst *limatype.Instance) *driver.ConfiguredDr
7878
}
7979

8080
func (l *LimaQemuDriver) Validate(ctx context.Context) error {
81-
return validateConfig(ctx, l.Instance.Config)
81+
if err := validateArch(ctx, l.Instance.Config); err != nil {
82+
return err
83+
}
84+
return validateConfig(l.Instance.Config)
8285
}
8386

84-
func validateConfig(ctx context.Context, cfg *limatype.LimaYAML) error {
87+
func validateConfig(cfg *limatype.LimaYAML) error {
8588
if cfg == nil {
8689
return errors.New("configuration is nil")
8790
}
88-
if runtime.GOOS == "darwin" {
89-
var vmArch string
90-
if cfg.Arch != nil {
91-
vmArch = *cfg.Arch
92-
}
93-
if err := checkBinarySignature(ctx, vmArch); err != nil {
94-
return err
95-
}
96-
}
9791
if err := validateMountType(cfg); err != nil {
9892
return err
9993
}
@@ -119,6 +113,20 @@ func validateConfig(ctx context.Context, cfg *limatype.LimaYAML) error {
119113
return nil
120114
}
121115

116+
// Helper method for checking the binary signature on macOS.
117+
func validateArch(ctx context.Context, cfg *limatype.LimaYAML) error {
118+
if runtime.GOOS == "darwin" {
119+
var vmArch string
120+
if cfg.Arch != nil {
121+
vmArch = *cfg.Arch
122+
}
123+
if err := checkBinarySignature(ctx, vmArch); err != nil {
124+
return err
125+
}
126+
}
127+
return nil
128+
}
129+
122130
// Helper method for mount type validation.
123131
func validateMountType(cfg *limatype.LimaYAML) error {
124132
if cfg.MountType != nil && *cfg.MountType == limatype.VIRTIOFS && runtime.GOOS != "linux" {
@@ -135,7 +143,7 @@ func validateMountType(cfg *limatype.LimaYAML) error {
135143
return nil
136144
}
137145

138-
func (l *LimaQemuDriver) FillConfig(ctx context.Context, cfg *limatype.LimaYAML, filePath string) error {
146+
func (l *LimaQemuDriver) FillConfig(_ context.Context, cfg *limatype.LimaYAML, filePath string) error {
139147
if cfg.VMType == nil {
140148
cfg.VMType = ptr.Of(limatype.QEMU)
141149
}
@@ -198,7 +206,7 @@ func (l *LimaQemuDriver) FillConfig(ctx context.Context, cfg *limatype.LimaYAML,
198206
return fmt.Errorf("mount type %q is explicitly unsupported", *cfg.MountType)
199207
}
200208

201-
return validateConfig(ctx, cfg)
209+
return validateConfig(cfg)
202210
}
203211

204212
func (l *LimaQemuDriver) BootScripts() (map[string][]byte, error) {

0 commit comments

Comments
 (0)