mirror of https://github.com/knative/docs.git
1798 lines
203 KiB
XML
1798 lines
203 KiB
XML
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
|
||
<channel>
|
||
<title>Knative – Knative Eventing code samples</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/</link>
|
||
<description>Recent content in Knative Eventing code samples on Knative</description>
|
||
<generator>Hugo -- gohugo.io</generator>
|
||
|
||
<atom:link href="https://knative.dev/v0.21-docs/eventing/samples/index.xml" rel="self" type="application/rss+xml" />
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Apache Kafka examples</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/kafka/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/kafka/</guid>
|
||
<description>
|
||
|
||
|
||
<p>The following examples will help you understand how to use the different Apache
|
||
Kafka components for Knative.</p>
|
||
<h2 id="prerequisites">Prerequisites</h2>
|
||
<p>All examples require:</p>
|
||
<ul>
|
||
<li>A Kubernetes cluster with
|
||
<ul>
|
||
<li>Knative Eventing v0.9+</li>
|
||
<li>Knative Serving v0.9+</li>
|
||
</ul>
|
||
</li>
|
||
<li>An Apache Kafka cluster</li>
|
||
</ul>
|
||
<h3 id="setting-up-apache-kafka">Setting up Apache Kafka</h3>
|
||
<p>If you want to run the Apache Kafka cluster on Kubernetes, the simplest option
|
||
is to install it by using <a href="https://strimzi.io">Strimzi</a>.</p>
|
||
<ol>
|
||
<li>Create a namespace for your Apache Kafka installation, like <code>kafka</code>:
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create namespace kafka
|
||
</code></pre></div></li>
|
||
<li>Install the Strimzi operator, like:
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">curl -L <span style="color:#4e9a06">&#34;https://github.com/strimzi/strimzi-kafka-operator/releases/download/0.16.2/strimzi-cluster-operator-0.16.2.yaml&#34;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> <span style="color:#000;font-weight:bold">|</span> sed <span style="color:#4e9a06">&#39;s/namespace: .*/namespace: kafka/&#39;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> <span style="color:#000;font-weight:bold">|</span> kubectl -n kafka apply -f -
|
||
</code></pre></div></li>
|
||
<li>Describe the size of your Apache Kafka installation in <code>kafka.yaml</code>, like:
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">kafka.strimzi.io/v1beta1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Kafka</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">my-cluster</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kafka</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">version</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">2.4.0</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">replicas</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">listeners</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">plain</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>{}<span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">tls</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>{}<span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">config</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">offsets.topic.replication.factor</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">transaction.state.log.replication.factor</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">transaction.state.log.min.isr</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">log.message.format.version</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;2.4&#34;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">storage</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">type</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ephemeral</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">zookeeper</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">replicas</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#0000cf;font-weight:bold">3</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">storage</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">type</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ephemeral</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">entityOperator</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">topicOperator</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>{}<span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">userOperator</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span>{}<span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div></li>
|
||
<li>Deploy the Apache Kafka cluster
|
||
<pre><code>$ kubectl apply -n kafka -f kafka.yaml
|
||
</code></pre></li>
|
||
</ol>
|
||
<p>This will install a small, non-production, cluster of Apache Kafka. To verify
|
||
your installation, check if the pods for Strimzi are all up, in the <code>kafka</code>
|
||
namespace:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ kubectl get pods -n kafka
|
||
NAME READY STATUS RESTARTS AGE
|
||
my-cluster-entity-operator-65995cf856-ld2zp 3/3 Running <span style="color:#0000cf;font-weight:bold">0</span> 102s
|
||
my-cluster-kafka-0 2/2 Running <span style="color:#0000cf;font-weight:bold">0</span> 2m8s
|
||
my-cluster-zookeeper-0 2/2 Running <span style="color:#0000cf;font-weight:bold">0</span> 2m39s
|
||
my-cluster-zookeeper-1 2/2 Running <span style="color:#0000cf;font-weight:bold">0</span> 2m49s
|
||
my-cluster-zookeeper-2 2/2 Running <span style="color:#0000cf;font-weight:bold">0</span> 2m59s
|
||
strimzi-cluster-operator-77555d4b69-sbrt4 1/1 Running <span style="color:#0000cf;font-weight:bold">0</span> 3m14s
|
||
</code></pre></div><blockquote>
|
||
<p>NOTE: For production ready installs check <a href="https://strimzi.io">Strimzi</a>.</p>
|
||
</blockquote>
|
||
<h3 id="installation-script">Installation script</h3>
|
||
<p>If you want to install the latest version of Strimzi, in just one step, we have
|
||
a <a href="./kafka_setup.sh">script</a> for your convenience, which does exactly the same
|
||
steps that are listed above:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">$ ./kafka_setup.sh
|
||
</code></pre></div><h2 id="examples-of-apache-kafka-and-knative">Examples of Apache Kafka and Knative</h2>
|
||
<p>A number of different examples, showing the <code>KafkaSource</code>, <code>KafkaChannel</code> and
|
||
<code>KafkaBinding</code> can be found here:</p>
|
||
<ul>
|
||
<li><a href="./source/index.html"><code>KafkaSource</code> to <code>Service</code></a></li>
|
||
<li><a href="./channel/index.html"><code>KafkaChannel</code> and Broker</a></li>
|
||
<li><a href="./binding/index.html"><code>KafkaBinding</code></a></li>
|
||
</ul>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Container Source Example</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/container-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/container-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>ContainerSource will start a container image which will generate events under
|
||
certain situations and send messages to a sink URI. It also can be an easy way
|
||
to support your own event sources in Knative. This guide shows how to configure
|
||
ContainerSource as an event source for functions and summarizes guidelines for
|
||
creating your own event source as a ContainerSource.</p>
|
||
<h2 id="create-a-heartbeats-containersource">Create a heartbeats ContainerSource</h2>
|
||
<h3 id="prerequisites">Prerequisites</h3>
|
||
<ol>
|
||
<li>Setup <a href="../../../serving">Knative Serving</a>.</li>
|
||
<li>Setup <a href="../../../eventing">Knative Eventing and Sources</a>.</li>
|
||
</ol>
|
||
<h3 id="prepare-the-heartbeats-image">Prepare the heartbeats image</h3>
|
||
<p>Knative <a href="https://github.com/knative/eventing-contrib">event-sources</a> has a
|
||
sample of heartbeats event source. You could clone the source code by</p>
|
||
<pre><code>git clone -b &quot;{{&lt; branch &gt;}}&quot; https://github.com/knative/eventing-contrib.git
|
||
</code></pre><p>And then build a heartbeats image and publish to your image repo with</p>
|
||
<pre><code>ko publish knative.dev/eventing-contrib/cmd/heartbeats
|
||
</code></pre><p><strong>Note</strong>: <code>ko publish</code> requires:</p>
|
||
<ul>
|
||
<li><a href="https://github.com/knative/serving/blob/master/DEVELOPMENT.md#environment-setup"><code>KO_DOCKER_REPO</code></a>
|
||
to be set. (e.g. <code>gcr.io/[gcloud-project]</code> or <code>docker.io/&lt;username&gt;</code>)</li>
|
||
<li>you to be authenticated with your <code>KO_DOCKER_REPO</code></li>
|
||
<li><a href="https://docs.docker.com/install/"><code>docker</code></a> to be installed</li>
|
||
</ul>
|
||
<h3 id="create-a-knative-service">Create a Knative Service</h3>
|
||
<p>In order to verify <code>ContainerSource</code> is working, we will create a Event Display
|
||
Service that dumps incoming messages to its log.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serving.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">event-display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">containers</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">image</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div><p>Use following command to create the service from <code>service.yaml</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl apply --filename service.yaml
|
||
</code></pre></div><p>The status of the created service can be seen using:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl get ksvc
|
||
|
||
NAME URL LATESTCREATED LATESTREADY READY REASON
|
||
event-display http://event-display.default.1.2.3.4.xip.io event-display-gqjbw event-display-gqjbw True
|
||
</code></pre></div><h3 id="create-a-containersource-using-the-heartbeats-image">Create a ContainerSource using the heartbeats image</h3>
|
||
<p>In order to run the heartbeats container as an event source, you have to create
|
||
a concrete ContainerSource with specific arguments and environment settings. Be
|
||
sure to replace <code>heartbeats_image_uri</code> with a valid uri for your heartbeats
|
||
image in your image repo in <a href="./heartbeats-source.yaml">heartbeats-source.yaml</a>
|
||
file. Note that arguments and environment variables are set and will be passed
|
||
to the container.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sources.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ContainerSource</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">test-heartbeats</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">containers</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">image</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">&lt;heartbeats_image_uri&gt;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">heartbeats</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">args</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- --<span style="color:#000">period=1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">env</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">POD_NAME</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">value</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;mypod&#34;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">POD_NAMESPACE</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">value</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#4e9a06">&#34;event-test&#34;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">sink</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ref</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serving.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">event-display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div><p>Use the following command to create the event source from
|
||
<code>heartbeats-source.yaml</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl apply --filename heartbeats-source.yaml
|
||
</code></pre></div><h3 id="verify">Verify</h3>
|
||
<p>We will verify that the message was sent to the Knative eventing system by
|
||
looking at event-display service logs.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl logs -l serving.knative.dev/service<span style="color:#ce5c00;font-weight:bold">=</span>event-display -c user-container --since<span style="color:#ce5c00;font-weight:bold">=</span>10m
|
||
</code></pre></div><p>You should see log lines showing the request headers and body of the event
|
||
message sent by the heartbeats source to the display function:</p>
|
||
<pre><code>☁️ cloudevents.Event
|
||
Validation: valid
|
||
Context Attributes,
|
||
specversion: 1.0
|
||
type: dev.knative.eventing.samples.heartbeat
|
||
source: https://knative.dev/eventing-contrib/cmd/heartbeats/#event-test/mypod
|
||
id: 2b72d7bf-c38f-4a98-a433-608fbcdd2596
|
||
time: 2019-10-18T15:23:20.809775386Z
|
||
contenttype: application/json
|
||
Extensions,
|
||
beats: true
|
||
heart: yes
|
||
the: 42
|
||
Data,
|
||
{
|
||
&quot;id&quot;: 2,
|
||
&quot;label&quot;: &quot;&quot;
|
||
}
|
||
</code></pre><h2 id="create-a-new-event-source-using-containersource">Create a new event source using ContainerSource</h2>
|
||
<p>In order to create a new event source using ContainerSource, you will create a
|
||
container image at first, and then create a ContainerSource with the image uri
|
||
and specify the values of parameters.</p>
|
||
<h3 id="develop-build-and-publish-a-container-image">Develop, build and publish a container image</h3>
|
||
<p>The container image can be developed with any language, build and publish with
|
||
any tools you like. Here are some basic guidelines:</p>
|
||
<ul>
|
||
<li>The container image must have a <code>main</code> method to start with.</li>
|
||
<li>The <code>main</code> method will accept parameters from arguments and environment
|
||
variables.</li>
|
||
<li>Two environments variables will be injected by the <code>ContainerSource</code> controller,
|
||
<code>K_SINK</code> and <code>K_CE_OVERRIDES</code>, resolved from <code>spec.sink</code> and <code>spec.ceOverrides</code> respectively.</li>
|
||
<li>The event messages shall be sent to the sink URI specified in <code>K_SINK</code>. The message can be any
|
||
format.
|
||
<a href="https://github.com/cloudevents/spec/blob/master/spec.md#design-goals">CloudEvents</a>
|
||
format is recommended.</li>
|
||
</ul>
|
||
<p><a href="https://github.com/knative/eventing-contrib/blob/master/cmd/heartbeats/main.go">heartbeats</a>
|
||
event source is a sample for your reference.</p>
|
||
<h3 id="create-the-containersource-using-this-container-image">Create the ContainerSource using this container image</h3>
|
||
<p>When the container image is ready, a YAML file will be used to create a concrete
|
||
<code>ContainerSource</code>. Use <a href="./heartbeats-source.yaml">heartbeats-source.yaml</a> as a
|
||
sample for reference. <a href="../../../eventing#containersource">Learn more about the ContainerSource
|
||
specification</a>.</p>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Writing an Event Source using the easy way</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/writing-event-source-easy-way/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/writing-event-source-easy-way/</guid>
|
||
<description>
|
||
|
||
|
||
<h1 id="introduction">Introduction</h1>
|
||
<p>As stated in <a href="../writing-event-source/index.html">tutorial on writing a Source with a Receive Adapter</a>, there are multiple ways to
|
||
create event sources. The way in that tutorial is to create an independent event source that has its own CRD.</p>
|
||
<p>This tutorial provides a simpler mechanism to build an event source in Javascript and use it with
|
||
<a href="../../../eventing/sources/index.html#meta-sources">ContainerSource</a> and / or the <a href="../../../eventing/sources/index.html#meta-sources">SinkBinding</a>.</p>
|
||
<p><a href="../../../eventing/sources/index.html#meta-sources">ContainerSource</a> is an easy way to turn any dispatcher container into an Event Source.
|
||
Similarly, another option is using <a href="../../../eventing/sources/index.html#meta-sources">SinkBinding</a>
|
||
which provides a framework for injecting environment variables into any Kubernetes resource which has a <code>spec.template</code> that looks like a Pod (aka PodSpecable).</p>
|
||
<p>SinkBinding is a newer concept and it should be preferred over ContainerSource.</p>
|
||
<p>Code for this tutorial is available <a href="../../../tree/master/docs/eventing/samples/writing-event-source-easy-way">here</a>.</p>
|
||
<h1 id="bootstrapping">Bootstrapping</h1>
|
||
<p>Create the project and add the dependencies:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">npm init
|
||
npm install cloudevents-sdk@2.0.1 --save
|
||
</code></pre></div><p>Please note that because of a <a href="https://github.com/cloudevents/sdk-javascript/issues/191">bug</a>, you will
|
||
need at least <code>2.0.1</code> version of the Javascript SDK.</p>
|
||
<h2 id="making-use-of-containersource">Making use of ContainerSource</h2>
|
||
<p><code>ContainerSource</code> and <code>SinkBinding</code> both work by injecting environment variables to an application.
|
||
Injected environment variables at minimum contain the URL of a sink that will receive events.</p>
|
||
<p>Following example emits an event to the sink every 1000 milliseconds.
|
||
The sink URL to post the events will be made available to the application via the <code>K_SINK</code> environment variable by <code>ContainerSource</code>.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-javascript" data-lang="javascript"><span style="color:#8f5902;font-style:italic">// File - index.js
|
||
</span><span style="color:#8f5902;font-style:italic"></span>
|
||
<span style="color:#204a87;font-weight:bold">const</span> <span style="color:#000;font-weight:bold">{</span> <span style="color:#000">CloudEvent</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#000">HTTPEmitter</span> <span style="color:#000;font-weight:bold">}</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">require</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;cloudevents-sdk&#34;</span><span style="color:#000;font-weight:bold">);</span>
|
||
|
||
<span style="color:#204a87;font-weight:bold">let</span> <span style="color:#000">sinkUrl</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#000">process</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">env</span><span style="color:#000;font-weight:bold">[</span><span style="color:#4e9a06">&#39;K_SINK&#39;</span><span style="color:#000;font-weight:bold">];</span>
|
||
|
||
<span style="color:#000">console</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">log</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Sink URL is &#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">sinkUrl</span><span style="color:#000;font-weight:bold">);</span>
|
||
|
||
<span style="color:#204a87;font-weight:bold">let</span> <span style="color:#000">emitter</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">HTTPEmitter</span><span style="color:#000;font-weight:bold">({</span>
|
||
<span style="color:#000">url</span><span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#000">sinkUrl</span>
|
||
<span style="color:#000;font-weight:bold">});</span>
|
||
|
||
<span style="color:#204a87;font-weight:bold">let</span> <span style="color:#000">eventIndex</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#0000cf;font-weight:bold">0</span><span style="color:#000;font-weight:bold">;</span>
|
||
<span style="color:#000">setInterval</span><span style="color:#000;font-weight:bold">(</span><span style="color:#204a87;font-weight:bold">function</span> <span style="color:#000;font-weight:bold">()</span> <span style="color:#000;font-weight:bold">{</span>
|
||
<span style="color:#000">console</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">log</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Emitting event #&#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#ce5c00;font-weight:bold">++</span><span style="color:#000">eventIndex</span><span style="color:#000;font-weight:bold">);</span>
|
||
|
||
<span style="color:#204a87;font-weight:bold">let</span> <span style="color:#000">myevent</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">CloudEvent</span><span style="color:#000;font-weight:bold">({</span>
|
||
<span style="color:#000">source</span><span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;urn:event:from:my-api/resource/123&#34;</span><span style="color:#000;font-weight:bold">,</span>
|
||
<span style="color:#000">type</span><span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;your.event.source.type&#34;</span><span style="color:#000;font-weight:bold">,</span>
|
||
<span style="color:#000">id</span><span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;your-event-id&#34;</span><span style="color:#000;font-weight:bold">,</span>
|
||
<span style="color:#000">dataContentType</span><span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;application/json&#34;</span><span style="color:#000;font-weight:bold">,</span>
|
||
<span style="color:#000">data</span><span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#000;font-weight:bold">{</span><span style="color:#4e9a06">&#34;hello&#34;</span><span style="color:#ce5c00;font-weight:bold">:</span> <span style="color:#4e9a06">&#34;World &#34;</span> <span style="color:#ce5c00;font-weight:bold">+</span> <span style="color:#000">eventIndex</span><span style="color:#000;font-weight:bold">},</span>
|
||
<span style="color:#000;font-weight:bold">});</span>
|
||
|
||
<span style="color:#8f5902;font-style:italic">// Emit the event
|
||
</span><span style="color:#8f5902;font-style:italic"></span> <span style="color:#000">emitter</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">send</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">myevent</span><span style="color:#000;font-weight:bold">)</span>
|
||
<span style="color:#000;font-weight:bold">.</span><span style="color:#000">then</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">response</span> <span style="color:#000;font-weight:bold">=&gt;</span> <span style="color:#000;font-weight:bold">{</span>
|
||
<span style="color:#8f5902;font-style:italic">// Treat the response
|
||
</span><span style="color:#8f5902;font-style:italic"></span> <span style="color:#000">console</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">log</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Event posted successfully&#34;</span><span style="color:#000;font-weight:bold">);</span>
|
||
<span style="color:#000">console</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">log</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">response</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">data</span><span style="color:#000;font-weight:bold">);</span>
|
||
<span style="color:#000;font-weight:bold">})</span>
|
||
<span style="color:#000;font-weight:bold">.</span><span style="color:#204a87;font-weight:bold">catch</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">err</span> <span style="color:#000;font-weight:bold">=&gt;</span> <span style="color:#000;font-weight:bold">{</span>
|
||
<span style="color:#8f5902;font-style:italic">// Deal with errors
|
||
</span><span style="color:#8f5902;font-style:italic"></span> <span style="color:#000">console</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">log</span><span style="color:#000;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Error during event post&#34;</span><span style="color:#000;font-weight:bold">);</span>
|
||
<span style="color:#000">console</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">error</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">err</span><span style="color:#000;font-weight:bold">);</span>
|
||
<span style="color:#000;font-weight:bold">});</span>
|
||
<span style="color:#000;font-weight:bold">},</span> <span style="color:#0000cf;font-weight:bold">1000</span><span style="color:#000;font-weight:bold">);</span>
|
||
</code></pre></div><div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-dockerfile" data-lang="dockerfile"><span style="color:#8f5902;font-style:italic"># File - Dockerfile</span><span style="color:#a40000">
|
||
</span><span style="color:#a40000">
|
||
</span><span style="color:#a40000"></span><span style="color:#204a87;font-weight:bold">FROM</span><span style="color:#4e9a06"> node:10</span><span style="color:#a40000">
|
||
</span><span style="color:#a40000"></span><span style="color:#204a87;font-weight:bold">WORKDIR</span><span style="color:#4e9a06"> /usr/src/app</span><span style="color:#a40000">
|
||
</span><span style="color:#a40000"></span><span style="color:#204a87;font-weight:bold">COPY</span> package*.json ./<span style="color:#a40000">
|
||
</span><span style="color:#a40000"></span><span style="color:#204a87;font-weight:bold">RUN</span> npm install<span style="color:#a40000">
|
||
</span><span style="color:#a40000"></span><span style="color:#204a87;font-weight:bold">COPY</span> . .<span style="color:#a40000">
|
||
</span><span style="color:#a40000"></span><span style="color:#204a87;font-weight:bold">EXPOSE</span><span style="color:#4e9a06"> 8080</span><span style="color:#a40000">
|
||
</span><span style="color:#a40000"></span><span style="color:#204a87;font-weight:bold">CMD</span> <span style="color:#000;font-weight:bold">[</span> <span style="color:#4e9a06">&#34;node&#34;</span><span style="color:#000;font-weight:bold">,</span> <span style="color:#4e9a06">&#34;index.js&#34;</span> <span style="color:#000;font-weight:bold">]</span><span style="color:#a40000">
|
||
</span><span style="color:#a40000">
|
||
</span></code></pre></div><p>Build and push the image:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">docker build . -t path/to/image/registry/node-knative-heartbeat-source:v1
|
||
docker push path/to/image/registry/node-knative-heartbeat-source:v1
|
||
</code></pre></div><p>Create the event display service which simply logs any cloudevents posted to it.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">cat <span style="color:#4e9a06">&lt;&lt;EOS |kubectl apply -f -
|
||
</span><span style="color:#4e9a06">---
|
||
</span><span style="color:#4e9a06">apiVersion: serving.knative.dev/v1
|
||
</span><span style="color:#4e9a06">kind: Service
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: event-display
|
||
</span><span style="color:#4e9a06">spec:
|
||
</span><span style="color:#4e9a06"> template:
|
||
</span><span style="color:#4e9a06"> spec:
|
||
</span><span style="color:#4e9a06"> containers:
|
||
</span><span style="color:#4e9a06"> - image: docker.io/aliok/event_display-864884f202126ec3150c5fcef437d90c@sha256:93cb4dcda8fee80a1f68662ae6bf20301471b046ede628f3c3f94f39752fbe08
|
||
</span><span style="color:#4e9a06">EOS</span>
|
||
</code></pre></div><p>Create the <code>ContainerSource</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">cat <span style="color:#4e9a06">&lt;&lt;EOS |kubectl apply -f -
|
||
</span><span style="color:#4e9a06">---
|
||
</span><span style="color:#4e9a06">apiVersion: sources.knative.dev/v1
|
||
</span><span style="color:#4e9a06">kind: ContainerSource
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: test-heartbeats
|
||
</span><span style="color:#4e9a06">spec:
|
||
</span><span style="color:#4e9a06"> template:
|
||
</span><span style="color:#4e9a06"> spec:
|
||
</span><span style="color:#4e9a06"> containers:
|
||
</span><span style="color:#4e9a06"> - image: path/to/image/registry/node-knative-heartbeat-source:v1
|
||
</span><span style="color:#4e9a06"> name: heartbeats
|
||
</span><span style="color:#4e9a06"> sink:
|
||
</span><span style="color:#4e9a06"> ref:
|
||
</span><span style="color:#4e9a06"> apiVersion: serving.knative.dev/v1
|
||
</span><span style="color:#4e9a06"> kind: Service
|
||
</span><span style="color:#4e9a06"> name: event-display
|
||
</span><span style="color:#4e9a06">EOS</span>
|
||
</code></pre></div><p>Check the logs of the event display service. You will see a new message is pushed every second:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ kubectl logs -l serving.knative.dev/service<span style="color:#ce5c00;font-weight:bold">=</span>event-display -c user-container
|
||
|
||
☁️ cloudevents.Event
|
||
Validation: valid
|
||
Context Attributes,
|
||
specversion: 1.0
|
||
type: your.event.source.type
|
||
source: urn:event:from:your-api/resource/123
|
||
id: your-event-id
|
||
datacontenttype: application/json
|
||
Data,
|
||
<span style="color:#ce5c00;font-weight:bold">{</span>
|
||
<span style="color:#4e9a06">&#34;hello&#34;</span>: <span style="color:#4e9a06">&#34;World 1&#34;</span>
|
||
<span style="color:#ce5c00;font-weight:bold">}</span>
|
||
</code></pre></div><p>If you are interested in seeing what is injected into the event source as a <code>K_SINK</code>, you can check the logs:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ kubectl logs test-heartbeats-deployment-7575c888c7-85w5t
|
||
|
||
Sink URL is http://event-display.default.svc.cluster.local
|
||
Emitting event <span style="color:#8f5902;font-style:italic">#1</span>
|
||
Emitting event <span style="color:#8f5902;font-style:italic">#2</span>
|
||
Event posted successfully
|
||
Event posted successfully
|
||
</code></pre></div><p>Please note that the example code above is using <em>Binary</em> mode for CloudEvents.
|
||
Simply change</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-javascript" data-lang="javascript"><span style="color:#204a87;font-weight:bold">let</span> <span style="color:#000">binding</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">v1</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">BinaryHTTPEmitter</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">config</span><span style="color:#000;font-weight:bold">);</span>
|
||
</code></pre></div><p>with</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-javascript" data-lang="javascript"><span style="color:#204a87;font-weight:bold">let</span> <span style="color:#000">binding</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">v1</span><span style="color:#000;font-weight:bold">.</span><span style="color:#000">StructuredHTTPEmitter</span><span style="color:#000;font-weight:bold">(</span><span style="color:#000">config</span><span style="color:#000;font-weight:bold">);</span>
|
||
</code></pre></div><p>to employ structured mode.</p>
|
||
<p>However, binary mode should be used in most of the cases as:</p>
|
||
<ul>
|
||
<li>It is faster in terms of serialization and deserialization</li>
|
||
<li>It works better with cloudevents-aware proxies (like Knative Channels) can simply check the header instead of parsing the payload</li>
|
||
</ul>
|
||
<h2 id="making-use-of-sinkbinding">Making use of SinkBinding</h2>
|
||
<p><code>SinkBinding</code> is a more powerful way of making any Kubernetes resource an event source.</p>
|
||
<p><code>ContainerSource</code> will create the container for your event source&rsquo;s image and it will be <code>ContainerSource</code> responsibility to manage the container.</p>
|
||
<p><code>SinkBinding</code> though, will not create any containers. It will inject the sink information to the already existing Kubernetes resources.
|
||
This is a more flexible approach as you can use any Kubernetes <code>PodSpecable</code> as an event source, such as <code>Deployment</code>, <code>Job</code>, <code>Knative Service</code>, <code>DaemonSet</code> etc.</p>
|
||
<p>We don&rsquo;t need any code changes in our source for making it work with <code>SinkBinding</code>.</p>
|
||
<p>Create the event display as in the section before:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">cat <span style="color:#4e9a06">&lt;&lt;EOS |kubectl apply -f -
|
||
</span><span style="color:#4e9a06">---
|
||
</span><span style="color:#4e9a06">apiVersion: serving.knative.dev/v1
|
||
</span><span style="color:#4e9a06">kind: Service
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: event-display
|
||
</span><span style="color:#4e9a06">spec:
|
||
</span><span style="color:#4e9a06"> template:
|
||
</span><span style="color:#4e9a06"> spec:
|
||
</span><span style="color:#4e9a06"> containers:
|
||
</span><span style="color:#4e9a06"> - image: docker.io/aliok/event_display-864884f202126ec3150c5fcef437d90c@sha256:93cb4dcda8fee80a1f68662ae6bf20301471b046ede628f3c3f94f39752fbe08
|
||
</span><span style="color:#4e9a06">EOS</span>
|
||
</code></pre></div><p>Create a Kubernetes deployment that runs the event source:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">cat <span style="color:#4e9a06">&lt;&lt;EOS |kubectl apply -f -
|
||
</span><span style="color:#4e9a06">---
|
||
</span><span style="color:#4e9a06">apiVersion: apps/v1
|
||
</span><span style="color:#4e9a06">kind: Deployment
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: node-heartbeats-deployment
|
||
</span><span style="color:#4e9a06"> labels:
|
||
</span><span style="color:#4e9a06"> app: node-heartbeats
|
||
</span><span style="color:#4e9a06">spec:
|
||
</span><span style="color:#4e9a06"> replicas: 2
|
||
</span><span style="color:#4e9a06"> selector:
|
||
</span><span style="color:#4e9a06"> matchLabels:
|
||
</span><span style="color:#4e9a06"> app: node-heartbeats
|
||
</span><span style="color:#4e9a06"> template:
|
||
</span><span style="color:#4e9a06"> metadata:
|
||
</span><span style="color:#4e9a06"> labels:
|
||
</span><span style="color:#4e9a06"> app: node-heartbeats
|
||
</span><span style="color:#4e9a06"> spec:
|
||
</span><span style="color:#4e9a06"> containers:
|
||
</span><span style="color:#4e9a06"> - name: node-heartbeats
|
||
</span><span style="color:#4e9a06"> image: path/to/image/registry/node-knative-heartbeat-source:v1
|
||
</span><span style="color:#4e9a06"> ports:
|
||
</span><span style="color:#4e9a06"> - containerPort: 8080
|
||
</span><span style="color:#4e9a06">EOS</span>
|
||
</code></pre></div><p>As the <code>SinkBinding</code> is not created yet, <code>K_SINK</code> environment variable is not yet injected and the event source will complain about that.</p>
|
||
<pre><code>$ kubectl logs node-heartbeats-deployment-9ffbb644b-llkzk
|
||
|
||
Sink URL is undefined
|
||
Emitting event #1
|
||
Error during event post
|
||
TypeError [ERR_INVALID_ARG_TYPE]: The &quot;url&quot; argument must be of type string. Received type undefined
|
||
</code></pre><p>Create the <code>SinkBinding</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">cat <span style="color:#4e9a06">&lt;&lt;EOS |kubectl apply -f -
|
||
</span><span style="color:#4e9a06">---
|
||
</span><span style="color:#4e9a06">apiVersion: sources.knative.dev/v1
|
||
</span><span style="color:#4e9a06">kind: SinkBinding
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: bind-node-heartbeat
|
||
</span><span style="color:#4e9a06">spec:
|
||
</span><span style="color:#4e9a06"> subject:
|
||
</span><span style="color:#4e9a06"> apiVersion: apps/v1
|
||
</span><span style="color:#4e9a06"> kind: Deployment
|
||
</span><span style="color:#4e9a06"> selector:
|
||
</span><span style="color:#4e9a06"> matchLabels:
|
||
</span><span style="color:#4e9a06"> app: node-heartbeats
|
||
</span><span style="color:#4e9a06"> sink:
|
||
</span><span style="color:#4e9a06"> ref:
|
||
</span><span style="color:#4e9a06"> apiVersion: serving.knative.dev/v1
|
||
</span><span style="color:#4e9a06"> kind: Service
|
||
</span><span style="color:#4e9a06"> name: event-display
|
||
</span><span style="color:#4e9a06">EOS</span>
|
||
</code></pre></div><p>You will see the pods are recreated and this time the <code>K_SINK</code> environment variable is injected.</p>
|
||
<p>Also note that since the <code>replicas</code> is set to 2, there will be 2 pods that are posting events to the sink.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-bash" data-lang="bash">$ kubectl logs event-display-dpplv-deployment-67c9949cf9-bvjvk -c user-container
|
||
|
||
☁️ cloudevents.Event
|
||
Validation: valid
|
||
Context Attributes,
|
||
specversion: 1.0
|
||
type: your.event.source.type
|
||
source: urn:event:from:your-api/resource/123
|
||
id: your-event-id
|
||
datacontenttype: application/json
|
||
Data,
|
||
<span style="color:#ce5c00;font-weight:bold">{</span>
|
||
<span style="color:#4e9a06">&#34;hello&#34;</span>: <span style="color:#4e9a06">&#34;World 1&#34;</span>
|
||
<span style="color:#ce5c00;font-weight:bold">}</span>
|
||
|
||
☁️ cloudevents.Event
|
||
Validation: valid
|
||
Context Attributes,
|
||
specversion: 1.0
|
||
type: your.event.source.type
|
||
source: urn:event:from:your-api/resource/123
|
||
id: your-event-id
|
||
datacontenttype: application/json
|
||
Data,
|
||
<span style="color:#ce5c00;font-weight:bold">{</span>
|
||
<span style="color:#4e9a06">&#34;hello&#34;</span>: <span style="color:#4e9a06">&#34;World 1&#34;</span>
|
||
<span style="color:#ce5c00;font-weight:bold">}</span>
|
||
</code></pre></div>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Knative Eventing - Hello World app</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/helloworld/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/helloworld/</guid>
|
||
<description>
|
||
|
||
|
||
<p>Following examples include a simple web app written in the language of your choice that you can
|
||
use to test knative eventing. It shows how to consume a <a href="https://cloudevents.io/">CloudEvent</a>
|
||
in Knative eventing, and optionally how to respond back with another CloudEvent in the HTTP response.</p>
|
||
<p>We will deploy the app as a
|
||
<a href="https://kubernetes.io/docs/concepts/workloads/controllers/deployment/">Kubernetes Deployment</a>
|
||
along with a
|
||
<a href="https://kubernetes.io/docs/concepts/services-networking/service/">Kubernetes Service</a>.
|
||
However, you can also deploy the app as a <a href="../../../serving/index.html">Knative Serving Service</a></p>
|
||
<h2 id="prerequisites">Prerequisites</h2>
|
||
<ul>
|
||
<li>A Kubernetes cluster with <a href="../../getting-started#installing-knative-eventing">Knative Eventing</a>
|
||
installed.
|
||
<ul>
|
||
<li>If you decide to deploy the app as a Knative Serving Service then you will have to install
|
||
<a href="../../../install/index.html">Knative Serving</a>.</li>
|
||
</ul>
|
||
</li>
|
||
<li><a href="https://www.docker.com">Docker</a> installed and running on your local machine,
|
||
and a Docker Hub account configured (we&rsquo;ll use it for a container registry).</li>
|
||
</ul>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Parallel Example</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/parallel/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/parallel/</guid>
|
||
<description>
|
||
|
||
|
||
<p>The following examples will help you understand how to use Parallel to describe
|
||
various flows.</p>
|
||
<h2 id="prerequisites">Prerequisites</h2>
|
||
<p>All examples require:</p>
|
||
<ul>
|
||
<li>A Kubernetes cluster with
|
||
<ul>
|
||
<li>Knative Eventing</li>
|
||
<li>Knative Serving</li>
|
||
</ul>
|
||
</li>
|
||
</ul>
|
||
<p>All examples are using the
|
||
<a href="../../channels/default-channels">default channel template</a>.</p>
|
||
<h2 id="examples">Examples</h2>
|
||
<p>For each of these examples below, we&rsquo;ll use
|
||
<a href="../ping-source/index.html"><code>PingSource</code></a> as the source of events.</p>
|
||
<p>We also use simple
|
||
<a href="https://github.com/lionelvillard/knative-functions">functions</a> to perform
|
||
trivial filtering, transformation and routing of the incoming events.</p>
|
||
<p>The examples are:</p>
|
||
<ul>
|
||
<li><a href="./multiple-branches/index.html">Parallel with multiple branches and global reply</a></li>
|
||
<li><a href="./mutual-exclusivity/index.html">Parallel with mutually exclusive cases</a></li>
|
||
</ul>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: PingSource example</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/ping-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/ping-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>This example shows how to configure PingSource as an event source targeting
|
||
a Knative Service.</p>
|
||
<h2 id="before-you-begin">Before you begin</h2>
|
||
<ol>
|
||
<li>Set up <a href="../../../serving">Knative Serving</a>.</li>
|
||
<li>Set up <a href="../../../eventing">Knative Eventing</a>.</li>
|
||
</ol>
|
||
<h2 id="create-a-knative-service">Create a Knative Service</h2>
|
||
<p>To verify that <code>PingSource</code> is working, create a simple Knative
|
||
Service that dumps incoming messages to its log.</p>
|
||
|
||
|
||
|
||
|
||
|
||
<ul class="nav nav-tabs" id="create-service" role="tablist">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<li class="nav-item active">
|
||
<a class="nav-link active" id="create-service-0-tab" data-toggle="tab" href="#create-service-0" role="tab" aria-controls="create-service-0" aria-selected="true">YAML</a>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
<li class="nav-item ">
|
||
<a class="nav-link " id="create-service-1-tab" data-toggle="tab" href="#create-service-1" role="tab" aria-controls="create-service-1" aria-selected="true">kn</a>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
<div class="tab-content" >
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade show active" id="create-service-0" role="tabpanel" aria-labelledby="create-service-0-tab">
|
||
|
||
<p>Use following command to create the service from STDIN:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">cat <span style="color:#4e9a06">&lt;&lt;EOF | kubectl create -f -
|
||
</span><span style="color:#4e9a06">apiVersion: serving.knative.dev/v1
|
||
</span><span style="color:#4e9a06">kind: Service
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: event-display
|
||
</span><span style="color:#4e9a06">spec:
|
||
</span><span style="color:#4e9a06"> template:
|
||
</span><span style="color:#4e9a06"> spec:
|
||
</span><span style="color:#4e9a06"> containers:
|
||
</span><span style="color:#4e9a06"> - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
|
||
</span><span style="color:#4e9a06">EOF</span>
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade " id="create-service-1" role="tabpanel" aria-labelledby="create-service-1-tab">
|
||
|
||
<p>Use following command to create the service using the kn cli:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kn service create event-display --image gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<h2 id="create-a-pingsource">Create a PingSource</h2>
|
||
<p>For each set of ping events that you want to request, create an Event
|
||
Source in the same namespace as the destination.</p>
|
||
|
||
|
||
|
||
|
||
|
||
<ul class="nav nav-tabs" id="create-source" role="tablist">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<li class="nav-item active">
|
||
<a class="nav-link active" id="create-source-0-tab" data-toggle="tab" href="#create-source-0" role="tab" aria-controls="create-source-0" aria-selected="true">YAML</a>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
<li class="nav-item ">
|
||
<a class="nav-link " id="create-source-1-tab" data-toggle="tab" href="#create-source-1" role="tab" aria-controls="create-source-1" aria-selected="true">kn</a>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
<div class="tab-content" >
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade show active" id="create-source-0" role="tabpanel" aria-labelledby="create-source-0-tab">
|
||
|
||
<p>Use following command to create the event source from STDIN:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">cat <span style="color:#4e9a06">&lt;&lt;EOF | kubectl create -f -
|
||
</span><span style="color:#4e9a06">apiVersion: sources.knative.dev/v1beta2
|
||
</span><span style="color:#4e9a06">kind: PingSource
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: test-ping-source
|
||
</span><span style="color:#4e9a06">spec:
|
||
</span><span style="color:#4e9a06"> schedule: &#34;*/2 * * * *&#34;
|
||
</span><span style="color:#4e9a06"> contentType: &#34;application/json&#34;
|
||
</span><span style="color:#4e9a06"> data: &#39;{&#34;message&#34;: &#34;Hello world!&#34;}&#39;
|
||
</span><span style="color:#4e9a06"> sink:
|
||
</span><span style="color:#4e9a06"> ref:
|
||
</span><span style="color:#4e9a06"> apiVersion: serving.knative.dev/v1
|
||
</span><span style="color:#4e9a06"> kind: Service
|
||
</span><span style="color:#4e9a06"> name: event-display
|
||
</span><span style="color:#4e9a06">EOF</span>
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade " id="create-source-1" role="tabpanel" aria-labelledby="create-source-1-tab">
|
||
|
||
<p>Use following command to create the event source from the <code>ping-source.yaml</code> file:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kn <span style="color:#204a87">source</span> ping create test-ping-source <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --schedule <span style="color:#4e9a06">&#34;*/2 * * * *&#34;</span> --data <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> <span style="color:#4e9a06">&#39;{ &#34;message&#34;: &#34;Hello world!&#34; }&#39;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --sink ksvc:event-display
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<h2 id="optional-create-a-pingsource-with-binary-data">(Optional) Create a PingSource with binary data</h2>
|
||
<p>Sometimes you may want to send binary data, which cannot be directly serialized in yaml, to downstream. This can be achieved by using <code>dataBase64</code> as the payload. As the name suggests, <code>dataBase64</code> should carry data that is base64 encoded.</p>
|
||
<p>Please note that <code>data</code> and <code>dataBase64</code> cannot co-exist.</p>
|
||
<p>Use the following command to create the event source with binary data from STDIN:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">cat <span style="color:#4e9a06">&lt;&lt;EOF | kubectl create -f -
|
||
</span><span style="color:#4e9a06">apiVersion: sources.knative.dev/v1beta2
|
||
</span><span style="color:#4e9a06">kind: PingSource
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: test-ping-source-binary
|
||
</span><span style="color:#4e9a06">spec:
|
||
</span><span style="color:#4e9a06"> schedule: &#34;*/2 * * * *&#34;
|
||
</span><span style="color:#4e9a06"> contentType: &#34;text/plain&#34;
|
||
</span><span style="color:#4e9a06"> dataBase64: &#34;ZGF0YQ==&#34;
|
||
</span><span style="color:#4e9a06"> sink:
|
||
</span><span style="color:#4e9a06"> ref:
|
||
</span><span style="color:#4e9a06"> apiVersion: serving.knative.dev/v1
|
||
</span><span style="color:#4e9a06"> kind: Service
|
||
</span><span style="color:#4e9a06"> name: event-display
|
||
</span><span style="color:#4e9a06">EOF</span>
|
||
</code></pre></div><h2 id="verify">Verify</h2>
|
||
<p>Verify that the message was sent to the Knative eventing system by
|
||
looking at message dumper logs.</p>
|
||
|
||
|
||
|
||
|
||
|
||
<ul class="nav nav-tabs" id="view-event" role="tablist">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<li class="nav-item active">
|
||
<a class="nav-link active" id="view-event-0-tab" data-toggle="tab" href="#view-event-0" role="tab" aria-controls="view-event-0" aria-selected="true">kubectl</a>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
<li class="nav-item ">
|
||
<a class="nav-link " id="view-event-1-tab" data-toggle="tab" href="#view-event-1" role="tab" aria-controls="view-event-1" aria-selected="true">kail</a>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
<div class="tab-content" >
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade show active" id="view-event-0" role="tabpanel" aria-labelledby="view-event-0-tab">
|
||
|
||
<p>Use following command to view the logs of the event-display service:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl logs -l serving.knative.dev/service<span style="color:#ce5c00;font-weight:bold">=</span>event-display -c user-container --since<span style="color:#ce5c00;font-weight:bold">=</span>10m
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade " id="view-event-1" role="tabpanel" aria-labelledby="view-event-1-tab">
|
||
|
||
<p>You can also use <a href="https://github.com/boz/kail"><code>kail</code></a> instead of <code>kubectl logs</code>
|
||
to tail the logs of the subscriber.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kail -l serving.knative.dev/service<span style="color:#ce5c00;font-weight:bold">=</span>event-display -c user-container --since<span style="color:#ce5c00;font-weight:bold">=</span>10m
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<p>You should see log lines showing the request headers and body from the source:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">☁️ cloudevents.Event
|
||
Validation: valid
|
||
Context Attributes,
|
||
specversion: 1.0
|
||
type: dev.knative.sources.ping
|
||
source: /apis/v1/namespaces/default/pingsources/test-ping-source
|
||
id: d8e761eb-30c7-49a3-a421-cd5895239f2d
|
||
time: 2019-12-04T14:24:00.000702251Z
|
||
datacontenttype: application/json
|
||
Data,
|
||
<span style="color:#ce5c00;font-weight:bold">{</span>
|
||
<span style="color:#4e9a06">&#34;message&#34;</span>: <span style="color:#4e9a06">&#34;Hello world!&#34;</span>
|
||
<span style="color:#ce5c00;font-weight:bold">}</span>
|
||
</code></pre></div><p>If you created a PingSource with binary data, you should also see the following:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">☁️ cloudevents.Event
|
||
Validation: valid
|
||
Context Attributes,
|
||
specversion: 1.0
|
||
type: dev.knative.sources.ping
|
||
source: /apis/v1/namespaces/default/pingsources/test-ping-source-binary
|
||
id: a195be33-ff65-49af-9045-0e0711d05e94
|
||
time: 2020-11-17T19:48:00.48334181Z
|
||
datacontenttype: text/plain
|
||
Data,
|
||
<span style="color:#000">ZGF0YQ</span><span style="color:#ce5c00;font-weight:bold">==</span>
|
||
</code></pre></div><h2 id="cleanup">Cleanup</h2>
|
||
<p>You can delete the PingSource instance by entering the following command:</p>
|
||
|
||
|
||
|
||
|
||
|
||
<ul class="nav nav-tabs" id="delete-source" role="tablist">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<li class="nav-item active">
|
||
<a class="nav-link active" id="delete-source-0-tab" data-toggle="tab" href="#delete-source-0" role="tab" aria-controls="delete-source-0" aria-selected="true">kubectl</a>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
<li class="nav-item ">
|
||
<a class="nav-link " id="delete-source-1-tab" data-toggle="tab" href="#delete-source-1" role="tab" aria-controls="delete-source-1" aria-selected="true">kn</a>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
<div class="tab-content" >
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade show active" id="delete-source-0" role="tabpanel" aria-labelledby="delete-source-0-tab">
|
||
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl delete pingsources.sources.knative.dev test-ping-source
|
||
kubectl delete pingsources.sources.knative.dev test-ping-source-binary
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade " id="delete-source-1" role="tabpanel" aria-labelledby="delete-source-1-tab">
|
||
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kn <span style="color:#204a87">source</span> ping delete test-ping-source
|
||
kn <span style="color:#204a87">source</span> ping delete test-ping-source-binary
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
<p>Similarly, you can delete the Service instance via:</p>
|
||
|
||
|
||
|
||
|
||
|
||
<ul class="nav nav-tabs" id="delete-service" role="tablist">
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<li class="nav-item active">
|
||
<a class="nav-link active" id="delete-service-0-tab" data-toggle="tab" href="#delete-service-0" role="tab" aria-controls="delete-service-0" aria-selected="true">kubectl</a>
|
||
</li>
|
||
|
||
|
||
|
||
|
||
<li class="nav-item ">
|
||
<a class="nav-link " id="delete-service-1-tab" data-toggle="tab" href="#delete-service-1" role="tab" aria-controls="delete-service-1" aria-selected="true">kn</a>
|
||
</li>
|
||
|
||
</ul>
|
||
|
||
<div class="tab-content" >
|
||
|
||
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade show active" id="delete-service-0" role="tabpanel" aria-labelledby="delete-service-0-tab">
|
||
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl delete service.serving.knative.dev event-display
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
|
||
|
||
|
||
<div class="tab-pane fade " id="delete-service-1" role="tabpanel" aria-labelledby="delete-service-1-tab">
|
||
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kn service delete event-display
|
||
</code></pre></div>
|
||
|
||
</div>
|
||
|
||
</div>
|
||
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Sequence Example</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/sequence/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/sequence/</guid>
|
||
<description>
|
||
|
||
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: CloudAuditLogsSource</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/cloud-audit-logs-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/cloud-audit-logs-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>Please refer to the <a href="https://github.com/google/knative-gcp/blob/master/docs/examples/cloudauditlogssource/README.md">example</a> in knative-gcp.</p>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: CloudPubSubSource</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/cloud-pubsub-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/cloud-pubsub-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>Please refer to the <a href="https://github.com/google/knative-gcp/blob/master/docs/examples/cloudpubsubsource/README.md">example</a> in knative-gcp.</p>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: CloudSchedulerSource</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/cloud-scheduler-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/cloud-scheduler-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>Please refer to the <a href="https://github.com/google/knative-gcp/blob/master/docs/examples/cloudschedulersource/README.md">example</a> in knative-gcp.</p>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: CloudStorageSource</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/cloud-storage-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/cloud-storage-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>Please refer to the <a href="https://github.com/google/knative-gcp/blob/master/docs/examples/cloudstoragesource/README.md">example</a> in knative-gcp.</p>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: GitHub source</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/github-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/github-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>GitHub Source example shows how to wire GitHub events for consumption
|
||
by a Knative Service.</p>
|
||
<h2 id="before-you-begin">Before you begin</h2>
|
||
<ol>
|
||
<li>Set up <a href="../../../serving">Knative Serving</a>.</li>
|
||
<li>Ensure Knative Serving is <a href="../../../serving/using-a-custom-domain">configured with a domain
|
||
name</a>
|
||
that allows GitHub to call into the cluster.</li>
|
||
<li>If you&rsquo;re using GKE, you&rsquo;ll also want to <a href="../../../serving/gke-assigning-static-ip-address">assign a static IP address</a>.</li>
|
||
<li>Set up <a href="../../../eventing">Knative Eventing</a> with the GitHub source.</li>
|
||
</ol>
|
||
<h3 id="create-a-knative-service">Create a Knative Service</h3>
|
||
<p>To verify the GitHub source is working, create a simple Knative
|
||
Service that dumps incoming messages to its log. The <code>service.yaml</code> file
|
||
defines this basic Service.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serving.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">github-message-dumper</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">containers</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">image</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div><p>Enter the following command to create the service from <code>service.yaml</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default apply --filename service.yaml
|
||
</code></pre></div><h3 id="create-github-tokens">Create GitHub Tokens</h3>
|
||
<p>Create a <a href="https://github.com/settings/tokens">personal access token</a>
|
||
for GitHub that the GitHub source can use to register webhooks with
|
||
the GitHub API. Also decide on a secret token that your code will use
|
||
to authenticate the incoming webhooks from GitHub (<em>secretToken</em>).</p>
|
||
<p>The token can be named anything you find convenient. The Source
|
||
requires <code>repo:public_repo</code> and <code>admin:repo_hook</code>, to let it fire
|
||
events from your public repositories and to create webhooks for those
|
||
repositories. Copy and save this token; GitHub will force you to
|
||
generate it again if misplaced.</p>
|
||
<p>Here&rsquo;s an example for a token named &ldquo;GitHubSource Sample&rdquo; with the
|
||
recommended scopes:</p>
|
||
<p><img src="personal_access_token.png" alt="GitHub UI" title="GitHub personal access token screenshot"></p>
|
||
<p>Update <code>githubsecret.yaml</code> with those values. If your generated access
|
||
token is <code>'personal_access_token_value'</code> and you choose your <em>secretToken</em>
|
||
as <code>'asdfasfdsaf'</code>, you&rsquo;d modify <code>githubsecret.yaml</code> like so:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Secret</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">githubsecret</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">type</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Opaque</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">stringData</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">accessToken</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">personal_access_token_value</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">secretToken</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">asdfasfdsaf</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div><p>Hint: you can makeup a random <em>secretToken</em> with:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">head -c <span style="color:#0000cf;font-weight:bold">8</span> /dev/urandom <span style="color:#000;font-weight:bold">|</span> base64
|
||
</code></pre></div><p>Then, apply the githubsecret using <code>kubectl</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default apply --filename githubsecret.yaml
|
||
</code></pre></div><h3 id="create-event-source-for-github-events">Create Event Source for GitHub Events</h3>
|
||
<p>In order to receive GitHub events, you have to create a concrete Event
|
||
Source for a specific namespace. Be sure to replace the
|
||
<code>ownerAndRepository</code> value with a valid GitHub public repository owned
|
||
by your GitHub user.</p>
|
||
<p>If using GitHub enterprise you will need to add an additional githubAPIURL
|
||
field to the spec specifying your GitHub enterprise API endpoint, see
|
||
<a href="../../index.html#githubsource">here</a></p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sources.knative.dev/v1alpha1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">GitHubSource</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">githubsourcesample</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">eventTypes</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#000">pull_request</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ownerAndRepository</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">&lt;YOUR USER&gt;/&lt;YOUR REPO&gt;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">accessToken</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">secretKeyRef</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">githubsecret</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">key</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">accessToken</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">secretToken</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">secretKeyRef</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">githubsecret</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">key</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">secretToken</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">sink</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ref</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serving.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">github-message-dumper</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div><p>Then, apply that yaml using <code>kubectl</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default apply --filename github-source.yaml
|
||
</code></pre></div><h3 id="verify">Verify</h3>
|
||
<p>Verify the GitHub webhook was created by looking at the list of
|
||
webhooks under the Settings tab in your GitHub repository. A hook
|
||
should be listed that points to your Knative cluster with a green
|
||
check mark to the left of the hook URL, as shown below.</p>
|
||
<p><img src="webhook_created.png" alt="GitHub Webhook" title="GitHub webhook screenshot"></p>
|
||
<h3 id="create-events">Create Events</h3>
|
||
<p>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.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default get pods
|
||
kubectl --namespace default logs github-event-display-XXXX user-container
|
||
</code></pre></div><p>You should log lines similar to:</p>
|
||
<pre><code>2018/11/08 18:25:34 Message Dumper received a message: POST / HTTP/1.1
|
||
Host: github-event-display.knative-demo.svc.cluster.local
|
||
Accept-Encoding: gzip
|
||
Ce-Cloudeventsversion: 0.1
|
||
Ce-Eventid: a8d4cf20-e383-11e8-8069-46e3c8ad2b4d
|
||
Ce-Eventtime: 2018-11-08T18:25:32.819548012Z
|
||
Ce-Eventtype: dev.knative.source.github.pull_request
|
||
Ce-Source: https://github.com/someuser/somerepo/pull/1
|
||
Content-Length: 21060
|
||
Content-Type: application/json
|
||
User-Agent: Go-http-client/1.1
|
||
X-B3-Parentspanid: b2e514c3dbe94c03
|
||
X-B3-Sampled: 1
|
||
X-B3-Spanid: c85e346d89c8be4e
|
||
X-B3-Traceid: abf6292d458fb8e7
|
||
X-Envoy-Expected-Rq-Timeout-Ms: 60000
|
||
X-Envoy-Internal: true
|
||
X-Forwarded-For: 127.0.0.1, 127.0.0.1
|
||
X-Forwarded-Proto: http
|
||
X-Request-Id: 8a2201af-5075-9447-b593-ec3a243aff52
|
||
|
||
{&quot;action&quot;:&quot;opened&quot;,&quot;number&quot;:1,&quot;pull_request&quot;: ...}
|
||
</code></pre><h3 id="cleanup">Cleanup</h3>
|
||
<p>You can remove the Github webhook by deleting the Github source:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default delete --filename github-source.yaml
|
||
</code></pre></div><p>Similarly, you can remove the Service and Secret via:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default delete --filename service.yaml
|
||
kubectl --namespace default delete --filename githubsecret.yaml
|
||
|
||
</code></pre></div>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: GitLab source</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/gitlab-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/gitlab-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>GitLab Source example shows how to wire GitLab events for consumption by a
|
||
Knative Service.</p>
|
||
<h2 id="gitlab-source-deployment">Gitlab source deployment</h2>
|
||
<h3 id="prerequisites">Prerequisites</h3>
|
||
<p>You will need:</p>
|
||
<ol>
|
||
<li>An internet-accessible Kubernetes cluster with Knative Serving installed.
|
||
Follow the <a href="../../../install/index.html">installation instructions</a> if you
|
||
need to create one.</li>
|
||
<li>Ensure Knative Serving is
|
||
<a href="../../../serving/using-a-custom-domain">configured with a domain name</a>
|
||
that allows GitLab to call into the cluster.</li>
|
||
<li>If you&rsquo;re using GKE, you&rsquo;ll also want to
|
||
<a href="../../../serving/gke-assigning-static-ip-address">assign a static IP address</a>.</li>
|
||
<li>Install <a href="../../../eventing">Knative Eventing</a>.</li>
|
||
</ol>
|
||
<h3 id="install-gitlab-event-source">Install GitLab Event Source</h3>
|
||
<p>GitLab Event source lives in the <a href="https://github.com/knative/eventing-contrib">knative/eventing-contrib</a>. Head to the releases page, find the latest release with <code>gitlab.yaml</code>
|
||
artifact and replace the <code>&lt;RELEASE&gt;</code> with version tag:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl apply -f https://github.com/knative/eventing-contrib/releases/download/&lt;RELEASE&gt;/gitlab.yaml
|
||
</code></pre></div><p>Check that the manager is running:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl -n knative-sources get pods --selector control-plane<span style="color:#ce5c00;font-weight:bold">=</span>gitlab-controller-manager
|
||
</code></pre></div><p>With the controller running you can now move on to a user persona and setup a
|
||
GitLab webhook as well as a function that will consume GitLab events.</p>
|
||
<h2 id="using-the-gitlab-event-source">Using the GitLab Event Source</h2>
|
||
<p>You are now ready to use the Event Source and trigger functions based on GitLab
|
||
projects events.</p>
|
||
<p>We will:</p>
|
||
<ul>
|
||
<li>Create a Knative service which will receive the events. To keep things simple
|
||
this service will simply dump the events to <code>stdout</code>, this is the so-called:
|
||
<em>event_display</em></li>
|
||
<li>Create a GitLab access token and a random secret token used to secure the
|
||
webhooks</li>
|
||
<li>Create the event source by posting a GitLab source object manifest to
|
||
Kubernetes</li>
|
||
</ul>
|
||
<h3 id="create-a-knative-service">Create a Knative Service</h3>
|
||
<p>The <code>event-display.yaml</code> file shown below defines the basic service which will
|
||
receive events from the GitLab source.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serving.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gitlab-event-display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">containers</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">image</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div><p>Create the service:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl -n default apply -f event-display.yaml
|
||
</code></pre></div><h3 id="create-gitlab-tokens">Create GitLab Tokens</h3>
|
||
<ol>
|
||
<li>
|
||
<p>Create a
|
||
<a href="https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html">personal access token</a>
|
||
which the GitLab source will use to register webhooks with the GitLab API.
|
||
The token must have an &ldquo;api&rdquo; access scope in order to create repository
|
||
webhooks. Also decide on a secret token that your source will use to
|
||
authenticate the incoming webhooks from GitLab.</p>
|
||
</li>
|
||
<li>
|
||
<p>Update a secret values in <code>secret.yaml</code> defined below:</p>
|
||
<p><code>accessToken</code> is the personal access token created in step 1 and
|
||
<code>secretToken</code> is any token of your choosing.</p>
|
||
<p>Hint: you can generate a random <em>secretToken</em> with:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">head -c <span style="color:#0000cf;font-weight:bold">8</span> /dev/urandom <span style="color:#000;font-weight:bold">|</span> base64
|
||
</code></pre></div><p><code>secret.yaml</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Secret</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gitlabsecret</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">type</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Opaque</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">stringData</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">accessToken</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">&lt;personal_access_token_value&gt;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">secretToken</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">&lt;random_string&gt;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div></li>
|
||
<li>
|
||
<p>Create the secret using <code>kubectl</code>.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl -n default apply -f secret.yaml
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="create-event-source-for-gitlab-events">Create Event Source for GitLab Events</h3>
|
||
<ol>
|
||
<li>
|
||
<p>In order to receive GitLab events, you have to create a concrete Event Source
|
||
for a specific namespace. Replace the <code>projectUrl</code> value in the
|
||
<code>gitlabsource.yaml</code> file with your GitLab project URL, for example
|
||
<code>https://gitlab.com/knative-examples/functions</code>.</p>
|
||
<p><code>gitlabsource.yaml</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sources.knative.dev/v1alpha1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">GitLabSource</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gitlabsource-sample</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">eventTypes</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#000">push_events</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#000">issues_events</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">projectUrl</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">&lt;project url&gt;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">accessToken</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">secretKeyRef</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gitlabsecret</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">key</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">accessToken</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">secretToken</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">secretKeyRef</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gitlabsecret</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">key</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">secretToken</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">sink</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ref</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serving.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gitlab-event-display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div></li>
|
||
<li>
|
||
<p>Apply the yaml file using <code>kubectl</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl -n default apply -f gitlabsource.yaml
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="verify">Verify</h3>
|
||
<p>Verify that GitLab webhook was created by looking at the list of webhooks under
|
||
<strong>Settings &raquo; Integrations</strong> in your GitLab project. A hook should be listed
|
||
that points to your Knative cluster.</p>
|
||
<p>Create a push event and check the logs of the Pod backing the
|
||
<code>gitlab-event-display</code> knative service. You will see the event:</p>
|
||
<pre><code>☁️ cloudevents.Event
|
||
Validation: valid
|
||
Context Attributes,
|
||
specversion: 0.3
|
||
type: dev.knative.sources.gitlabsource.Push Hook
|
||
source: https://gitlab.com/&lt;user&gt;/&lt;project&gt;
|
||
id: f83c080f-c2af-48ff-8d8b-fd5b21c5938e
|
||
time: 2020-03-12T11:08:41.414572482Z
|
||
datacontenttype: application/json
|
||
Data,
|
||
{
|
||
&lt;Event payload&gt;
|
||
}
|
||
</code></pre><h3 id="cleanup">Cleanup</h3>
|
||
<p>You can remove the GitLab webhook by deleting the GitLab source:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default delete --filename gitlabsource.yaml
|
||
</code></pre></div><p>Similarly, you can remove the Service and Secret via:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default delete --filename event-display.yaml
|
||
kubectl --namespace default delete --filename secret.yaml
|
||
|
||
</code></pre></div>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Binding running services to an IoT core</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/iot-core/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/iot-core/</guid>
|
||
<description>
|
||
|
||
|
||
<p>This sample shows how to bind a running service to an
|
||
<a href="https://cloud.google.com/iot-core/">IoT core</a> using
|
||
<a href="https://cloud.google.com/pubsub/">GCP PubSub</a> as the event source. With minor
|
||
modifications, it can be used to bind a running service to anything that sends
|
||
events via GCP PubSub.</p>
|
||
<pre><code>Note: All commands are given relative to the root of this repository.
|
||
</code></pre><h2 id="deployment-steps">Deployment Steps</h2>
|
||
<h3 id="environment-variables">Environment Variables</h3>
|
||
<p>To make the following commands easier, we are going to set the various variables
|
||
here and use them later.</p>
|
||
<h4 id="variables-you-must-change">Variables you must Change</h4>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#204a87">export</span> <span style="color:#000">IOTCORE_PROJECT</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;s9-demo&#34;</span>
|
||
</code></pre></div><h4 id="variables-you-may-change">Variables you may Change</h4>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#204a87">export</span> <span style="color:#000">IOTCORE_REGISTRY</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;iot-demo&#34;</span>
|
||
<span style="color:#204a87">export</span> <span style="color:#000">IOTCORE_DEVICE</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;iot-demo-client&#34;</span>
|
||
<span style="color:#204a87">export</span> <span style="color:#000">IOTCORE_REGION</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;us-central1&#34;</span>
|
||
<span style="color:#204a87">export</span> <span style="color:#000">IOTCORE_TOPIC_DATA</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;iot-demo-pubsub-topic&#34;</span>
|
||
<span style="color:#204a87">export</span> <span style="color:#000">IOTCORE_TOPIC_DEVICE</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#4e9a06">&#34;iot-demo-device-pubsub-topic&#34;</span>
|
||
</code></pre></div><h3 id="prerequisites">Prerequisites</h3>
|
||
<h4 id="kubernetes">Kubernetes</h4>
|
||
<ol>
|
||
<li>Have a running Kubernetes cluster with <code>kubectl</code> pointing at it.</li>
|
||
</ol>
|
||
<h4 id="gcp">GCP</h4>
|
||
<ol>
|
||
<li>
|
||
<p>Create a
|
||
<a href="https://cloud.google.com/resource-manager/docs/creating-managing-projects">Google Cloud Project</a>.</p>
|
||
</li>
|
||
<li>
|
||
<p>Have <a href="https://cloud.google.com/sdk/gcloud/">gcloud</a> installed and pointing
|
||
at that project.</p>
|
||
</li>
|
||
<li>
|
||
<p>Enable the <code>Cloud Pub/Sub API</code> on that project.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">gcloud services <span style="color:#204a87">enable</span> pubsub.googleapis.com
|
||
</code></pre></div></li>
|
||
<li>
|
||
<p>Create the two GCP PubSub <code>topic</code>s.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">gcloud pubsub topics create <span style="color:#000">$IOTCORE_TOPIC_DATA</span>
|
||
gcloud pubsub topics create <span style="color:#000">$IOTCORE_TOPIC_DEVICE</span>
|
||
</code></pre></div></li>
|
||
<li>
|
||
<p>Setup <a href="../../../eventing">Knative Eventing</a>.</p>
|
||
</li>
|
||
</ol>
|
||
<h4 id="gcp-pubsub-source">GCP PubSub Source</h4>
|
||
<ol>
|
||
<li>
|
||
<p>Create a GCP
|
||
<a href="https://console.cloud.google.com/iam-admin/serviceaccounts/project">Service Account</a>.</p>
|
||
<ol>
|
||
<li>
|
||
<p>Determine the Service Account to use, or create a new one.</p>
|
||
</li>
|
||
<li>
|
||
<p>Give that Service Account the &lsquo;Pub/Sub Editor&rsquo; role on your GCP project.</p>
|
||
</li>
|
||
<li>
|
||
<p>Download a new JSON private key for that Service Account.</p>
|
||
</li>
|
||
<li>
|
||
<p>Create two secrets with the downloaded key (one for the Source, one for
|
||
the Receive Adapter):</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace knative-sources create secret generic gcppubsub-source-key --from-file<span style="color:#ce5c00;font-weight:bold">=</span>key.json<span style="color:#ce5c00;font-weight:bold">=</span>PATH_TO_KEY_FILE.json
|
||
kubectl --namespace default create secret generic google-cloud-key --from-file<span style="color:#ce5c00;font-weight:bold">=</span>key.json<span style="color:#ce5c00;font-weight:bold">=</span>PATH_TO_KEY_FILE.json
|
||
</code></pre></div></li>
|
||
</ol>
|
||
</li>
|
||
<li>
|
||
<p>Deploy the <code>GcpPubSubSource</code> controller as part of eventing-source&rsquo;s
|
||
controller.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl apply --filename https://github.com/knative/eventing-contrib/releases/download/v0.8.2/gcppubsub.yaml
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="deploying">Deploying</h3>
|
||
<h4 id="broker">Broker</h4>
|
||
<ol>
|
||
<li>
|
||
<p>Install the default <code>Broker</code>.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create -f - <span style="color:#4e9a06">&lt;&lt;EOF
|
||
</span><span style="color:#4e9a06">apiVersion: eventing.knative.dev/v1
|
||
</span><span style="color:#4e9a06">kind: Broker
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: default
|
||
</span><span style="color:#4e9a06">EOF</span>
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h4 id="gcp-pubsub-source-1">GCP PubSub Source</h4>
|
||
<ol>
|
||
<li>
|
||
<p>Deploy <code>gcp-pubsub-source.yaml</code>.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">sed -e <span style="color:#4e9a06">&#34;s/PROJECT_ID/</span><span style="color:#000">$IOTCORE_PROJECT</span><span style="color:#4e9a06">/&#34;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -e <span style="color:#4e9a06">&#34;s/TOPIC_NAME/</span><span style="color:#000">$IOTCORE_TOPIC_DATA</span><span style="color:#4e9a06">/&#34;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> docs/eventing/samples/iot-core/gcp-pubsub-source.yaml <span style="color:#000;font-weight:bold">|</span>
|
||
kubectl apply --filename -
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h4 id="trigger">Trigger</h4>
|
||
<p>Even though the <code>Source</code> isn&rsquo;t completely ready yet, we can setup the <code>Trigger</code>
|
||
for all events coming out of it.</p>
|
||
<ol>
|
||
<li>
|
||
<p>Deploy <code>trigger.yaml</code>.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl apply --filename docs/eventing/samples/iot-core/trigger.yaml
|
||
</code></pre></div><ul>
|
||
<li>This uses a very simple Knative Service to see that events are flowing.
|
||
Feel free to replace it.</li>
|
||
</ul>
|
||
</li>
|
||
</ol>
|
||
<h4 id="iot-core">IoT Core</h4>
|
||
<p>We now have everything setup on the Knative side. We will now setup the IoT
|
||
Core.</p>
|
||
<ol>
|
||
<li>
|
||
<p>Create a device registry:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">gcloud iot registries create <span style="color:#000">$IOTCORE_REGISTRY</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --project<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$IOTCORE_PROJECT</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --region<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$IOTCORE_REGION</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --event-notification-config<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">topic</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$IOTCORE_TOPIC_DATA</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --state-pubsub-topic<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$IOTCORE_TOPIC_DEVICE</span>
|
||
</code></pre></div></li>
|
||
<li>
|
||
<p>Create the certificates.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">openssl req -x509 -nodes -newkey rsa:2048 <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -keyout device.key.pem <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -out device.crt.pem <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -days <span style="color:#0000cf;font-weight:bold">365</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -subj <span style="color:#4e9a06">&#34;/CN=unused&#34;</span>
|
||
curl https://pki.google.com/roots.pem &gt; ./root-ca.pem
|
||
</code></pre></div></li>
|
||
<li>
|
||
<p>Register a device using the generated certificates.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">gcloud iot devices create <span style="color:#000">$IOTCORE_DEVICE</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --project<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$IOTCORE_PROJECT</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --region<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$IOTCORE_REGION</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --registry<span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">$IOTCORE_REGISTRY</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> --public-key <span style="color:#000">path</span><span style="color:#ce5c00;font-weight:bold">=</span>./device.crt.pem,type<span style="color:#ce5c00;font-weight:bold">=</span>rsa-x509-pem
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="running">Running</h3>
|
||
<p>We now have everything installed and ready to go. We will generate events and
|
||
see them in the subscriber.</p>
|
||
<ol>
|
||
<li>
|
||
<p>Run the following program to generate events:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">go run github.com/knative/docs/docs/eventing/samples/iot-core/generator <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -project <span style="color:#000">$IOTCORE_PROJECT</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -region <span style="color:#000">$IOTCORE_REGION</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -registry <span style="color:#000">$IOTCORE_REGISTRY</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -device <span style="color:#000">$IOTCORE_DEVICE</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -ca <span style="color:#4e9a06">&#34;</span><span style="color:#000">$PWD</span><span style="color:#4e9a06">/root-ca.pem&#34;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -key <span style="color:#4e9a06">&#34;</span><span style="color:#000">$PWD</span><span style="color:#4e9a06">/device.key.pem&#34;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -src <span style="color:#4e9a06">&#34;iot-core demo&#34;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -events <span style="color:#0000cf;font-weight:bold">10</span>
|
||
</code></pre></div></li>
|
||
<li>
|
||
<p>Inspect the logs of the subscriber:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl logs --selector serving.knative.dev/service<span style="color:#ce5c00;font-weight:bold">=</span>event-display -c user-container
|
||
</code></pre></div><p>You should see something along the similar to:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell"><span style="color:#ce5c00;font-weight:bold">{</span><span style="color:#4e9a06">&#34;ID&#34;</span>:<span style="color:#4e9a06">&#34;481014114648052&#34;</span>,<span style="color:#4e9a06">&#34;Data&#34;</span>:<span style="color:#4e9a06">&#34;eyJzb3VyY2VfaWQiOiJpb3QtY29yZSBkZW1vIiwiZXZlbnRfaWQiOiJlaWQtMzI3MjJiMzItZWU5Mi00YzZlLWEzOTgtNDlmYjRkYWYyNGE1IiwiZXZlbnRfdHMiOjE1NTM3MTczOTYsIm1ldHJpYyI6MC4xMzY1MjI5OH0=&#34;</span>,<span style="color:#4e9a06">&#34;Attributes&#34;</span>:<span style="color:#ce5c00;font-weight:bold">{</span><span style="color:#4e9a06">&#34;deviceId&#34;</span>:<span style="color:#4e9a06">&#34;iot-demo-client&#34;</span>,<span style="color:#4e9a06">&#34;deviceNumId&#34;</span>:<span style="color:#4e9a06">&#34;2754785852315736&#34;</span>,<span style="color:#4e9a06">&#34;deviceRegistryId&#34;</span>:<span style="color:#4e9a06">&#34;iot-demo&#34;</span>,<span style="color:#4e9a06">&#34;deviceRegistryLocation&#34;</span>:<span style="color:#4e9a06">&#34;us-central1&#34;</span>,<span style="color:#4e9a06">&#34;projectId&#34;</span>:<span style="color:#4e9a06">&#34;s9-demo&#34;</span>,<span style="color:#4e9a06">&#34;subFolder&#34;</span>:<span style="color:#4e9a06">&#34;&#34;</span><span style="color:#ce5c00;font-weight:bold">}</span>,<span style="color:#4e9a06">&#34;PublishTime&#34;</span>:<span style="color:#4e9a06">&#34;2019-03-27T20:09:56.685Z&#34;</span><span style="color:#ce5c00;font-weight:bold">}</span>
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="cleanup">Cleanup</h3>
|
||
<p>To cleanup the knative resources:</p>
|
||
<ol>
|
||
<li>
|
||
<p>Remove the <code>GcpPubSubSource</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">sed -e <span style="color:#4e9a06">&#34;s/PROJECT_ID/</span><span style="color:#000">$IOTCORE_PROJECT</span><span style="color:#4e9a06">/&#34;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> -e <span style="color:#4e9a06">&#34;s/TOPIC_NAME/</span><span style="color:#000">$IOTCORE_TOPIC_DATA</span><span style="color:#4e9a06">/&#34;</span> <span style="color:#4e9a06">\
|
||
</span><span style="color:#4e9a06"></span> docs/eventing/samples/iot-core/gcp-pubsub-source.yaml <span style="color:#000;font-weight:bold">|</span>
|
||
kubectl delete --filename -
|
||
</code></pre></div></li>
|
||
<li>
|
||
<p>Remove the Trigger:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl delete --filename docs/eventing/samples/iot-core/trigger.yaml
|
||
</code></pre></div></li>
|
||
<li>
|
||
<p>Remove the <code>GcpPubSubSource</code> controller:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl delete --filename https://github.com/knative/eventing-contrib/releases/download/v0.8.2/gcppubsub.yaml
|
||
</code></pre></div></li>
|
||
</ol>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Kubernetes event using the API Server Source</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/kubernetes-event-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/kubernetes-event-source/</guid>
|
||
<description>
|
||
|
||
|
||
<p>This example shows how to wire
|
||
<a href="https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.18/#event-v1-core">Kubernetes cluster events</a>,
|
||
using the API Server Source, for consumption by a function that has been
|
||
implemented as a Knative Service.</p>
|
||
<h2 id="before-you-begin">Before you begin</h2>
|
||
<ol>
|
||
<li>
|
||
<p>You must have a Knative cluster running both the Serving and Eventing
|
||
components. To learn how to install the required components, see
|
||
<a href="../../../install">Installing Knative</a>.</p>
|
||
</li>
|
||
<li>
|
||
<p>You can follow the steps below to create new files, or you clone a copy from
|
||
the repo by running:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">git clone -b <span style="color:#4e9a06">&#34;release-0.13&#34;</span> https://github.com/knative/docs knative-docs
|
||
<span style="color:#204a87">cd</span> knative-docs/docs/eventing/samples/kubernetes-event-source
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h2 id="deployment-steps">Deployment Steps</h2>
|
||
<h3 id="broker">Broker</h3>
|
||
<p>These instructions assume the namespace <code>default</code>, which you can change to your
|
||
preferred namespace. If you use a different namespace, you will need to modify
|
||
all the YAML files deployed in this sample to point at that namespace.</p>
|
||
<ol>
|
||
<li>
|
||
<p>Create the <code>default</code> Broker in your namespace:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl create -f - <span style="color:#4e9a06">&lt;&lt;EOF
|
||
</span><span style="color:#4e9a06">apiVersion: eventing.knative.dev/v1
|
||
</span><span style="color:#4e9a06">kind: Broker
|
||
</span><span style="color:#4e9a06">metadata:
|
||
</span><span style="color:#4e9a06"> name: default
|
||
</span><span style="color:#4e9a06">EOF</span>
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="service-account">Service Account</h3>
|
||
<ol>
|
||
<li>
|
||
<p>Create a Service Account that the <code>ApiServerSource</code> runs as. The
|
||
<code>ApiServerSource</code> watches for Kubernetes events and forwards them to the
|
||
Knative Eventing Broker. Create a file named <code>serviceaccount.yaml</code> and copy
|
||
the code block below into it.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ServiceAccount</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">events-sa</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">namespace</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">default</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000">---</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">rbac.authorization.k8s.io/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ClusterRole</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">event-watcher</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">rules</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">apiGroups</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#4e9a06">&#34;&#34;</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">resources</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#000">events</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">verbs</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#000">get</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#000">list</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#000">watch</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000">---</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">rbac.authorization.k8s.io/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ClusterRoleBinding</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">k8s-ra-event-watcher</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">roleRef</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">apiGroup</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">rbac.authorization.k8s.io</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ClusterRole</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">event-watcher</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">subjects</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ServiceAccount</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">events-sa</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">namespace</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">default</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div><p>If you want to re-use an existing Service Account with the appropriate
|
||
permissions, you need to modify the <code>serviceaccount.yaml</code>.</p>
|
||
</li>
|
||
<li>
|
||
<p>Enter the following command to create the service account from
|
||
<code>serviceaccount.yaml</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl apply --filename serviceaccount.yaml
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="create-event-source-for-kubernetes-events">Create Event Source for Kubernetes Events</h3>
|
||
<ol>
|
||
<li>
|
||
<p>In order to receive events, you have to create a concrete Event Source for a
|
||
specific namespace. Create a file named <code>k8s-events.yaml</code> and copy the code
|
||
block below into it.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">sources.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">ApiServerSource</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">testevents</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">namespace</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">default</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">serviceAccountName</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">events-sa</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">mode</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Resource</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">resources</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Event</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">sink</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ref</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">eventing.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Broker</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">default</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div><p>If you want to consume events from a different namespace or use a different
|
||
<code>Service Account</code>, you need to modify <code>k8s-events.yaml</code> accordingly.</p>
|
||
</li>
|
||
<li>
|
||
<p>Enter the following command to create the event source:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl apply --filename k8s-events.yaml
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="trigger">Trigger</h3>
|
||
<p>In order to check the <code>ApiServerSource</code> is fully working, we will create a
|
||
simple Knative Service that dumps incoming messages to its log and creates a
|
||
<code>Trigger</code> from the <code>Broker</code> to that Knative Service.</p>
|
||
<ol>
|
||
<li>
|
||
<p>Create a file named <code>trigger.yaml</code> and copy the code block below into it.</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-yaml" data-lang="yaml"><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">eventing.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Trigger</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">testevents-trigger</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">namespace</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">default</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">broker</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">default</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">subscriber</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">ref</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serving.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">event-display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#000">---</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#8f5902;font-style:italic"># This is a very simple Knative Service that writes the input request to its log.</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">apiVersion</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">serving.knative.dev/v1</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">kind</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">Service</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">metadata</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">name</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">event-display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">namespace</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">default</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"></span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">template</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">spec</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">containers</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span>- <span style="color:#8f5902;font-style:italic"># This corresponds to</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#8f5902;font-style:italic"># https://github.com/knative/eventing-contrib/tree/master/cmd/event_display/main.go</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#204a87;font-weight:bold">image</span><span style="color:#000;font-weight:bold">:</span><span style="color:#f8f8f8;text-decoration:underline"> </span><span style="color:#000">gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display</span><span style="color:#f8f8f8;text-decoration:underline">
|
||
</span></code></pre></div></li>
|
||
<li>
|
||
<p>If the deployed <code>ApiServerSource</code> is pointing at a <code>Broker</code> other than
|
||
<code>default</code>, modify <code>trigger.yaml</code> by adding <code>spec.broker</code> with the <code>Broker</code>&rsquo;s
|
||
name.</p>
|
||
</li>
|
||
<li>
|
||
<p>Deploy <code>trigger.yaml</code>:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl apply --filename trigger.yaml
|
||
</code></pre></div></li>
|
||
</ol>
|
||
<h3 id="create-events">Create Events</h3>
|
||
<p>Create events by launching a pod in the default namespace. Create a <code>busybox</code>
|
||
container and immediately delete it:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl run busybox --image<span style="color:#ce5c00;font-weight:bold">=</span>busybox --restart<span style="color:#ce5c00;font-weight:bold">=</span>Never -- ls
|
||
kubectl delete pod busybox
|
||
</code></pre></div><h3 id="verify">Verify</h3>
|
||
<p>We will verify that the Kubernetes events were sent into the Knative eventing
|
||
system by looking at our message dumper function logs. If you deployed the
|
||
<a href="#trigger">Trigger</a>, continue using this section. If not, you will need to look
|
||
downstream yourself:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl get pods
|
||
kubectl logs -l serving.knative.dev/service<span style="color:#ce5c00;font-weight:bold">=</span>event-display -c user-container
|
||
</code></pre></div><p>You should see log lines similar to:</p>
|
||
<pre><code>☁️ cloudevents.Event
|
||
Validation: valid
|
||
Context Attributes,
|
||
specversion: 1.0
|
||
type: dev.knative.apiserver.resource.update
|
||
source: https://10.96.0.1:443
|
||
subject: /apis/v1/namespaces/default/events/testevents.15dd3050eb1e6f50
|
||
id: e0447eb7-36b5-443b-9d37-faf4fe5c62f0
|
||
time: 2020-07-28T16:35:14.172979816Z
|
||
datacontenttype: application/json
|
||
Extensions,
|
||
kind: Event
|
||
knativearrivaltime: 2020-07-28T16:35:14.173381505Z
|
||
knativehistory: default-kne-trigger-kn-channel.default.svc.cluster.local
|
||
name: busybox.1625f7cfa4cd12f8
|
||
namespace: default
|
||
Data,
|
||
{
|
||
&quot;apiVersion&quot;: &quot;v1&quot;,
|
||
&quot;count&quot;: 1,
|
||
&quot;eventTime&quot;: null,
|
||
&quot;firstTimestamp&quot;: &quot;2020-07-28T16:35:14Z&quot;,
|
||
&quot;involvedObject&quot;: {
|
||
&quot;apiVersion&quot;: &quot;v1&quot;,
|
||
&quot;fieldPath&quot;: &quot;spec.containers{busybox}&quot;,
|
||
&quot;kind&quot;: &quot;Pod&quot;,
|
||
&quot;name&quot;: &quot;busybox&quot;,
|
||
&quot;namespace&quot;: &quot;default&quot;,
|
||
&quot;resourceVersion&quot;: &quot;28987493&quot;,
|
||
&quot;uid&quot;: &quot;1efb342a-737b-11e9-a6c5-42010a8a00ed&quot;
|
||
},
|
||
&quot;kind&quot;: &quot;Event&quot;,
|
||
&quot;lastTimestamp&quot;: &quot;2020-07-28T16:35:14Z&quot;,
|
||
&quot;message&quot;: &quot;Started container&quot;,
|
||
&quot;metadata&quot;: {
|
||
&quot;creationTimestamp&quot;: &quot;2020-07-28T16:35:14Z&quot;,
|
||
&quot;name&quot;: &quot;busybox.1625f7cfa4cd12f8&quot;,
|
||
&quot;namespace&quot;: &quot;default&quot;,
|
||
&quot;resourceVersion&quot;: &quot;506088&quot;,
|
||
&quot;selfLink&quot;: &quot;/api/v1/namespaces/default/events/busybox.1625f7cfa4cd12f8&quot;,
|
||
&quot;uid&quot;: &quot;7f841049-7979-48db-9cbc-93ed2346a1b5&quot;,
|
||
},
|
||
&quot;reason&quot;: &quot;Started&quot;,
|
||
&quot;reportingComponent&quot;: &quot;&quot;,
|
||
&quot;reportingInstance&quot;: &quot;&quot;,
|
||
&quot;source&quot;: {
|
||
&quot;component&quot;: &quot;kubelet&quot;,
|
||
&quot;host&quot;: &quot;gke-knative-auto-cluster-default-pool-23c23c4f-xdj0&quot;
|
||
},
|
||
&quot;type&quot;: &quot;Normal&quot;
|
||
}
|
||
</code></pre><h3 id="cleanup">Cleanup</h3>
|
||
<p>You can remove the <code>ServiceAccount</code>, <code>ClusterRoles</code>, <code>ClusterRoleBinding</code>,
|
||
<code>ApiServerSource</code>, <code>Service</code> and <code>Trigger</code> using:</p>
|
||
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">kubectl --namespace default delete --filename serviceaccount.yaml
|
||
kubectl --namespace default delete --filename k8s-events.yaml
|
||
kubectl --namespace default delete --filename trigger.yaml
|
||
|
||
</code></pre></div>
|
||
</description>
|
||
</item>
|
||
|
||
<item>
|
||
<title>V0.21-Docs: Writing an Event Source</title>
|
||
<link>https://knative.dev/v0.21-docs/eventing/samples/writing-event-source/</link>
|
||
<pubDate>Mon, 01 Jan 0001 00:00:00 +0000</pubDate>
|
||
|
||
<guid>https://knative.dev/v0.21-docs/eventing/samples/writing-event-source/</guid>
|
||
<description>
|
||
|
||
|
||
<h2 id="introduction">Introduction</h2>
|
||
<p>This tutorial will walk you though writing a new event source for Knative
|
||
Eventing using a sample repository and explaining the key concepts used
|
||
throughout each component.</p>
|
||
<p>After completing the tutorial, you&rsquo;ll have a basic event source controller as
|
||
well as receive adapter, which events can be viewed through a basic
|
||
<code>event_display</code> Knative Service.</p>
|
||
<p>Just want to see the code? The reference project is
|
||
<a href="https://github.com/knative-sandbox/sample-source">https://github.com/knative-sandbox/sample-source</a>.</p>
|
||
<p><a href="../../sources/#knative-sources">Knative Sources</a> can be used as a reference.</p>
|
||
<h2 id="other-ways">Other ways</h2>
|
||
<p>With the approach in this tutorial, you will create a CRD and a controller for the event source which makes it reusable.</p>
|
||
<p>You can also write your own event source using a <a href="../../../eventing/sources/index.html#meta-sources">ContainerSource</a> which
|
||
is an easy way to turn any dispatcher container into an Event Source. Similarly, another option is using <a href="../../../eventing/sources/index.html#meta-sources">SinkBinding</a>
|
||
which provides a framework for injecting environment variables into any Kubernetes resource which has a <code>spec.template</code> that looks like a Pod (aka PodSpecable).</p>
|
||
<h2 id="target-audience">Target Audience</h2>
|
||
<p>The target audience is already familiar with Kubernetes and Go development and
|
||
wants to develop a new event source, importing their custom events via Knative
|
||
Eventing into the Knative system.</p>
|
||
<h2 id="before-you-begin">Before You Begin</h2>
|
||
<p>You&rsquo;ll need these tools installed:</p>
|
||
<ul>
|
||
<li>git</li>
|
||
<li>golang</li>
|
||
<li><a href="https://github.com/google/ko/">ko</a> (optional)</li>
|
||
<li><a href="https://kubernetes.io/docs/tasks/tools/install-kubectl/">kubectl</a> (optional)</li>
|
||
<li><a href="https://github.com/kubernetes/minikube">minikube</a> (optional)</li>
|
||
</ul>
|
||
<p>You&rsquo;re encouraged to clone the <a href="https://github.com/knative-sandbox/sample-source">sample source</a> and make changes there.</p>
|
||
<h2 id="steps">Steps</h2>
|
||
<ol>
|
||
<li><a href="./01-theory">Separation of Concerns</a></li>
|
||
<li><a href="./02-lifecycle-and-types">API Definition</a></li>
|
||
<li><a href="./03-controller">Controller</a></li>
|
||
<li><a href="./04-reconciler">Reconciler</a></li>
|
||
<li><a href="./05-receive-adapter">Receive Adapter</a></li>
|
||
<li><a href="./06-yaml">Example YAML</a></li>
|
||
<li><a href="./07-knative-sandbox">Moving the event source to the <code>knative-sandbox</code> organization</a></li>
|
||
</ol>
|
||
|
||
</description>
|
||
</item>
|
||
|
||
</channel>
|
||
</rss>
|