mirror of https://github.com/knative/docs.git
Simplify the Github sample. (#587)
* Simplify the Github sample. This simplifies the Github sample as outlined in #586 to drop the concepts that aren't needed for the sample to work end-to-end. Fixes: https://github.com/knative/docs/issues/586 Fixes: https://github.com/knative/docs/issues/584 Fixes: https://github.com/knative/docs/issues/552 Fixes: https://github.com/knative/docs/issues/551 Progress on: https://github.com/knative/docs/issues/541 * Update eventing/samples/github-source/README.md Co-Authored-By: mattmoor <mattmoor@google.com>
This commit is contained in:
parent
b11a0d4de3
commit
cadea5ebe1
|
@ -21,13 +21,32 @@ You will need:
|
||||||
Eventing](https://github.com/knative/docs/tree/master/eventing). Those
|
Eventing](https://github.com/knative/docs/tree/master/eventing). Those
|
||||||
instructions also install the default eventing sources, including
|
instructions also install the default eventing sources, including
|
||||||
the `GitHubSource` we'll use.
|
the `GitHubSource` we'll use.
|
||||||
1. Create a `Channel`. You can use your own `Channel` or use the
|
|
||||||
provided sample, which creates a channel called `githubchannel`. If
|
### Create a Knative Service
|
||||||
you use your own `Channel` with a different name, then you will
|
|
||||||
need to alter other commands later.
|
To verify the `GitHubSource` is working, we will create a simple Knative
|
||||||
|
`Service` that dumps incoming messages to its log. The `service.yaml` file
|
||||||
|
defines this basic service.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: github-message-dumper
|
||||||
|
spec:
|
||||||
|
runLatest:
|
||||||
|
configuration:
|
||||||
|
revisionTemplate:
|
||||||
|
spec:
|
||||||
|
container:
|
||||||
|
image: gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/message_dumper
|
||||||
|
```
|
||||||
|
|
||||||
|
Enter the following command to create the service from `service.yaml`:
|
||||||
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl --namespace default apply --filename eventing/samples/github-source/channel.yaml
|
kubectl --namespace default apply --filename eventing/samples/github-source/service.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Create GitHub Tokens
|
### Create GitHub Tokens
|
||||||
|
@ -49,9 +68,8 @@ recommended scopes:
|
||||||

|

|
||||||
|
|
||||||
Update `githubsecret.yaml` with those values. If your generated access
|
Update `githubsecret.yaml` with those values. If your generated access
|
||||||
token is `'asdfasfdsaf'` and you choose your *secretToken* as
|
token is `'personal_access_token_value'` and you choose your *secretToken*
|
||||||
`'personal_access_token_value'`, you'd modify `githubsecret.yaml` like
|
as `'asdfasfdsaf'`, you'd modify `githubsecret.yaml` like so:
|
||||||
so:
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: v1
|
apiVersion: v1
|
||||||
|
@ -60,11 +78,11 @@ metadata:
|
||||||
name: githubsecret
|
name: githubsecret
|
||||||
type: Opaque
|
type: Opaque
|
||||||
stringData:
|
stringData:
|
||||||
accessToken: asdfasfdsaf
|
accessToken: personal_access_token_value
|
||||||
secretToken: personal_access_token_value
|
secretToken: asdfasfdsaf
|
||||||
```
|
```
|
||||||
|
|
||||||
Hint: you can makeup a random *accessToken* with:
|
Hint: you can makeup a random *secretToken* with:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
head -c 8 /dev/urandom | base64
|
head -c 8 /dev/urandom | base64
|
||||||
|
@ -81,8 +99,7 @@ kubectl --namespace default apply --filename eventing/samples/github-source/gith
|
||||||
In order to receive GitHub events, you have to create a concrete Event
|
In order to receive GitHub events, you have to create a concrete Event
|
||||||
Source for a specific namespace. Be sure to replace the
|
Source for a specific namespace. Be sure to replace the
|
||||||
`ownerAndRepository` value with a valid GitHub public repository owned
|
`ownerAndRepository` value with a valid GitHub public repository owned
|
||||||
by your GitHub user. If you are using a different `Secret` name or
|
by your GitHub user.
|
||||||
`Channel`, modify the yaml accordingly.
|
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
apiVersion: sources.eventing.knative.dev/v1alpha1
|
apiVersion: sources.eventing.knative.dev/v1alpha1
|
||||||
|
@ -102,9 +119,9 @@ spec:
|
||||||
name: githubsecret
|
name: githubsecret
|
||||||
key: secretToken
|
key: secretToken
|
||||||
sink:
|
sink:
|
||||||
apiVersion: eventing.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
kind: Channel
|
kind: Service
|
||||||
name: githubchannel
|
name: github-message-dumper
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -114,62 +131,6 @@ Then, apply that yaml using `kubectl`:
|
||||||
kubectl --namespace default apply --filename eventing/samples/github-source/github-source.yaml
|
kubectl --namespace default apply --filename eventing/samples/github-source/github-source.yaml
|
||||||
```
|
```
|
||||||
|
|
||||||
### Subscription
|
|
||||||
|
|
||||||
To verify the `GitHubSource` is fully working, create a simple Knative
|
|
||||||
`Service` that dumps incoming messages to its log and create a
|
|
||||||
`Subscription` from the `Channel` to that Knative `Service`.
|
|
||||||
|
|
||||||
If the deployed `GitHubEventSource` is pointing at a `Channel` other
|
|
||||||
than `githubchannel`, modify `subscription.yaml` by replacing
|
|
||||||
`githubchannel` with that `Channel`'s name.
|
|
||||||
|
|
||||||
```yaml
|
|
||||||
apiVersion: eventing.knative.dev/v1alpha1
|
|
||||||
kind: Subscription
|
|
||||||
metadata:
|
|
||||||
name: github-source-sample
|
|
||||||
namespace: knative-demo
|
|
||||||
spec:
|
|
||||||
channel:
|
|
||||||
apiVersion: eventing.knative.dev/v1alpha1
|
|
||||||
kind: Channel
|
|
||||||
name: githubchannel
|
|
||||||
subscriber:
|
|
||||||
ref:
|
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
|
||||||
kind: Service
|
|
||||||
name: github-message-dumper
|
|
||||||
|
|
||||||
---
|
|
||||||
# This is a very simple Knative Service that writes the input request to its log.
|
|
||||||
|
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: github-message-dumper
|
|
||||||
namespace: knative-demo
|
|
||||||
spec:
|
|
||||||
runLatest:
|
|
||||||
configuration:
|
|
||||||
revisionTemplate:
|
|
||||||
spec:
|
|
||||||
container:
|
|
||||||
image: github.com/knative/eventing-sources/cmd/message_dumper
|
|
||||||
|
|
||||||
```
|
|
||||||
|
|
||||||
Then, deploy `subscription.yaml`, creating both the `Service` and
|
|
||||||
`Subscription`.
|
|
||||||
|
|
||||||
```shell
|
|
||||||
ko apply --filename eventing/samples/github-source/subscription.yaml
|
|
||||||
```
|
|
||||||
|
|
||||||
### Create Events
|
|
||||||
|
|
||||||
Create a Pull Request in your GitHub repository.
|
|
||||||
|
|
||||||
### Verify
|
### Verify
|
||||||
|
|
||||||
Verify the GitHub webhook was created by looking at the list of
|
Verify the GitHub webhook was created by looking at the list of
|
||||||
|
@ -179,10 +140,12 @@ check mark to the left of the hook URL, as shown below.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
We will verify that the GitHub events were sent into the Knative
|
### Create Events
|
||||||
eventing system by looking at our message dumper function logs. If you
|
|
||||||
deployed the [Subscription](#subscription), then continue using this
|
Create a pull request in your GitHub repository. We will verify
|
||||||
section. If not, then you will need to look downstream yourself.
|
that the GitHub events were sent into the Knative eventing system
|
||||||
|
by looking at our message dumper function logs.
|
||||||
|
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
kubectl --namespace default get pods
|
kubectl --namespace default get pods
|
||||||
|
@ -215,3 +178,19 @@ X-Request-Id: 8a2201af-5075-9447-b593-ec3a243aff52
|
||||||
|
|
||||||
{"action":"opened","number":1,"pull_request": ...}
|
{"action":"opened","number":1,"pull_request": ...}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Cleanup
|
||||||
|
|
||||||
|
You can remove the Github webhook by deleting the Github source:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
kubectl --namespace default delete --filename eventing/samples/github-source/github-source.yaml
|
||||||
|
```
|
||||||
|
|
||||||
|
Similarly, you can remove the Service and Secret via:
|
||||||
|
|
||||||
|
```shell
|
||||||
|
kubectl --namespace default delete --filename eventing/samples/github-source/service.yaml
|
||||||
|
kubectl --namespace default delete --filename eventing/samples/github-source/githubsecret.yaml
|
||||||
|
|
||||||
|
```
|
||||||
|
|
|
@ -1,9 +0,0 @@
|
||||||
apiVersion: eventing.knative.dev/v1alpha1
|
|
||||||
kind: Channel
|
|
||||||
metadata:
|
|
||||||
name: githubchannel
|
|
||||||
spec:
|
|
||||||
provisioner:
|
|
||||||
apiVersion: eventing.knative.dev/v1alpha1
|
|
||||||
kind: ClusterChannelProvisioner
|
|
||||||
name: in-memory-channel
|
|
|
@ -15,6 +15,6 @@ spec:
|
||||||
name: githubsecret
|
name: githubsecret
|
||||||
key: secretToken
|
key: secretToken
|
||||||
sink:
|
sink:
|
||||||
apiVersion: eventing.knative.dev/v1alpha1
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
kind: Channel
|
kind: Service
|
||||||
name: githubchannel
|
name: github-message-dumper
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
# This is a very simple Knative Service that writes the input request to its log.
|
||||||
|
apiVersion: serving.knative.dev/v1alpha1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: github-message-dumper
|
||||||
|
spec:
|
||||||
|
runLatest:
|
||||||
|
configuration:
|
||||||
|
revisionTemplate:
|
||||||
|
spec:
|
||||||
|
container:
|
||||||
|
image: gcr.io/knative-releases/github.com/knative/eventing-sources/cmd/message_dumper
|
|
@ -1,31 +0,0 @@
|
||||||
apiVersion: eventing.knative.dev/v1alpha1
|
|
||||||
kind: Subscription
|
|
||||||
metadata:
|
|
||||||
name: github-source-sample
|
|
||||||
namespace: knative-demo
|
|
||||||
spec:
|
|
||||||
channel:
|
|
||||||
apiVersion: eventing.knative.dev/v1alpha1
|
|
||||||
kind: Channel
|
|
||||||
name: githubchannel
|
|
||||||
subscriber:
|
|
||||||
ref:
|
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
|
||||||
kind: Service
|
|
||||||
name: github-message-dumper
|
|
||||||
|
|
||||||
---
|
|
||||||
# This is a very simple Knative Service that writes the input request to its log.
|
|
||||||
|
|
||||||
apiVersion: serving.knative.dev/v1alpha1
|
|
||||||
kind: Service
|
|
||||||
metadata:
|
|
||||||
name: github-message-dumper
|
|
||||||
namespace: knative-demo
|
|
||||||
spec:
|
|
||||||
runLatest:
|
|
||||||
configuration:
|
|
||||||
revisionTemplate:
|
|
||||||
spec:
|
|
||||||
container:
|
|
||||||
image: github.com/knative/eventing-sources/cmd/message_dumper
|
|
Loading…
Reference in New Issue