Skip to content

Commit 69101f7

Browse files
authored
bugfix(k8s): Drop TailContainer's logsContext to avoid early cancel (#337)
1 parent e8d5718 commit 69101f7

File tree

3 files changed

+6
-8
lines changed

3 files changed

+6
-8
lines changed

executor/linux/build.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,7 @@ func (c *client) StreamBuild(ctx context.Context) error {
536536
return nil
537537
})
538538
case <-ctx.Done():
539+
c.Logger.Debug("streaming context canceled")
539540
// build done or canceled
540541
return nil
541542
}

executor/local/build.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ func (c *client) StreamBuild(ctx context.Context) error {
374374
select {
375375
case req := <-c.streamRequests:
376376
streams.Go(func() error {
377-
fmt.Fprintf(os.Stdout, "streaming %s container %s", req.Key, req.Container.ID)
377+
fmt.Fprintf(os.Stdout, "[%s: %s] > Streaming container '%s'...\n", req.Key, req.Container.Name, req.Container.ID)
378378

379379
err := req.Stream(streamCtx, req.Container)
380380
if err != nil {

runtime/kubernetes/container.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -232,10 +232,6 @@ func (c *client) setupContainerEnvironment(ctn *pipeline.Container) error {
232232
func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io.ReadCloser, error) {
233233
c.Logger.Tracef("tailing output for container %s", ctn.ID)
234234

235-
// create a logsContext that will be canceled at the end of this
236-
logsContext, logsDone := context.WithCancel(ctx)
237-
defer logsDone()
238-
239235
// create object to store container logs
240236
var logs io.ReadCloser
241237

@@ -259,9 +255,9 @@ func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io
259255
stream, err := c.Kubernetes.CoreV1().
260256
Pods(c.config.Namespace).
261257
GetLogs(c.Pod.ObjectMeta.Name, opts).
262-
Stream(logsContext)
258+
Stream(ctx)
263259
if err != nil {
264-
c.Logger.Errorf("%v", err)
260+
c.Logger.Errorf("error while requesting pod/logs stream for container %s: %v", ctn.ID, err)
265261
return false, nil
266262
}
267263

@@ -303,8 +299,9 @@ func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io
303299
// perform the function to capture logs with periodic backoff
304300
//
305301
// https://pkg.go.dev/k8s.io/apimachinery/pkg/util/wait?tab=doc#ExponentialBackoff
306-
err := wait.ExponentialBackoffWithContext(logsContext, backoff, logsFunc)
302+
err := wait.ExponentialBackoffWithContext(ctx, backoff, logsFunc)
307303
if err != nil {
304+
c.Logger.Errorf("exponential backoff error while tailing container %s: %v", ctn.ID, err)
308305
return nil, err
309306
}
310307

0 commit comments

Comments
 (0)