From 57e7a0dfffe6be207531188e840647011173ffd6 Mon Sep 17 00:00:00 2001 From: Wei Fu Date: Sat, 2 May 2020 22:26:48 +0800 Subject: [PATCH] crictl: add Runtime column for RuntimeHandler If the RuntimeHandler is empty, show (default) as CRI's default runtime. Signed-off-by: Wei Fu --- cmd/crictl/display.go | 33 +++++++++++++++++---------------- cmd/crictl/sandbox.go | 32 +++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 19 deletions(-) diff --git a/cmd/crictl/display.go b/cmd/crictl/display.go index 7acfda2cbf..aa6b10aa1a 100644 --- a/cmd/crictl/display.go +++ b/cmd/crictl/display.go @@ -24,22 +24,23 @@ import ( ) const ( - columnContainer = "CONTAINER" - columnImage = "IMAGE" - columnImageID = "IMAGE ID" - columnCreated = "CREATED" - columnState = "STATE" - columnName = "NAME" - columnAttempt = "ATTEMPT" - columnPodID = "POD ID" - columnNamespace = "NAMESPACE" - columnSize = "SIZE" - columnTag = "TAG" - columnDigest = "DIGEST" - columnMemory = "MEM" - columnInodes = "INODES" - columnDisk = "DISK" - columnCPU = "CPU %" + columnContainer = "CONTAINER" + columnImage = "IMAGE" + columnImageID = "IMAGE ID" + columnCreated = "CREATED" + columnState = "STATE" + columnName = "NAME" + columnAttempt = "ATTEMPT" + columnPodID = "POD ID" + columnPodRuntime = "RUNTIME" + columnNamespace = "NAMESPACE" + columnSize = "SIZE" + columnTag = "TAG" + columnDigest = "DIGEST" + columnMemory = "MEM" + columnInodes = "INODES" + columnDisk = "DISK" + columnCPU = "CPU %" ) // display use to output something on screen with table format. diff --git a/cmd/crictl/sandbox.go b/cmd/crictl/sandbox.go index f8ec378d11..233cd1ccbc 100644 --- a/cmd/crictl/sandbox.go +++ b/cmd/crictl/sandbox.go @@ -504,7 +504,15 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error { display := newTableDisplay(20, 1, 3, ' ', 0) if !opts.verbose && !opts.quiet { - display.AddRow([]string{columnPodID, columnCreated, columnState, columnName, columnNamespace, columnAttempt}) + display.AddRow([]string{ + columnPodID, + columnCreated, + columnState, + columnName, + columnNamespace, + columnAttempt, + columnPodRuntime, + }) } for _, pod := range r.Items { if opts.quiet { @@ -518,8 +526,15 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error { if !opts.noTrunc { id = getTruncatedID(id, "") } - display.AddRow([]string{id, ctm, convertPodState(pod.State), pod.Metadata.Name, - pod.Metadata.Namespace, fmt.Sprintf("%d", pod.Metadata.Attempt)}) + display.AddRow([]string{ + id, + ctm, + convertPodState(pod.State), + pod.Metadata.Name, + pod.Metadata.Namespace, + fmt.Sprintf("%d", pod.Metadata.Attempt), + getSandboxesRuntimeHandler(pod), + }) continue } @@ -553,6 +568,10 @@ func ListPodSandboxes(client pb.RuntimeServiceClient, opts listOptions) error { fmt.Printf("\t%s -> %s\n", k, pod.Annotations[k]) } } + fmt.Printf("%s: %s\n", + strings.Title(strings.ToLower(columnPodRuntime)), + getSandboxesRuntimeHandler(pod)) + fmt.Println() } @@ -572,6 +591,13 @@ func convertPodState(state pb.PodSandboxState) string { } } +func getSandboxesRuntimeHandler(sandbox *pb.PodSandbox) string { + if sandbox.RuntimeHandler == "" { + return "(default)" + } + return sandbox.RuntimeHandler +} + func getSandboxesList(sandboxesList []*pb.PodSandbox, opts listOptions) []*pb.PodSandbox { filtered := []*pb.PodSandbox{} for _, p := range sandboxesList {