Skip to content

Commit

Permalink
chore: restructure scheduling API a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
rangoo94 committed Dec 20, 2024
1 parent 9337141 commit bb1b729
Show file tree
Hide file tree
Showing 8 changed files with 895 additions and 825 deletions.
2 changes: 1 addition & 1 deletion cmd/tcl/testworkflow-toolkit/execute/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func executeTestWorkflowGrpc(workflowName string, request testkube.TestWorkflowE
opts := []grpc.CallOption{grpc.UseCompressor(gzip.Name), grpc.MaxCallRecvMsgSize(math.MaxInt32)}
resp, err := client.ScheduleExecution(ctx, &cloud.ScheduleRequest{
EnvironmentId: cfg.Execution.EnvironmentId,
Selectors: []*cloud.ScheduleSelector{{Name: workflowName, Config: request.Config}},
Executions: []*cloud.ScheduleExecution{{Selector: &cloud.ScheduleResourceSelector{Name: workflowName}, Config: request.Config}},
DisableWebhooks: cfg.Execution.DisableWebhooks,
Tags: request.Tags,
RunningContext: &cloud.RunningContext{
Expand Down
17 changes: 8 additions & 9 deletions internal/app/api/v1/testworkflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,12 @@ func (s *TestkubeAPI) ExecuteTestWorkflowHandler() fiber.Handler {
return s.BadRequest(c, errPrefix, "invalid body", err)
}

// Pro edition only (tcl protected code)
runningContext, untrustedUser := testworkflowexecutor.GetNewRunningContext(request.RunningContext, request.ParentExecutionIds)
runningContext, user := testworkflowexecutor.GetNewRunningContext(request.RunningContext, request.ParentExecutionIds)

var scheduleSelector cloud.ScheduleSelector
var scheduleExecution cloud.ScheduleExecution
if name != "" {
scheduleSelector.Name = name
scheduleSelector.Config = request.Config
scheduleExecution.Selector = &cloud.ScheduleResourceSelector{Name: name}
scheduleExecution.Config = request.Config
} else if selector != "" {
sel, err := metav1.ParseToLabelSelector(selector)
if err != nil {
Expand All @@ -398,19 +397,19 @@ func (s *TestkubeAPI) ExecuteTestWorkflowHandler() fiber.Handler {
if len(sel.MatchExpressions) > 0 {
return s.InternalError(c, errPrefix, "invalid selector", errors.New("only simple selectors are allowed"))
}
scheduleSelector.LabelSelector = sel.MatchLabels
scheduleSelector.Config = request.Config
scheduleExecution.Selector = &cloud.ScheduleResourceSelector{Labels: sel.MatchLabels}
scheduleExecution.Config = request.Config
}

resp := s.testWorkflowExecutor.Execute(ctx, &cloud.ScheduleRequest{
EnvironmentId: "", // use default
Selectors: []*cloud.ScheduleSelector{&scheduleSelector},
Executions: []*cloud.ScheduleExecution{&scheduleExecution},
DisableWebhooks: request.DisableWebhooks,
Tags: request.Tags,
RunningContext: runningContext,
ParentExecutionIds: request.ParentExecutionIds,
KubernetesObjectName: request.TestWorkflowExecutionName,
UntrustedUser: untrustedUser,
User: user,
})

results := make([]testkube.TestWorkflowExecution, 0)
Expand Down
Loading

0 comments on commit bb1b729

Please sign in to comment.