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

Add GitHub dispatch provider #369

Merged

Conversation

alekspog
Copy link
Contributor

@alekspog alekspog commented Apr 22, 2022

Add support for GitHub repository dispatch provider.

Ref: fluxcd/flux2#2122
Fix: #329

Example of the notification message payload in the GitHub workflow

Screenshot from 2022-04-22 10-07-16

Signed-off-by: Aleksey Pogibelev <aleksey.pogibelev@gmail.com>
Signed-off-by: Aleksey Pogibelev <aleksey.pogibelev@gmail.com>
@@ -0,0 +1,121 @@
/*
Copyright 2020 The Flux authors
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Copyright 2020 The Flux authors
Copyright 2022 The Flux authors

@@ -730,3 +732,141 @@ kubectl create secret generic webhook-url \
--from-literal=address="Endpoint=sb://fluxv2.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=yoursaskeygeneatedbyazure"
```

### GitHub repository dispatch

The `githubdispatch` webhook triggers a GitHub webhook event called [`repository_dispatch`](https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event) for the selected repository. The `repository_dispatch` event can be used to trigger a GitHub Actions workflow with tests for the deployed service.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
The `githubdispatch` webhook triggers a GitHub webhook event called [`repository_dispatch`](https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event) for the selected repository. The `repository_dispatch` event can be used to trigger a GitHub Actions workflow with tests for the deployed service.
The `githubdispatch` provider generates GitHub events of type [`repository_dispatch`](https://docs.github.com/en/rest/reference/repos#create-a-repository-dispatch-event) for the selected repository. The `repository_dispatch` events can be used to trigger GitHub Actions workflow.


The request includes the `event_type` and `client_payload` fields:

* The `event_type` is generated by GitHub Dispatch provider by combining the Kind, Name and Namespace of the involved object in the format `{Kind}/{Name}.{Namespace}`. For example, the `event_type` for Flux configuration named `podinfo` in the `flux-system` namespace looks like this: `Kustomization/podinfo.flux-system`
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* The `event_type` is generated by GitHub Dispatch provider by combining the Kind, Name and Namespace of the involved object in the format `{Kind}/{Name}.{Namespace}`. For example, the `event_type` for Flux configuration named `podinfo` in the `flux-system` namespace looks like this: `Kustomization/podinfo.flux-system`
* The `event_type` is generated by GitHub Dispatch provider by combining the Kind, Name and Namespace of the involved object in the format `{Kind}/{Name}.{Namespace}`. For example, the `event_type` for a Flux Kustomization named `podinfo` in the `flux-system` namespace looks like this: `Kustomization/podinfo.flux-system`.


* The `event_type` is generated by GitHub Dispatch provider by combining the Kind, Name and Namespace of the involved object in the format `{Kind}/{Name}.{Namespace}`. For example, the `event_type` for Flux configuration named `podinfo` in the `flux-system` namespace looks like this: `Kustomization/podinfo.flux-system`

* The `client_payload` contains the event data from the notification controller and looks like this:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* The `client_payload` contains the event data from the notification controller and looks like this:
* The `client_payload` contains the Kubernetes event issued by Flux, e.g.:


#### Setting up a GitHub workflow

You need to add `repository_dispatch` trigger to trigger your GitHub workflow using the Flux notification with the relevant event type:
Copy link
Member

Choose a reason for hiding this comment

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

To trigger a GitHub Actions workflow when a Flux Kustomization finishes reconciling, you need to set the event type on the repository_dispatch to match the Flux object ID:

run: echo "running tests.."
```

### Setting up the GitHub dispatch provider
Copy link
Member

Choose a reason for hiding this comment

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

Let's move this before "Setting up a GitHub workflow" please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed

Signed-off-by: Aleksey Pogibelev <aleksey.pogibelev@gmail.com>
Signed-off-by: Aleksey Pogibelev <aleksey.pogibelev@gmail.com>
@alekspog alekspog force-pushed the feature/add-github-dispatch-provider branch from 56e350d to e320370 Compare May 10, 2022 10:36
@stefanprodan stefanprodan added enhancement New feature or request area/alerting Alerting related issues and PRs labels May 10, 2022
@stefanprodan stefanprodan added this to the GA milestone May 10, 2022
Copy link
Member

@stefanprodan stefanprodan left a comment

Choose a reason for hiding this comment

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

LGTM

Thanks @alekspog 🥇

@stefanprodan stefanprodan merged commit 01b428d into fluxcd:main May 11, 2022
@alekspog alekspog deleted the feature/add-github-dispatch-provider branch May 12, 2022 11:29
@stefanprodan stefanprodan modified the milestones: GA, Bootstrap GA Jul 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/alerting Alerting related issues and PRs enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Is it possible to add additional data to generic webhook body request?
2 participants