From 35c972822eace3d8c856bad6fa569e61cf93cbf9 Mon Sep 17 00:00:00 2001 From: Sascha Grunert Date: Thu, 27 Jun 2024 11:42:07 +0200 Subject: [PATCH] Add support to reopen container logs Signed-off-by: Sascha Grunert --- cmd/crictl/logs.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/crictl/logs.go b/cmd/crictl/logs.go index 9166a8c386..484f9e7497 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" @@ -49,6 +50,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, @@ -85,6 +91,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"))