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 users/integrators to pass arbitrary keys/values through Result and RecordSummary annotations #426

Conversation

alan-ghelardi
Copy link
Contributor

@alan-ghelardi alan-ghelardi commented Apr 3, 2023

Changes

Resolves #343.

Users can pass arbitrary keys/values to the Result.Annotations and
Result.Summary.Annotations fields by adding certain annotations to their
PipelineRuns and TaskRuns.

/feature

Submitter Checklist

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

  • Has Docs included if any changes are user facing
  • Has Tests included if any functionality added or changed
  • Tested your changes locally (if this is a code change)
  • Follows the commit message standard
  • Meets the Tekton contributor standards (including functionality, content, code)
  • Has a kind label. You can add a comment on this PR that contains /kind <type>. Valid types are bug, cleanup, design, documentation, feature, flake, misc, question, tep
  • Release notes block below has been updated with any user-facing changes (API changes, bug fixes, changes requiring upgrade notices or deprecation warnings)
  • Release notes contain the string "action required" if the change requires additional action from users switching to the new release

Release Notes

Allow users/integrators to pass arbitrary keys/values to the Result.Annotations
and Result.Summary.Annotations fields, by adding the newly created annotations
results.tekton.dev/resultAnnotations and
results.tekton.dev/recordSummaryAnnotations to their PipelineRuns and TaskRuns.

Those annotations can be used to store relevant metadata (e.g. repository name,
Git commit SHA, pull request number among others) along with results into the
database, in order to be used later to retrieve those resources via the API.

@tekton-robot tekton-robot added the release-note Denotes a PR that will be considered when it comes time to generate release notes. label Apr 3, 2023
@tekton-robot tekton-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Apr 3, 2023
@alan-ghelardi
Copy link
Contributor Author

/kind feature

@tekton-robot tekton-robot added the kind/feature Categorizes issue or PR as related to a new feature. label Apr 3, 2023
Copy link
Contributor

@khrm khrm 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 Apr 3, 2023
@alan-ghelardi alan-ghelardi force-pushed the result-and-record-summary-annotations branch from db319d5 to 9ca4778 Compare April 3, 2023 19:39
@tekton-robot tekton-robot removed the lgtm Indicates that a PR is ready to be merged. label Apr 3, 2023
@alan-ghelardi
Copy link
Contributor Author

/assign @khrm
/assign @adambkaplan
/assign @dibyom

Copy link
Contributor

@adambkaplan adambkaplan left a comment

Choose a reason for hiding this comment

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

@alan-ghelardi can you please add markdown documentation for this feature?

In general looks good, I just have one question on the implementation.

if annotations, err := parseAnnotations(annotation.ResultAnnotations, value); err != nil {
return nil, err
} else {
res.Annotations = annotations
Copy link
Contributor

Choose a reason for hiding this comment

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

Are there other annotations that we add to the Result record? Should we merge annotations instead of overwrite?

Copy link
Contributor

Choose a reason for hiding this comment

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

We are just copying these annotations from PR for LIST API. So no merge requires. If these annotation changes, then we require a new one. I think it's the responsibility of integrators to ensure that we always merge not overwrite these.

if annotations, err := parseAnnotations(annotation.RecordSummaryAnnotations, value); err != nil {
return nil, err
} else if res.Summary != nil {
res.Summary.Annotations = annotations
Copy link
Contributor

Choose a reason for hiding this comment

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

Likewise - merge instead of overwrite?

@adambkaplan
Copy link
Contributor

/approve

This feature can be useful for operators and integrators.

@tekton-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan

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 approved Indicates a PR has been approved by an approver from all required OWNERS files. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. labels Apr 11, 2023
@dibyom
Copy link
Member

dibyom commented Apr 20, 2023

I have the same question as Adam around merging vs overwriting values but otherwise looks good. Thanks @alan-ghelardi

@alan-ghelardi alan-ghelardi force-pushed the result-and-record-summary-annotations branch from 9ca4778 to 02150f5 Compare April 20, 2023 22:21
@tekton-robot tekton-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Apr 20, 2023
@alan-ghelardi alan-ghelardi force-pushed the result-and-record-summary-annotations branch from 02150f5 to f8d7707 Compare April 20, 2023 22:33
if res.Annotations == nil {
res.Annotations = make(map[string]string, len(annotations))
}
copyKeys(annotations, res.Annotations)
Copy link
Contributor

@khrm khrm Apr 21, 2023

Choose a reason for hiding this comment

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

Isn't res.Annotations always empty? You should use curr.Annotations and copy it to res.Annotations if we want to merge.

Copy link
Contributor

@khrm khrm Apr 21, 2023

Choose a reason for hiding this comment

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

If we don't want to employ merge, was there any issue with the previous approach of just copying?

We can just delegate the responsibility of ensuring that the merge happens to integrators. And we always do upsert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Merging values made the code trickier, but ultimately, it seems a good idea thinking about future extensibility.

if annotations, err := parseAnnotations(annotation.RecordSummaryAnnotations, value); err != nil {
return nil, err
} else if res.Summary != nil {
if res.Summary.Annotations == nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same issue here. We should first copy curr.Summary.Annotations to res.Summary.Annotations .

@alan-ghelardi alan-ghelardi force-pushed the result-and-record-summary-annotations branch from f8d7707 to 7fde7d9 Compare April 21, 2023 01:42
@alan-ghelardi alan-ghelardi force-pushed the result-and-record-summary-annotations branch from 7fde7d9 to 65a2e33 Compare April 21, 2023 11:17
@alan-ghelardi
Copy link
Contributor Author

@adambkaplan and @dibyom in practice nowadays there aren't other entrypoints to set those annotations, but I like the idea of merging the values to support extensibility.

@tektoncd/results-maintainers could you have a second review here, please?

@alan-ghelardi
Copy link
Contributor Author

I updated the docs with the new feature, by thee way.

@dibyom
Copy link
Member

dibyom commented Apr 25, 2023

/lgtm

@tekton-robot tekton-robot added the lgtm Indicates that a PR is ready to be merged. label Apr 25, 2023
@tekton-robot tekton-robot merged commit fdc4754 into tektoncd:main Apr 25, 2023
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.

Allow users to pass values to the Result.Annotations and RecordSummary.Annotations fields
5 participants