Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: [TKC-2556] test workflow running context #5926

Open
wants to merge 60 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
29ba776
feat: running context model for test workflows
vsukhin Jul 4, 2024
a0ed48a
feat: add running context to test workflow execution models
vsukhin Jul 4, 2024
7fd49ad
fix: unit test
vsukhin Jul 4, 2024
6911023
Merge commit '7da22fdf8a5f96cf3cf4606e138bceffed17c3ba' into vsukhin/…
vsukhin Jul 5, 2024
c3b438e
fix: dep update
vsukhin Jul 5, 2024
ee741fb
feat: map test workflow running context
vsukhin Jul 5, 2024
6e49ecb
feat: pass running context to execution
vsukhin Jul 5, 2024
d54ca82
fix: running context for test workflows
vsukhin Jul 8, 2024
2b7b2b6
fix: add test workflow running context model
vsukhin Jul 8, 2024
66c39d5
fix: additional enum for test workflow running context
vsukhin Jul 8, 2024
8e467d0
fix: add one more enum
vsukhin Jul 9, 2024
48042d7
fix: mapping for test workflow running context
vsukhin Jul 9, 2024
c5d9641
fix: mapping for cd events for test workflow running context
vsukhin Jul 9, 2024
6b537c2
fix: show test workflow running context
vsukhin Jul 9, 2024
581d826
feat: get full psth
vsukhin Jul 9, 2024
b1b25cc
fix: add parent ids for test workflow running context
vsukhin Jul 10, 2024
235dfb7
fix: format running context ui
vsukhin Jul 10, 2024
e751657
fux: add to mock
vsukhin Jul 10, 2024
e6f9a62
fix: remove unused var
vsukhin Jul 10, 2024
eb5d7d2
Merge branch 'main' into vsukhin/feature/test-workflow-running-context
vsukhin Oct 4, 2024
60e5ebd
fix: dep update
vsukhin Oct 7, 2024
88866c4
Merge branch 'main' into vsukhin/feature/test-workflow-running-context
vsukhin Oct 7, 2024
6e5d1e3
fix: merge
vsukhin Oct 7, 2024
b68824d
fix: change running context model
vsukhin Oct 7, 2024
b5052ef
fix: use reference instead of array
vsukhin Oct 7, 2024
f459b3b
fix: dep update
vsukhin Oct 8, 2024
d972b1a
fix: additional running contexts
vsukhin Oct 8, 2024
3269f3d
fix: add tcl for testworkflow mapper
vsukhin Oct 8, 2024
f91bb1b
fix: trigger running context
vsukhin Oct 16, 2024
6f2ac47
feat: move runnng context to tcl
vsukhin Oct 16, 2024
c3a077a
Merge branch 'main' into vsukhin/feature/test-workflow-running-context
vsukhin Oct 16, 2024
9dc607f
fixL move mapper to tcl
vsukhin Oct 16, 2024
d4825eb
fix: remove test
vsukhin Oct 16, 2024
db28fd1
ifx: move running context to tcl package
vsukhin Oct 21, 2024
386af08
fix: parse uername and email
vsukhin Oct 21, 2024
cca4c38
fix: dep update
vsukhin Oct 22, 2024
b574bc6
Merge branch 'main' into vsukhin/feature/test-workflow-running-context
vsukhin Oct 22, 2024
8a3ffdf
fix: merge
vsukhin Oct 22, 2024
fc61c7f
fix: use api running context from cloud
vsukhin Oct 22, 2024
9cde4b6
fix: remove username
vsukhin Oct 22, 2024
7669083
fix: remove username
vsukhin Oct 22, 2024
9c841e4
fix: check for cloud mode in api call
vsukhin Oct 22, 2024
34ceae9
fix: check for trigger cloud mode
vsukhin Oct 22, 2024
17eb28b
fix: check cloud for executing test workflow
vsukhin Oct 22, 2024
8e87626
fix: fmt
vsukhin Oct 22, 2024
89a0da2
fix: tcl for printing running context
vsukhin Oct 22, 2024
0b9e2f8
fix: unit test
vsukhin Oct 22, 2024
07cad5d
fix: support ci/cd
vsukhin Oct 23, 2024
8cd4890
fix: add actor filters
vsukhin Oct 23, 2024
0af724d
Merge branch 'main' into vsukhin/feature/test-workflow-running-context
vsukhin Oct 23, 2024
226ae32
fix: mongo query
vsukhin Oct 23, 2024
f33a1a8
fix: test
vsukhin Oct 23, 2024
21766bf
fix: int test
vsukhin Oct 23, 2024
dd747b8
fix: unit tests
vsukhin Oct 23, 2024
9d4f463
fix: assign running context
vsukhin Oct 24, 2024
11f7fe9
fix: tune printing running context
vsukhin Oct 24, 2024
0dedd68
fix: forrmat printing
vsukhin Oct 24, 2024
13a231a
fix: field name
vsukhin Oct 24, 2024
b768027
fix: rename parameters
vsukhin Oct 24, 2024
993a133
Merge branch 'main' into vsukhin/feature/test-workflow-running-context
vsukhin Oct 24, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 98 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3806,6 +3806,8 @@ paths:
parameters:
- $ref: "#/components/parameters/ID"
- $ref: "#/components/parameters/TagSelector"
- $ref: "#/components/parameters/ActorName"
- $ref: "#/components/parameters/ActorType"
summary: List test workflow executions
description: List test workflow executions
operationId: listTestWorkflowExecutionsByTestWorkflow
Expand Down Expand Up @@ -4071,6 +4073,8 @@ paths:
parameters:
- $ref: "#/components/parameters/ID"
- $ref: "#/components/parameters/TagSelector"
- $ref: "#/components/parameters/ActorName"
- $ref: "#/components/parameters/ActorType"
summary: List test workflow executions
description: List test workflow executions
operationId: listTestWorkflowExecutions
Expand Down Expand Up @@ -7158,10 +7162,77 @@ components:
- testsuite
- testtrigger
- scheduler
- testworkflow
context:
type: string
description: Context value depending from its type

TestWorkflowRunningContext:
description: running context for test workflow execution
type: object
required:
- interface
- actor
properties:
interface:
$ref: "#/components/schemas/TestWorkflowRunningContextInterface"
actor:
$ref: "#/components/schemas/TestWorkflowRunningContextActor"

TestWorkflowRunningContextInterface:
description: running context interface for test workflow execution
type: object
required:
- type
properties:
name:
type: string
description: interface name
type:
$ref: "#/components/schemas/TestWorkflowRunningContextInterfaceType"

TestWorkflowRunningContextActor:
description: running context actor for test workflow execution
type: object
required:
- type
properties:
name:
type: string
description: actor name
email:
type: string
description: actor email
executionId:
type: string
description: test workflow execution id
executionPath:
type: string
description: all test workflow execution ids starting from the root
type:
$ref: "#/components/schemas/TestWorkflowRunningContextActorType"

TestWorkflowRunningContextInterfaceType:
description: supported interfaces for test workflow running context
type: string
enum:
- cli
- ui
- api
- ci/cd
- internal

TestWorkflowRunningContextActorType:
description: supported actors for test workflow running context
type: string
enum:
- cron
- testtrigger
- user
- testworkflow
- testworkflowexecution
- program

Webhook:
description: CRD based webhook data
type: object
Expand Down Expand Up @@ -8012,6 +8083,14 @@ components:
default: false
tags:
$ref: "#/components/schemas/TestWorkflowTagValue"
runningContext:
description: running context for the test workflow execution (Pro edition only)
$ref: "#/components/schemas/TestWorkflowRunningContext"
parentExecutionIds:
type: array
description: parent execution ids
items:
type: string

TestWorkflowWithExecution:
type: object
Expand Down Expand Up @@ -8110,6 +8189,9 @@ components:
- false
tags:
$ref: "#/components/schemas/TestWorkflowTagValue"
runningContext:
description: running context for the test workflow execution (Pro edition only)
$ref: "#/components/schemas/TestWorkflowRunningContext"
required:
- id
- name
Expand Down Expand Up @@ -8144,6 +8226,9 @@ components:
$ref: "#/components/schemas/TestWorkflowSummary"
tags:
$ref: "#/components/schemas/TestWorkflowTagValue"
runningContext:
description: running context for the test workflow execution (Pro edition only)
$ref: "#/components/schemas/TestWorkflowRunningContext"
required:
- id
- name
Expand Down Expand Up @@ -10672,6 +10757,19 @@ components:
schema:
type: string
description: Test workflow execution tags
ActorName:
in: query
name: actorName
schema:
type: string
description: Test workflow running conntext actor name
ActorType:
in: query
name: actorType
schema:
type: string
description: Test workflow running conntext actor type

requestBodies:
UploadsBody:
description: "Upload files request body data"
Expand Down
1 change: 1 addition & 0 deletions cmd/api-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,7 @@ func main() {
triggers.WithTestkubeNamespace(cfg.TestkubeNamespace),
triggers.WithWatcherNamespaces(cfg.TestkubeWatcherNamespaces),
triggers.WithDisableSecretCreation(!secretConfig.AutoCreate),
triggers.WithProContext(&proContext),
)
log.DefaultLogger.Info("starting trigger service")
g.Go(func() error {
Expand Down
47 changes: 40 additions & 7 deletions cmd/kubectl-testkube/commands/testworkflows/executions.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package testworkflows

import (
"fmt"
"os"
"strings"

Expand All @@ -9,17 +10,18 @@ import (
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/render"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer"
tc "github.com/kubeshop/testkube/pkg/api/v1/client"
"github.com/kubeshop/testkube/pkg/api/v1/testkube"
"github.com/kubeshop/testkube/pkg/ui"
)

func NewGetTestWorkflowExecutionsCmd() *cobra.Command {
var (
limit int
selectors []string
testWorkflowName string
logsOnly bool
tags []string
limit int
selectors []string
testWorkflowName, actorName, actorType string
logsOnly bool
tags []string
)

cmd := &cobra.Command{
Expand All @@ -41,12 +43,20 @@ func NewGetTestWorkflowExecutionsCmd() *cobra.Command {
client, _, err := common.GetClient(cmd)
ui.ExitOnError("getting client", err)

err = validateActorType(testkube.TestWorkflowRunningContextActorType(actorType))
ui.ExitOnError("validatig actor type", err)

if len(args) == 0 {
client, _, err := common.GetClient(cmd)
ui.ExitOnError("getting client", err)

executions, err := client.ListTestWorkflowExecutions(testWorkflowName, limit,
strings.Join(selectors, ","), strings.Join(tags, ","))
options := tc.FilterTestWorkflowExecutionOptions{
Selector: strings.Join(selectors, ","),
TagSelector: strings.Join(tags, ","),
ActorName: actorName,
ActorType: testkube.TestWorkflowRunningContextActorType(actorType),
}
executions, err := client.ListTestWorkflowExecutions(testWorkflowName, limit, options)
ui.ExitOnError("getting test workflow executions list", err)
err = render.List(cmd, testkube.TestWorkflowExecutionSummaries(executions.Results), os.Stdout)
ui.ExitOnError("rendering list", err)
Expand Down Expand Up @@ -87,6 +97,29 @@ func NewGetTestWorkflowExecutionsCmd() *cobra.Command {
cmd.Flags().StringSliceVarP(&selectors, "label", "l", nil, "label key value pair: --label key1=value1")
cmd.Flags().BoolVar(&logsOnly, "logs-only", false, "show only execution logs")
cmd.Flags().StringSliceVarP(&tags, "tag", "", nil, "tag key value pair: --tag key1=value1")
cmd.Flags().StringVarP(&actorName, "actor-name", "", "", "test workflow running context actor name")
cmd.Flags().StringVarP(&actorType, "actor-type", "", "", "test workflow running context actor type one of cron|testtrigger|user|testworkfow|testworkflowexecution|program")

return cmd
}

func validateActorType(actorType testkube.TestWorkflowRunningContextActorType) error {
if actorType == "" {
return nil
}

actorTypes := map[testkube.TestWorkflowRunningContextActorType]struct{}{
testkube.CRON_TestWorkflowRunningContextActorType: {},
testkube.TESTTRIGGER_TestWorkflowRunningContextActorType: {},
testkube.USER_TestWorkflowRunningContextActorType: {},
testkube.TESTWORKFLOW_TestWorkflowRunningContextActorType: {},
testkube.TESTWORKFLOWEXECUTION_TestWorkflowRunningContextActorType: {},
testkube.PROGRAM_TestWorkflowRunningContextActorType: {},
}

if _, ok := actorTypes[actorType]; !ok {
return fmt.Errorf("please pass one of cron|testtrigger|user|testworkfow|testworkflowexecution|program for actor type")
}

return nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/render"
"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/ui"
)

Expand Down Expand Up @@ -63,6 +64,8 @@ func printPrettyOutput(ui *ui.UI, execution testkube.TestWorkflowExecution) {
ui.NL()
ui.Warn("Tags: ", testkube.MapToString(execution.Tags))
}
// Pro edition only (tcl protected code)
tclcmd.PrintRunningContext(ui, execution)
if execution.Result != nil && execution.Result.Status != nil {
ui.Warn("Status: ", string(*execution.Result.Status))
if !execution.Result.QueuedAt.IsZero() {
Expand Down
21 changes: 21 additions & 0 deletions cmd/kubectl-testkube/commands/testworkflows/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ import (
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/common/render"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/tests"
"github.com/kubeshop/testkube/cmd/kubectl-testkube/commands/testworkflows/renderer"
testkubecfg "github.com/kubeshop/testkube/cmd/kubectl-testkube/config"
"github.com/kubeshop/testkube/cmd/testworkflow-init/instructions"
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 @@ -63,11 +66,29 @@ func NewRunTestWorkflowCmd() *cobra.Command {
ui.ExitOnError("getting client", err)

name := args[0]
runContext := telemetry.GetCliRunContext()
interfaceType := testkube.CICD_TestWorkflowRunningContextInterfaceType
if runContext == "others|local" {
runContext = ""
interfaceType = testkube.CLI_TestWorkflowRunningContextInterfaceType
}

cfg, err := testkubecfg.Load()
ui.ExitOnError("loading config file", err)
ui.NL()

var runningContext *testkube.TestWorkflowRunningContext
// Pro edition only (tcl protected code)
if cfg.ContextType == testkubecfg.ContextTypeCloud {
runningContext = tclcmd.GetRunningContext(runContext, cfg.CloudContext.ApiKey, interfaceType)
}

execution, err := client.ExecuteTestWorkflow(name, testkube.TestWorkflowExecutionRequest{
Name: executionName,
Config: config,
DisableWebhooks: disableWebhooks,
Tags: tags,
RunningContext: runningContext,
})
if err != nil {
// User friendly Open Source operation error
Expand Down
20 changes: 19 additions & 1 deletion cmd/tcl/testworkflow-toolkit/commands/execute.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"encoding/json"
"fmt"
"os"
"strings"
"sync"
"time"

Expand Down Expand Up @@ -72,7 +73,7 @@ func buildTestExecution(test testworkflowsv1.StepExecuteTest, async bool) (func(

exec, err := c.ExecuteTest(test.Name, test.ExecutionRequest.Name, client.ExecuteTestOptions{
RunningContext: &testkube.RunningContext{
Type_: "testworkflow",
Type_: string(testkube.RunningContextTypeTestWorkflow),
Context: fmt.Sprintf("%s/executions/%s", config.WorkflowName(), config.ExecutionId()),
},
IsVariablesFileUploaded: test.ExecutionRequest.IsVariablesFileUploaded,
Expand Down Expand Up @@ -162,13 +163,30 @@ func buildWorkflowExecution(workflow testworkflowsv1.StepExecuteWorkflow, async

tags := config.ExecutionTags()

parentIds := []string{config.ExecutionId()}
if config.Config().Execution.ParentIds != "" {
parentIds = append(strings.Split(config.Config().Execution.ParentIds, "/"), parentIds...)
}

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: config.ExecutionDisableWebhooks(),
Tags: tags,
RunningContext: &testkube.TestWorkflowRunningContext{
Interface_: &testkube.TestWorkflowRunningContextInterface{
Type_: common.Ptr(testkube.API_TestWorkflowRunningContextInterfaceType),
},
Actor: &testkube.TestWorkflowRunningContextActor{
Name: workflow.Name,
ExecutionId: config.ExecutionId(),
ExecutionPath: strings.Join(parentIds, "/"),
Type_: common.Ptr(testkube.TESTWORKFLOW_TestWorkflowRunningContextActorType),
},
},
ParentExecutionIds: parentIds,
})
if err == nil {
break
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ require (
github.com/gookit/color v1.5.4
github.com/gorilla/websocket v1.5.0
github.com/h2non/filetype v1.1.3
github.com/hashicorp/golang-lru/v2 v2.0.1
github.com/itchyny/gojq v0.12.14
github.com/joshdk/go-junit v1.0.0
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51
github.com/kelseyhightower/envconfig v1.4.0
github.com/kubepug/kubepug v1.7.1
github.com/kubeshop/testkube-operator v1.17.55-0.20241023094459-ac7c03dedade
github.com/kubeshop/testkube-operator v1.17.55-0.20241022123644-9de69044548e
github.com/minio/minio-go/v7 v7.0.47
github.com/montanaflynn/stats v0.6.6
github.com/moogar0880/problems v0.1.1
Expand Down Expand Up @@ -73,6 +74,7 @@ require (
k8s.io/api v0.28.4
k8s.io/apimachinery v0.28.4
k8s.io/client-go v0.28.4
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
sigs.k8s.io/controller-runtime v0.16.3
sigs.k8s.io/kustomize/kyaml v0.15.0
)
Expand Down Expand Up @@ -133,7 +135,6 @@ require (
github.com/google/pprof v0.0.0-20210720184732-4bb14d4b1be1 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gorilla/css v1.0.0 // indirect
github.com/hashicorp/golang-lru/v2 v2.0.1 // indirect
github.com/henvic/httpretty v0.0.6 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
Expand Down Expand Up @@ -226,7 +227,6 @@ require (
k8s.io/component-base v0.28.3 // indirect
k8s.io/klog/v2 v2.100.1 // indirect
k8s.io/kube-openapi v0.0.0-20230918164632-68afd615200d // indirect
k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect
sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
sigs.k8s.io/structured-merge-diff/v4 v4.3.0 // indirect
sigs.k8s.io/yaml v1.3.0 // indirect
Expand Down
Loading
Loading