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

Introducing InternalTektonResultType as a ResultType #3138

Merged
merged 1 commit into from
Sep 22, 2020

Conversation

Peaorl
Copy link
Contributor

@Peaorl Peaorl commented Aug 26, 2020

Changes

This PR introduces a new TektonResultType namely 'InternalTektonResultType'.
Currently TaskRunResultType, PipelineResourceResultType and UnknownResultType exist as a ResultType for a PipelineResourceResult.
All results that conform to one of these ResultTypes are normally exposed as either as a task or resource result.

In light of #3087 the need for a ResultType that is not exposed arises.
In #3087, a Step can emit a result indicating a Step timeout has occurred.
This is a result that should not be exposed hence the need for a new ResultType named InternalTektonResultType.
This PR ensures results of this type are filtered out.

Introducing an InternalTektonResultType ensures a future proof solution to internal results that should not be exposed as a TaskRun or PipelineResource result.
Aside from the example in #3087, a present candidate is the result written out by a Step containing a "StartedAt" key.
Up until now this result is filtered out by a specific function.
Marking it as an InternalTektonResultType now allows for this result to automatically be filtered out.

Up until this PR Sidecars can write results.
Since this is not explicitly documented it's unclear whether this is intended behavior.
In this PR it's ensured only Steps can write results.

Additionally this commit brings about refactoring/moving (and sometimes renaming) of functions related to converting Pod statuses to TaskRun statuses from pkg/reconciler/taskrun/taskrun.go to pkg/pod/status/status.go.
This is accompanied with moving unit tests from taskrun_test.go to status_test.go.

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

NONE

@tekton-robot tekton-robot added the release-note-none Denotes a PR that doesnt merit a release note. label Aug 26, 2020
@tekton-robot tekton-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 26, 2020
@tekton-robot
Copy link
Collaborator

Hi @Peaorl. Thanks for your PR.

I'm waiting for a tektoncd member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@Peaorl
Copy link
Contributor Author

Peaorl commented Aug 26, 2020

/kind feature
/kind cleanup

@tekton-robot tekton-robot added kind/feature Categorizes issue or PR as related to a new feature. kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. labels Aug 26, 2020
@Peaorl Peaorl mentioned this pull request Aug 27, 2020
4 tasks
pkg/pod/status.go Outdated Show resolved Hide resolved
pkg/pod/status.go Outdated Show resolved Hide resolved
@afrittoli
Copy link
Member

/ok-to-test

@tekton-robot tekton-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Sep 1, 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/pod/status.go 87.0% 91.2% 4.2
pkg/reconciler/taskrun/taskrun.go 78.9% 76.4% -2.6

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

Looking good! I left a few comments but I don't think there are any major blockers from my pov.

pkg/pod/status.go Outdated Show resolved Hide resolved
pkg/pod/status.go Show resolved Hide resolved
pkg/reconciler/taskrun/taskrun.go Outdated 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/pod/status.go 87.0% 91.8% 4.8
pkg/reconciler/taskrun/taskrun.go 78.9% 76.6% -2.3

@Peaorl Peaorl marked this pull request as draft September 2, 2020 18:33
@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/pod/status.go 87.0% 92.8% 5.8
pkg/reconciler/taskrun/taskrun.go 78.9% 76.6% -2.3

@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/pod/status.go 87.0% 93.4% 6.4
pkg/reconciler/taskrun/taskrun.go 78.9% 76.6% -2.3
pkg/termination/parse.go 100.0% 84.2% -15.8

@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/pod/status.go 87.0% 93.4% 6.4
pkg/reconciler/taskrun/taskrun.go 78.9% 76.6% -2.3
pkg/termination/parse.go 100.0% 84.2% -15.8

@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/pod/status.go 87.0% 93.4% 6.4
pkg/reconciler/taskrun/taskrun.go 78.9% 76.6% -2.3
pkg/termination/parse.go 100.0% 84.2% -15.8

@Peaorl
Copy link
Contributor Author

Peaorl commented Sep 3, 2020

While migrating unit tests from pkg/reconciler/taskrun/taskrun_test.go to pkg/pod/status/status.go I encountered one test case I don't fully understand.
I believe this test case aims to check whether a taskrun status is set to false if the corresponding task fails.
Nevertheless, this test case does not actually execute a function and the function it presumably would call is not responsible for setting the taskrun status. The described podStatus is also not set to fail.
In this PR I changed the test such that if a task (pod) fails it's checked whether the taskrun status is set accordingly.

Another thing I noticed in the same test is that the description has a termination message with a result that does not follow the struct format of a PipelineResourceResult. For example, the key name does not exist as PipelineResourceResult field.
On master and also in this PR, such "results" get dropped from the taskrun termination message.
Once the termination message is unmarshalled into PipelineResourceResults, JSON objects that don't adhere to the PipelineResourceResult structure are dropped without error by the unmarshal function.

I am wondering, is this behavior intentional? On master, no test case catches this behavior.
This test now records the behavior of dropping incorrect results from the taskrun termination message.
Additionally, ParseMessage now logs incorrect results.
Alternatively, we could decide that incorrect results are kept "as is" for the taskrun termination message.
Note that it's normally impossible for incorrect results to show up in the taskrun termination message if the Tekton code only writes PipelineResourceResults to its termination message.

Lastly, ResourceRef is now a pointer. This ensures that an empty resourceRef field is not marshalled back into the termination message (zero values like a nil pointer are not marshalled) as is the case on master currently.

@Peaorl Peaorl marked this pull request as ready for review September 3, 2020 22:04
@@ -123,10 +123,10 @@ type PipelineResourceResult struct {
Key string `json:"key"`
Value string `json:"value"`
ResourceName string `json:"resourceName,omitempty"`
// This field should be deprecated and removed in the next API version.
// The field ResourceName should be deprecated and removed in the next API version.
Copy link

Choose a reason for hiding this comment

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

Is this right? I have to confess I'm a bit confused by these fields and #2694 doesn't make it totally clear. @dlorenc is it ResourceName or ResourceRef that's supposed to be deprecated?

Copy link
Contributor Author

@Peaorl Peaorl Sep 10, 2020

Choose a reason for hiding this comment

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

You're right, it should actually be ResourceRef.

@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/pod/status.go 87.0% 93.3% 6.3
pkg/reconciler/taskrun/taskrun.go 78.7% 76.2% -2.4
pkg/termination/parse.go 100.0% 84.2% -15.8

Copy link

@ghost ghost left a comment

Choose a reason for hiding this comment

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

While migrating unit tests from pkg/reconciler/taskrun/taskrun_test.go to pkg/pod/status/status.go I encountered one test case I don't fully understand.
I believe this test case aims to check whether a taskrun status is set to false if the corresponding task fails.
Nevertheless, this test case does not actually execute a function and the function it presumably would call is not responsible for setting the taskrun status. The described podStatus is also not set to fail.
In this PR I changed the test such that if a task (pod) fails it's checked whether the taskrun status is set accordingly.

Good catch. I think the idea of the original test was to confirm that a failed Task does not generate any Results. But as you say this test didn't actually call any functions and didn't test anything 😨

Another thing I noticed in the same test is that the description has a termination message with a result that does not follow the struct format of a PipelineResourceResult. For example, the key name does not exist as PipelineResourceResult field.
On master and also in this PR, such "results" get dropped from the taskrun termination message.
Once the termination message is unmarshalled into PipelineResourceResults, JSON objects that don't adhere to the PipelineResourceResult structure are dropped without error by the unmarshal function.

digest and name were fields used in the alpha API that have since been removed. Have a look through the git history of pkg/apis/pipeline/v1alpha1/resource_types.go, for example, and you'll spot those field names. I think the best course of action is what you've done - removing the old test and codifying the behavior in a new test.

Lastly, ResourceRef is now a pointer. This ensures that an empty resourceRef field is not marshalled back into the termination message (zero values like a nil pointer are not marshalled) as is the case on master currently.

👍 I think this is totally fine.

pkg/pod/status.go Outdated Show resolved Hide resolved
pkg/pod/status.go Outdated Show resolved Hide resolved
pkg/reconciler/taskrun/taskrun.go Show resolved Hide resolved
@ghost
Copy link

ghost commented Sep 10, 2020

I left some small nits but no blockers from my perspective!

/approve

@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 Sep 10, 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/pod/status.go 87.0% 93.3% 6.3
pkg/reconciler/taskrun/taskrun.go 78.7% 76.5% -2.2
pkg/termination/parse.go 100.0% 84.2% -15.8

@Peaorl
Copy link
Contributor Author

Peaorl commented Sep 15, 2020

/remove-label cleanup
/remove-label feature

@ghost ghost removed kind/cleanup Categorizes issue or PR as related to cleaning up code, process, or technical debt. kind/feature Categorizes issue or PR as related to a new feature. labels Sep 15, 2020
@ghost
Copy link

ghost commented Sep 15, 2020

/kind feature

Copy link
Member

@imjasonh imjasonh left a comment

Choose a reason for hiding this comment

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

Mostly lgtm, just a few style/readability comments. 👍

pkg/pod/status.go Show resolved Hide resolved
pkg/pod/status_test.go Show resolved Hide resolved
In light of tektoncd#3087 the need for a ResultType that is not exposed
as a TaskRunResult or PipelineResourceResult arises.
In tektoncd#3087, a Step can emit a result indicating a Step timeout
has occurred. This is a result that should not be exposed hence
the need for a new ResultType called InternalTektonResultType.
This commit ensures results of this type are filtered out.

Introducing an InternalTektonResultType ensures a future proof
solution to internal results that should not be exposed.
Aside from the example in tektoncd#3087, a present candidate is the
result written out by a Step containing a "StartedAt" key.
Currently this result is filtered out with a specific function.
Marking it as an InternalTektonResultType now allows for
this result to automatically be filtered out.

Additionally this commit brings about refactoring (and sometimes
renaming) of functions related to converting pod statuses to
taskrun statuses from pkg/reconciler/taskrun/taskrun.go to
pkg/pod/status/status.go. This is accompanied with moving unit
test cases from taskrun_test.go to status_test.go.
@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/pod/status.go 87.0% 93.3% 6.3
pkg/termination/parse.go 100.0% 84.2% -15.8

Copy link
Member

@imjasonh imjasonh 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 Sep 22, 2020
@tekton-robot tekton-robot merged commit a9e7b54 into tektoncd:master Sep 22, 2020
@Peaorl Peaorl deleted the internaltektonresulttype branch November 3, 2020 13:27
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. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note-none Denotes a PR that doesnt merit a release note. 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.

4 participants