Skip to content

Commit

Permalink
fix: additional running contexts
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <[email protected]>
  • Loading branch information
vsukhin committed Oct 8, 2024
1 parent f459b3b commit d972b1a
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,22 @@ func printPrettyOutput(ui *ui.UI, execution testkube.TestWorkflowExecution) {
ui.Warn("Running context: ")
ctx := execution.RunningContext
if ctx.Interface_ != nil {
ui.Warn("Interface: ", string(*ctx.Interface_.Type_))
ui.Warn("Interface: ")
ui.Warn(" Name: ", ctx.Interface_.Name)
if ctx.Interface_.Type_ != nil {
ui.Warn(" Type: ", string(*ctx.Interface_.Type_))
}
}
if ctx.Actor != nil {
ui.Warn("Actor: ", string(*ctx.Actor.Type_))
ui.Warn("Actor: ")
ui.Warn(" Name: ", ctx.Actor.Name)
ui.Warn(" Username: ", ctx.Actor.Username)
ui.Warn(" Email: ", ctx.Actor.Email)
ui.Warn(" Execution id: ", ctx.Actor.ExecutionId)
ui.Warn(" Execution path: ", ctx.Actor.ExecutionPath)
if ctx.Actor.Type_ != nil {
ui.Warn(" Type: ", string(*ctx.Actor.Type_))
}
}
}
if execution.Result != nil && execution.Result.Status != nil {
Expand Down
14 changes: 12 additions & 2 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
intcommon "github.com/kubeshop/testkube/internal/common"
apiclientv1 "github.com/kubeshop/testkube/pkg/api/v1/client"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/telemetry"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/constants"
"github.com/kubeshop/testkube/pkg/ui"
)
Expand Down Expand Up @@ -64,17 +65,26 @@ func NewRunTestWorkflowCmd() *cobra.Command {
ui.ExitOnError("getting client", err)

name := args[0]
runContext := telemetry.GetCliRunContext()
interfaceType := testkube.CLI_TestWorkflowRunningContextInterfaceType
if runContext == "others|local" {
runContext = ""
interfaceType = testkube.CICD_TestWorkflowRunningContextInterfaceType
}
execution, err := client.ExecuteTestWorkflow(name, testkube.TestWorkflowExecutionRequest{
Name: executionName,
Config: config,
DisableWebhooks: disableWebhooks,
Tags: tags,
RunningContext: &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Type_: intcommon.Ptr(testkube.CLI_TestWorkflowRunningContextInterfaceType),
Name: runContext,
Type_: intcommon.Ptr(interfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: intcommon.Ptr(testkube.USER_TestWorkflowRunningContextActorType),
Type_: intcommon.Ptr(testkube.USER_TestWorkflowRunningContextActorType),
Username: "",
Email: "",
},
},
})
Expand Down
19 changes: 15 additions & 4 deletions cmd/tcl/testworkflow-toolkit/commands/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,21 @@ func buildWorkflowExecution(workflow testworkflowsv1.StepExecuteWorkflow, async
var exec testkube.TestWorkflowExecution
for i := 0; i < CreateExecutionRetryOnFailureMaxAttempts; i++ {
exec, err = c.ExecuteTestWorkflow(workflow.Name, testkube.TestWorkflowExecutionRequest{
Name: workflow.ExecutionName,
Config: testworkflows.MapConfigValueKubeToAPI(workflow.Config),
DisableWebhooks: env.ExecutionDisableWebhooks(),
Tags: tags,
Name: workflow.ExecutionName,
Config: testworkflows.MapConfigValueKubeToAPI(workflow.Config),
DisableWebhooks: env.ExecutionDisableWebhooks(),
Tags: tags,
RunningContext: &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Type_: common.Ptr(testkube.API_TestWorkflowRunningContextInterfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Name: workflow.Name,
ExecutionId: env.ExecutionId(),
ExecutionPath: strings.Join(parentIds, "/"),
Type_: common.Ptr(testkube.TESTWORKFLOW_TestWorkflowRunningContextActorType),
},
},
ParentExecutionIds: parentIds,
})
if err == nil {
Expand Down
13 changes: 13 additions & 0 deletions internal/app/api/v1/testworkflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -373,6 +373,19 @@ func (s *TestkubeAPI) ExecuteTestWorkflowHandler() fiber.Handler {
var errs []error

request.TestWorkflowExecutionName = strings.Clone(c.Query("testWorkflowExecutionName"))
if request.RunningContext == nil {
request.RunningContext = &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Type_: common.Ptr(testkube.API_TestWorkflowRunningContextInterfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Name: "",
Username: "",
Email: "",
Type_: common.Ptr(testkube.PROGRAM_TestWorkflowRunningContextActorType),
},
}
}
concurrencyLevel := scheduler.DefaultConcurrencyLevel
workerpoolService := workerpool.New[testworkflowsv1.TestWorkflow, testkube.TestWorkflowExecutionRequest,
testkube.TestWorkflowExecution](concurrencyLevel)
Expand Down
2 changes: 1 addition & 1 deletion pkg/mapper/cdevents/mapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ func MapTestkubeRunningContextTypeToCDEventTiggerType(contextType string) string
// MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType maps OpenAPI spec Test Workflow Running Context Actor to CDEvent Trigger Type
func MapTestkubeTestWorkflowRunningContextActorToCDEventTiggerType(actor testkube.TestWorkflowRunningContextActorType) string {
switch actor {
case testkube.USER_TestWorkflowRunningContextActorType:
case testkube.USER_TestWorkflowRunningContextActorType, testkube.PROGRAM_TestWorkflowRunningContextActorType:
return "manual"
case testkube.TESTWORKFLOW_TestWorkflowRunningContextActorType, testkube.TESTWORKFLOWEXECUTION_TestWorkflowRunningContextActorType,
testkube.TESTRIGGER_TestWorkflowRunningContextActorType:
Expand Down

0 comments on commit d972b1a

Please sign in to comment.