Skip to content

Commit

Permalink
rebase changes
Browse files Browse the repository at this point in the history
Signed-off-by: fahed dorgaa <[email protected]>
  • Loading branch information
fahedouch committed Nov 1, 2023
1 parent 6f46d77 commit 10676af
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 7 additions & 3 deletions pkg/cmd/container/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@ import (
"os"
"os/signal"
"syscall"
"time"

"github.com/containerd/log"

"github.com/containerd/containerd"
"github.com/containerd/containerd/errdefs"
"github.com/containerd/log"
"github.com/containerd/nerdctl/pkg/api/types"
"github.com/containerd/nerdctl/pkg/api/types/cri"
"github.com/containerd/nerdctl/pkg/clientutil"
Expand Down Expand Up @@ -91,7 +91,11 @@ func Logs(ctx context.Context, client *containerd.Client, container string, opti
// Setup goroutine to send stop event if container task finishes:
go func() {
<-waitCh
log.G(ctx).Debugf("container task has finished, sending kill signal to log viewer")
// Wait for logger to process remaining logs after container exit
if err = logging.WaitForLogger(dataStore, l[labels.Namespace], found.Container.ID()); err != nil {
log.L.WithError(err).Error("failed to wait for logger shutdown")
}
log.L.Debugf("container task has finished, sending kill signal to log viewer")
stopChannel <- os.Interrupt
}()
}
Expand Down
7 changes: 4 additions & 3 deletions pkg/logging/logging.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,10 +177,11 @@ func getContainerWait(ctx context.Context, hostAddress string, config *logging.C
// If task was not found, it's possible that the container runtime is still being created.
// Retry every 100ms.
ticker := time.NewTicker(100 * time.Millisecond)
defer ticker.Stop()
for {
select {
case <-ctx.Done():
return nil, fmt.Errorf("timed out waiting for container task to start")
return nil, errors.New("timed out waiting for container task to start")
case <-ticker.C:
task, err = con.Task(ctx, nil)
if err != nil {
Expand All @@ -207,7 +208,7 @@ func loggingProcessAdapter(ctx context.Context, driver Driver, dataStore, hostAd
buf := make([]byte, 32<<10)
_, err := io.CopyBuffer(writer, reader, buf)
if err != nil {
logrus.Errorf("failed to copy stream: %s", err)
log.L.Errorf("failed to copy stream: %v", err)
}
}
go copyStream(config.Stdout, stdoutW)
Expand Down Expand Up @@ -244,7 +245,7 @@ func loggingProcessAdapter(ctx context.Context, driver Driver, dataStore, hostAd

exitCh, err := getContainerWait(ctx, hostAddress, config)
if err != nil {
logrus.Errorf("failed to get container task wait channel: %v", err)
log.L.Errorf("failed to get container task wait channel: %v", err)
return
}
<-exitCh
Expand Down

0 comments on commit 10676af

Please sign in to comment.