Skip to content

Commit

Permalink
use single kurtosis_backend interface def for exec
Browse files Browse the repository at this point in the history
  • Loading branch information
christophercampbell committed Jan 14, 2025
1 parent 6b9898f commit 97dc53d
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 148 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,6 @@ func (backend *DockerKurtosisBackend) GetUserServiceLogs(

// NOTE: This function will block while the exec is ongoing; if we need more perf we can make it async
func (backend *DockerKurtosisBackend) RunUserServiceExecCommands(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
userServiceCommands map[service.ServiceUUID][]string,
) (
map[service.ServiceUUID]*exec_result.ExecResult,
map[service.ServiceUUID]error,
error,
) {
return user_service_functions.RunUserServiceExecCommands(ctx, enclaveUuid, "", userServiceCommands, backend.dockerManager)
}

func (backend *DockerKurtosisBackend) RunUserServiceExecCommandsAsUser(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
containerUser string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func storeConfigInVolume(
}
for i := uint(0); i < maxRetries; i++ {
outputBuffer := &bytes.Buffer{}
exitCode, err := dockerManager.RunExecCommand(ctx, containerId, execCmd, outputBuffer)
exitCode, err := dockerManager.RunUserServiceExecCommands(ctx, containerId, "", execCmd, outputBuffer)
if err == nil {
if exitCode == creationSuccessExitCode {
logrus.Debugf("The Docker config file was successfully added into the volume.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bytes"
"context"
"fmt"
"os"
"path"
"time"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/consts"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_manager"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"
"os"
"path"
"time"
)

const (
Expand Down Expand Up @@ -124,7 +125,7 @@ func storeTokenInVolume(
}
for i := uint(0); i < maxRetries; i++ {
outputBuffer := &bytes.Buffer{}
exitCode, err := dockerManager.RunExecCommand(ctx, containerId, execCmd, outputBuffer)
exitCode, err := dockerManager.RunUserServiceExecCommands(ctx, containerId, "", execCmd, outputBuffer)
if err == nil {
if exitCode == authStorageCreationSuccessExitCode {
logrus.Debugf("The GitHub auth token was successfully added into the volume.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ func (fluent *fluentbitConfigurationCreator) createFluentbitConfigFileInVolume(
}
for i := uint(0); i < maxRetries; i++ {
outputBuffer := &bytes.Buffer{}
exitCode, err := dockerManager.RunExecCommand(ctx, containerId, execCmd, outputBuffer)
exitCode, err := dockerManager.RunUserServiceExecCommands(ctx, containerId, "", execCmd, outputBuffer)
if err == nil {
if exitCode == configFileCreationSuccessExitCode {
logrus.Debugf("The Fluentbit config file with content '%v' was successfully added into the volume", configFileContentStr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"encoding/json"
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key"
"io"
"net"
"os"
Expand All @@ -14,6 +13,8 @@ import (
"strings"
"time"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key"

"github.com/docker/docker/pkg/stdcopy"
"github.com/docker/go-connections/nat"
"github.com/gammazero/workerpool"
Expand Down Expand Up @@ -379,7 +380,7 @@ func WaitForPortAvailabilityUsingNetstat(
}
for i := uint(0); i < maxRetries; i++ {
outputBuffer := &bytes.Buffer{}
exitCode, err := dockerManager.RunExecCommand(ctx, containerId, execCmd, outputBuffer)
exitCode, err := dockerManager.RunUserServiceExecCommands(ctx, containerId, "", execCmd, outputBuffer)
if err == nil {
if exitCode == netstatSuccessExitCode {
return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@ package user_service_functions
import (
"bytes"
"context"
"reflect"

"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"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/exec_result"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/service"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/operation_parallelizer"
"github.com/kurtosis-tech/stacktrace"
"reflect"
)

// TODO Switch these to streaming so that huge command outputs don't blow up the API container memory
Expand Down Expand Up @@ -119,7 +120,7 @@ func createExecOperation(
execOutputBuf := &bytes.Buffer{}
userServiceDockerContainer := userServiceDockerResource.ServiceContainer

exitCode, err := dockerManager.RunExecCommandAsUser(
exitCode, err := dockerManager.RunUserServiceExecCommands(
ctx,
userServiceDockerContainer.GetId(),
containerUser,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -990,14 +990,10 @@ func (manager *DockerManager) GetContainerLogs(
}

/*
RunExecCommand
RunUserServiceExecCommands
Executes the given command inside the container with the given ID, blocking until the command completes
*/
func (manager *DockerManager) RunExecCommand(context context.Context, containerId string, command []string, logOutput io.Writer) (int32, error) {
return manager.RunExecCommandAsUser(context, containerId, "", command, logOutput)
}

func (manager *DockerManager) RunExecCommandAsUser(context context.Context, containerId, userId string, command []string, logOutput io.Writer) (int32, error) {
func (manager *DockerManager) RunUserServiceExecCommands(context context.Context, containerId, userId string, command []string, logOutput io.Writer) (int32, error) {
dockerClient := manager.dockerClient
execConfig := types.ExecConfig{
User: userId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -347,12 +347,17 @@ func (backend *KubernetesKurtosisBackend) GetUserServiceLogs(
func (backend *KubernetesKurtosisBackend) RunUserServiceExecCommands(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
containerUser string,
userServiceCommands map[service.ServiceUUID][]string,
) (
succesfulUserServiceExecResults map[service.ServiceUUID]*exec_result.ExecResult,
erroredUserServiceUuids map[service.ServiceUUID]error,
resultErr error,
) {
if containerUser != "" {
resultErr = stacktrace.NewError("--user not implemented for kurtosis backend")
return
}
return user_services_functions.RunUserServiceExecCommands(
ctx,
enclaveUuid,
Expand All @@ -363,20 +368,6 @@ func (backend *KubernetesKurtosisBackend) RunUserServiceExecCommands(
backend.kubernetesManager)
}

func (backend *KubernetesKurtosisBackend) RunUserServiceExecCommandsAsUser(
ctx context.Context,
_ enclave.EnclaveUUID,
_ string,
_ map[service.ServiceUUID][]string,
) (
succesfulUserServiceExecResults map[service.ServiceUUID]*exec_result.ExecResult,
erroredUserServiceUuids map[service.ServiceUUID]error,
resultErr error,
) {
resultErr = stacktrace.NewError("--user not implemented for kurtosis backend")
return
}

func (backend *KubernetesKurtosisBackend) RunUserServiceExecCommandWithStreamedOutput(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ func (backend *MetricsReportingKurtosisBackend) GetUserServiceLogs(
return userServiceLogs, erroredUserServices, nil
}

func (backend *MetricsReportingKurtosisBackend) RunUserServiceExecCommandsAsUser(
func (backend *MetricsReportingKurtosisBackend) RunUserServiceExecCommands(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
containerUser string,
Expand All @@ -329,7 +329,7 @@ func (backend *MetricsReportingKurtosisBackend) RunUserServiceExecCommandsAsUser
erroredUserServiceUuids map[service.ServiceUUID]error,
resultErr error,
) {
successfulUserServiceExecResults, erroredUserServiceUuids, err := backend.underlying.RunUserServiceExecCommandsAsUser(ctx, enclaveUuid, containerUser, userServiceCommands)
successfulUserServiceExecResults, erroredUserServiceUuids, err := backend.underlying.RunUserServiceExecCommands(ctx, enclaveUuid, containerUser, userServiceCommands)
if err != nil {
return nil, nil, stacktrace.Propagate(
err,
Expand All @@ -341,18 +341,6 @@ func (backend *MetricsReportingKurtosisBackend) RunUserServiceExecCommandsAsUser
return successfulUserServiceExecResults, erroredUserServiceUuids, nil
}

func (backend *MetricsReportingKurtosisBackend) RunUserServiceExecCommands(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
userServiceCommands map[service.ServiceUUID][]string,
) (
successfulUserServiceExecResults map[service.ServiceUUID]*exec_result.ExecResult,
erroredUserServiceUuids map[service.ServiceUUID]error,
resultErr error,
) {
return backend.underlying.RunUserServiceExecCommands(ctx, enclaveUuid, userServiceCommands)
}

func (backend *MetricsReportingKurtosisBackend) RunUserServiceExecCommandWithStreamedOutput(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
Expand Down
11 changes: 0 additions & 11 deletions container-engine-lib/lib/backend_interface/kurtosis_backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,6 @@ type KurtosisBackend interface {

// Executes a shell command inside an user service instance indenfified by its ID
RunUserServiceExecCommands(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
userServiceCommands map[service.ServiceUUID][]string,
) (
successfulUserServiceExecResults map[service.ServiceUUID]*exec_result.ExecResult,
erroredUserServiceUuids map[service.ServiceUUID]error,
resultErr error,
)

// Executes a shell command inside an user service instance indenfified by its ID and as a specifc user
RunUserServiceExecCommandsAsUser(
ctx context.Context,
enclaveUuid enclave.EnclaveUUID,
containerUser string,
Expand Down
93 changes: 12 additions & 81 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 97dc53d

Please sign in to comment.