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

WhenExpressions in Finally Tasks #3738

Merged
merged 1 commit into from
Feb 4, 2021
Merged

Conversation

jerop
Copy link
Member

@jerop jerop commented Feb 1, 2021

Changes

Users can guard execution of Tasks using WhenExpressions, but that
is currently not supported in Finally Tasks.

This change adds support for WhenExpressions in Finally Tasks not
only to provide efficient guarded execution but also to improve the
reusability of Tasks in Finally. The proposal is described further in
the WhenExpressions in Finally Tasks TEP.

Given we've recently added support for Results and Status in
Finally Tasks, this is an opportune time to enable WhenExpressions
in Finally Tasks.

/kind feature

Submitter Checklist

These are the criteria that every PR should meet, please check them off as you
review them:

  • Includes tests (if functionality changed/added)
  • Includes docs (if user facing)
  • Commit messages follow commit message best practices
  • Release notes block has been filled in or deleted (only if no user facing changes)

See the contribution guide for more details.

Double check this list of stuff that's easy to miss:

Reviewer Notes

If API changes are included, additive changes must be approved by at least two OWNERS and backwards incompatible changes must be approved by more than 50% of the OWNERS, and they must first be added in a backwards compatible way.

Release Notes

WhenExpressions are supported in Finally Tasks not only to provide efficient guarded execution but also to improve the
reusability of `Tasks` in `Finally`

@jerop jerop requested review from pritidesai and a user February 1, 2021 13:34
@tekton-robot tekton-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. kind/feature Categorizes issue or PR as related to a new feature. labels Feb 1, 2021
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Feb 1, 2021
@jerop
Copy link
Member Author

jerop commented Feb 1, 2021

closes #3438

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.6% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.0% 92.1% 0.1

@pritidesai
Copy link
Member

thanks @jerop, I haven't reviewed the PR yet but I would like to see e2e tests in pipelinefinally_test.go

@jerop
Copy link
Member Author

jerop commented Feb 1, 2021

thanks @jerop, I haven't reviewed the PR yet but I would like to see e2e tests in pipelinefinally_test.go

i'd added reconciler tests in pipelinerun_test.go, will add more tests in pipelinefinally_test.go, thanks @pritidesai!

/hold

@tekton-robot tekton-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 1, 2021
@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Feb 1, 2021
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.6% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.0% 92.1% 0.1

@jerop
Copy link
Member Author

jerop commented Feb 1, 2021

@pritidesai I've added the tests in pipelinefinally_test.go, please take a look 🙏🏾

/hold cancel

@tekton-robot tekton-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 1, 2021
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.6% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.0% 92.1% 0.1

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: sbwsg

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@tekton-robot tekton-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Feb 2, 2021
@tektoncd tektoncd deleted a comment from tekton-robot Feb 2, 2021
@jerop
Copy link
Member Author

jerop commented Feb 2, 2021

/test check-pr-has-kind-label

Copy link
Collaborator

@bobcatfish bobcatfish left a comment

Choose a reason for hiding this comment

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

So far I've reviewed docs, examples and the end to end test - planning to come back and review the rest but dont want to lose this so far :)

docs/pipelines.md Outdated Show resolved Hide resolved
docs/pipelines.md Show resolved Hide resolved
docs/pipelines.md Outdated Show resolved Hide resolved
docs/pipelines.md Outdated Show resolved Hide resolved
docs/pipelines.md Show resolved Hide resolved
test/pipelinefinally_test.go Outdated Show resolved Hide resolved
test/pipelinefinally_test.go Outdated Show resolved Hide resolved
test/pipelinefinally_test.go Outdated Show resolved Hide resolved
test/pipelinefinally_test.go Outdated Show resolved Hide resolved
test/pipelinefinally_test.go Show resolved Hide resolved
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.6% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.0% 92.1% 0.1

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.6% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.0% 92.1% 0.1

@jerop
Copy link
Member Author

jerop commented Feb 3, 2021

/test check-pr-has-kind-label

1 similar comment
@afrittoli
Copy link
Member

/test check-pr-has-kind-label

@pritidesai
Copy link
Member

pritidesai commented Feb 4, 2021

@jerop GetSkippedTasks adds the finally tasks into the list of skippedTasks:

func (facts *PipelineRunFacts) GetSkippedTasks() []v1beta1.SkippedTask {
var skipped []v1beta1.SkippedTask
for _, rprt := range facts.State {
if rprt.Skip(facts) {
skippedTask := v1beta1.SkippedTask{
Name: rprt.PipelineTask.Name,
WhenExpressions: rprt.PipelineTask.WhenExpressions,
}
skipped = append(skipped, skippedTask)
}
if rprt.IsFinallySkipped(facts) {
skippedTask := v1beta1.SkippedTask{
Name: rprt.PipelineTask.Name,
}
skipped = append(skipped, skippedTask)
}
}
return skipped

Can we please set WhenExpressions for finally tasks when one or more expressions are specified?

		if rprt.IsFinallySkipped(facts) {
			skippedTask := v1beta1.SkippedTask{
				Name: rprt.PipelineTask.Name,
			}
			if rprt.PipelineTask.WhenExpressions != nil || len(rprt.PipelineTask.WhenExpressions) != 0 {
				skippedTask.WhenExpressions = rprt.PipelineTask.WhenExpressions
			}
			skipped = append(skipped, skippedTask)
		}

such that finally tasks being in the list of skipped tasks have the when expressions initialized.

    {
        "name": "finally-task-should-be-skipped-1"
      },
      {
        "name": "finally-task-should-be-skipped-2"
      },
      {
        "name": "finally-task-should-be-skipped-3"
      }

After these changes:

     {
        "name": "finally-task-should-be-skipped-1",
        "whenExpressions": [
          {
            "input": "Succeeded",
            "operator": "in",
            "values": [
              "Failure"
            ]
          }
        ]
      },
      {
        "name": "finally-task-should-be-skipped-2",
        "whenExpressions": [
          {
            "input": "yes",
            "operator": "in",
            "values": [
              "missing"
            ]
          }
        ]
      },
      {
        "name": "finally-task-should-be-skipped-3",
        "whenExpressions": [
          {
            "input": "README.md",
            "operator": "notin",
            "values": [
              "README.md"
            ]
          }
        ]
      }

@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.6% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.0% 92.1% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 69.5% 69.8% 0.4

@jerop
Copy link
Member Author

jerop commented Feb 4, 2021

thanks for the review @pritidesai! 🙏🏾

Can we please set WhenExpressions for finally tasks when one or more expressions are specified?

		if rprt.IsFinallySkipped(facts) {
			skippedTask := v1beta1.SkippedTask{
				Name: rprt.PipelineTask.Name,
			}
			if rprt.PipelineTask.WhenExpressions != nil || len(rprt.PipelineTask.WhenExpressions) != 0 {
				skippedTask.WhenExpressions = rprt.PipelineTask.WhenExpressions
			}
			skipped = append(skipped, skippedTask)
		}

makes sense to do it similarly to Tasks, but did it a bit differently to ensure we don't include WhenExpressions in Finally Tasks that were skipped because they referenced missing Results (not because their WhenExpressions evaluated to False):

if rprt.IsFinallySkipped(facts) {
skippedTask := v1beta1.SkippedTask{
Name: rprt.PipelineTask.Name,
}
// include the when expressions only when the finally task was skipped because
// its when expressions evaluated to false (not because results variables were missing)
if !rprt.PipelineTask.WhenExpressions.HaveVariables() {
skippedTask.WhenExpressions = rprt.PipelineTask.WhenExpressions
}
skipped = append(skipped, skippedTask)
}

@pritidesai
Copy link
Member

thanks a bunch @jerop, great point 🙇‍♀️

Users can guard execution of `Tasks` using `WhenExpressions`, but that
is currently not supported in `Finally Tasks`.

This change adds support for `WhenExpressions` in `Finally Tasks` not
only to provide efficient guarded execution but also to improve the
reusability of `Tasks` in `Finally`. The proposal is described further in
the [WhenExpressions in Finally Tasks TEP](https://github.com/tektoncd/community/blob/master/teps/0045-whenexpressions-in-finally-tasks.md).

Given we've recently added support for `Results` and `Status` in
`Finally Tasks`, this is an opportune time to enable `WhenExpressions`
in `Finally Tasks`.
@pritidesai
Copy link
Member

Thanks a bunch @jerop for this feature.

I am having hard time understanding validation unit tests. I feel we have many overlapping tests. Ideally, would like to see the separate unit tests validating when expression syntax e.g. input and values are initialized, a valid operator is specified, etc. Now once we have validated the syntax, I don't see a need to have separate tests to validate the syntax again as part of either tasks or finally. Rather validate when expressions references (e.g. referencing a task result or defined parameter) with the tasks and finally sections. This can be refactored and simplified later and will not block this PR.

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2021
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2021
@tekton-robot
Copy link
Collaborator

The following is the coverage report on the affected files.
Say /test pull-tekton-pipeline-go-coverage to re-run this coverage report

File Old Coverage New Coverage Delta
pkg/apis/pipeline/v1beta1/pipeline_validation.go 99.6% 99.6% 0.0
pkg/reconciler/pipelinerun/resources/pipelinerunresolution.go 92.0% 92.1% 0.1
pkg/reconciler/pipelinerun/resources/pipelinerunstate.go 69.5% 69.8% 0.4

@jerop
Copy link
Member Author

jerop commented Feb 4, 2021

@pritidesai I agree, we need to refactor the validation testing -- can open an issue to track that

@jerop jerop requested a review from pritidesai February 4, 2021 18:04
@pritidesai
Copy link
Member

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Feb 4, 2021
@tekton-robot tekton-robot merged commit 62d8621 into tektoncd:master Feb 4, 2021
jerop added a commit to jerop/community that referenced this pull request Jun 3, 2021
jerop added a commit to jerop/community that referenced this pull request Jun 3, 2021
tekton-robot pushed a commit to tektoncd/community that referenced this pull request Jun 3, 2021
@@ -630,7 +630,7 @@ func (c *Reconciler) runNextSchedulableTask(ctx context.Context, pr *v1beta1.Pip
}

for _, rprt := range nextRprts {
if rprt == nil || rprt.Skip(pipelineRunFacts) {
if rprt == nil || rprt.Skip(pipelineRunFacts) || rprt.IsFinallySkipped(pipelineRunFacts) {
Copy link
Member

Choose a reason for hiding this comment

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

hey @jerop, based on my understanding, rprt.Skip(pipelineRunFacts) returns false for any finally task but rprt.IsFinallySkipped(pipelineRunFacts) evaluates when expression and returns true since the when expression evaluates to false.

Copy link
Member

Choose a reason for hiding this comment

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

but this would work, provided nextRprts contains the finally tasks 🤣

@jerop jerop deleted the weinft branch June 11, 2022 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. kind/feature Categorizes issue or PR as related to a new feature. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants