diff --git a/cmd/crictl/logs.go b/cmd/crictl/logs.go index ca3912d2d7..aba00cc845 100644 --- a/cmd/crictl/logs.go +++ b/cmd/crictl/logs.go @@ -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" @@ -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, @@ -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"))