Skip to content

Commit

Permalink
feat: [TKC-2966] Store TestWorkflowExecutionRequest config in TestWor…
Browse files Browse the repository at this point in the history
…kflowExecution (#6070)
  • Loading branch information
povilasv authored Dec 6, 2024
1 parent 9dce5f2 commit b60b697
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 1 deletion.
2 changes: 2 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8243,6 +8243,8 @@ components:
runningContext:
description: running context for the test workflow execution (Pro edition only)
$ref: "#/components/schemas/TestWorkflowRunningContext"
config:
$ref: "#/components/schemas/TestWorkflowConfigValue"
required:
- id
- name
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/testkube/model_test_workflow_execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,5 @@ type TestWorkflowExecution struct {
DisableWebhooks bool `json:"disableWebhooks,omitempty"`
Tags map[string]string `json:"tags,omitempty"`
RunningContext *TestWorkflowRunningContext `json:"runningContext,omitempty"`
Config map[string]string `json:"config,omitempty"`
}
21 changes: 20 additions & 1 deletion pkg/testworkflows/testworkflowexecutor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import (
configRepo "github.com/kubeshop/testkube/pkg/repository/config"
"github.com/kubeshop/testkube/pkg/repository/testworkflow"
"github.com/kubeshop/testkube/pkg/secretmanager"
"github.com/kubeshop/testkube/pkg/testworkflows"
"github.com/kubeshop/testkube/pkg/testworkflows/executionworker/controller"
"github.com/kubeshop/testkube/pkg/testworkflows/executionworker/executionworkertypes"
"github.com/kubeshop/testkube/pkg/testworkflows/testworkflowconfig"
Expand All @@ -45,6 +46,8 @@ const (

SaveLogsRetryMaxAttempts = 10
SaveLogsRetryBaseDelay = 300 * time.Millisecond

ConfigSizeLimit = 3 * 1024 * 1024
)

//go:generate mockgen -destination=./mock_executor.go -package=testworkflowexecutor "github.com/kubeshop/testkube/pkg/testworkflows/testworkflowexecutor" TestWorkflowExecutor
Expand Down Expand Up @@ -467,7 +470,23 @@ func (e *executor) initialize(ctx context.Context, workflow *testworkflowsv1.Tes
RunningContext: request.RunningContext,
}

// Try to resolve tags initially
// Store the configuration if it is small and not sensitive
if testworkflows.CountMapBytes(request.Config) < ConfigSizeLimit {
storeConfig := true
schema := workflow.Spec.Config

for k, _ := range request.Config {
if s, ok := schema[k]; ok && s.Sensitive {
storeConfig = false
}
}

if storeConfig {
execution.Config = request.Config
}
}

// Try to resolve tags initialily
if workflow.Spec.Execution != nil {
execution.Tags = workflow.Spec.Execution.Tags
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/testworkflows/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,12 @@ func GetClusterID(ctx context.Context, configMap configRepo.Repository) string {
}
return clusterID
}

// CountMapBytes returns the total bytes of the map
func CountMapBytes(m map[string]string) int {
totalBytes := 0
for k, v := range m {
totalBytes += len(k) + len(v)
}
return totalBytes
}

0 comments on commit b60b697

Please sign in to comment.