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

Merged
merged 62 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
62 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
ad85fa0
Merge branch 'main' into vsukhin/feature/test-workflow-running-context
vsukhin Oct 28, 2024
c7b125c
fix: dep update
vsukhin Oct 28, 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 @@ -385,6 +385,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 @@ -6,6 +6,7 @@ require (
github.com/99designs/gqlgen v0.17.27
github.com/Masterminds/semver v1.5.0
github.com/adhocore/gronx v1.6.3
github.com/avast/retry-go/v4 v4.6.0
github.com/bmatcuk/doublestar/v4 v4.6.1
github.com/cdevents/sdk-go v0.3.0
github.com/cli/cli/v2 v2.20.2
Expand Down Expand Up @@ -38,7 +39,7 @@ require (
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.20241028132112-e2a9c1706edd
github.com/minio/minio-go/v7 v7.0.47
github.com/montanaflynn/stats v0.6.6
github.com/moogar0880/problems v0.1.1
Expand All @@ -48,7 +49,6 @@ require (
github.com/olekukonko/tablewriter v0.0.6-0.20230925090304-df64c4bbad77
github.com/onsi/ginkgo/v2 v2.15.0
github.com/onsi/gomega v1.31.0
github.com/opencontainers/image-spec v1.1.0-rc3
github.com/otiai10/copy v1.11.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.18.0
Expand Down Expand Up @@ -91,7 +91,6 @@ require (
github.com/agnivade/levenshtein v1.1.1 // indirect
github.com/alecthomas/chroma v0.10.0 // indirect
github.com/andybalholm/brotli v1.0.5 // indirect
github.com/avast/retry-go/v4 v4.6.0 // indirect
github.com/aymerick/douceur v0.2.0 // indirect
github.com/beorn7/perks v1.0.1 // indirect
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 // indirect
Expand Down Expand Up @@ -173,6 +172,7 @@ require (
github.com/nats-io/nkeys v0.4.7 // indirect
github.com/nats-io/nuid v1.0.1 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/opencontainers/image-spec v1.1.0-rc3 // indirect
github.com/package-url/packageurl-go v0.1.0 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/power-devops/perfstat v0.0.0-20210106213030-5aafc221ea8c // indirect
Expand Down
Loading
Loading