From fc38298838dd2add989b8dbe8be5c37346071f3e Mon Sep 17 00:00:00 2001
From: Povilas Versockas
Date: Thu, 5 Dec 2024 12:32:14 +0200
Subject: [PATCH] feat: [TKC-2966] Store TestWorkflowExecutionRequest config in
TestWorkflowExecution
---
api/v1/testkube.yaml | 2 ++
.../testkube/model_test_workflow_execution.go | 1 +
.../testworkflowexecutor/executor.go | 21 ++++++++++++++++++-
pkg/testworkflows/utils.go | 9 ++++++++
4 files changed, 32 insertions(+), 1 deletion(-)
diff --git a/api/v1/testkube.yaml b/api/v1/testkube.yaml
index 26fafe05258..50079b8db75 100644
--- a/api/v1/testkube.yaml
+++ b/api/v1/testkube.yaml
@@ -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
diff --git a/pkg/api/v1/testkube/model_test_workflow_execution.go b/pkg/api/v1/testkube/model_test_workflow_execution.go
index 6fdea115b99..35fdd19bdbb 100644
--- a/pkg/api/v1/testkube/model_test_workflow_execution.go
+++ b/pkg/api/v1/testkube/model_test_workflow_execution.go
@@ -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"`
}
diff --git a/pkg/testworkflows/testworkflowexecutor/executor.go b/pkg/testworkflows/testworkflowexecutor/executor.go
index b586b92c36f..9a91acd5281 100644
--- a/pkg/testworkflows/testworkflowexecutor/executor.go
+++ b/pkg/testworkflows/testworkflowexecutor/executor.go
@@ -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"
@@ -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
@@ -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
}
diff --git a/pkg/testworkflows/utils.go b/pkg/testworkflows/utils.go
index a3719c87f88..7df6ad52dba 100644
--- a/pkg/testworkflows/utils.go
+++ b/pkg/testworkflows/utils.go
@@ -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
+}