@@ -5,7 +5,7 @@ package krunkit
55
66import (
77 "context"
8- _ "embed"
8+ "embed"
99 "errors"
1010 "fmt"
1111 "net"
@@ -39,25 +39,9 @@ type LimaKrunkitDriver struct {
3939 krunkitWaitCh chan error
4040}
4141
42- type KrunkitOpts struct {
43- GPUAccel * bool `yaml:"gpuAccel,omitempty"`
44- }
45-
46- func NewKrunkitOpts (cfg * limatype.LimaYAML ) (* KrunkitOpts , error ) {
47- var krunkitOpts KrunkitOpts
48- if err := limayaml .Convert (cfg .VMOpts [vmType ], & krunkitOpts , "vmOpts.krunkit" ); err != nil {
49- return nil , err
50- }
51-
52- return & krunkitOpts , nil
53- }
54-
5542var (
5643 _ driver.Driver = (* LimaKrunkitDriver )(nil )
5744 vmType limatype.VMType = "krunkit"
58-
59- //go:embed hack/install-vulkan-gpu.sh
60- gpuProvisionScript string
6145)
6246
6347func New () * LimaKrunkitDriver {
@@ -188,17 +172,6 @@ func validateConfig(cfg *limatype.LimaYAML) error {
188172 return fmt .Errorf ("field `mountType` must be %q or %q for krunkit driver, got %q" , limatype .VIRTIOFS , limatype .REVSSHFS , * cfg .MountType )
189173 }
190174
191- // If GPU acceleration is requested, ensure Fedora image/template is used
192- krunkitOpts , err := NewKrunkitOpts (cfg )
193- if err != nil {
194- return err
195- }
196- if krunkitOpts .GPUAccel != nil && * krunkitOpts .GPUAccel {
197- if ! isFedoraConfigured (cfg ) {
198- logrus .Warn ("gpuAccel: true requires a Fedora image (use a Fedora base template or image)" )
199- }
200- }
201-
202175 return nil
203176}
204177
@@ -231,51 +204,39 @@ func (l *LimaKrunkitDriver) FillConfig(_ context.Context, cfg *limatype.LimaYAML
231204
232205 cfg .VMType = ptr .Of (vmType )
233206
234- krunkitOpts , err := NewKrunkitOpts (cfg )
235- if err != nil {
236- return err
237- }
238-
239- if krunkitOpts .GPUAccel == nil {
240- krunkitOpts .GPUAccel = ptr .Of (false )
241- }
242-
243- if * krunkitOpts .GPUAccel {
244- gpuInstallScript := limatype.Provision {
245- Mode : limatype .ProvisionModeData ,
246- Script : ptr .Of (gpuProvisionScript ),
247- ProvisionData : limatype.ProvisionData {
248- Content : ptr .Of (gpuProvisionScript ),
249- Path : ptr .Of ("/usr/local/bin/install-vulkan-gpu.sh" ),
250- Permissions : ptr .Of ("0755" ),
251- Overwrite : ptr .Of (false ),
252- Owner : cfg .User .Name ,
253- },
254- }
255- cfg .Provision = append (cfg .Provision , gpuInstallScript )
256- cfg .Message = "To enable GPU support for krunkit, run the following command inside the VM:\n \033 [32msudo install-vulkan-gpu.sh\033 [0m\n "
257- }
258-
259207 return validateConfig (cfg )
260208}
261209
210+ //go:embed boot/*.sh
211+ var bootFS embed.FS
212+
262213func (l * LimaKrunkitDriver ) BootScripts () (map [string ][]byte , error ) {
263- // Override default reboot-if-required with a no-op because Fedora does not support this well and
264- // takes a long time to start up.
265- krunkitOpts , err := NewKrunkitOpts (l .Instance .Config )
266- if err != nil {
267- return nil , err
268- }
269- if krunkitOpts .GPUAccel == nil || ! * krunkitOpts .GPUAccel {
270- return nil , nil
214+ scripts := make (map [string ][]byte )
215+
216+ entries , err := bootFS .ReadDir ("boot" )
217+ if err == nil && ! isFedoraConfigured (l .Instance .Config ) {
218+ for _ , entry := range entries {
219+ if entry .IsDir () {
220+ continue
221+ }
222+
223+ content , err := bootFS .ReadFile ("boot/" + entry .Name ())
224+ if err != nil {
225+ return nil , err
226+ }
227+
228+ scripts [entry .Name ()] = content
229+ }
271230 }
272- scripts := map [string ][]byte {
273- "00-reboot-if-required.sh" : []byte (`#!/bin/sh
231+
232+ // Disabled by krunkit driver for Fedora to make boot time faster
233+ if isFedoraConfigured (l .Instance .Config ) {
234+ scripts ["00-reboot-if-required.sh" ] = []byte (`#!/bin/sh
274235set -eu
275- # Disabled by krunkit driver
276236exit 0
277- ` ),
237+ ` )
278238 }
239+
279240 return scripts , nil
280241}
281242
0 commit comments