Skip to content

Commit

Permalink
fix: show container status instead of service status in enclave inspe…
Browse files Browse the repository at this point in the history
…ct (#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
  • Loading branch information
h4ck3rk3y authored Oct 16, 2023
1 parent eb952bb commit 3e1208b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 13 deletions.
21 changes: 8 additions & 13 deletions cli/cli/commands/enclave/inspect/user_services.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "<none>"
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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
}
}

0 comments on commit 3e1208b

Please sign in to comment.