Skip to content

Commit

Permalink
feat: rerun client method
Browse files Browse the repository at this point in the history
Signed-off-by: Vladislav Sukhin <vladislav@kubeshop.io>
  • Loading branch information
vsukhin committed Feb 12, 2025
1 parent 0e798b8 commit 593fc3b
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
4 changes: 2 additions & 2 deletions internal/app/api/v1/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ func (s *TestkubeAPI) Init(server server.HTTPServer) {
testWorkflows.Post("/:id/executions/:executionID/pause", s.PauseTestWorkflowExecutionHandler())
testWorkflows.Post("/:id/executions/:executionID/resume", s.ResumeTestWorkflowExecutionHandler())
testWorkflows.Get("/:id/executions/:executionID/logs", s.GetTestWorkflowExecutionLogsHandler())
testWorkflows.Post("/:id/executions/:executionID/rerun", s.ReRunTestWorkflowHandler())
testWorkflows.Post("/:id/executions/:executionID/rerun", s.ReRunTestWorkflowExecutionHandler())

testWorkflowExecutions := root.Group("/test-workflow-executions")
testWorkflowExecutions.Get("/", s.ListTestWorkflowExecutionsHandler())
Expand All @@ -182,7 +182,7 @@ func (s *TestkubeAPI) Init(server server.HTTPServer) {
testWorkflowExecutions.Get("/:executionID/artifacts", s.ListTestWorkflowExecutionArtifactsHandler())
testWorkflowExecutions.Get("/:executionID/artifacts/:filename", s.GetTestWorkflowArtifactHandler())
testWorkflowExecutions.Get("/:executionID/artifact-archive", s.GetTestWorkflowArtifactArchiveHandler())
testWorkflowExecutions.Post("/:executionID/rerun", s.ReRunTestWorkflowHandler())
testWorkflowExecutions.Post("/:executionID/rerun", s.ReRunTestWorkflowExecutionHandler())

testWorkflowWithExecutions := root.Group("/test-workflow-with-executions")
testWorkflowWithExecutions.Get("/", s.ListTestWorkflowWithExecutionsHandler())
Expand Down
2 changes: 1 addition & 1 deletion internal/app/api/v1/testworkflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ func (s *TestkubeAPI) ExecuteTestWorkflowHandler() fiber.Handler {
}

// TODO: Add metrics
func (s *TestkubeAPI) ReRunTestWorkflowHandler() fiber.Handler {
func (s *TestkubeAPI) ReRunTestWorkflowExecutionHandler() fiber.Handler {
return func(c *fiber.Ctx) (err error) {
ctx := c.Context()
executionID := c.Params("executionID")
Expand Down
1 change: 1 addition & 0 deletions pkg/api/v1/client/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,7 @@ type TestWorkflowExecutionAPI interface {
GetTestWorkflowExecutionArtifacts(executionID string) (artifacts testkube.Artifacts, err error)
DownloadTestWorkflowArtifact(executionID, fileName, destination string) (artifact string, err error)
DownloadTestWorkflowArtifactArchive(executionID, destination string, masks []string) (archive string, err error)
ReRunTestWorkflowExecution(workflow string, id string, runningContext testkube.TestWorkflowRunningContext) (testkube.TestWorkflowExecution, error)
}

// TestWorkflowTemplateAPI describes test workflow api methods
Expand Down
16 changes: 16 additions & 0 deletions pkg/api/v1/client/testworkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,3 +219,19 @@ func (c TestWorkflowClient) GetTestWorkflowExecutionLogs(id string) (result []by
uri := c.testWorkflowTransport.GetURI("/test-workflow-executions/%s/logs", id)
return c.testWorkflowTransport.GetRawBody(http.MethodGet, uri, nil, nil)
}

// ReRunTestWorkflowExecution reruns selected execution
func (c TestWorkflowClient) ReRunTestWorkflowExecution(workflow, id string, runningContext testkube.TestWorkflowRunningContext) (result testkube.TestWorkflowExecution, err error) {
if workflow == "" {
return result, fmt.Errorf("test workflow name '%s' is not valid", workflow)
}

uri := c.testWorkflowTransport.GetURI("/test-workflows/%s/executions/%s/rerun", workflow, id)

body, err := json.Marshal(runningContext)
if err != nil {
return result, err
}

return c.testWorkflowExecutionTransport.Execute(http.MethodPost, uri, body, nil)
}

0 comments on commit 593fc3b

Please sign in to comment.