From fc1faf750a87a1f2151205fde546676c4cacc5bd Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Mon, 24 Jul 2023 17:39:23 +0300 Subject: [PATCH] feat(run)!: Disable QEMU preamble and add option to show it Signed-off-by: Cezar Craciunoiu --- machine/qemu/init.go | 19 ++++++++++++++++++- machine/qemu/v1alpha1.go | 25 ++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/machine/qemu/init.go b/machine/qemu/init.go index c0b418643..023cb8041 100644 --- a/machine/qemu/init.go +++ b/machine/qemu/init.go @@ -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 @@ -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", + ), + ) } diff --git a/machine/qemu/v1alpha1.go b/machine/qemu/v1alpha1.go index 4595270fd..44b8b49e2 100644 --- a/machine/qemu/v1alpha1.go +++ b/machine/qemu/v1alpha1.go @@ -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