mirror of
https://github.com/openshift/openshift-docs.git
synced 2026-02-05 12:46:18 +01:00
122 lines
3.0 KiB
Plaintext
122 lines
3.0 KiB
Plaintext
[id="apiserversource-kn_{context}"]
|
|
= Creating an API server source by using the Knative CLI
|
|
|
|
This section describes the steps required to create an API server source using `kn` commands.
|
|
|
|
.Prerequisites
|
|
|
|
* You must have {ServerlessProductName}, the Knative Serving and Eventing components, and the `kn` CLI installed.
|
|
|
|
.Procedure
|
|
|
|
. Create an API server source that uses a broker as a sink:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ kn source apiserver create <event_source_name> --sink broker:<broker_name> --resource "event:v1" --service-account <service_account_name> --mode Resource
|
|
----
|
|
|
|
. To check that the API server source is set up correctly, create a Knative service that dumps incoming messages to its log:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ kn service create <service_name> --image quay.io/openshift-knative/knative-eventing-sources-event-display:latest
|
|
----
|
|
|
|
. Create a trigger to filter events from the `default` broker to the service:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ kn trigger create <trigger_name> --sink ksvc:<service_name>
|
|
----
|
|
|
|
. Create events by launching a pod in the default namespace:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc create deployment hello-node --image quay.io/openshift-knative/knative-eventing-sources-event-display:latest
|
|
----
|
|
|
|
. Check that the controller is mapped correctly by inspecting the output generated by the following command:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ kn source apiserver describe <source_name>
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
Name: mysource
|
|
Namespace: default
|
|
Annotations: sources.knative.dev/creator=developer, sources.knative.dev/lastModifier=developer
|
|
Age: 3m
|
|
ServiceAccountName: events-sa
|
|
Mode: Resource
|
|
Sink:
|
|
Name: default
|
|
Namespace: default
|
|
Kind: Broker (eventing.knative.dev/v1)
|
|
Resources:
|
|
Kind: event (v1)
|
|
Controller: false
|
|
Conditions:
|
|
OK TYPE AGE REASON
|
|
++ Ready 3m
|
|
++ Deployed 3m
|
|
++ SinkProvided 3m
|
|
++ SufficientPermissions 3m
|
|
++ EventTypesProvided 3m
|
|
----
|
|
|
|
.Verification
|
|
|
|
You can verify that the Kubernetes events were sent to Knative by looking at the message dumper function logs.
|
|
|
|
. Get the pods:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc get pods
|
|
----
|
|
|
|
. View the message dumper function logs for the pods:
|
|
+
|
|
[source,terminal]
|
|
----
|
|
$ oc logs $(oc get pod -o name | grep event-display) -c user-container
|
|
----
|
|
+
|
|
.Example output
|
|
[source,terminal]
|
|
----
|
|
☁️ cloudevents.Event
|
|
Validation: valid
|
|
Context Attributes,
|
|
specversion: 1.0
|
|
type: dev.knative.apiserver.resource.update
|
|
datacontenttype: application/json
|
|
...
|
|
Data,
|
|
{
|
|
"apiVersion": "v1",
|
|
"involvedObject": {
|
|
"apiVersion": "v1",
|
|
"fieldPath": "spec.containers{hello-node}",
|
|
"kind": "Pod",
|
|
"name": "hello-node",
|
|
"namespace": "default",
|
|
.....
|
|
},
|
|
"kind": "Event",
|
|
"message": "Started container",
|
|
"metadata": {
|
|
"name": "hello-node.159d7608e3a3572c",
|
|
"namespace": "default",
|
|
....
|
|
},
|
|
"reason": "Started",
|
|
...
|
|
}
|
|
----
|