From 831964871fad4306467baf90b25f28fb6b2da88e Mon Sep 17 00:00:00 2001 From: Dawid Rusnak Date: Fri, 15 Mar 2024 09:13:17 +0100 Subject: [PATCH] hotfix: support Retry Policies in TestWorkflows (#5199) * fix: use `retry` policy for TestWorkflow stages * fix: process Retry Policy in TestWorkflows init process --- cmd/tcl/testworkflow-init/main.go | 6 +++--- .../testworkflowstcl/testworkflowprocessor/operations.go | 5 +++++ .../testworkflowprocessor/stagelifecycle.go | 9 ++++++--- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/cmd/tcl/testworkflow-init/main.go b/cmd/tcl/testworkflow-init/main.go index d387ed452db..ae1e8d25e46 100644 --- a/cmd/tcl/testworkflow-init/main.go +++ b/cmd/tcl/testworkflow-init/main.go @@ -161,17 +161,17 @@ func main() { } // Load the rest of the configuration + var err error for k, v := range config { - value, err := data.Template(v) + config[k], err = data.Template(v) if err != nil { output.Failf(output.CodeInputError, `resolving "%s" param: %s: %s`, k, v, err.Error()) } - data.LoadConfig(map[string]string{k: value}) } + data.LoadConfig(config) // Compute templates in the cmd/args original := slices.Clone(args) - var err error for i := range args { args[i], err = data.Template(args[i]) if err != nil { diff --git a/pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go b/pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go index 4724eb79959..d86de08cd64 100644 --- a/pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go +++ b/pkg/tcl/testworkflowstcl/testworkflowprocessor/operations.go @@ -46,6 +46,7 @@ func ProcessShellCommand(_ InternalProcessor, layer Intermediate, container Cont shell := container.CreateChild().SetCommand(defaultShell).SetArgs("-c", step.Shell) stage := NewContainerStage(layer.NextRef(), shell) stage.SetCategory("Run shell command") + stage.SetRetryPolicy(step.Retry) return stage, nil } @@ -55,6 +56,7 @@ func ProcessRunCommand(_ InternalProcessor, layer Intermediate, container Contai } container = container.CreateChild().ApplyCR(&step.Run.ContainerConfig) stage := NewContainerStage(layer.NextRef(), container) + stage.SetRetryPolicy(step.Retry) stage.SetCategory("Run") return stage, nil } @@ -89,6 +91,7 @@ func ProcessExecute(_ InternalProcessor, layer Intermediate, container Container } container = container.CreateChild() stage := NewContainerStage(layer.NextRef(), container) + stage.SetRetryPolicy(step.Retry) hasWorkflows := len(step.Execute.Workflows) > 0 hasTests := len(step.Execute.Tests) > 0 @@ -212,6 +215,7 @@ func ProcessContentGit(_ InternalProcessor, layer Intermediate, container Contai selfContainer := container.CreateChild() stage := NewContainerStage(layer.NextRef(), selfContainer) + stage.SetRetryPolicy(step.Retry) stage.SetCategory("Clone Git repository") // Compute mount path @@ -283,6 +287,7 @@ func ProcessArtifacts(_ InternalProcessor, layer Intermediate, container Contain selfContainer := container.CreateChild(). ApplyCR(&testworkflowsv1.ContainerConfig{WorkingDir: step.Artifacts.WorkingDir}) stage := NewContainerStage(layer.NextRef(), selfContainer) + stage.SetRetryPolicy(step.Retry) stage.SetCondition("always") stage.SetCategory("Upload artifacts") diff --git a/pkg/tcl/testworkflowstcl/testworkflowprocessor/stagelifecycle.go b/pkg/tcl/testworkflowstcl/testworkflowprocessor/stagelifecycle.go index 13b922ea77b..bc236e38e39 100644 --- a/pkg/tcl/testworkflowstcl/testworkflowprocessor/stagelifecycle.go +++ b/pkg/tcl/testworkflowstcl/testworkflowprocessor/stagelifecycle.go @@ -30,7 +30,7 @@ type StageLifecycle interface { SetOptional(optional bool) StageLifecycle SetCondition(expr string) StageLifecycle AppendConditions(expr ...string) StageLifecycle - SetRetryPolicy(policy testworkflowsv1.RetryPolicy) StageLifecycle + SetRetryPolicy(policy *testworkflowsv1.RetryPolicy) StageLifecycle SetTimeout(tpl string) StageLifecycle } @@ -100,8 +100,11 @@ func (s *stageLifecycle) AppendConditions(expr ...string) StageLifecycle { return s } -func (s *stageLifecycle) SetRetryPolicy(policy testworkflowsv1.RetryPolicy) StageLifecycle { - s.retry = policy +func (s *stageLifecycle) SetRetryPolicy(policy *testworkflowsv1.RetryPolicy) StageLifecycle { + if policy == nil { + policy = &testworkflowsv1.RetryPolicy{} + } + s.retry = *policy return s }