Skip to content

Commit

Permalink
feat(run)!: Disable QEMU preamble and add option to show it (#656)
Browse files Browse the repository at this point in the history
Approved-by: Alexander Jung <[email protected]>
  • Loading branch information
nderjung authored Jul 25, 2023
2 parents 0f3ebc3 + fc1faf7 commit c6f82ab
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 2 deletions.
19 changes: 18 additions & 1 deletion machine/qemu/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@
// You may not use this file except in compliance with the License.
package qemu

import "encoding/gob"
import (
"encoding/gob"

"kraftkit.sh/cmdfactory"
)

var qemuShowSgaBiosPreamble bool

func init() {
// Register only used supported interfaces later used for serialization. To
Expand Down Expand Up @@ -468,4 +474,15 @@ func init() {

// CLI configuration
gob.Register(QemuConfig{})

// Register additional command-line arguments
cmdfactory.RegisterFlag(
"kraft run",
cmdfactory.BoolVar(
&qemuShowSgaBiosPreamble,
"qemu-sgabios-preamble",
false,
"Show the QEMU SGABIOS preamble when running a unikernel",
),
)
}
25 changes: 24 additions & 1 deletion machine/qemu/v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -685,7 +685,30 @@ func (service *machineV1alpha1Service) Pause(ctx context.Context, machine *machi

// Logs implements kraftkit.sh/api/machine/v1alpha1.MachineService
func (service *machineV1alpha1Service) Logs(ctx context.Context, machine *machinev1alpha1.Machine) (chan string, chan error, error) {
return logtail.NewLogTail(ctx, machine.Status.LogFile)
out, errOut, err := logtail.NewLogTail(ctx, machine.Status.LogFile)
if err != nil {
return nil, nil, err
}

// Wait and trim the preamble from the logs before returning
for {
select {
case line := <-out:
if !qemuShowSgaBiosPreamble {
if strings.Contains(line, "Booting from ") {
qemuShowSgaBiosPreamble = true
}
continue
}
return out, errOut, nil

case err := <-errOut:
return nil, nil, err

case <-ctx.Done():
return out, errOut, nil
}
}
}

// Get implements kraftkit.sh/api/machine/v1alpha1/MachineService.Get
Expand Down

0 comments on commit c6f82ab

Please sign in to comment.