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

Only copy output resource to PVC for storage/git output #414

Merged
merged 2 commits into from
Jan 22, 2019

Conversation

afrittoli
Copy link
Member

At the moment the output_resource module unconditionally adds a
copy step for every output resource in the taskrun.
However not every output resource will generate content to be
copied. Limit the copy to Storage and Git outoputs for now.

This is meant as a hotfix for bug #401 until an implementation
of the image output resource is available via #216. Until
image resource output is implemented, any consumer won't
have guarantee that the image has been actually built and pushed,
and won't know the hash of the created image.

@knative-prow-robot knative-prow-robot added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jan 21, 2019
@knative-prow-robot knative-prow-robot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 21, 2019
@afrittoli afrittoli changed the title Onpy copy output resource to PVC for storage/git output Only copy output resource to PVC for storage/git output Jan 21, 2019
Copy link
Contributor

@shashwathi shashwathi left a comment

Choose a reason for hiding this comment

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

Thank you so much for adding this PR. Can you add test in output resources package that image outputs does not create output related steps?

@afrittoli
Copy link
Member Author

Thank you so much for adding this PR. Can you add test in output resources package that image outputs does not create output related steps?

Sure I can do that. I didn't add tests so far because - I think - this is going away once image output resource is fully implemented, but it's better to have the test and remove it :)

@shashwathi
Copy link
Contributor

/assign @shashwathi

@shashwathi
Copy link
Contributor

this is going away once image output resource is fully implemented, but it's better to have the test and remove it

Yes I agree with that too

At the moment the output_resource module unconditionally adds a
copy step for every output resource in the taskrun.
However not every output resource will generate content to be
copied. Limit the copy to Storage and Git outoputs for now.

This is meant as a hotfix for bug tektoncd#401 until an implementation
of the image output resource is available via tektoncd#216. Until
image resource output is implemented, any consumer won't
have guarantee that the image has been actually built and pushed,
and won't know the hash of the created image.

// allowedOutputResource checks if an output resource type produces
// an output that should be copied to the PVC
func allowedOutputResource(resourceType v1alpha1.PipelineResourceType) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

allowedOutputResources is not going to change so makes sense to define it in variable section. Something like

var (
// allowedOutputResource checks if an output resource type produces
// an output that should be copied to the PVC
	allowedOutputResources = map[v1alpha1.PipelineResourceType]bool{
		v1alpha1.PipelineResourceTypeStorage: true,
		v1alpha1.PipelineResourceTypeGit:     true,
	}
)

and update the if condition to be

if allowedOutputResources[resource.Spec.Type] && pipelineRunpvcName != "" {
}

Code is simple and does not need a function. WDYT?

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 made a function because you asked for it to begin with :)

I'm not sure that list is not going to change... other resources will have output to be copied, like logs of the build process for the image resource.
I hope eventually that list will go away for good and it will be replaced by a proper interface on the resource to declare whether they have output to be copied or not.

The advantage of having a function is also that it's possible to write a simple unit test for it, but it's true that there's little value in that unit test, so I'm ok with dropping the function if you prefer so.

Copy link
Contributor

Choose a reason for hiding this comment

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

I made a function because you asked for it to begin with :)

Sorry for the confusion. My intention was to make the if condition simpler and easier to read so I jumped at function as solution. I should have left up to you come up with simpler solution instead of influencing my solution on you. After I saw your solution it felt declaring map in variables section seemed a lot simpler than function

Copy link
Contributor

Choose a reason for hiding this comment

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

The advantage of having a function is also that it's possible to write a simple unit test for it, but it's true that there's little value in that unit test, so I'm ok with dropping the function if you prefer so.

You can still have the tests. I think it holds value in showing supported output types explicitly. I like the tests. I have suggested below how to update tests to use map instead of function.

Copy link
Member Author

Choose a reason for hiding this comment

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

OK, addressed everything - hopefully - in the version :)

Copy link
Collaborator

Choose a reason for hiding this comment

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

I hope eventually that list will go away for good and it will be replaced by a proper interface on the resource to declare whether they have output to be copied or not.

yuusssss

expectedAllowed: false,
}} {
t.Run(c.desc, func(t *testing.T) {
actual := allowedOutputResource(c.resourceType)
Copy link
Contributor

Choose a reason for hiding this comment

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

Test assertion can be combined into single like

if c.expectedAllowed != allowedOutputResources[c.resourceType] {
  t.Fatalf("Test AllowedOutputResource %s expected %t but got %t", c.desc, c.expectedAllowed, allowedOutputResources[c.resourceType])}

Copy link
Contributor

Choose a reason for hiding this comment

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

If test error contains the expected result and current result then debugging test failures is much easier.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, thanks

Add a map that defines which output resource produces an output
that should be copied to the PVC. Add unit tests for it too.
@bobcatfish
Copy link
Collaborator

Seems like a reasonable approach to me! I'll leave it to @shashwathi for the final sign off tho :D

Copy link
Contributor

@shashwathi shashwathi left a comment

Choose a reason for hiding this comment

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

/ok-to-test
/lgtm

@knative-prow-robot knative-prow-robot added the lgtm Indicates that a PR is ready to be merged. label Jan 22, 2019
@knative-prow-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: afrittoli, shashwathi

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

@knative-prow-robot knative-prow-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jan 22, 2019
@shashwathi
Copy link
Contributor

/ok-to-test

@knative-prow-robot knative-prow-robot removed the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jan 22, 2019
@shashwathi
Copy link
Contributor

@afrittoli Thank you so much for your patience on addressing all my comments. 👍 I appreciate that.

@knative-metrics-robot
Copy link

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

File Old Coverage New Coverage Delta
pkg/reconciler/v1alpha1/taskrun/resources/output_resource.go 93.1% 91.5% -1.6

piyush-garg pushed a commit to piyush-garg/pipeline that referenced this pull request May 29, 2020
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. lgtm Indicates that a PR is ready to be merged. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants