Skip to content

Commit

Permalink
feat: Remove --exec flag for kurtosis service shell (#712)
Browse files Browse the repository at this point in the history
## Description:
`--exec` flag for `kurtosis service shell` command is getting deleted in
favour of the new `kurtosis service exec` command.

## Is this change user facing?
YES
<!-- If yes, please add the "user facing" label to the PR -->
<!-- If yes, don't forget to include docs changes where relevant -->

## References (if applicable):
<!-- Add relevant Github Issues, Discord threads, or other helpful
information. -->
  • Loading branch information
Guillaume Bouvignies committed Jun 13, 2023
1 parent 8340651 commit d8bc320
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 60 deletions.
4 changes: 1 addition & 3 deletions .circleci/config.yml
Expand Up @@ -687,10 +687,8 @@ jobs:
- run: "${KURTOSIS_BINPATH} service add test-enclave test1 httpd --ports http=80"
- run: "${KURTOSIS_BINPATH} service add test-enclave test2 httpd --ports http=80"

# Shell & Exec
# Service Exec
# Emulates GitHub Actions
- run: "${KURTOSIS_BINPATH} service shell test-enclave test1 --exec 'echo 1' < /dev/null > /dev/null"
- run: "${KURTOSIS_BINPATH} service shell test-enclave test1 --exec 'echo 1'"
- run: "${KURTOSIS_BINPATH} service exec test-enclave test1 'echo hello'"
- run: "! ${KURTOSIS_BINPATH} service exec test-enclave test1 'echo hello; exit 1'"

Expand Down
26 changes: 7 additions & 19 deletions cli/cli/commands/service/shell/shell.go
Expand Up @@ -27,11 +27,11 @@ import (
)

const (
enclaveIdentifierArgKey = "enclave"
isEnclaveIdArgOptional = false
isEnclaveIdArgGreedy = false
commandToRunFlagKey = "exec"
commandToRunInsteadOfBashFlagKey = ""
enclaveIdentifierArgKey = "enclave"
isEnclaveIdArgOptional = false
isEnclaveIdArgGreedy = false

commandToRunInsteadOfBashEmpty = ""

serviceIdentifierArgKey = "service"
isServiceGuidArgOptional = false
Expand All @@ -47,14 +47,7 @@ var ServiceShellCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosis
LongDescription: "Starts a shell on the specified service",
KurtosisBackendContextKey: kurtosisBackendCtxKey,
EngineClientContextKey: engineClientCtxKey,
Flags: []*flags.FlagConfig{
{
Key: commandToRunFlagKey,
Usage: "If this flag is used Kurtosis will not run bash/sh on the container by default instead; Kurtosis will run the passed in command. Note if the command being run is multiple words you should wrap it in quotes",
Type: flags.FlagType_String,
Default: commandToRunInsteadOfBashFlagKey,
},
},
Flags: []*flags.FlagConfig{},
Args: []*args.ArgConfig{
enclave_id_arg.NewEnclaveIdentifierArg(
enclaveIdentifierArgKey,
Expand Down Expand Up @@ -89,11 +82,6 @@ func run(
return stacktrace.Propagate(err, "An error occurred getting the service identifier using arg key '%v'", serviceIdentifierArgKey)
}

commandToRunInsteadOfBash, err := flags.GetString(commandToRunFlagKey)
if err != nil {
return stacktrace.Propagate(err, "An error occurred while getting the command to run using key '%v'", commandToRunFlagKey)
}

kurtosisCtx, err := kurtosis_context.NewKurtosisContextFromLocalEngine()
if err != nil {
return stacktrace.Propagate(err, "An error occurred connecting to the local Kurtosis engine")
Expand All @@ -112,7 +100,7 @@ func run(
}
serviceUuid := service.ServiceUUID(serviceCtx.GetServiceUUID())

conn, err := kurtosisBackend.GetConnectionWithUserService(ctx, enclaveUuid, serviceUuid, commandToRunInsteadOfBash)
conn, err := kurtosisBackend.GetConnectionWithUserService(ctx, enclaveUuid, serviceUuid)
if err != nil {
return stacktrace.Propagate(err, "An error occurred getting connection with user service with UUID '%v' in enclave '%v'", serviceUuid, enclaveIdentifier)
}
Expand Down
Expand Up @@ -282,8 +282,8 @@ func (backend *DockerKurtosisBackend) RunUserServiceExecCommands(
return user_service_functions.RunUserServiceExecCommands(ctx, enclaveUuid, userServiceCommands, backend.dockerManager)
}

func (backend *DockerKurtosisBackend) GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID, commandToRunInsteadOfBash string) (net.Conn, error) {
return user_service_functions.GetConnectionWithUserService(ctx, enclaveUuid, serviceUuid, backend.dockerManager, commandToRunInsteadOfBash)
func (backend *DockerKurtosisBackend) GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID) (net.Conn, error) {
return user_service_functions.GetConnectionWithUserService(ctx, enclaveUuid, serviceUuid, backend.dockerManager)
}

// It returns io.ReadCloser which is a tar stream. It's up to the caller to close the reader.
Expand Down
Expand Up @@ -2,7 +2,6 @@ package user_service_functions

import (
"context"
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/shared_helpers"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/enclave"
Expand All @@ -11,14 +10,7 @@ import (
"net"
)

const (
defaultCommandToRunInsteadOfBash = ""
commandToRunIndex = 2
lineToEchoWhileUserWaitsForTheirCommandToBeRun = `echo "Running '%v'" && %v`
)

// We'll try to use the nicer-to-use shells first before we drop down to the lower shells
// If the user passes a different commandToRunInsteadOfBash than defaultCommandToRunInsteadOfBash we try to run that instead
var commandToRunWhenCreatingUserServiceShell = []string{
"sh",
"-c",
Expand All @@ -29,23 +21,18 @@ var commandToRunWhenCreatingUserServiceShell = []string{
fi`,
}

func GetConnectionWithUserService(ctx context.Context, enclaveId enclave.EnclaveUUID, serviceUuid service.ServiceUUID, dockerManager *docker_manager.DockerManager, commandToRunInsteadOfBash string) (net.Conn, error) {
func GetConnectionWithUserService(ctx context.Context, enclaveId enclave.EnclaveUUID, serviceUuid service.ServiceUUID, dockerManager *docker_manager.DockerManager) (net.Conn, error) {
_, serviceDockerResources, err := shared_helpers.GetSingleUserServiceObjAndResourcesNoMutex(ctx, enclaveId, serviceUuid, dockerManager)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred getting service object and Docker resources for service '%v' in enclave '%v'", serviceUuid, enclaveId)
}
container := serviceDockerResources.ServiceContainer

if commandToRunInsteadOfBash != defaultCommandToRunInsteadOfBash {
commandToRunWhenCreatingUserServiceShell[commandToRunIndex] = fmt.Sprintf(lineToEchoWhileUserWaitsForTheirCommandToBeRun, commandToRunInsteadOfBash, commandToRunInsteadOfBash)
}

hijackedResponse, err := dockerManager.CreateContainerExec(ctx, container.GetId(), commandToRunWhenCreatingUserServiceShell)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred getting a shell on user service with UUID '%v' in enclave '%v'", serviceUuid, enclaveId)
}

newConnection := hijackedResponse.Conn

return newConnection, nil
}
Expand Up @@ -332,7 +332,7 @@ func (backend *KubernetesKurtosisBackend) RunUserServiceExecCommands(
backend.kubernetesManager)
}

func (backend *KubernetesKurtosisBackend) GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUUID service.ServiceUUID, commandToRunInsteadOfBash string) (resultConn net.Conn, resultErr error) {
func (backend *KubernetesKurtosisBackend) GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUUID service.ServiceUUID) (resultConn net.Conn, resultErr error) {
// See https://github.com/kubernetes/client-go/issues/912
/*
in := streams.NewIn(os.Stdin)
Expand Down
Expand Up @@ -320,8 +320,8 @@ func (backend *MetricsReportingKurtosisBackend) RunUserServiceExecCommands(
return succesfulUserServiceExecResults, erroredUserServiceUuids, nil
}

func (backend *MetricsReportingKurtosisBackend) GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID, commandToRunInsteadOfBash string) (resultConn net.Conn, resultErr error) {
newConn, err := backend.underlying.GetConnectionWithUserService(ctx, enclaveUuid, serviceUuid, commandToRunInsteadOfBash)
func (backend *MetricsReportingKurtosisBackend) GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID) (resultConn net.Conn, resultErr error) {
newConn, err := backend.underlying.GetConnectionWithUserService(ctx, enclaveUuid, serviceUuid)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred getting connection with user service with UUID '%v'", serviceUuid)
}
Expand Down
Expand Up @@ -152,8 +152,8 @@ func (backend *RemoteContextKurtosisBackend) RunUserServiceExecCommands(ctx cont
return backend.remoteKurtosisBackend.RunUserServiceExecCommands(ctx, enclaveUuid, userServiceCommands)
}

func (backend *RemoteContextKurtosisBackend) GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID, commandToRunInsteadOfBash string) (resultConn net.Conn, resultErr error) {
return backend.remoteKurtosisBackend.GetConnectionWithUserService(ctx, enclaveUuid, serviceUuid, "")
func (backend *RemoteContextKurtosisBackend) GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID) (resultConn net.Conn, resultErr error) {
return backend.remoteKurtosisBackend.GetConnectionWithUserService(ctx, enclaveUuid, serviceUuid)
}

func (backend *RemoteContextKurtosisBackend) CopyFilesFromUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID, srcPathOnService string, output io.Writer) error {
Expand Down
Expand Up @@ -267,7 +267,7 @@ type KurtosisBackend interface {
)

// Get a connection with user service to execute commands in
GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID, commandToRunInsteadOfBash string) (resultConn net.Conn, resultErr error)
GetConnectionWithUserService(ctx context.Context, enclaveUuid enclave.EnclaveUUID, serviceUuid service.ServiceUUID) (resultConn net.Conn, resultErr error)

// Copy files, packaged as a TAR, from the given user service and writes the bytes to the given output writer
CopyFilesFromUserService(
Expand Down
31 changes: 15 additions & 16 deletions container-engine-lib/lib/backend_interface/mock_kurtosis_backend.go

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

0 comments on commit d8bc320

Please sign in to comment.