From 3e1208bc9340302db49a041fc93b1e2d565e6abc Mon Sep 17 00:00:00 2001 From: Gyanendra Mishra Date: Mon, 16 Oct 2023 13:48:07 +0100 Subject: [PATCH] fix: show container status instead of service status in enclave inspect (#1560) ## Description: If a service eventually dies we would still show `RUNNING` while in reality it would be stopped 1. Create an enclave 2. Stop a service 3. Use inspect -> this prints service status Running (Kurtosis was told to keep it running) Post this PR 3. This would print container status -> Stopped - actually reflecting reality ## Is this change user facing? YES ## References (if applicable): Closes #1351 --- .../commands/enclave/inspect/user_services.go | 21 +++++++---------- .../container_status_stringifier.go | 23 +++++++++++++++++++ 2 files changed, 31 insertions(+), 13 deletions(-) create mode 100644 cli/cli/helpers/container_status_stringifier/container_status_stringifier.go diff --git a/cli/cli/commands/enclave/inspect/user_services.go b/cli/cli/commands/enclave/inspect/user_services.go index 7ac185f5dc..983d75e480 100644 --- a/cli/cli/commands/enclave/inspect/user_services.go +++ b/cli/cli/commands/enclave/inspect/user_services.go @@ -5,22 +5,17 @@ import ( "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" "github.com/kurtosis-tech/kurtosis/api/golang/engine/kurtosis_engine_rpc_api_bindings" "github.com/kurtosis-tech/kurtosis/api/golang/engine/lib/kurtosis_context" + "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/container_status_stringifier" "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/output_printers" - "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/service_status_stringifier" "github.com/kurtosis-tech/kurtosis/cli/cli/helpers/user_services" "github.com/kurtosis-tech/stacktrace" ) const ( - userServiceUUIDColHeader = "UUID" - userServiceNameColHeader = "Name" - userServicePortsColHeader = "Ports" - userServiceStatusColHeader = "Status" - defaultEmptyIPAddrForServices = "" - emptyApplicationProtocol = "" - missingPortPlaceholder = "" - linkDelimeter = "://" - defaultEmptyIPAddrForAPIC = "" + userServiceUUIDColHeader = "UUID" + userServiceNameColHeader = "Name" + userServicePortsColHeader = "Ports" + userServiceStatusColHeader = "Status" ) func printUserServices(ctx context.Context, _ *kurtosis_context.KurtosisContext, enclaveInfo *kurtosis_engine_rpc_api_bindings.EnclaveInfo, showFullUuids bool, isAPIContainerRunning bool) error { @@ -49,8 +44,8 @@ func printUserServices(ctx context.Context, _ *kurtosis_context.KurtosisContext, uuidToPrint = uuidStr } - serviceStatus := userService.GetServiceStatus() - serviceStatusStr := service_status_stringifier.ServiceStatusStringifier(serviceStatus) + containerStatus := userService.GetContainer().GetStatus() + containerStatusStr := container_status_stringifier.ContainerStatusStringifier(containerStatus) portBindingLines, err := user_services.GetUserServicePortBindingStrings(userService) if err != nil { @@ -59,7 +54,7 @@ func printUserServices(ctx context.Context, _ *kurtosis_context.KurtosisContext, firstPortBindingLine := portBindingLines[0] additionalPortBindingLines := portBindingLines[1:] - if err := tablePrinter.AddRow(uuidToPrint, serviceIdStr, firstPortBindingLine, serviceStatusStr); err != nil { + if err := tablePrinter.AddRow(uuidToPrint, serviceIdStr, firstPortBindingLine, containerStatusStr); err != nil { return stacktrace.Propagate( err, "An error occurred adding row for user service with UUID '%v' to the table printer", diff --git a/cli/cli/helpers/container_status_stringifier/container_status_stringifier.go b/cli/cli/helpers/container_status_stringifier/container_status_stringifier.go new file mode 100644 index 0000000000..5d64f07c0b --- /dev/null +++ b/cli/cli/helpers/container_status_stringifier/container_status_stringifier.go @@ -0,0 +1,23 @@ +package container_status_stringifier + +import ( + "github.com/fatih/color" + "github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings" +) + +var ( + colorizeRunning = color.New(color.FgGreen).SprintFunc() + colorizeStopped = color.New(color.FgYellow).SprintFunc() +) + +func ContainerStatusStringifier(containerStatus kurtosis_core_rpc_api_bindings.Container_Status) string { + containerStatusStr := kurtosis_core_rpc_api_bindings.Container_Status_name[int32(containerStatus)] + switch containerStatus { + case kurtosis_core_rpc_api_bindings.Container_STOPPED: + return colorizeStopped(containerStatusStr) + case kurtosis_core_rpc_api_bindings.Container_RUNNING: + return colorizeRunning(containerStatusStr) + default: + return containerStatusStr + } +}