-
Notifications
You must be signed in to change notification settings - Fork 743
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
feat: custom trigger #620
Merged
Merged
feat: custom trigger #620
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
c5cdf69
feat: custom trigger
VaibhavPage be298f9
chore: added debug log stmts.
VaibhavPage 94f2f40
docs: custom trigger walkthrough
VaibhavPage 7de69b1
docs: custom trigger walkthrough
VaibhavPage 7ac99d3
merge master
VaibhavPage 61bb320
docs: custom trigger walkthrough
VaibhavPage a2ce25a
docs: custom trigger walkthrough
VaibhavPage 2bedd9d
merge changes
VaibhavPage 7ab767f
docs: custom trigger walkthrough
VaibhavPage File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
# Build Your Own Trigger | ||
|
||
Argo Events supports a variety of triggers out of box like Argo Workflow, K8s Objects, AWS Lambda, HTTP Requests etc., but you may want to write your own logic to trigger a pipeline or create an object in K8s cluster. An example would be to trigger | ||
TektonCD or AirFlow pipelines on GitHub events. | ||
|
||
## Custom Trigger | ||
|
||
In order to plug your own implementation for a trigger with Argo Events Sensor, you need to | ||
run a gRPC server that implements the interface that the sensor expects. | ||
|
||
### Interface | ||
|
||
The interface exposed via proto file, | ||
|
||
// Trigger offers services to build a custom trigger | ||
service Trigger { | ||
// FetchResource fetches the resource to be triggered. | ||
rpc FetchResource(FetchResourceRequest) returns (FetchResourceResponse); | ||
// Execute executes the requested trigger resource. | ||
rpc Execute(ExecuteRequest) returns (ExecuteResponse); | ||
// ApplyPolicy applies policies on the trigger execution result. | ||
rpc ApplyPolicy(ApplyPolicyRequest) returns (ApplyPolicyResponse); | ||
} | ||
|
||
The complete proto file is available [here](https://github.com/argoproj/argo-events/blob/master/sensors/triggers/trigger.proto). | ||
|
||
Let's walk through the contract, | ||
|
||
1. `FetchResource`: If the trigger server needs to fetch a resource from external sources like S3, Git or a URL, this is the | ||
place to do so. e.g. if the trigger server aims to invoke a TektonCD pipeline and the `PipelineRun` resource lives on Git, then | ||
trigger server can first fetch it from Git and return it back to sensor. | ||
|
||
2. `Execute`: In this method, the trigger server executes/invokes the trigger. e.g. TektonCD pipeline resource being | ||
created in K8s cluster. | ||
|
||
3. `ApplyPolicy`: This is where your trigger implementation can check whether the triggered resource transitioned into the success state. | ||
Depending upon the response from the trigger server, the sensor will either stop processing subsequent triggers, or it will continue to | ||
process them. | ||
|
||
|
||
### How to define the Custom Trigger in a sensor? | ||
|
||
Let's look at the following sensor, | ||
|
||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Sensor | ||
metadata: | ||
name: webhook-sensor | ||
labels: | ||
sensors.argoproj.io/sensor-controller-instanceid: argo-events | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: sensor | ||
image: metalgearsolid/sensor:v0.15.0 | ||
imagePullPolicy: Always | ||
serviceAccountName: argo-events-sa | ||
dependencies: | ||
- name: test-dep | ||
gatewayName: webhook-gateway | ||
eventName: example | ||
subscription: | ||
http: | ||
port: 9300 | ||
triggers: | ||
- template: | ||
name: webhook-workflow-trigger | ||
custom: | ||
# the url of the trigger server. | ||
serverURL: tekton-trigger.argo-events.svc:9000 | ||
# spec is map of string->string and it is sent over to trigger server. | ||
# the spec can be anything you want as per your use-case, just make sure the trigger server understands the spec map. | ||
spec: | ||
url: "https://raw.githubusercontent.com/VaibhavPage/tekton-cd-trigger/master/example.yaml" | ||
# These parameters are applied on resource fetched and returned by the trigger server. | ||
# e.g. consider a trigger server which invokes TektonCD pipeline runs, then | ||
# the trigger server can return a TektonCD PipelineRun resource. | ||
# The parameters are then applied on that PipelineRun resource. | ||
parameters: | ||
- src: | ||
dependencyName: test-dep | ||
dataKey: body.namespace | ||
dest: metadata.namespace | ||
# These parameters are applied on entire template body. | ||
# So that you can parameterize anything under `custom` key such as `serverURL`, `spec` etc. | ||
parameters: | ||
- src: | ||
dependencyName: test-dep | ||
dataKey: body.url | ||
dest: custom.spec.url | ||
|
||
The sensor definition should look familiar to you. The only difference is the `custom` key under `triggers -> template`. | ||
The specification under `custom` key defines the custom trigger. | ||
|
||
The most important fields are, | ||
|
||
1. `serverURL`: This is the URL of the trigger gRPC server. | ||
|
||
1. `spec`: It is a map of string -> string. The spec can be anything you want as per your use-case. The sensor sends | ||
the spec to trigger server, and it is upto the trigger gRPC server to interpret the spec. | ||
|
||
1. `parameters`: The parameters override the resource that is fetched by the trigger server. | ||
Read more info on parameters [here](https://argoproj.github.io/argo-events/tutorials/02-parameterization/). | ||
|
||
1. `payload`: Payload to send to the trigger server. Read more on payload [here](https://argoproj.github.io/argo-events/triggers/http-trigger/#request-payload). | ||
|
||
The complete spec for the custom trigger is available [here](https://github.com/argoproj/argo-events/blob/master/api/sensor.md#customtrigger). | ||
|
||
## Custom Trigger in Action | ||
|
||
Refer to a sample [trigger server](https://github.com/VaibhavPage/tekton-cd-trigger) that invokes TektonCD pipeline on events. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
apiVersion: argoproj.io/v1alpha1 | ||
kind: Sensor | ||
metadata: | ||
name: webhook-sensor | ||
labels: | ||
sensors.argoproj.io/sensor-controller-instanceid: argo-events | ||
spec: | ||
template: | ||
spec: | ||
containers: | ||
- name: sensor | ||
image: metalgearsolid/sensor:v0.15.0 | ||
imagePullPolicy: Always | ||
serviceAccountName: argo-events-sa | ||
dependencies: | ||
- name: test-dep | ||
gatewayName: webhook-gateway | ||
eventName: example | ||
subscription: | ||
http: | ||
port: 9300 | ||
triggers: | ||
- template: | ||
name: webhook-workflow-trigger | ||
custom: | ||
# the url of the trigger server. | ||
serverURL: tekton-trigger.argo-events.svc:9000 | ||
# spec is map of string->string and it is sent over to trigger server. | ||
# the spec can be anything you want as per your use-case, just make sure the trigger server understands the spec map. | ||
spec: | ||
url: "https://raw.githubusercontent.com/VaibhavPage/tekton-cd-trigger/master/example.yaml" | ||
# These parameters are applied on resource fetched and returned by the trigger server. | ||
# e.g. consider a trigger server which invokes TektonCD pipeline runs, then | ||
# the trigger server can return a TektonCD PipelineRun resource. | ||
# The parameters are then applied on that PipelineRun resource. | ||
parameters: | ||
- src: | ||
dependencyName: test-dep | ||
dataKey: body.namespace | ||
dest: metadata.namespace | ||
# These parameters are applied on entire template body. | ||
# So that you can parameterize anything under `custom` key such as `serverURL`, `spec` etc. | ||
parameters: | ||
- src: | ||
dependencyName: test-dep | ||
dataKey: body.url | ||
dest: custom.spec.url |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Curious, what made these changes?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
gen-crd-api-reference-docs
underupdate-api-docs.sh