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 context variables for PipelineRun & TaskRun UIDs and add validation for all context variables #3017

Merged
merged 1 commit into from Aug 3, 2020

Conversation

jerop
Copy link
Member

@jerop jerop commented Jul 27, 2020

Changes

A user may want to tag an oci image with the TaskRun or PipelineRun UIDs.
Currently, they can't do that because metadata.uid for TaskRuns and
PipelineRuns are not exposed.

In this PR, we add the UID context variable for TaskRuns and
PipelineRun. Users can now use $(context.taskRun.uid) and
$(context.pipelineRun.uid) to access and use UIDs.

In addition, we add validation for all context variables that are
supported so far -- context.task.name, context.taskRun.name,
context.taskRun.namespace, context.taskRun.uid,
context.pipeline.name, context.pipelineRun.name,
context.pipelineRun.namespace, context.pipelineRun.uid.

Partially fixes #2958

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

- User can access the uid of the `PipelineRun` that a `Pipeline` is running in using `context.pipelineRun.uid`.
- User can access the uid of the `TaskRun` that a `Task` is running in using `context.taskRun.uid`. 
- All context variables that are supported so far are now validated. 

@tekton-robot tekton-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. 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. labels Jul 27, 2020
@tekton-robot tekton-robot requested review from a user and vdemeester July 27, 2020 17:56
@jerop
Copy link
Member Author

jerop commented Jul 27, 2020

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Jul 27, 2020
@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/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from 80e76b1 to fd2d31e Compare July 27, 2020 20:40
@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/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from fd2d31e to 1623109 Compare July 27, 2020 20:45
@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/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch 2 times, most recently from f6a20cd to f0c51cd Compare July 27, 2020 22:19
@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
internal/builder/v1beta1/owner_reference.go 100.0% 80.0% -20.0
internal/builder/v1beta1/pipeline.go 81.2% 80.2% -0.9
internal/builder/v1beta1/task.go 75.5% 74.9% -0.6
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from f0c51cd to 607106a Compare July 27, 2020 22:21
@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
internal/builder/v1beta1/owner_reference.go 100.0% 80.0% -20.0
internal/builder/v1beta1/pipeline.go 81.2% 80.2% -0.9
internal/builder/v1beta1/task.go 75.5% 74.9% -0.6
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@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
internal/builder/v1beta1/owner_reference.go 100.0% 80.0% -20.0
internal/builder/v1beta1/pipeline.go 81.2% 80.2% -0.9
internal/builder/v1beta1/task.go 75.5% 74.9% -0.6
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from 607106a to f5867de Compare July 27, 2020 22:41
@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
internal/builder/v1beta1/owner_reference.go 100.0% 80.0% -20.0
internal/builder/v1beta1/pipeline.go 81.2% 80.2% -0.9
internal/builder/v1beta1/task.go 75.5% 74.9% -0.6
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch 2 times, most recently from bb9ac5e to 26166ab Compare July 27, 2020 22:54
@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
internal/builder/v1beta1/owner_reference.go 100.0% 80.0% -20.0
internal/builder/v1beta1/pipeline.go 81.2% 80.2% -0.9
internal/builder/v1beta1/task.go 75.5% 74.9% -0.6
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from 26166ab to 7ce79a3 Compare July 27, 2020 22:57
@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
internal/builder/v1beta1/owner_reference.go 100.0% 80.0% -20.0
internal/builder/v1beta1/pipeline.go 81.2% 80.2% -0.9
internal/builder/v1beta1/task.go 75.5% 74.9% -0.6
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@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
internal/builder/v1beta1/pipeline.go 81.2% 80.2% -0.9
internal/builder/v1beta1/task.go 75.5% 74.9% -0.6
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from 7ce79a3 to e8a167d Compare July 27, 2020 23:23
@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
internal/builder/v1beta1/pipeline.go 81.2% 80.2% -0.9
internal/builder/v1beta1/task.go 75.5% 74.9% -0.6
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 85.6% -0.4
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 76.6% 75.9% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from e8a167d to e8aa5d5 Compare July 27, 2020 23:34
@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
internal/builder/v1beta1/pipeline.go 81.2% 81.4% 0.2
internal/builder/v1beta1/task.go 75.5% 75.7% 0.2
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 86.1% 0.1
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 77.3% 76.6% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from 293beab to 8d8db44 Compare July 28, 2020 14:01
@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
internal/builder/v1beta1/pipeline.go 81.2% 81.4% 0.2
internal/builder/v1beta1/task.go 75.5% 75.7% 0.2
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 86.1% 0.1
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 77.3% 76.7% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop force-pushed the uid-and-annotation-variables branch from 8d8db44 to d0388c3 Compare July 28, 2020 14:40
@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
internal/builder/v1beta1/pipeline.go 81.2% 81.4% 0.2
internal/builder/v1beta1/task.go 75.5% 75.7% 0.2
pkg/reconciler/pipelinerun/pipelinerun.go 86.0% 86.1% 0.1
pkg/reconciler/pipelinerun/resources/validate_contexts.go Do not exist 100.0%
pkg/reconciler/taskrun/taskrun.go 77.3% 76.7% -0.7
pkg/reconciler/taskrun/validate_contexts.go Do not exist 100.0%

@jerop jerop marked this pull request as ready for review July 28, 2020 15:40
@tekton-robot tekton-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jul 28, 2020
pkg/reconciler/pipelinerun/pipelinerun.go Outdated Show resolved Hide resolved
@@ -300,6 +300,12 @@ func (c *Reconciler) prepare(ctx context.Context, tr *v1beta1.TaskRun) (*v1beta1
return nil, nil, controller.NewPermanentError(err)
}

if err := validateContextVariables(taskSpec, tr); err != nil {
Copy link
Member

Choose a reason for hiding this comment

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

I am having trouble seeing this one as non-exported in taskrun and the other one exported in pipelinerun/resources. Could they share code even ? (because we are "validating" the same thing, be it taskrun or other objects)

@jerop jerop force-pushed the uid-and-annotation-variables branch from d0388c3 to 0bd4707 Compare August 3, 2020 12:38
@tekton-robot tekton-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Aug 3, 2020
@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 96.2% 96.1% -0.1
pkg/apis/pipeline/v1beta1/task_validation.go 84.0% 84.7% 0.7

@jerop jerop force-pushed the uid-and-annotation-variables branch from 0bd4707 to 658f70f Compare August 3, 2020 12:42
@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 96.2% 96.1% -0.1
pkg/apis/pipeline/v1beta1/task_validation.go 84.0% 84.7% 0.7

@jerop jerop force-pushed the uid-and-annotation-variables branch from 658f70f to a2559ec Compare August 3, 2020 12:46
@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 96.2% 96.1% -0.1
pkg/apis/pipeline/v1beta1/task_validation.go 84.0% 84.7% 0.7

@jerop jerop force-pushed the uid-and-annotation-variables branch from a2559ec to a695f09 Compare August 3, 2020 12:52
@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 96.2% 96.1% -0.2
pkg/apis/pipeline/v1beta1/task_validation.go 84.0% 84.7% 0.7

A user may want to tag an oci image with the TaskRun or PipelineRun UIDs.
Currently, they can't do that because `metadata.uid` for TaskRuns and
PipelineRuns are not exposed.

In this PR, we add the UID context variable for TaskRuns and
PipelineRun. Users can now use `$(context.taskRun.uid)` and
`$(context.pipelineRun.uid)` to access and use UIDs.

In addition, we add validation for all context variables that are
supported so far -- `context.task.name`, `context.taskRun.name`,
`context.taskRun.namespace`, `context.taskRun.uid`,
`context.pipeline.name`, `context.pipelineRun.name`,
`context.pipelineRun.namespace`, `context.pipelineRun.uid`.

Partially fixes tektoncd#2958
@jerop jerop force-pushed the uid-and-annotation-variables branch from a695f09 to 5c0d1b0 Compare August 3, 2020 14:24
@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 96.2% 96.1% -0.2
pkg/apis/pipeline/v1beta1/task_validation.go 84.0% 84.7% 0.7

Copy link
Member

@vdemeester vdemeester left a comment

Choose a reason for hiding this comment

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

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 3, 2020
@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 Aug 3, 2020
@tekton-robot tekton-robot merged commit aef69cc into tektoncd:master Aug 3, 2020
@jerop jerop deleted the uid-and-annotation-variables branch September 30, 2020 15:59
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/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support more context variables (uid, annotations, …)
3 participants