Skip to content

Commit

Permalink
add optional names to tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
tedim52 committed Jun 6, 2024
1 parent ffbd30b commit 93028a5
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func NewRunPythonService(
Name: RunPythonBuiltinName,

Arguments: []*builtin_argument.BuiltinArgument{
{
Name: TaskNameArgName,
IsOptional: true,
ZeroValueProvider: builtin_argument.ZeroValueProvider[starlark.String],
},
{
Name: RunArgName,
IsOptional: false,
Expand Down Expand Up @@ -163,8 +168,16 @@ type RunPythonCapabilities struct {
}

func (builtin *RunPythonCapabilities) Interpret(locatorOfModuleInWhichThisBuiltinIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) {
randomUuid := uuid.NewRandom()
builtin.name = fmt.Sprintf("task-%v", randomUuid.String())
if arguments.IsSet(TaskNameArgName) {
taskName, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, TaskNameArgName)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", TaskNameArgName)
}
builtin.name = taskName.GoString()
} else {
randomUuid := uuid.NewRandom()
builtin.name = fmt.Sprintf("task-%v", randomUuid.String())
}

pythonScript, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, RunArgName)
if err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import (
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_packages"
"github.com/kurtosis-tech/kurtosis/core/server/api_container/server/startosis_engine/startosis_validator"
"github.com/kurtosis-tech/stacktrace"
"github.com/xtgo/uuid"
"go.starlark.net/starlark"
"go.starlark.net/starlarkstruct"
)
Expand All @@ -49,6 +48,11 @@ func NewRunShService(
Name: RunShBuiltinName,

Arguments: []*builtin_argument.BuiltinArgument{
{
Name: TaskNameArgName,
IsOptional: true,
ZeroValueProvider: builtin_argument.ZeroValueProvider[starlark.String],
},
{
Name: RunArgName,
IsOptional: false,
Expand Down Expand Up @@ -141,6 +145,22 @@ type RunShCapabilities struct {
}

func (builtin *RunShCapabilities) Interpret(locatorOfModuleInWhichThisBuiltinIsBeingCalled string, arguments *builtin_argument.ArgumentValuesSet) (starlark.Value, *startosis_errors.InterpretationError) {
if arguments.IsSet(TaskNameArgName) {
taskName, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, TaskNameArgName)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", TaskNameArgName)
}
builtin.name = taskName.GoString()
} else {
randomUuid := uuid.NewRandom()
builtin.name = fmt.Sprintf("task-%v", randomUuid.String())
}
taskName, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, TaskNameArgName)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", TaskNameArgName)
}
builtin.name = taskName.GoString()

runCommand, err := builtin_argument.ExtractArgumentValue[starlark.String](arguments, RunArgName)
if err != nil {
return nil, startosis_errors.WrapWithInterpretationError(err, "Unable to extract value for '%s' argument", RunArgName)
Expand Down Expand Up @@ -225,8 +245,6 @@ func (builtin *RunShCapabilities) Interpret(locatorOfModuleInWhichThisBuiltinIsB
return nil, startosis_errors.NewInterpretationError("An error occurred while generating UUID for future reference for %v instruction", RunShBuiltinName)
}
builtin.resultUuid = resultUuid
randomUuid := uuid.NewRandom()
builtin.name = fmt.Sprintf("task-%v", randomUuid.String())

defaultDescription := runningShScriptPrefix
if len(builtin.run) < shScriptPrintCharLimit {
Expand All @@ -253,7 +271,7 @@ func (builtin *RunShCapabilities) Validate(_ *builtin_argument.ArgumentValuesSet
// Make task as its own entity instead of currently shown under services
func (builtin *RunShCapabilities) Execute(ctx context.Context, _ *builtin_argument.ArgumentValuesSet) (string, error) {
// swap env vars with their runtime value
serviceConfigWithReplacedEnvVars, err := repacaeMagicStringsInEnvVars(builtin.runtimeValueStore, builtin.serviceConfig)
serviceConfigWithReplacedEnvVars, err := replaceMagicStringsInEnvVars(builtin.runtimeValueStore, builtin.serviceConfig)
if err != nil {
return "", stacktrace.Propagate(err, "An error occurred replacing magic strings in env vars.")
}
Expand Down Expand Up @@ -343,7 +361,7 @@ func getCommandToRun(builtin *RunShCapabilities) (string, error) {
return maybeSubCommandWithRuntimeValues, nil
}

func repacaeMagicStringsInEnvVars(runtimeValueStore *runtime_value_store.RuntimeValueStore, serviceConfig *service.ServiceConfig) (
func replaceMagicStringsInEnvVars(runtimeValueStore *runtime_value_store.RuntimeValueStore, serviceConfig *service.ServiceConfig) (
*service.ServiceConfig,
error) {
var envVars map[string]string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
// shared constants
const (
ImageNameArgName = "image"
TaskNameArgName = "name"
RunArgName = "run"
StoreFilesArgName = "store"
WaitArgName = "wait"
Expand Down

0 comments on commit 93028a5

Please sign in to comment.