Skip to content

Commit

Permalink
fix: Fix confusing warning about port mapping (#396)
Browse files Browse the repository at this point in the history
## Description:
That was happening when the portal daemon was not running

## Is this change user facing?
NO
<!-- 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 Mar 30, 2023
1 parent cfe4310 commit 2bc2e13
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
17 changes: 17 additions & 0 deletions cli/cli/commands/run/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/kurtosis-tech/kurtosis/cli/cli/helpers/portal_manager"
"github.com/kurtosis-tech/kurtosis/cli/cli/user_support_constants"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface"
"github.com/kurtosis-tech/kurtosis/contexts-config-store/store"
metrics_client "github.com/kurtosis-tech/metrics-library/golang/lib/client"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -330,6 +331,21 @@ func run(
logrus.Info("Not mapping service ports locally as requested")
return nil
}

currentContext, err := store.GetContextsConfigStore().GetCurrentContext()
if err != nil {
logrus.Warnf("Could not retrieve the current context. Kurtosis will assume context is local and not" +
"map the enclave service ports. If you're running on a remote context and are seeing this error, then" +
"the enclave services will be unreachable locally. Turn on debug logging to see the actual error.")
logrus.Debugf("Error was: %v", err.Error())
return nil
}
if !store.IsRemote(currentContext) {
logrus.Debugf("Current context is local, not mapping enclave service ports")
return nil
}

// Context is remote. All enclave service ports will be mapped locally
portalManager := portal_manager.NewPortalManager()
portsMapping := map[uint16]*services.PortSpec{}
for serviceInEnclaveName, servicesInEnclaveUuid := range servicesInEnclavePostRun {
Expand All @@ -351,6 +367,7 @@ func run(
logrus.Warnf("The enclave was successfully run but the following port(s) could not be mapped locally: %s. "+
"The associated service(s) will not be reachable on the local host",
strings.Join(stringifiedPortMapping, portMappingSeparatorForLogs))
logrus.Debugf("Error was: %v", err.Error())
return nil
}
logrus.Infof("Successfully mapped %d ports. All services running inside the enclave are reachable locally on"+
Expand Down
14 changes: 14 additions & 0 deletions cli/cli/commands/service/add/add.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/kurtosis-tech/kurtosis/cli/cli/helpers/portal_manager"
"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/kurtosis/contexts-config-store/store"
metrics_client "github.com/kurtosis-tech/metrics-library/golang/lib/client"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -319,6 +320,19 @@ func run(
publicPorts := serviceCtx.GetPublicPorts()
publicIpAddr := serviceCtx.GetMaybePublicIPAddress()

currentContext, err := store.GetContextsConfigStore().GetCurrentContext()
if err != nil {
logrus.Warnf("Could not retrieve the current context. Kurtosis will assume context is local and not" +
"map the service ports. If you're running on a remote context and are seeing this error, then" +
"the service will be unreachable locally. Turn on debug logging to see the actual error.")
logrus.Debugf("Error was: %v", err.Error())
return nil
}
if !store.IsRemote(currentContext) {
logrus.Debugf("Current context is local, not mapping service ports")
return nil
}

// Map the service public ports to their local port
if mapPorts {
portalManager := portal_manager.NewPortalManager()
Expand Down

0 comments on commit 2bc2e13

Please sign in to comment.