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

Simplify the Github sample. #587

Merged
merged 2 commits into from Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
131 changes: 55 additions & 76 deletions eventing/samples/github-source/README.md
Expand Up @@ -21,13 +21,32 @@ You will need:
Eventing](https://github.com/knative/docs/tree/master/eventing). Those
instructions also install the default eventing sources, including
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
you use your own `Channel` with a different name, then you will
need to alter other commands later.

### Create a Knative Service

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
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
Expand All @@ -49,9 +68,8 @@ recommended scopes:
![GitHub UI](personal_access_token.png "GitHub personal access token screenshot")

Update `githubsecret.yaml` with those values. If your generated access
token is `'asdfasfdsaf'` and you choose your *secretToken* as
`'personal_access_token_value'`, you'd modify `githubsecret.yaml` like
so:
token is `'personal_access_token_value'` and you choose your *secretToken*
as `'asdfasfdsaf'`, you'd modify `githubsecret.yaml` like so:

```yaml
apiVersion: v1
Expand All @@ -60,11 +78,11 @@ metadata:
name: githubsecret
type: Opaque
stringData:
accessToken: asdfasfdsaf
secretToken: personal_access_token_value
accessToken: personal_access_token_value
secretToken: asdfasfdsaf
```

Hint: you can makeup a random *accessToken* with:
Hint: you can makeup a random *secretToken* with:

```shell
head -c 8 /dev/urandom | base64
Expand All @@ -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
Source for a specific namespace. Be sure to replace the
`ownerAndRepository` value with a valid GitHub public repository owned
by your GitHub user. If you are using a different `Secret` name or
`Channel`, modify the yaml accordingly.
by your GitHub user.

```yaml
apiVersion: sources.eventing.knative.dev/v1alpha1
Expand All @@ -102,9 +119,9 @@ spec:
name: githubsecret
key: secretToken
sink:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: githubchannel
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: github-message-dumper

```

Expand All @@ -114,62 +131,6 @@ Then, apply that yaml using `kubectl`:
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 the GitHub webhook was created by looking at the list of
Expand All @@ -179,10 +140,12 @@ check mark to the left of the hook URL, as shown below.

![GitHub Webhook](webhook_created.png "GitHub webhook screenshot")

We will verify that the GitHub events were sent into the Knative
eventing system by looking at our message dumper function logs. If you
deployed the [Subscription](#subscription), then continue using this
section. If not, then you will need to look downstream yourself.
### Create Events

Create a pull request in your GitHub repository. We will verify
that the GitHub events were sent into the Knative eventing system
by looking at our message dumper function logs.


Copy link
Contributor

Choose a reason for hiding this comment

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

Can you add the clean up section below?

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

```shell
kubectl --namespace default get pods
Expand Down Expand Up @@ -215,3 +178,19 @@ X-Request-Id: 8a2201af-5075-9447-b593-ec3a243aff52

{"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

```
9 changes: 0 additions & 9 deletions eventing/samples/github-source/channel.yaml

This file was deleted.

6 changes: 3 additions & 3 deletions eventing/samples/github-source/github-source.yaml
Expand Up @@ -15,6 +15,6 @@ spec:
name: githubsecret
key: secretToken
sink:
apiVersion: eventing.knative.dev/v1alpha1
kind: Channel
name: githubchannel
apiVersion: serving.knative.dev/v1alpha1
kind: Service
name: github-message-dumper
12 changes: 12 additions & 0 deletions eventing/samples/github-source/service.yaml
@@ -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
31 changes: 0 additions & 31 deletions eventing/samples/github-source/subscription.yaml

This file was deleted.