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

Shipwright Triggers API #1008

Merged
merged 3 commits into from
Jul 9, 2022

Conversation

otaviof
Copy link
Member

@otaviof otaviof commented Mar 9, 2022

Changes

Adding the API for Shipwright Triggers (EP) with validation and initial documentation.

Submitter Checklist

  • Includes tests if functionality changed/was added
  • Includes docs if changes are user-facing
  • Set a kind label on this PR
  • Release notes block has been filled in, or marked NONE

Release Notes

Adding the API for Shipwright Triggers, a event driven approach to instantiate new builds

@openshift-ci openshift-ci bot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 9, 2022
@otaviof otaviof force-pushed the shipwright-trigger-api branch 2 times, most recently from bab9210 to ebf188d Compare March 10, 2022 15:03
@openshift-ci openshift-ci bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label May 12, 2022
@lookis
Copy link

lookis commented Jun 3, 2022

Hi @otaviof , thanks for your works, any update on this PR?

@otaviof otaviof force-pushed the shipwright-trigger-api branch from 17c8188 to 15304e2 Compare June 9, 2022 17:05
@openshift-ci openshift-ci bot added release-note Label for when a PR has specified a release note and removed needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Jun 9, 2022
@otaviof
Copy link
Member Author

otaviof commented Jun 9, 2022

/retitle Shipwright Triggers API

@openshift-ci openshift-ci bot changed the title [WIP] Shipwright-Triggers API Shipwright Triggers API Jun 9, 2022
@openshift-ci openshift-ci bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 9, 2022
@otaviof
Copy link
Member Author

otaviof commented Jun 9, 2022

/assign @SaschaSchwarze0 @adambkaplan

/cc @coreydaley

@coreydaley
Copy link
Contributor

coreydaley commented Jun 9, 2022

@otaviof I don't see the use of the trigger.when, why not just have triggers? Do you expect to add additional adverbs in the future? I would like some clarification on that before commenting on the specifics of the pull request since a lot of my thoughts pertain to that.

@otaviof otaviof changed the title Shipwright Triggers API Shipwright-Triggers API Jun 10, 2022
@otaviof otaviof changed the title Shipwright-Triggers API Shipwright Triggers API Jun 10, 2022
@otaviof otaviof added the kind/feature Categorizes issue or PR as related to a new feature. label Jun 10, 2022
@otaviof
Copy link
Member Author

otaviof commented Jun 10, 2022

Hi @otaviof , thanks for your works, any update on this PR?

Hello! Sorry for the delay, we are moving forward with this feature again 👍 And thanks for the heads up too.

@otaviof
Copy link
Member Author

otaviof commented Jun 10, 2022

@otaviof I don't see the use of the trigger.when, why not just have triggers? Do you expect to add additional adverbs in the future? I would like some clarification on that before commenting on the specifics of the pull request since a lot of my thoughts pertain to that.

I'm implementing the changes we've discussed during the EP review without changes, so that's why we have the nested attribute approach.

Personally, the trigger.when sounds straightforward to explain the concept behind the API, thus a contender to .spec.triggers could be .spec.triggerWhen.

Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

I suggest to add validation to https://github.com/shipwright-io/build/blob/v0.10.0/pkg/validate/validate.go#L83-L119. Basically a BuildRun with an inline spec must not have triggers set.

docs/build.md Outdated Show resolved Hide resolved
docs/build.md Outdated Show resolved Hide resolved
docs/build.md Outdated

The GitHub type is meant to react on events coming from GitHub WebHook, the events are compared against the existing `Build` resources and therefore it can find `Build` based on `.spec.source.url` combined with the attributes on `.spec.trigger.when[].github`.

When `.spec.trigger.when[].github.branches` is empty, the `.spec.source.revision` is employed, the default "branch" name employed is based on the regular source repository configuration.
Copy link
Member

Choose a reason for hiding this comment

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

I suggest to have a full defined list of all possible combinations to leave no room for speculation:

  • If the source contains a revision that is a branch name, and the trigger branches are empty, then BuildRuns get submitted for this single branch only.
  • If the source contains no revision and the trigger branches are empty, then ... TBD (how do we behave here, is that valid at all ?)
  • If the source contains a revision, and the trigger branches are not empty, then BuildRuns get submitted for the branches defined in the trigger.
  • If the source contains no revision, and the trigger branches are not empty, then BuildRuns get submitted for the branches defined in the trigger.

Copy link
Member Author

Choose a reason for hiding this comment

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

Let me start with an example, please. Let's imagine a pull-request is open at the repository X against the main branch, it will dispatch a GitHub Event which contains detailed

Okay, so let me start with a use-case example, please. Let's imagine the user is receiving WebHook events from GitHub, a event comes along with the type PullRequest listing the target branch as main and as well the repository URL. Based on those, it must then trigger a single BuildRun per Build object that matches both repository URL and revision, so in other words, there's a direct relationship between one GitHub event and one (or more) Build instance.

Given a single GitHub Event must trigger a single BuildRun per Build instance responsible for that repository, the business rule is basically a fallback approach: probe if the event branch name is listed on .spec.trigger.when[].github.branches slice, or, uses the .spec.source.revision (by default is assumed "main" when empty).

type: Image
image:
names:
- ghcr.io/some/base-image:latest
Copy link
Member

Choose a reason for hiding this comment

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

Should not here be the name of the Image resource that must be in the same namespace ? Especially if the image is not at all in an external registry, it would be complicated to provide such an image name.

Copy link
Member Author

Choose a reason for hiding this comment

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

Here we are looking for a fully qualified image name and to later on rely on the image controller to handle this business logic. However, the image name is a free form string initially.

Copy link
Member Author

Choose a reason for hiding this comment

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

Comment on lines +697 to +705
status:
- Succeeded
Copy link
Member

Choose a reason for hiding this comment

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

I may need to check the ship again, why do we filter on the status here? Should not it be always on successful completion?

Copy link
Member Author

Choose a reason for hiding this comment

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

In order to have a flexible workflow we should allow any state to be filled in, and it's expected that "Succeeded" is the most common.

Copy link
Member

Choose a reason for hiding this comment

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

Flexibility is fine, but out of interest, what would be the use case to trigger a BuildRun on a Pipeline status change other than to Succeeded?

Copy link
Member Author

Choose a reason for hiding this comment

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

The "status" is reported as a string, and the .objectRef can match more than one type of Kubernetes CRD.

Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my understanding, does Pipeline CRD has a state, or is more about PipelineRun states?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sorry, I haven't been clear before. The object that carries the state is the PipelineRun.

- Succeeded
name: tekton-pipeline-name
```

Copy link
Member

Choose a reason for hiding this comment

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

What about the BuildRun trigger? In my own subjective opinion, that is more important than pipelines.

Copy link
Member Author

Choose a reason for hiding this comment

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

The triggers is a mechanism to instantiate BuildRun objects based on a Build, so BuildRun would not be able to trigger itself.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, I meant Build trigger. But I just notice it is not part of the SHIP, then it is fine for now. It is being discussed here: shipwright-io/community#75 (comment).

Comment on lines 63 to 72
// SpecTriggersNameCanNotBeBlank indicates the when condition does not have a name
SpecTriggersNameCanNotBeBlank BuildReason = "SpecTriggersWhenNameCanNotBeBlank"
// SpecTriggersInvalidType indicates the when type is invalid
SpecTriggersInvalidType BuildReason = "SpecTriggersWhenInvalidType"
// SpecTriggersInvalidGitHub indicates the when type GitHub is invalid
SpecTriggersInvalidGitHub BuildReason = "SpecTriggersWhenInvalidGitHub"
// SpecTriggersInvalidImage indicates the when type Image is invalid
SpecTriggersInvalidImage BuildReason = "SpecTriggersWhenInvalidImage"
// SpecTriggersInvalidPipeline indicates the when type Pipeline is invalid
SpecTriggersInvalidPipeline BuildReason = "SpecTriggersWhenInvalidPipeline"
Copy link
Member

Choose a reason for hiding this comment

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

For consistency, I suggest to remove the Spec prefix everywhere. Those error codes are also documented on https://github.com/shipwright-io/build/blob/main/docs/build.md#build-validations. And I just notice that we forgot to add the Volume-related reasons.

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure!

Name string `json:"name"`

// Type the event type, the name of the webhook event.
Type WhenTypeName `json:"type,omitempty"`
Copy link
Member

Choose a reason for hiding this comment

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

If this is required, should we remove omitempty ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, indeed the omitempty must not be there.

pkg/apis/build/v1alpha1/trigger_when.go Outdated Show resolved Hide resolved
pkg/apis/build/v1alpha1/trigger_types.go Show resolved Hide resolved
@lookis
Copy link

lookis commented Jun 21, 2022

I have a question, If we watch github event, how to apply carried information to Build result?
for example, I have tag a commit in github repo, and trigger the Build. how to apply the tag to the output Image

@SaschaSchwarze0
Copy link
Member

I have a question, If we watch github event, how to apply carried information to Build result? for example, I have tag a commit in github repo, and trigger the Build. how to apply the tag to the output Image

Hi @lookis, qq, are you:

  • pushing a tag to your GitHub repository and expect a build to start for this tag ? This is not covered of the Triggers SHIP, but would be an interesting scenario @otaviof.
  • interested in getting the tag name or commit sha that is built somewhere into the image (as a label or annotation), or as its image tag ? Or as annotation of an image signature ? That's all future.

@lookis
Copy link

lookis commented Jun 21, 2022

@SaschaSchwarze0 Thanks, looking forward to it.

@otaviof otaviof force-pushed the shipwright-trigger-api branch from 54d4af1 to 7082c9e Compare June 21, 2022 09:43
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jun 21, 2022

@otaviof: GitHub didn't allow me to request PR reviews from the following users: ricardomaraschini.

Note that only shipwright-io members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

/cc @ricardomaraschini

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.

@otaviof otaviof requested a review from SaschaSchwarze0 June 21, 2022 09:49
@otaviof
Copy link
Member Author

otaviof commented Jun 21, 2022

I suggest to add validation to https://github.com/shipwright-io/build/blob/v0.10.0/pkg/validate/validate.go#L83-L119. Basically a BuildRun with an inline spec must not have triggers set.

Thanks for the review, please consider the latest changes.

@otaviof
Copy link
Member Author

otaviof commented Jun 21, 2022

I have a question, If we watch github event, how to apply carried information to Build result? for example, I have tag a commit in github repo, and trigger the Build. how to apply the tag to the output Image

Hi @lookis, qq, are you:

* pushing a tag to your GitHub repository and expect a build to start for this tag ? This is not covered of the [Triggers SHIP](https://github.com/shipwright-io/community/blob/main/ships/0031-shipwright-trigger.md), but would be an interesting scenario @otaviof.

* interested in getting the tag name or commit sha that is built somewhere into the image (as a label or annotation), or as its image tag ? Or as annotation of an image signature ? That's all future.

Most definitely an interesting use-case, @lookis! I think we've spoken about having automation to tag the image accordingly with the context, like in this case the repository metadata. I think we should keep this in the radar.

Lets bring this on the next community meeting?

Copy link
Member

@SaschaSchwarze0 SaschaSchwarze0 left a comment

Choose a reason for hiding this comment

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

/approve

@openshift-ci openshift-ci bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Jun 22, 2022
Copy link
Contributor

@qu1queee qu1queee left a comment

Choose a reason for hiding this comment

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

@otaviof thank you, neat neat work!

Some minor comments, pls take a look

Comment on lines +697 to +705
status:
- Succeeded
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my understanding, does Pipeline CRD has a state, or is more about PipelineRun states?

pkg/apis/build/v1alpha1/trigger_when.go Outdated Show resolved Hide resolved
pkg/validate/trigger.go Show resolved Hide resolved
pkg/validate/trigger.go Outdated Show resolved Hide resolved
pkg/validate/validate.go Outdated Show resolved Hide resolved
otaviof and others added 3 commits July 7, 2022 14:10
Co-authored-by: Enrique Encalada <encaladaenrique@gmail.com>
Co-authored-by: Sascha Schwarze <schwarzs@de.ibm.com>
@otaviof otaviof force-pushed the shipwright-trigger-api branch from cdaf481 to 3f6ef66 Compare July 7, 2022 12:10
@otaviof otaviof requested a review from qu1queee July 7, 2022 13:12
@qu1queee
Copy link
Contributor

qu1queee commented Jul 9, 2022

@otaviof ty, approving.

/approve

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Jul 9, 2022

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: qu1queee, SaschaSchwarze0

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:
  • OWNERS [SaschaSchwarze0,qu1queee]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@qu1queee
Copy link
Contributor

qu1queee commented Jul 9, 2022

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Jul 9, 2022
@openshift-ci openshift-ci bot merged commit a44ef99 into shipwright-io:main Jul 9, 2022
@SaschaSchwarze0 SaschaSchwarze0 added this to the release-v0.11.0 milestone Aug 15, 2022
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 Label for when a PR has specified a release note
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants