Skip to content

Commit

Permalink
fix: make WF global parameters available in retries (#12698)
Browse files Browse the repository at this point in the history
Signed-off-by: eduardodbr <eduardodbr@hotmail.com>
  • Loading branch information
eduardodbr committed Feb 25, 2024
1 parent a927379 commit 9bec114
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2128,7 +2128,7 @@ func (woc *wfOperationCtx) executeTemplate(ctx context.Context, nodeName string,
// Inject the retryAttempt number
localParams[common.LocalVarRetries] = strconv.Itoa(retryNum)

processedTmpl, err = common.SubstituteParams(processedTmpl, map[string]string{}, localParams)
processedTmpl, err = common.SubstituteParams(processedTmpl, woc.globalParams, localParams)
if errorsutil.IsTransientErr(err) {
return node, err
}
Expand Down
57 changes: 57 additions & 0 deletions workflow/controller/operator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1322,6 +1322,63 @@ func TestRetriesVariableInPodSpecPatch(t *testing.T) {
assert.ElementsMatch(t, actual, expected)
}

var retriesVariableWithGlobalVariablesInPodSpecPatchTemplate = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
metadata:
name: whalesay
spec:
entrypoint: whalesay
arguments:
parameters:
- name: memreqnum
value: 100
templates:
- name: whalesay
retryStrategy:
limit: 10
podSpecPatch: |
containers:
- name: main
resources:
limits:
memory: "{{= (sprig.int(retries)+1)* sprig.int(workflow.parameters.memreqnum)}}Mi"
container:
image: docker/whalesay:latest
command: [sh, -c]
args: ["cowsay hello"]
`

func TestRetriesVariableWithGlobalVariableInPodSpecPatch(t *testing.T) {
wf := wfv1.MustUnmarshalWorkflow(retriesVariableWithGlobalVariablesInPodSpecPatchTemplate)
cancel, controller := newController(wf)
defer cancel()
ctx := context.Background()
iterations := 5
var woc *wfOperationCtx
for i := 1; i <= iterations; i++ {
woc = newWorkflowOperationCtx(wf, controller)
if i != 1 {
makePodsPhase(ctx, woc, apiv1.PodFailed)
}
woc.operate(ctx)
wf = woc.wf
}

pods, err := listPods(woc)
assert.NoError(t, err)
assert.Len(t, pods.Items, iterations)
expected := []string{}
actual := []string{}
for i := 0; i < iterations; i++ {
actual = append(actual, pods.Items[i].Spec.Containers[1].Resources.Limits.Memory().String())
expected = append(expected, fmt.Sprintf("%dMi", (i+1)*100))
}
// expecting memory limit to increase after each retry: "100Mi", "200Mi", "300Mi", "400Mi", "500Mi"
// ordering not preserved
assert.ElementsMatch(t, actual, expected)
}

var stepsRetriesVariableTemplate = `
apiVersion: argoproj.io/v1alpha1
kind: Workflow
Expand Down

0 comments on commit 9bec114

Please sign in to comment.