Skip to content

Commit

Permalink
feat: Make service start and stop support multiple services (#1304)
Browse files Browse the repository at this point in the history
## Description:
<!-- Describe this change, how it works, and the motivation behind it.
-->

## 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. -->
Closes #1089
  • Loading branch information
victorcolombo committed Sep 18, 2023
1 parent ec6ea14 commit 1b34b00
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 20 deletions.
24 changes: 14 additions & 10 deletions cli/cli/commands/service/start/start.go
Expand Up @@ -3,6 +3,7 @@ package start
import (
"context"
"fmt"
"github.com/sirupsen/logrus"

"github.com/kurtosis-tech/kurtosis/api/golang/core/kurtosis_core_rpc_api_bindings"
"github.com/kurtosis-tech/kurtosis/api/golang/core/lib/enclaves"
Expand All @@ -27,7 +28,7 @@ const (

serviceIdentifierArgKey = "service"
isServiceIdentifierArgOptional = false
isServiceIdentifierArgGreedy = false
isServiceIdentifierArgGreedy = true

kurtosisBackendCtxKey = "kurtosis-backend"
engineClientCtxKey = "engine-client"
Expand Down Expand Up @@ -62,8 +63,8 @@ var ServiceStartCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosis
service_identifier_arg.NewServiceIdentifierArg(
serviceIdentifierArgKey,
enclaveIdentifierArgKey,
isServiceIdentifierArgGreedy,
isServiceIdentifierArgOptional,
isServiceIdentifierArgGreedy,
),
},
Flags: []*flags.FlagConfig{},
Expand All @@ -83,7 +84,7 @@ func run(
return stacktrace.Propagate(err, "An error occurred getting the enclave identifier value using key '%v'", enclaveIdentifierArgKey)
}

serviceIdentifier, err := args.GetNonGreedyArg(serviceIdentifierArgKey)
serviceIdentifiers, err := args.GetGreedyArg(serviceIdentifierArgKey)
if err != nil {
return stacktrace.Propagate(err, "An error occurred getting the service identifier value using key '%v'", serviceIdentifierArgKey)
}
Expand All @@ -98,15 +99,18 @@ func run(
return stacktrace.Propagate(err, "An error occurred getting an enclave context from enclave info for enclave '%v'", enclaveIdentifier)
}

serviceContext, err := enclaveCtx.GetServiceContext(serviceIdentifier)
if err != nil {
return stacktrace.NewError("Couldn't validate whether the service exists for identifier '%v'", serviceIdentifier)
}
for _, serviceIdentifier := range serviceIdentifiers {
logrus.Infof("Starting service '%v'", serviceIdentifier)
serviceContext, err := enclaveCtx.GetServiceContext(serviceIdentifier)
if err != nil {
return stacktrace.NewError("Couldn't validate whether the service exists for identifier '%v'", serviceIdentifier)
}

serviceName := serviceContext.GetServiceName()
serviceName := serviceContext.GetServiceName()

if err := startServiceStarlarkCommand(ctx, enclaveCtx, serviceName); err != nil {
return stacktrace.Propagate(err, "An error occurred starting service '%v' from enclave '%v'", serviceIdentifier, enclaveIdentifier)
if err := startServiceStarlarkCommand(ctx, enclaveCtx, serviceName); err != nil {
return stacktrace.Propagate(err, "An error occurred starting service '%v' from enclave '%v'", serviceIdentifier, enclaveIdentifier)
}
}
return nil
}
Expand Down
24 changes: 14 additions & 10 deletions cli/cli/commands/service/stop/stop.go
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface"
metrics_client "github.com/kurtosis-tech/metrics-library/golang/lib/client"
"github.com/kurtosis-tech/stacktrace"
"github.com/sirupsen/logrus"
)

const (
Expand All @@ -26,7 +27,7 @@ const (

serviceIdentifierArgKey = "service"
isServiceIdentifierArgOptional = false
isServiceIdentifierArgGreedy = false
isServiceIdentifierArgGreedy = true

kurtosisBackendCtxKey = "kurtosis-backend"
engineClientCtxKey = "engine-client"
Expand Down Expand Up @@ -61,8 +62,8 @@ var ServiceStopCmd = &engine_consuming_kurtosis_command.EngineConsumingKurtosisC
service_identifier_arg.NewServiceIdentifierArg(
serviceIdentifierArgKey,
enclaveIdentifierArgKey,
isServiceIdentifierArgGreedy,
isServiceIdentifierArgOptional,
isServiceIdentifierArgGreedy,
),
},
Flags: []*flags.FlagConfig{},
Expand All @@ -82,7 +83,7 @@ func run(
return stacktrace.Propagate(err, "An error occurred getting the enclave identifier value using key '%v'", enclaveIdentifierArgKey)
}

serviceIdentifier, err := args.GetNonGreedyArg(serviceIdentifierArgKey)
serviceIdentifiers, err := args.GetGreedyArg(serviceIdentifierArgKey)
if err != nil {
return stacktrace.Propagate(err, "An error occurred getting the service identifier value using key '%v'", serviceIdentifierArgKey)
}
Expand All @@ -97,15 +98,18 @@ func run(
return stacktrace.Propagate(err, "An error occurred getting an enclave context from enclave info for enclave '%v'", enclaveIdentifier)
}

serviceContext, err := enclaveCtx.GetServiceContext(serviceIdentifier)
if err != nil {
return stacktrace.NewError("Couldn't validate whether the service exists for identifier '%v'", serviceIdentifier)
}
for _, serviceIdentifier := range serviceIdentifiers {
logrus.Infof("Stopping service '%v'", serviceIdentifier)
serviceContext, err := enclaveCtx.GetServiceContext(serviceIdentifier)
if err != nil {
return stacktrace.NewError("Couldn't validate whether the service exists for identifier '%v'", serviceIdentifier)
}

serviceName := serviceContext.GetServiceName()
serviceName := serviceContext.GetServiceName()

if err := stopServiceStarlarkCommand(ctx, enclaveCtx, serviceName); err != nil {
return stacktrace.Propagate(err, "An error occurred stopping service '%v' from enclave '%v'", serviceIdentifier, enclaveIdentifier)
if err := stopServiceStarlarkCommand(ctx, enclaveCtx, serviceName); err != nil {
return stacktrace.Propagate(err, "An error occurred stopping service '%v' from enclave '%v'", serviceIdentifier, enclaveIdentifier)
}
}
return nil
}
Expand Down

0 comments on commit 1b34b00

Please sign in to comment.