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-2966] Store TestWorkflowExecutionRequest config in TestWorkflowExecution #6070

Merged
merged 1 commit into from
Dec 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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
}
}
Comment on lines +478 to +482
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sure, but could be that iterating over workflow.Spec.Config could be more correct - as a sensitive property set to default value may also be kind of sensitive (similar to uncertainty when working with PII rules - single information may not be sensitive, but in conjunction with others - it can become sensitive)

But, I guess, we can ignore that for now 👍

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding given users can mark their properties as sensitive, I think we can keep it as is?

I.e. if it's kind of sensitive in relation to others, you can still set it to sensitive, right? 🤔

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I.e. if it's kind of sensitive in relation to others, you can still set it to sensitive, right?

Yes, but I'm more saying about the default value - i.e. if you specify:

spec:
  config:
    apiUrl: { type: string, default: "my-value", sensitve: true }

And you request execution with config:

{}

The code above will save the configuration properly, despite it actually is using sensitive my-value value.

As mentioned though, I think that we can ignore it for now :)


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 {
povilasv marked this conversation as resolved.
Show resolved Hide resolved
totalBytes := 0
for k, v := range m {
totalBytes += len(k) + len(v)
}
return totalBytes
}
Loading