Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Counter task type in Flow #23

Open
corcoja opened this issue Nov 16, 2020 · 1 comment
Open

Add Counter task type in Flow #23

corcoja opened this issue Nov 16, 2020 · 1 comment
Labels
enhancement New feature or request

Comments

@corcoja
Copy link
Member

corcoja commented Nov 16, 2020

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:

  1. 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.
  2. 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.
  1. 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

Boomerang Flow - Counter-Page-1.svg

A flow of control modifying the iterator variable value

Boomerang Flow - Counter-Page-2.svg

A flow of control that allows an early exit from the loop

Boomerang Flow - Counter-Page-3.svg

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:

  1. 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).
  1. If no cycles are present in the graph, graph is valid.

Boomerang Flow - Counter-Page-4.svg

Draw.io file: Boomerang Flow - Counter.drawio

@tlawrie tlawrie added the enhancement New feature or request label Nov 17, 2020
@tlawrie
Copy link
Member

tlawrie commented May 24, 2021

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants