Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: using the CLI+KurtosisCloud should not rely on the local Docker engine running #1726

Merged
merged 3 commits into from
Nov 9, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 23 additions & 8 deletions cli/cli/commands/kurtosis_context/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package set
import (
"context"
"fmt"

"github.com/kurtosis-tech/kurtosis-portal/api/golang/constructors"
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/highlevel/context_id_arg"
"github.com/kurtosis-tech/kurtosis/cli/cli/command_framework/lowlevel"
Expand All @@ -16,11 +15,15 @@ import (
"github.com/kurtosis-tech/kurtosis/contexts-config-store/store"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"
"strings"
)

const (
contextIdentifierArgKey = "context"
contextIdentifierArgIsGreedy = false

dockerDaemonIsNotRunningErrorSubStr = "Is the docker daemon running?"
cantConnectToLocalKubernetesErrorSubStr = "connect: connection refused"
)

var ContextSetCmd = &lowlevel.LowlevelKurtosisCommand{
Expand Down Expand Up @@ -66,12 +69,15 @@ func SetContext(
if err != nil {
return stacktrace.Propagate(err, "An error occurred creating an engine manager.")
}
if err := engineManager.StopEngineIdempotently(ctx); err != nil {
return stacktrace.Propagate(err, "An error occurred stopping the local engine. The local engine"+
"needs to be stopped before the context can be set. The engine status can be obtained running"+
"kurtosis %s %s and it can be stopped manually by running kurtosis %s %s.",
command_str_consts.EngineCmdStr, command_str_consts.EngineStatusCmdStr,
command_str_consts.EngineCmdStr, command_str_consts.EngineStopCmdStr)
if stopLocalEngineErr := engineManager.StopEngineIdempotently(ctx); stopLocalEngineErr != nil {
if !isDockerOrKubernetesNotRunningErr(stopLocalEngineErr) {
return stacktrace.Propagate(stopLocalEngineErr, "An error occurred stopping the local engine. The local engine "+
"needs to be stopped before the context can be set. The engine status can be obtained running "+
"kurtosis %s %s and it can be stopped manually by running kurtosis %s %s.",
command_str_consts.EngineCmdStr, command_str_consts.EngineStatusCmdStr,
command_str_consts.EngineCmdStr, command_str_consts.EngineStopCmdStr)
}

}
}

Expand Down Expand Up @@ -126,7 +132,7 @@ func SetContext(
} else {
// We stop the portal when the user switches back to the local context.
// We do that to be consistent with the start above.
// However the portal is designed to also work with the local context with a client and server
// However, the portal is designed to also work with the local context with a client and server
// running locally.
if err := portalManager.StopExisting(ctx); err != nil {
return stacktrace.Propagate(err, "An error occurred stopping Kurtosis Portal")
Expand Down Expand Up @@ -159,3 +165,12 @@ func SetContext(
isContextSetSuccessful = true
return nil
}

func isDockerOrKubernetesNotRunningErr(err error) bool {
rootCauseErrStr := stacktrace.RootCause(err).Error()
if strings.Contains(rootCauseErrStr, dockerDaemonIsNotRunningErrorSubStr) ||
strings.Contains(rootCauseErrStr, cantConnectToLocalKubernetesErrorSubStr) {
return true
}
return false
}