Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#1469 from saschagrunert/log-reopen
Browse files Browse the repository at this point in the history
Add support to reopen container logs
  • Loading branch information
k8s-ci-robot authored Jun 27, 2024
2 parents db407a2 + 35c9728 commit 7cb99e5
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions cmd/crictl/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"time"

timetypes "github.com/docker/docker/api/types/time"
"github.com/sirupsen/logrus"
"github.com/urfave/cli/v2"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
Expand All @@ -50,6 +51,11 @@ var logsCommand = &cli.Command{
Aliases: []string{"p"},
Usage: "Print the logs for the previous instance of the container in a pod if it exists",
},
&cli.BoolFlag{
Name: "reopen",
Aliases: []string{"r"},
Usage: "Reopen the container logs for the provided container",
},
&cli.Int64Flag{
Name: "tail",
Value: -1,
Expand Down Expand Up @@ -86,6 +92,15 @@ var logsCommand = &cli.Command{
return err
}

if c.Bool("reopen") {
if _, err := InterruptableRPC(nil, func(ctx context.Context) (any, error) {
return nil, runtimeService.ReopenContainerLog(ctx, containerID)
}); err != nil {
return fmt.Errorf("reopen container logs: %w", err)
}
logrus.Info("Container logs reopened")
}

tailLines := c.Int64("tail")
limitBytes := c.Int64("limit-bytes")
since, err := parseTimestamp(c.String("since"))
Expand Down

0 comments on commit 7cb99e5

Please sign in to comment.