Skip to content

Commit

Permalink
ifx: move running context to tcl package
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin committed Oct 21, 2024
1 parent d4825eb commit db28fd1
Show file tree
Hide file tree
Showing 6 changed files with 79 additions and 24 deletions.
18 changes: 5 additions & 13 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ import (
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/tests"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer"
"github.com/kubeshop/testkube/cmd/testworkflow-init/instructions"
intcommon "github.com/kubeshop/testkube/internal/common"
apiclientv1 "github.com/kubeshop/testkube/pkg/api/v1/client"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
tclcmd "github.com/kubeshop/testkube/pkg/tcl/testworkflowstcl/cmd"
"github.com/kubeshop/testkube/pkg/telemetry"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowprocessor/constants"
"github.com/kubeshop/testkube/pkg/ui"
Expand Down Expand Up @@ -76,18 +76,10 @@ func NewRunTestWorkflowCmd() *cobra.Command {
Config: config,
DisableWebhooks: disableWebhooks,
Tags: tags,
RunningContext: &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Name: runContext,
Type_: intcommon.Ptr(interfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: intcommon.Ptr(testkube.USER_TestWorkflowRunningContextActorType),
Username: "",
Email: "",
},
},
})
// Pro edition only (tcl protected code)
RunningContext: tclcmd.GetRunningContext(runContext, "", "", interfaceType),
},
)
if err != nil {
// User friendly Open Source operation error
errMessage := err.Error()
Expand Down
14 changes: 3 additions & 11 deletions internal/app/api/v1/testworkflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/mapper/testworkflows"
"github.com/kubeshop/testkube/pkg/scheduler"
"github.com/kubeshop/testkube/pkg/tcl/testworkflowstcl/api"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowresolver"
"github.com/kubeshop/testkube/pkg/workerpool"
)
Expand Down Expand Up @@ -374,17 +375,8 @@ func (s *TestkubeAPI) ExecuteTestWorkflowHandler() fiber.Handler {

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),
},
}
// Pro edition only (tcl protected code)
request.RunningContext = api.GetRunningContext("", "", "")
}
concurrencyLevel := scheduler.DefaultConcurrencyLevel
workerpoolService := workerpool.New[testworkflowsv1.TestWorkflow, testkube.TestWorkflowExecutionRequest,
Expand Down
27 changes: 27 additions & 0 deletions pkg/tcl/testworkflowstcl/api/api.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// Copyright 2024 Testkube.
//
// Licensed as a Testkube Pro file under the Testkube Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt
package api

import (
"github.com/kubeshop/testkube/internal/common"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
)

func GetRunningContext(name, username, email string) *testkube.TestWorkflowRunningContext {
return &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Type_: common.Ptr(testkube.API_TestWorkflowRunningContextInterfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Name: name,
Username: username,
Email: email,
Type_: common.Ptr(testkube.PROGRAM_TestWorkflowRunningContextActorType),
},
}
}
28 changes: 28 additions & 0 deletions pkg/tcl/testworkflowstcl/cmd/cmd.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
// Copyright 2024 Testkube.
//
// Licensed as a Testkube Pro file under the Testkube Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt

package cmd

import (
"github.com/kubeshop/testkube/internal/common"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
)

func GetRunningContext(runContext, username, email string, interfaceType testkube.TestWorkflowRunningContextInterfaceType) *testkube.TestWorkflowRunningContext {
return &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Name: runContext,
Type_: common.Ptr(interfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Type_: common.Ptr(testkube.USER_TestWorkflowRunningContextActorType),
Username: username,
Email: email,
},
}
}
8 changes: 8 additions & 0 deletions pkg/tcl/testworkflowstcl/mapper/cdevents.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Copyright 2024 Testkube.
//
// Licensed as a Testkube Pro file under the Testkube Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt

package mapper

import "github.com/kubeshop/testkube/pkg/api/v1/testkube"
Expand Down
8 changes: 8 additions & 0 deletions pkg/tcl/testworkflowstcl/triggers/executor.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
// Copyright 2024 Testkube.
//
// Licensed as a Testkube Pro file under the Testkube Community
// License (the "License"); you may not use this file except in compliance with
// the License. You may obtain a copy of the License at
//
// https://github.com/kubeshop/testkube/blob/main/licenses/TCL.txt

package triggers

import (
Expand Down

0 comments on commit db28fd1

Please sign in to comment.