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

KEP 93: Lifecycle Toolkit - on-success and on-error-tasks #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
88 changes: 88 additions & 0 deletions text/0093-klt-on-success-failure.md
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like what @grabnerandi mentioned of defining them at KeptnApp level, and see what @agardnerIT, is there any way that the tasks can be executed and then those results aggregated and then sent in one response back to KeptnApp?

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# KEP 93: Run Tasks on Evaluation Success or Failure

**State: DRAFTING**

## Motivation
The Keptn Lifecycle Toolkit allows to define tasks which are executed before or after a deployment. Currently, it is not possible to define tasks, which are based on the evaluation result. This is a limitation for users, as it is currently not possible to react on the evaluation result.

## Current Design
Currently, the Lifecycle Toolkit knows following phases which are executed sequentially:

* Application Pre-Deployment-Tasks
* Application Pre-Deployment-Evaluations
* Application Deployment
* Workload Pre-Deployment-Tasks
* Workload Pre-Deployment-Evaluations
* Workload Deployment
* Workload Post-Deployment-Tasks
* Workload Post-Deployment-Evaluations
* Post-Deployment-Tasks
* Post-Deployment-Evaluations

Tasks and Evaluations are marked as successful when the respective task or evaluation is executed successfully. If a task or evaluation fails, the whole phase is marked as failed. The phases are executed sequentially, which means that the next phase is only executed if the previous phase was successful. The tasks in a phase are executed in parallel.

## Assumptions / Definitions
* Additional Tasks and Evaluations can be defined on per Application or per Workload basis


## Proposed Design
Whether there are some ways to extend the current design, this KEP will focus on an approach where the user can define on-success and on-failure tasks for KeptnTaskDefinitions and KeptnEvaluations. Therefore, a KeptnTaskDefinition might look as follows afterward:

```yaml
apiVersion: lifecycle.keptn.sh/v1alpha2
kind: KeptnTaskDefinition
metadata:
name: promote-staging
spec:
function:
httpRef:
url: https://raw.githubusercontent.com/keptn-contrib/klt-tasks/main/trigger-github-action/function.ts
parameters:
map:
nextStage: staging
username: thschue
repository: easy-promotion-example
job: promotion.yaml
ref: main
secureParameters:
secret: github
on-success: <KeptnTaskDefinition>
on-failure: <KeptnTaskDefinition>
```

This would allow the user to define a task which is executed when the task was successful. The same applies for the KeptnEvaluationDefinition:

```yaml
apiVersion: lifecycle.keptn.sh/v1alpha2
kind: KeptnEvaluationDefinition
metadata:
name: app-pre-deploy-eval-1
namespace: podtato-kubectl
spec:
objectives:
- name: available-cpus ## this query should fail
query: "sum(kube_pod_container_resource_limits{resource='cpu'}) - sum(kube_node_status_capacity{resource='cpu'})"
evaluationTarget: ">4"
on-success: <KeptnTaskDefinition>
on-failure: <KeptnTaskDefinition>
```

This design allows the user to define tasks which are executed when the evaluation was successful or failed. The tasks are executed in parallel to the evaluation. The tasks are executed in the same namespace as the evaluation or the TaskDefinitions.

## Alternative Design
It would be possible to define a new phase after the respective evaluation or task phases. This would lead to the situation in which the author of functions has to deal with the phases and functions would not be as generic as they are now. As an example:

**As a developer, I want to get a notification when the evaluation after a deployment was successful.**

With the proposed design, the function developer would implement the function to send a notification without having to deal with the phases and define this as an on-success action as described above.

With the alternative design, the function developer would have to implement all possible cases (on-success, on-failure) and would also have to take care if the certain task should be executed for the corresponding workload. This would lead to a lot of complexity for the function developer.

## Things to consider
* This would lead to a situation where tasks can be chained. Therefore, it is important to define a maximum number of chained tasks, e.g. it's only possible to run one task after another task. This has to be defined and tracked somewhere.
* The "child" tasks should also be visible in the traces of the parent task. This would allow the user to see the whole execution flow.

## Benefits
* It's possible to define tasks which are executed when the evaluation was successful or failed
* Therefore, it's possible to react on the evaluation result and e.g. trigger a notification or promotion/rollback steps