Skip to content

Commit

Permalink
feat: Enclave inspect relying on the API container service only (#1070)
Browse files Browse the repository at this point in the history
## Description:
The current `enclave inspect` command gets the services info from the
backend and from the APIC. This is done to be able to display the
enclave details even when the enclave (APIC) is stopped. In practice,
inspecting a stopped enclave hasn't proven useful so we are migrating
this command to only use the APIC. This change is also required by the
bastion/remote host design because the CLI only has access to the remote
backend APIC.

The APIC provides all the information required except the service status
so we are adding it to `ServiceInfo`.

## Is this change user facing?
YES
  • Loading branch information
laurentluce committed Aug 7, 2023
1 parent 752d6c5 commit da171ea
Show file tree
Hide file tree
Showing 16 changed files with 811 additions and 652 deletions.
1,216 changes: 642 additions & 574 deletions api/golang/core/kurtosis_core_rpc_api_bindings/api_container_service.pb.go

Large diffs are not rendered by default.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Expand Up @@ -297,6 +297,7 @@ func NewServiceInfo(
privatePorts map[string]*kurtosis_core_rpc_api_bindings.Port,
maybePublicIpAddr string,
maybePublicPorts map[string]*kurtosis_core_rpc_api_bindings.Port,
serviceStatus kurtosis_core_rpc_api_bindings.ServiceStatus,
) *kurtosis_core_rpc_api_bindings.ServiceInfo {
return &kurtosis_core_rpc_api_bindings.ServiceInfo{
ServiceUuid: uuid,
Expand All @@ -306,6 +307,7 @@ func NewServiceInfo(
PrivatePorts: privatePorts,
MaybePublicIpAddr: maybePublicIpAddr,
MaybePublicPorts: maybePublicPorts,
ServiceStatus: serviceStatus,
}
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions api/protobuf/core/api_container_service.proto
Expand Up @@ -68,6 +68,12 @@ message Port {
string maybe_wait_timeout = 4;
}

enum ServiceStatus {
STOPPED = 0;
RUNNING = 1;
UNKNOWN = 2;
}

message ServiceInfo {
// UUID of the service
string service_uuid = 1;
Expand All @@ -93,6 +99,9 @@ message ServiceInfo {

// Shortened uuid of the service
string shortened_uuid = 7;

// Service status: stopped, running.
ServiceStatus service_status = 8;
}

// ==============================================================================================
Expand Down
32 changes: 32 additions & 0 deletions api/rust/src/api_container_api.rs
Expand Up @@ -88,6 +88,9 @@ pub struct ServiceInfo {
/// Shortened uuid of the service
#[prost(string, tag = "7")]
pub shortened_uuid: ::prost::alloc::string::String,
/// Service status: stopped, running.
#[prost(enumeration = "ServiceStatus", tag = "8")]
pub service_status: i32,
}
/// ==============================================================================================
/// Execute Starlark Arguments
Expand Down Expand Up @@ -552,6 +555,35 @@ pub struct FileArtifactContentsFileDescription {
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum ServiceStatus {
Stopped = 0,
Running = 1,
Unknown = 2,
}
impl ServiceStatus {
/// String value of the enum field names used in the ProtoBuf definition.
///
/// The values are not transformed in any way and thus are considered stable
/// (if the ProtoBuf definition does not change) and safe for programmatic use.
pub fn as_str_name(&self) -> &'static str {
match self {
ServiceStatus::Stopped => "STOPPED",
ServiceStatus::Running => "RUNNING",
ServiceStatus::Unknown => "UNKNOWN",
}
}
/// Creates an enum from field names used in the ProtoBuf definition.
pub fn from_str_name(value: &str) -> ::core::option::Option<Self> {
match value {
"STOPPED" => Some(Self::Stopped),
"RUNNING" => Some(Self::Running),
"UNKNOWN" => Some(Self::Unknown),
_ => None,
}
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, ::prost::Enumeration)]
#[repr(i32)]
pub enum KurtosisFeatureFlag {
NoInstructionsCaching = 0,
}
Expand Down
Expand Up @@ -61,6 +61,9 @@ export class ServiceInfo extends jspb.Message {
getShortenedUuid(): string;
setShortenedUuid(value: string): ServiceInfo;

getServiceStatus(): ServiceStatus;
setServiceStatus(value: ServiceStatus): ServiceInfo;

serializeBinary(): Uint8Array;
toObject(includeInstance?: boolean): ServiceInfo.AsObject;
static toObject(includeInstance: boolean, msg: ServiceInfo): ServiceInfo.AsObject;
Expand All @@ -78,6 +81,7 @@ export namespace ServiceInfo {
maybePublicPortsMap: Array<[string, Port.AsObject]>,
name: string,
shortenedUuid: string,
serviceStatus: ServiceStatus,
}
}

Expand Down Expand Up @@ -1072,6 +1076,11 @@ export namespace FileArtifactContentsFileDescription {
}
}

export enum ServiceStatus {
STOPPED = 0,
RUNNING = 1,
UNKNOWN = 2,
}
export enum KurtosisFeatureFlag {
NO_INSTRUCTIONS_CACHING = 0,
}
Expand Up @@ -43,6 +43,7 @@ goog.exportSymbol('proto.api_container_api.RunStarlarkPackageArgs.StarlarkPackag
goog.exportSymbol('proto.api_container_api.RunStarlarkScriptArgs', null, global);
goog.exportSymbol('proto.api_container_api.ServiceIdentifiers', null, global);
goog.exportSymbol('proto.api_container_api.ServiceInfo', null, global);
goog.exportSymbol('proto.api_container_api.ServiceStatus', null, global);
goog.exportSymbol('proto.api_container_api.StarlarkError', null, global);
goog.exportSymbol('proto.api_container_api.StarlarkError.ErrorCase', null, global);
goog.exportSymbol('proto.api_container_api.StarlarkExecutionError', null, global);
Expand Down Expand Up @@ -1109,7 +1110,8 @@ proto.api_container_api.ServiceInfo.toObject = function(includeInstance, msg) {
maybePublicIpAddr: jspb.Message.getFieldWithDefault(msg, 4, ""),
maybePublicPortsMap: (f = msg.getMaybePublicPortsMap()) ? f.toObject(includeInstance, proto.api_container_api.Port.toObject) : [],
name: jspb.Message.getFieldWithDefault(msg, 6, ""),
shortenedUuid: jspb.Message.getFieldWithDefault(msg, 7, "")
shortenedUuid: jspb.Message.getFieldWithDefault(msg, 7, ""),
serviceStatus: jspb.Message.getFieldWithDefault(msg, 8, 0)
};

if (includeInstance) {
Expand Down Expand Up @@ -1178,6 +1180,10 @@ proto.api_container_api.ServiceInfo.deserializeBinaryFromReader = function(msg,
var value = /** @type {string} */ (reader.readString());
msg.setShortenedUuid(value);
break;
case 8:
var value = /** @type {!proto.api_container_api.ServiceStatus} */ (reader.readEnum());
msg.setServiceStatus(value);
break;
default:
reader.skipField();
break;
Expand Down Expand Up @@ -1250,6 +1256,13 @@ proto.api_container_api.ServiceInfo.serializeBinaryToWriter = function(message,
f
);
}
f = message.getServiceStatus();
if (f !== 0.0) {
writer.writeEnum(
8,
f
);
}
};


Expand Down Expand Up @@ -1387,6 +1400,24 @@ proto.api_container_api.ServiceInfo.prototype.setShortenedUuid = function(value)
};


/**
* optional ServiceStatus service_status = 8;
* @return {!proto.api_container_api.ServiceStatus}
*/
proto.api_container_api.ServiceInfo.prototype.getServiceStatus = function() {
return /** @type {!proto.api_container_api.ServiceStatus} */ (jspb.Message.getFieldWithDefault(this, 8, 0));
};


/**
* @param {!proto.api_container_api.ServiceStatus} value
* @return {!proto.api_container_api.ServiceInfo} returns this
*/
proto.api_container_api.ServiceInfo.prototype.setServiceStatus = function(value) {
return jspb.Message.setProto3EnumField(this, 8, value);
};



/**
* List of repeated fields within this message type.
Expand Down Expand Up @@ -8474,6 +8505,15 @@ proto.api_container_api.FileArtifactContentsFileDescription.prototype.hasTextPre
};


/**
* @enum {number}
*/
proto.api_container_api.ServiceStatus = {
STOPPED: 0,
RUNNING: 1,
UNKNOWN: 2
};

/**
* @enum {number}
*/
Expand Down
1 change: 1 addition & 0 deletions api/typescript/src/core/lib/enclaves/enclave_context.ts
Expand Up @@ -254,6 +254,7 @@ export class EnclaveContext {
serviceCtxPrivatePorts,
serviceInfo.getMaybePublicIpAddr(),
serviceCtxPublicPorts,
serviceInfo.getServiceStatus(),
);

return ok(serviceContext);
Expand Down
8 changes: 7 additions & 1 deletion api/typescript/src/core/lib/services/service_context.ts
@@ -1,6 +1,6 @@
import { err, ok, Result } from 'neverthrow';
import { newExecCommandArgs } from '../constructor_calls';
import type { ExecCommandArgs } from '../../kurtosis_core_rpc_api_bindings/api_container_service_pb';
import type { ExecCommandArgs, ServiceStatus } from '../../kurtosis_core_rpc_api_bindings/api_container_service_pb';
import type { PortSpec } from './port_spec';
import type { ServiceName, ServiceUUID } from './service';
import { GenericApiContainerClient } from '../enclaves/generic_api_container_client';
Expand All @@ -15,6 +15,7 @@ export class ServiceContext {
private readonly privatePorts: Map<string, PortSpec>,
private readonly publicIpAddress: string,
private readonly publicPorts: Map<string, PortSpec>,
private readonly serviceStatus: ServiceStatus,
) {}

// Docs available at https://docs.kurtosis.com/sdk/#getservicename---servicename
Expand Down Expand Up @@ -47,6 +48,11 @@ export class ServiceContext {
return this.publicPorts
}

// Docs available at https://docs.kurtosis.com/sdk/#getservicestatus---servicestatus
public getServiceStatus(): ServiceStatus {
return this.serviceStatus
}

// Docs available at https://docs.kurtosis.com/sdk/#execcommandliststring-command---int-exitcode-string-logs
public async execCommand(command: string[]): Promise<Result<[number, string], Error>> {
const execCommandArgs: ExecCommandArgs = newExecCommandArgs(this.serviceName, command);
Expand Down
3 changes: 1 addition & 2 deletions cli/cli/commands/enclave/inspect/files_artifacts.go
Expand Up @@ -6,7 +6,6 @@ import (
"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/output_printers"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/uuid_generator"
"github.com/kurtosis-tech/stacktrace"
"sort"
Expand All @@ -17,7 +16,7 @@ const (
fileNameHeader = "Name"
)

func printFilesArtifacts(ctx context.Context, kurtosisCtx *kurtosis_context.KurtosisContext, _ backend_interface.KurtosisBackend, enclaveInfo *kurtosis_engine_rpc_api_bindings.EnclaveInfo, showFullUuids bool, _ bool) error {
func printFilesArtifacts(ctx context.Context, kurtosisCtx *kurtosis_context.KurtosisContext, enclaveInfo *kurtosis_engine_rpc_api_bindings.EnclaveInfo, showFullUuids bool, _ bool) error {
enclaveContext, err := kurtosisCtx.GetEnclaveContext(ctx, enclaveInfo.GetName())
if err != nil {
return stacktrace.Propagate(err, "An error occurred while fetching enclave with name '%v'", enclaveInfo.GetName())
Expand Down
11 changes: 6 additions & 5 deletions cli/cli/commands/enclave/inspect/inspect.go
Expand Up @@ -47,12 +47,13 @@ const (
kurtosisBackendCtxKey = "kurtosis-backend"
engineClientCtxKey = "engine-client"

filesArtifactsHeader = "Files Artifacts"
userServicesArtifactsHeader = "User Services"
filesArtifactsHeader = "Files Artifacts"
)

var enclaveObjectPrintingFuncs = map[string]func(ctx context.Context, kurtosisCtx *kurtosis_context.KurtosisContext, kurtosisBackend backend_interface.KurtosisBackend, enclaveInfo *kurtosis_engine_rpc_api_bindings.EnclaveInfo, showFullUuid bool, isAPIContainerRunning bool) error{
"User Services": printUserServices,
filesArtifactsHeader: printFilesArtifacts,
var enclaveObjectPrintingFuncs = map[string]func(ctx context.Context, kurtosisCtx *kurtosis_context.KurtosisContext, enclaveInfo *kurtosis_engine_rpc_api_bindings.EnclaveInfo, showFullUuid bool, isAPIContainerRunning bool) error{
userServicesArtifactsHeader: printUserServices,
filesArtifactsHeader: printFilesArtifacts,
}

var EnclaveInspectCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosisCommand{
Expand Down Expand Up @@ -171,7 +172,7 @@ func PrintEnclaveInspect(ctx context.Context, kurtosisBackend backend_interface.
padStr := strings.Repeat(headerPadChar, numPadChars)
fmt.Printf("%v %v %v\n", padStr, header, padStr)

if err := printingFunc(ctx, kurtosisCtx, kurtosisBackend, enclaveInfo, showFullUuids, isApiContainerRunning); err != nil {
if err := printingFunc(ctx, kurtosisCtx, enclaveInfo, showFullUuids, isApiContainerRunning); err != nil {
logrus.Error(err)
headersWithPrintErrs = append(headersWithPrintErrs, header)
}
Expand Down

0 comments on commit da171ea

Please sign in to comment.