Skip to content

Commit

Permalink
feat: [TKC-2074] delete worklows by name
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Jun 3, 2024
1 parent cd5b3d1 commit a3ce8cf
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 7 deletions.
8 changes: 8 additions & 0 deletions api/v1/testkube.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3346,6 +3346,7 @@ paths:
- pro
parameters:
- $ref: "#/components/parameters/Selector"
- $ref: "#/components/parameters/TestWorkflowNames"
summary: Delete test workflows
description: Delete test workflows from the kubernetes cluster
operationId: deleteTestWorkflows
Expand Down Expand Up @@ -9983,6 +9984,13 @@ components:
schema:
type: string
description: Labels to filter by
TestWorkflowNames:
in: query
name: testWorkflowNames
schema:
items:
type: string
type: array
ExecutionSelector:
in: query
name: executionSelector
Expand Down
29 changes: 26 additions & 3 deletions pkg/tcl/apitcl/v1/testworkflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,27 @@ func (s *apiTCL) DeleteTestWorkflowsHandler() fiber.Handler {
errPrefix := "failed to delete test workflows"
return func(c *fiber.Ctx) error {
selector := c.Query("selector")
workflows, err := s.TestWorkflowsClient.List(selector)
if err != nil {
return s.BadGateway(c, errPrefix, "client problem", err)

var (
workflows *testworkflowsv1.TestWorkflowList
err error
)
testWorkflowNames := c.Query("testWorkflowNames")
if testWorkflowNames != "" {
names := strings.Split(testWorkflowNames, ",")
workflows = &testworkflowsv1.TestWorkflowList{}
for _, name := range names {
workflow, err := s.TestWorkflowsClient.Get(name)
if err != nil {
return s.ClientError(c, errPrefix, err)
}
workflows.Items = append(workflows.Items, *workflow)
}
} else {
workflows, err = s.TestWorkflowsClient.List(selector)
if err != nil {
return s.BadGateway(c, errPrefix, "client problem", err)
}
}

// Delete
Expand All @@ -108,6 +126,11 @@ func (s *apiTCL) DeleteTestWorkflowsHandler() fiber.Handler {
names := common.MapSlice(workflows.Items, func(t testworkflowsv1.TestWorkflow) string {
return t.Name
})

err = s.TestWorkflowOutput.DeleteOutputForTestWorkflows(context.Background(), names)
if err != nil {
return s.ClientError(c, "deleting executions output", err)
}
err = s.TestWorkflowResults.DeleteByTestWorkflows(context.Background(), names)
if err != nil {
return s.ClientError(c, "deleting executions", err)
Expand Down
11 changes: 7 additions & 4 deletions pkg/tcl/cloudtcl/data/testworkflow/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,11 @@ const (
CmdTestWorkflowExecutionDeleteByWorkflows executor.Command = "workflow_execution_delete_by_workflows"
CmdTestWorkflowExecutionGetWorkflowMetrics executor.Command = "workflow_execution_get_workflow_metrics"

CmdTestWorkflowOutputPresignSaveLog executor.Command = "workflow_output_presign_save_log"
CmdTestWorkflowOutputPresignReadLog executor.Command = "workflow_output_presign_read_log"
CmdTestWorkflowOutputHasLog executor.Command = "workflow_output_has_log"
CmdTestWorkflowOutputDeleteByTestWorkflow executor.Command = "workflow_output_delete_by_test_workflow"
CmdTestWorkflowOutputPresignSaveLog executor.Command = "workflow_output_presign_save_log"
CmdTestWorkflowOutputPresignReadLog executor.Command = "workflow_output_presign_read_log"
CmdTestWorkflowOutputHasLog executor.Command = "workflow_output_has_log"
CmdTestWorkflowOutputDeleteByTestWorkflow executor.Command = "workflow_output_delete_by_test_workflow"
CmdTestworkflowOutputDeleteForTestWorkflows executor.Command = "workflow_output_delete_for_test_workflows"
)

func command(v interface{}) executor.Command {
Expand Down Expand Up @@ -78,6 +79,8 @@ func command(v interface{}) executor.Command {
return CmdTestWorkflowOutputHasLog
case ExecutionDeleteOutputByWorkflowRequest:
return CmdTestWorkflowOutputDeleteByTestWorkflow
case ExecutionDeleteOutputForTestWorkflowsRequest:
return CmdTestworkflowOutputDeleteForTestWorkflows
}
panic("unknown test workflows Cloud request")
}
7 changes: 7 additions & 0 deletions pkg/tcl/cloudtcl/data/testworkflow/execution_models.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,13 @@ type ExecutionDeleteOutputByWorkflowRequest struct {
type ExecutionDeleteOutputByWorkflowResponse struct {
}

type ExecutionDeleteOutputForTestWorkflowsRequest struct {
WorkflowNames []string `json:"workflowNames"`
}

type ExecutionDeleteOutputForTestWorkflowsResponse struct {
}

type ExecutionDeleteAllRequest struct {
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/tcl/cloudtcl/data/testworkflow/output.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,8 @@ func (r *CloudOutputRepository) DeleteOutputByTestWorkflow(ctx context.Context,
req := ExecutionDeleteOutputByWorkflowRequest{WorkflowName: workflowName}
return passNoContent(r.executor, ctx, req)
}

func (r *CloudOutputRepository) DeleteOutputForTestWorkflows(ctx context.Context, workflowNames []string) (err error) {
req := ExecutionDeleteOutputForTestWorkflowsRequest{WorkflowNames: workflowNames}
return passNoContent(r.executor, ctx, req)
}
2 changes: 2 additions & 0 deletions pkg/tcl/repositorytcl/testworkflow/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,6 @@ type OutputRepository interface {

// DeleteOutputByTestWorkflow deletes execution output by test workflow
DeleteOutputByTestWorkflow(ctx context.Context, testWorkflowName string) error
// DeleteOutputForTestWorkflows deletes execution output by test workflows
DeleteOutputForTestWorkflows(ctx context.Context, workflowNames []string) error
}
11 changes: 11 additions & 0 deletions pkg/tcl/repositorytcl/testworkflow/minio_output_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,17 @@ func (m *MinioRepository) DeleteOutputByTestWorkflow(ctx context.Context, testWo
return nil
}

func (m *MinioRepository) DeleteOutputForTestWorkflows(ctx context.Context, workflowNames []string) error {
log.DefaultLogger.Debugw("deleting output for testWorkflows", "testWorkflowNames", workflowNames)
for _, testName := range workflowNames {
err := m.DeleteOutputByTestWorkflow(ctx, testName)
if err != nil {
return err
}
}
return nil
}

func (m *MinioRepository) DeleteOutput(ctx context.Context, id string) error {
log.DefaultLogger.Debugw("deleting test workflow output", "id", id)
return m.storage.DeleteFileFromBucket(ctx, m.bucket, bucketFolder, id)
Expand Down

0 comments on commit a3ce8cf

Please sign in to comment.