From 2b7b2b64a0315c11c55b386b24a620daba8876b3 Mon Sep 17 00:00:00 2001 From: Vladislav Sukhin Date: Mon, 8 Jul 2024 19:14:52 +0300 Subject: [PATCH] fix: add test workflow running context model Signed-off-by: Vladislav Sukhin --- api/v1/testkube.yaml | 75 +++++++++++++++++-- .../renderer/testworkflowexecution_obj.go | 6 +- .../commands/testworkflows/run.go | 10 ++- .../testkube/model_test_workflow_execution.go | 5 +- .../model_test_workflow_execution_request.go | 5 +- .../model_test_workflow_execution_summary.go | 9 ++- .../model_test_workflow_running_context.go | 17 +++++ ...del_test_workflow_running_context_actor.go | 20 +++++ ...el_test_workflow_running_context_caller.go | 21 ++++++ ...ow_running_context_caller_resource_type.go | 18 +++++ ...test_workflow_running_context_interface.go | 20 +++++ 11 files changed, 186 insertions(+), 20 deletions(-) create mode 100644 pkg/api/v1/testkube/model_test_workflow_running_context.go create mode 100644 pkg/api/v1/testkube/model_test_workflow_running_context_actor.go create mode 100644 pkg/api/v1/testkube/model_test_workflow_running_context_caller.go create mode 100644 pkg/api/v1/testkube/model_test_workflow_running_context_caller_resource_type.go create mode 100644 pkg/api/v1/testkube/model_test_workflow_running_context_interface.go diff --git a/api/v1/testkube.yaml b/api/v1/testkube.yaml index 2ea8e6005e8..f1992ca6bd5 100644 --- a/api/v1/testkube.yaml +++ b/api/v1/testkube.yaml @@ -7043,6 +7043,63 @@ components: 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" + caller: + $ref: "#/components/schemas/TestWorkflowRunningContextCaller" + + TestWorkflowRunningContextCaller: + description: running context caller for test workflow execution + type: object + required: + - callerResourceType + - callerResourceName + - callerResourceExecutionID + - fullExecutionPath + properties: + callerResourceType: + $ref: "#/components/schemas/TestWorkflowRunningContextCallerResourceType" + callerResourceName: + type: string + description: caller resource name + callerResourceExecutionID: + type: string + description: caller resource execution id + fullExecutionPath: + type: string + description: all test workflow execution ids starting from the root + + TestWorkflowRunningContextInterface: + description: supported interfaces for test workflow running context + type: string + enum: + - cli + - ui + - api + + TestWorkflowRunningContextActor: + description: supported actors for test workflow running context + type: string + enum: + - cron + - testrigger + - user + + TestWorkflowRunningContextCallerResourceType: + description: supported caller resource types for test workflow running context + type: string + enum: + - testworkflow + Webhook: description: CRD based webhook data type: object @@ -7876,8 +7933,10 @@ components: description: whether webhooks on the executions of this test workflow are disabled default: false runningContext: - $ref: "#/components/schemas/RunningContext" - description: running context for the test suite execution + type: array + description: running context for the test workflow execution + items: + $ref: "#/components/schemas/TestWorkflowRunningContext" TestWorkflowWithExecution: type: object @@ -7970,8 +8029,10 @@ components: - true - false runningContext: - $ref: "#/components/schemas/RunningContext" - description: running context for the test suite execution + type: array + description: running context for the test workflow execution + items: + $ref: "#/components/schemas/TestWorkflowRunningContext" required: - id - name @@ -8005,8 +8066,10 @@ components: workflow: $ref: "#/components/schemas/TestWorkflowSummary" runningContext: - $ref: "#/components/schemas/RunningContext" - description: running context for the test suite execution + type: array + description: running context for the test workflow execution + items: + $ref: "#/components/schemas/TestWorkflowRunningContext" required: - id - name diff --git a/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go b/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go index f321030606a..f0ba6c94163 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go +++ b/cmd/kubectl-testkube/commands/testworkflows/renderer/testworkflowexecution_obj.go @@ -58,10 +58,10 @@ func printPrettyOutput(ui *ui.UI, execution testkube.TestWorkflowExecution) { ui.Warn("Execution number: ", fmt.Sprintf("%d", execution.Number)) } ui.Warn("Requested at: ", execution.ScheduledAt.String()) - if execution.RunningContext != nil { + for _, ctx := range execution.RunningContext { ui.Warn("Running context: ") - ui.Warn("Type: ", execution.RunningContext.Type_) - ui.Warn("Context: ", execution.RunningContext.Context) + ui.Warn("Type: ", string(*ctx.Interface_)) + ui.Warn("Context: ", string(*ctx.Actor)) } if execution.Result != nil && execution.Result.Status != nil { ui.Warn("Status: ", string(*execution.Result.Status)) diff --git a/cmd/kubectl-testkube/commands/testworkflows/run.go b/cmd/kubectl-testkube/commands/testworkflows/run.go index 7cce049dfad..5760f4beae2 100644 --- a/cmd/kubectl-testkube/commands/testworkflows/run.go +++ b/cmd/kubectl-testkube/commands/testworkflows/run.go @@ -68,13 +68,17 @@ func NewRunTestWorkflowCmd() *cobra.Command { } name := args[0] + interface_ := testkube.CLI_TestWorkflowRunningContextInterface + actor := testkube.USER_TestWorkflowRunningContextActor execution, err := client.ExecuteTestWorkflow(name, testkube.TestWorkflowExecutionRequest{ Name: executionName, Config: config, DisableWebhooks: disableWebhooks, - RunningContext: &testkube.RunningContext{ - Type_: string(testkube.RunningContextTypeUserCLI), - Context: runningContext, + RunningContext: []testkube.TestWorkflowRunningContext{ + { + Interface_: &interface_, + Actor: &actor, + }, }, }) if err != nil { diff --git a/pkg/api/v1/testkube/model_test_workflow_execution.go b/pkg/api/v1/testkube/model_test_workflow_execution.go index b895b93dfd4..41596a81a85 100644 --- a/pkg/api/v1/testkube/model_test_workflow_execution.go +++ b/pkg/api/v1/testkube/model_test_workflow_execution.go @@ -38,6 +38,7 @@ type TestWorkflowExecution struct { // test workflow execution name started the test workflow execution TestWorkflowExecutionName string `json:"testWorkflowExecutionName,omitempty"` // whether webhooks on the executions of this test workflow are disabled - DisableWebhooks bool `json:"disableWebhooks,omitempty"` - RunningContext *RunningContext `json:"runningContext,omitempty"` + DisableWebhooks bool `json:"disableWebhooks,omitempty"` + // running context for the test workflow execution + RunningContext []TestWorkflowRunningContext `json:"runningContext,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_execution_request.go b/pkg/api/v1/testkube/model_test_workflow_execution_request.go index 2f86c9db227..e47f5f8e101 100644 --- a/pkg/api/v1/testkube/model_test_workflow_execution_request.go +++ b/pkg/api/v1/testkube/model_test_workflow_execution_request.go @@ -16,6 +16,7 @@ type TestWorkflowExecutionRequest struct { // test workflow execution name started the test workflow execution TestWorkflowExecutionName string `json:"testWorkflowExecutionName,omitempty"` // whether webhooks on the executions of this test workflow are disabled - DisableWebhooks bool `json:"disableWebhooks,omitempty"` - RunningContext *RunningContext `json:"runningContext,omitempty"` + DisableWebhooks bool `json:"disableWebhooks,omitempty"` + // running context for the test workflow execution + RunningContext []TestWorkflowRunningContext `json:"runningContext,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_execution_summary.go b/pkg/api/v1/testkube/model_test_workflow_execution_summary.go index 68bd4ebdb29..e930e26d48d 100644 --- a/pkg/api/v1/testkube/model_test_workflow_execution_summary.go +++ b/pkg/api/v1/testkube/model_test_workflow_execution_summary.go @@ -23,8 +23,9 @@ type TestWorkflowExecutionSummary struct { // when the execution has been scheduled to run ScheduledAt time.Time `json:"scheduledAt,omitempty"` // when the execution result's status has changed last time (queued, passed, failed) - StatusAt time.Time `json:"statusAt,omitempty"` - Result *TestWorkflowResultSummary `json:"result,omitempty"` - Workflow *TestWorkflowSummary `json:"workflow"` - RunningContext *RunningContext `json:"runningContext,omitempty"` + StatusAt time.Time `json:"statusAt,omitempty"` + Result *TestWorkflowResultSummary `json:"result,omitempty"` + Workflow *TestWorkflowSummary `json:"workflow"` + // running context for the test workflow execution + RunningContext []TestWorkflowRunningContext `json:"runningContext,omitempty"` } diff --git a/pkg/api/v1/testkube/model_test_workflow_running_context.go b/pkg/api/v1/testkube/model_test_workflow_running_context.go new file mode 100644 index 00000000000..17470343923 --- /dev/null +++ b/pkg/api/v1/testkube/model_test_workflow_running_context.go @@ -0,0 +1,17 @@ +/* + * Testkube API + * + * Testkube provides a Kubernetes-native framework for test definition, execution and results + * + * API version: 1.0.0 + * Contact: testkube@kubeshop.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package testkube + +// running context for test workflow execution +type TestWorkflowRunningContext struct { + Interface_ *TestWorkflowRunningContextInterface `json:"interface"` + Actor *TestWorkflowRunningContextActor `json:"actor"` + Caller *TestWorkflowRunningContextCaller `json:"caller,omitempty"` +} diff --git a/pkg/api/v1/testkube/model_test_workflow_running_context_actor.go b/pkg/api/v1/testkube/model_test_workflow_running_context_actor.go new file mode 100644 index 00000000000..985d624e652 --- /dev/null +++ b/pkg/api/v1/testkube/model_test_workflow_running_context_actor.go @@ -0,0 +1,20 @@ +/* + * Testkube API + * + * Testkube provides a Kubernetes-native framework for test definition, execution and results + * + * API version: 1.0.0 + * Contact: testkube@kubeshop.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package testkube + +// TestWorkflowRunningContextActor : supported actors for test workflow running context +type TestWorkflowRunningContextActor string + +// List of TestWorkflowRunningContextActor +const ( + CRON_TestWorkflowRunningContextActor TestWorkflowRunningContextActor = "cron" + TESTRIGGER_TestWorkflowRunningContextActor TestWorkflowRunningContextActor = "testrigger" + USER_TestWorkflowRunningContextActor TestWorkflowRunningContextActor = "user" +) diff --git a/pkg/api/v1/testkube/model_test_workflow_running_context_caller.go b/pkg/api/v1/testkube/model_test_workflow_running_context_caller.go new file mode 100644 index 00000000000..3b5c9355417 --- /dev/null +++ b/pkg/api/v1/testkube/model_test_workflow_running_context_caller.go @@ -0,0 +1,21 @@ +/* + * Testkube API + * + * Testkube provides a Kubernetes-native framework for test definition, execution and results + * + * API version: 1.0.0 + * Contact: testkube@kubeshop.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package testkube + +// running context caller for test workflow execution +type TestWorkflowRunningContextCaller struct { + CallerResourceType *TestWorkflowRunningContextCallerResourceType `json:"callerResourceType"` + // caller resource name + CallerResourceName string `json:"callerResourceName"` + // caller resource execution id + CallerResourceExecutionID string `json:"callerResourceExecutionID"` + // all test workflow execution ids starting from the root + FullExecutionPath string `json:"fullExecutionPath"` +} diff --git a/pkg/api/v1/testkube/model_test_workflow_running_context_caller_resource_type.go b/pkg/api/v1/testkube/model_test_workflow_running_context_caller_resource_type.go new file mode 100644 index 00000000000..67013d4cc78 --- /dev/null +++ b/pkg/api/v1/testkube/model_test_workflow_running_context_caller_resource_type.go @@ -0,0 +1,18 @@ +/* + * Testkube API + * + * Testkube provides a Kubernetes-native framework for test definition, execution and results + * + * API version: 1.0.0 + * Contact: testkube@kubeshop.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package testkube + +// TestWorkflowRunningContextCallerResourceType : supported caller resource types for test workflow running context +type TestWorkflowRunningContextCallerResourceType string + +// List of TestWorkflowRunningContextCallerResourceType +const ( + TESTWORKFLOW_TestWorkflowRunningContextCallerResourceType TestWorkflowRunningContextCallerResourceType = "testworkflow" +) diff --git a/pkg/api/v1/testkube/model_test_workflow_running_context_interface.go b/pkg/api/v1/testkube/model_test_workflow_running_context_interface.go new file mode 100644 index 00000000000..648bc21029e --- /dev/null +++ b/pkg/api/v1/testkube/model_test_workflow_running_context_interface.go @@ -0,0 +1,20 @@ +/* + * Testkube API + * + * Testkube provides a Kubernetes-native framework for test definition, execution and results + * + * API version: 1.0.0 + * Contact: testkube@kubeshop.io + * Generated by: Swagger Codegen (https://github.com/swagger-api/swagger-codegen.git) + */ +package testkube + +// TestWorkflowRunningContextInterface : supported interfaces for test workflow running context +type TestWorkflowRunningContextInterface string + +// List of TestWorkflowRunningContextInterface +const ( + CLI_TestWorkflowRunningContextInterface TestWorkflowRunningContextInterface = "cli" + UI_TestWorkflowRunningContextInterface TestWorkflowRunningContextInterface = "ui" + API_TestWorkflowRunningContextInterface TestWorkflowRunningContextInterface = "api" +)