From 104d0f81950671706f25376f34702761e5581ccd Mon Sep 17 00:00:00 2001 From: Cezar Craciunoiu Date: Fri, 4 Oct 2024 12:59:12 +0300 Subject: [PATCH] fix(cloud): Ensure exit message is consistent When instances are stopped and logs are small enough there is a 50/50 chance that the exit message does not show because it is done in a separate thread. To fix this fetch details once before starting the thread. Signed-off-by: Cezar Craciunoiu --- .../cli/kraft/cloud/instance/logs/logs.go | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/internal/cli/kraft/cloud/instance/logs/logs.go b/internal/cli/kraft/cloud/instance/logs/logs.go index 998252b4e..9c3d8c678 100644 --- a/internal/cli/kraft/cloud/instance/logs/logs.go +++ b/internal/cli/kraft/cloud/instance/logs/logs.go @@ -150,11 +150,27 @@ func Logs(ctx context.Context, opts *LogOptions, args ...string) error { observations.Add(instance) - var inst *kcinstances.GetResponseItem + resp, err := opts.Client.Instances().WithMetro(opts.Metro).Get(ctx, instance) + if err != nil { + // Likely there was an issue performing the request; so we'll just + // skip and attempt to retrieve more logs. + if !errors.Is(err, io.EOF) { + log.G(ctx).Error(err) + } + + continue + } + + inst, err := resp.FirstOrErr() + if err != nil { + errGroup = append(errGroup, err) + } // Continuously check the state in a separate thread every 1 second. go func() { for { + time.Sleep(time.Second) + resp, err := opts.Client.Instances().WithMetro(opts.Metro).Get(ctx, instance) if err != nil { // Likely there was an issue performing the request; so we'll just @@ -174,8 +190,6 @@ func Logs(ctx context.Context, opts *LogOptions, args ...string) error { if len(observations.Items()) == 0 { return } - - time.Sleep(time.Second) } }()