Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bugfix(k8s): Drop TailContainer's logsContext to avoid early cancel #337

Merged
merged 3 commits into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions executor/linux/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,7 @@ func (c *client) StreamBuild(ctx context.Context) error {
return nil
})
case <-ctx.Done():
c.Logger.Debug("streaming context canceled")
// build done or canceled
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion executor/local/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func (c *client) StreamBuild(ctx context.Context) error {
select {
case req := <-c.streamRequests:
streams.Go(func() error {
fmt.Fprintf(os.Stdout, "streaming %s container %s", req.Key, req.Container.ID)
fmt.Fprintf(os.Stdout, "[%s: %s] > Streaming container '%s'...\n", req.Key, req.Container.Name, req.Container.ID)

err := req.Stream(streamCtx, req.Container)
if err != nil {
Expand Down
11 changes: 4 additions & 7 deletions runtime/kubernetes/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -232,10 +232,6 @@ func (c *client) setupContainerEnvironment(ctn *pipeline.Container) error {
func (c *client) TailContainer(ctx context.Context, ctn *pipeline.Container) (io.ReadCloser, error) {
c.Logger.Tracef("tailing output for container %s", ctn.ID)

// create a logsContext that will be canceled at the end of this
logsContext, logsDone := context.WithCancel(ctx)
defer logsDone()

// create object to store container logs
var logs io.ReadCloser

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

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

Expand Down