You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Add a new type of task in Flow, that similar to control flow statement for-loop in programming languages, will allow other tasks to be executed repeatedly. The task itself will perform a few simple operations, like checking the end condition and incrementing the counter, hence named "Counter".
Description
The "Counter" task will have multiple inputs, but exactly two outputs (see description below). Analogous to C programming language for-loops, the task is split into 3 parts:
Initialization
The "Counter" will always create a new variable (the name can be defined within the task configuration page) which by default is initialized with and Integer value 0.
Condition
The condition has to be manually defined by the user and must return a Boolean type of data:
If the returned Boolean value is True, the Afterthought is performed and then flow execution will continue to the first output, the output for "Condition Satisfied".
If the returned Boolean value is False, flow execution will continue to the second output, the output for "Condition Not Satisfied", leading to an exit from the loop.
Afterthought
The afterthought has to be manually defined by the user and is performed exactly once every time the execution reaches the "Counter" and the Condition is False.
We might provide some default statements for each part: Initialization: ${p:iterator} = 0; Condition: return ${p:iterator} < 10;
** Afterthought**: ${p:iterator} = ${p:iterator} + 1;
Use Cases
Classic for-loop which executes a contiguous sequence of tasks
A flow of control modifying the iterator variable value
A flow of control that allows an early exit from the loop
Benefits and Justification
The for-loop is probably the most common and well known type of loop in any programming language. Having a counter type of task in Flow, enables the possibility to performs operations similar to for-loops by repeating a chain of tasks, but with additional functionality like the modification of the iterator inside the looping flow or an early exit from the loop.
Note
The above concept contradicts with the DAG idea of Flow since cycles are present in the graph. The checker has to be modified with the following rules:
If cycles are present in the graph, check conditions below:
If the cycle starts and ends at the same node ("Counter" task), or ends at the "end" node in the graph, the graph is valid.
If nodes within the cycle have paths to other nodes that are located before the cycle begun, the graph is invalid (see diagram below).
If no cycles are present in the graph, graph is valid.
Hey @corcoja with the next version of Flow it will actually be running Tekton TaskRuns instead of Kubernetes Jobs.
This is discussed here with the experimental custom task here
I think if we were to implement it in the UI via the concept of Advanced Task Configuration it may be possible.
Alternatively we build it ourselves outside of Tekton which may also be a possibility as otherwise I'm not sure how we would support a user importing a standard Tekton Task and then wanting to make it iterate in a loop.
The interesting concept from both Tekton and Argo is that it matches the design you have put together of using an iterator item (i.e. array) or withItems which is also an array.
General Idea
Add a new type of task in Flow, that similar to control flow statement for-loop in programming languages, will allow other tasks to be executed repeatedly. The task itself will perform a few simple operations, like checking the end condition and incrementing the counter, hence named "Counter".
Description
The "Counter" task will have multiple inputs, but exactly two outputs (see description below). Analogous to C programming language for-loops, the task is split into 3 parts:
The "Counter" will always create a new variable (the name can be defined within the task configuration page) which by default is initialized with and
Integer
value0
.The condition has to be manually defined by the user and must return a
Boolean
type of data:Boolean
value isTrue
, the Afterthought is performed and then flow execution will continue to the first output, the output for "Condition Satisfied".Boolean
value isFalse
, flow execution will continue to the second output, the output for "Condition Not Satisfied", leading to an exit from the loop.The afterthought has to be manually defined by the user and is performed exactly once every time the execution reaches the "Counter" and the Condition is
False
.We might provide some default statements for each part:
Initialization:
${p:iterator} = 0;
Condition:
return ${p:iterator} < 10;
** Afterthought**:
${p:iterator} = ${p:iterator} + 1;
Use Cases
Classic for-loop which executes a contiguous sequence of tasks
A flow of control modifying the iterator variable value
A flow of control that allows an early exit from the loop
Benefits and Justification
The for-loop is probably the most common and well known type of loop in any programming language. Having a counter type of task in Flow, enables the possibility to performs operations similar to for-loops by repeating a chain of tasks, but with additional functionality like the modification of the iterator inside the looping flow or an early exit from the loop.
Note
The above concept contradicts with the DAG idea of Flow since cycles are present in the graph. The checker has to be modified with the following rules:
Draw.io file: Boomerang Flow - Counter.drawio
The text was updated successfully, but these errors were encountered: