Skip to content

Commit d2ac116

Browse files
authored
gcp(logs): make --watch more resilient to remote errors (#1537)
1 parent 691aea3 commit d2ac116

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

provider/gcp/gcp_instance.go

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -435,15 +435,13 @@ func (p *GCloud) PrintInstanceLogs(ctx *lepton.Context, instancename string, wat
435435
if watch {
436436
line := int64(0)
437437
for {
438-
439438
l, last, err := p.getLogs(ctx, instancename, line)
440439
if err != nil {
441440
fmt.Println(err)
441+
} else {
442+
line = last
443+
fmt.Printf(l)
442444
}
443-
444-
line = last
445-
446-
fmt.Printf(l)
447445
time.Sleep(1 * time.Second)
448446
}
449447
}
@@ -464,17 +462,10 @@ func (p *GCloud) GetInstanceLogs(ctx *lepton.Context, instancename string) (stri
464462

465463
func (p *GCloud) getLogs(ctx *lepton.Context, instancename string, start int64) (string, int64, error) {
466464
context := context.TODO()
467-
468465
cloudConfig := ctx.Config().CloudConfig
469-
lastPos := start
470-
471-
resp, err := p.Service.Instances.GetSerialPortOutput(cloudConfig.ProjectID, cloudConfig.Zone, instancename).Start(lastPos).Context(context).Do()
466+
resp, err := p.Service.Instances.GetSerialPortOutput(cloudConfig.ProjectID, cloudConfig.Zone, instancename).Start(start).Context(context).Do()
472467
if err != nil {
473-
return "", resp.Next, err
474-
}
475-
if resp.Contents != "" {
476-
return resp.Contents, resp.Next, nil
468+
return "", start, err
477469
}
478-
479-
return "", resp.Next, nil
470+
return resp.Contents, resp.Next, nil
480471
}

0 commit comments

Comments
 (0)