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

Allow Resources to be Optional in Task, ClusterTask, and Condition #1601

Merged
merged 1 commit into from
Dec 13, 2019

Conversation

pritidesai
Copy link
Member

@pritidesai pritidesai commented Nov 21, 2019

Changes

Task inputs and outputs are considered required, there is no way
today to mark them optional. This change introduced a new field called
optional as part of the PipelineResourceDeclaration by default a resource
is required. To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
 name: task-check-workspace
spec:
 inputs:
   resources:
     - name: workspace
       type: git
       optional: true
 steps:
   - name: check-workspace

These changes apply to Task, ClusterTask and Condition resources.

Closes #812

Submitter Checklist

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

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

Introducing a new key called optional as part of the PipelineResourceDeclaration by default a resource is required (as is - no change in behavior). To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Task
metadata:
 name: task-check-workspace
spec:
 inputs:
   resources:
     - name: workspace
       type: git
       optional: true
 steps:
   - name: check-workspace

@tekton-robot tekton-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 21, 2019
@googlebot googlebot added the cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit label Nov 21, 2019
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Nov 21, 2019
@pritidesai
Copy link
Member Author

/wip

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/taskrun/resources/input_resources.go 94.1% 92.5% -1.7
pkg/reconciler/taskrun/resources/output_resource.go 90.5% 88.6% -1.8
pkg/reconciler/taskrun/validate_resources.go 94.7% 93.7% -1.1
test/builder/task.go 80.2% 80.7% 0.5

@imjasonh
Copy link
Member

Hey Priti, thanks for this change!

Is there an issue or design doc to describe the motivations for this change? It seems useful but I want to make sure we've thought through some of the use cases and new error scenariros before we add this to the API

There's also a bit of work going on in the PipelineResources space at the moment, so this change might be easier to land after that dust has settled. Is there a particular use case you're trying to support, and how soon do you need it?

@pritidesai
Copy link
Member Author

hey @imjasonh, sorry forgot to link the GitHub issue #812 and Design Doc, yup the motivation is included in there ...

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/taskrun/resources/input_resources.go 94.1% 92.5% -1.7
pkg/reconciler/taskrun/resources/output_resource.go 90.5% 90.9% 0.4
pkg/reconciler/taskrun/validate_resources.go 94.7% 93.7% -1.1
test/builder/task.go 80.2% 80.7% 0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/taskrun/resources/input_resources.go 94.1% 94.3% 0.2
pkg/reconciler/taskrun/resources/output_resource.go 90.5% 90.9% 0.4
pkg/reconciler/taskrun/validate_resources.go 94.7% 93.7% -1.1
test/builder/task.go 80.2% 80.7% 0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/taskrun/resources/input_resources.go 94.1% 94.3% 0.2
pkg/reconciler/taskrun/resources/output_resource.go 90.5% 90.9% 0.4
pkg/reconciler/taskrun/validate_resources.go 94.7% 95.2% 0.5
test/builder/task.go 80.2% 80.7% 0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/taskrun/resources/input_resources.go 94.1% 94.3% 0.2
pkg/reconciler/taskrun/resources/output_resource.go 90.5% 90.9% 0.4
pkg/reconciler/taskrun/validate_resources.go 94.7% 95.2% 0.5
test/builder/task.go 80.2% 80.7% 0.5

@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 Nov 22, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/taskrun/resources/input_resources.go 94.1% 94.3% 0.2
pkg/reconciler/taskrun/resources/output_resource.go 90.5% 90.9% 0.4
pkg/reconciler/taskrun/validate_resources.go 94.7% 95.2% 0.5
test/builder/task.go 80.2% 80.7% 0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/taskrun/resources/input_resources.go 94.1% 94.3% 0.2
pkg/reconciler/taskrun/resources/output_resource.go 90.5% 90.9% 0.4
pkg/reconciler/taskrun/validate_resources.go 94.7% 95.2% 0.5
test/builder/task.go 80.2% 80.7% 0.5

@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
pkg/reconciler/taskrun/resources/input_resources.go 94.1% 94.3% 0.2
pkg/reconciler/taskrun/resources/output_resource.go 90.5% 90.9% 0.4
pkg/reconciler/taskrun/validate_resources.go 94.7% 95.2% 0.5
test/builder/task.go 80.2% 80.7% 0.5

@pritidesai
Copy link
Member Author

its ready for review now ...

Please let me know if there are any changes needed 😄

@pritidesai pritidesai changed the title WIP: Allow Resources to be Optional in Task Allow Resources to be Optional in Task, ClusterTask, and Condition Nov 22, 2019
@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 Nov 22, 2019
@ghost
Copy link

ghost commented Dec 5, 2019

It would be great to add some doc updates here as well - in particular I'm a bit unclear on the expected behaviour of variable substitutions when a resource is optional.

@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Dec 11, 2019
@tekton-robot
Copy link
Collaborator

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

File Old Coverage New Coverage Delta
test/builder/task.go 81.4% 81.8% 0.4

@pritidesai
Copy link
Member Author

failed again 😢

I1211 16:59:30.399] ---- Checking links in the markdown files ----
I1211 16:59:30.399] ----------------------------------------------
I1211 16:59:32.799] docs/resources.md
I1211 16:59:32.800] 	ERROR	https://godoc.org/github.com/jenkins-x/go-scm/scm#State
I1211 16:59:32.800] 		Not Found (HTTP error 404)

https://godoc.org/github.com/jenkins-x/go-scm/scm#State is accessible from the browser when I try.

@vdemeester
Copy link
Member

/test pull-tekton-pipeline-build-tests
/shrug

👼 🙏

@tekton-robot tekton-robot added the ¯\_(ツ)_/¯ ¯\\\_(ツ)_/¯ label Dec 11, 2019
@pritidesai
Copy link
Member Author

/retest

@ghost
Copy link

ghost commented Dec 11, 2019

i've made a pr against plumbing to try disabling the md link checker: tektoncd/plumbing#154

not sure at the moment what else to do beyond removing the links.

@pritidesai
Copy link
Member Author

was hoping (PR #1737 but now realizing its for nightly builds)to see coverage build fixed but doesnt look like 😞, still produces failure https://tekton-releases.appspot.com/build/tekton-prow/pr-logs/pull/tektoncd_pipeline/1601/pull-tekton-pipeline-go-coverage/1204807757975261187/?log#log

# github.com/tektoncd/pipeline/pkg/artifacts
pkg/artifacts/artifacts_storage.go:182: Errorf format %w has unknown verb w

Copy link
Member

@dibyom dibyom left a comment

Choose a reason for hiding this comment

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

Thanks for adding this @pritidesai
I was a bit concerned about potential edge cases when the resource is missing but from looking at the code, it seems like that it would be up to the task author to ensure that their tasks behave correctly when a resource is missing!

@@ -94,6 +94,11 @@ type ResourceDeclaration struct {
// will be copied.
// +optional
TargetPath string `json:"targetPath,omitempty"`
// Optional declares the resource as optional.
Copy link
Member

Choose a reason for hiding this comment

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

This is a tiny nitpick but I think the last two lines comment lines are not required as the first two are descriptive enough.

Copy link
Member Author

Choose a reason for hiding this comment

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

would like to keep them in as those two lines show the usage and its behavior vs first two lines explains the key itself.

@@ -239,20 +239,30 @@ func InputsResource(name string, resourceType v1alpha1.PipelineResourceType, ops
}
}

func ResourceOptional(optional bool) TaskResourceOp {
Copy link
Member

Choose a reason for hiding this comment

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

This is totally fine but is there a easier/simpler for doing test builders for boolean values? @vdemeester

Copy link
Member Author

Choose a reason for hiding this comment

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

I dont think so, its more about following our convention of building a resource, for example,

Required Resource:

tb.InputsResource("resource-to-build", v1alpha1.PipelineResourceTypeGit),

Optional Resource:

tb.InputsResource("optional-resource-to-build", v1alpha1.PipelineResourceTypeGit, tb.ResourceOptional(true)),

But would be ideal to refactor the way we initialize a resource in future, as we add more keys/fields, we end up adding setters for each.

@tekton-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: dibyom

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 Dec 11, 2019
@dibyom
Copy link
Member

dibyom commented Dec 11, 2019

/test pull-tekton-pipeline-build-tests

1 similar comment
@vdemeester
Copy link
Member

/test pull-tekton-pipeline-build-tests

@vdemeester vdemeester removed the ¯\_(ツ)_/¯ ¯\\\_(ツ)_/¯ label Dec 12, 2019
@pritidesai
Copy link
Member Author

/retest

@pritidesai
Copy link
Member Author

💃 the build succeeds 😄 thanks everyone for fixing it 👍

@pritidesai
Copy link
Member Author

Thanks for adding this @pritidesai
I was a bit concerned about potential edge cases when the resource is missing but from looking at the code, it seems like that it would be up to the task author to ensure that their tasks behave correctly when a resource is missing!

Thanks @dibyom
Scenario 1: If a required resource is not specified in TaskRun, its behavior remains same, failure with Didn''t provide required values ...
Scenario 2: If an optional resource is not specified in TaskRun but referred to in a task, the task execution still succeeds and a pod displays message such as outputs.resources.optionalimage.url: command not found which is reasonable and its up to user how to handle such use case.

@ghost
Copy link

ghost commented Dec 13, 2019

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Dec 13, 2019
@tekton-robot tekton-robot merged commit ccacb0c into tektoncd:master Dec 13, 2019
pritidesai added a commit to pritidesai/pipeline that referenced this pull request Jan 21, 2020
Pipeline inputs and outputs are considered required, there is no way
today to mark them optional. This change introduces a new field called
optional as part of the PipelineDeclaredResource similar to previous PR tektoncd#1601,
by default optional is set to false and a resource is required.
To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
 name: pipeline-build-image
spec:
 resources:
   - name: workspace
     type: git
     optional: true
 tasks:
   - name: check-workspace

Closes tektoncd#1710
pritidesai added a commit to pritidesai/pipeline that referenced this pull request Jan 21, 2020
Pipeline inputs and outputs are considered required, there is no way
today to mark them optional. This change introduces a new field called
optional as part of the PipelineDeclaredResource similar to previous PR tektoncd#1601,
by default optional is set to false and a resource is required.
To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
 name: pipeline-build-image
spec:
 resources:
   - name: workspace
     type: git
     optional: true
 tasks:
   - name: check-workspace

Closes tektoncd#1710
pritidesai added a commit to pritidesai/pipeline that referenced this pull request Jan 21, 2020
Pipeline inputs and outputs are considered required, there is no way
today to mark them optional. This change introduces a new field called
optional as part of the PipelineDeclaredResource similar to previous PR tektoncd#1601,
by default optional is set to false and a resource is required.
To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
 name: pipeline-build-image
spec:
 resources:
   - name: workspace
     type: git
     optional: true
 tasks:
   - name: check-workspace

Closes tektoncd#1710
pritidesai added a commit to pritidesai/pipeline that referenced this pull request Jan 21, 2020
Pipeline inputs and outputs are considered required, there is no way
today to mark them optional. This change introduces a new field called
optional as part of the PipelineDeclaredResource similar to previous PR tektoncd#1601,
by default optional is set to false and a resource is required.
To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
 name: pipeline-build-image
spec:
 resources:
   - name: workspace
     type: git
     optional: true
 tasks:
   - name: check-workspace

Closes tektoncd#1710
pritidesai added a commit to pritidesai/pipeline that referenced this pull request Jan 22, 2020
Pipeline inputs and outputs are considered required, there is no way
today to mark them optional. This change introduces a new field called
optional as part of the PipelineDeclaredResource similar to previous PR tektoncd#1601,
by default optional is set to false and a resource is required.
To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
 name: pipeline-build-image
spec:
 resources:
   - name: workspace
     type: git
     optional: true
 tasks:
   - name: check-workspace

Closes tektoncd#1710
pritidesai added a commit to pritidesai/pipeline that referenced this pull request Jan 23, 2020
Pipeline inputs and outputs are considered required, there is no way
today to mark them optional. This change introduces a new field called
optional as part of the PipelineDeclaredResource similar to previous PR tektoncd#1601,
by default optional is set to false and a resource is required.
To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
 name: pipeline-build-image
spec:
 resources:
   - name: workspace
     type: git
     optional: true
 tasks:
   - name: check-workspace

Closes tektoncd#1710
pritidesai added a commit to pritidesai/pipeline that referenced this pull request Jan 23, 2020
Pipeline inputs and outputs are considered required, there is no way
today to mark them optional. This change introduces a new field called
optional as part of the PipelineDeclaredResource similar to previous PR tektoncd#1601,
by default optional is set to false and a resource is required.
To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
 name: pipeline-build-image
spec:
 resources:
   - name: workspace
     type: git
     optional: true
 tasks:
   - name: check-workspace

Closes tektoncd#1710
tekton-robot pushed a commit that referenced this pull request Feb 3, 2020
Pipeline inputs and outputs are considered required, there is no way
today to mark them optional. This change introduces a new field called
optional as part of the PipelineDeclaredResource similar to previous PR #1601,
by default optional is set to false and a resource is required.
To mark any resource optional, set optional to true:

apiVersion: tekton.dev/v1alpha1
kind: Pipeline
metadata:
 name: pipeline-build-image
spec:
 resources:
   - name: workspace
     type: git
     optional: true
 tasks:
   - name: check-workspace

Closes #1710
@pritidesai pritidesai deleted the optional-resources branch December 5, 2020 00:01
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. cla: yes Trying to make the CLA bot happy with ppl from different companies work on one commit lgtm Indicates that a PR is ready to be merged. 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.

FR: Allow Resources to be declared as "optional"
7 participants