Questo contenuto non è disponibile nella lingua selezionata.
Chapter 3. Knative CLI plugins
The Knative (kn) CLI supports the use of plugins, which enable you to extend the functionality of your kn installation by adding custom commands and other shared commands that are not part of the core distribution. Knative (kn) CLI plugins are used in the same way as the main kn functionality.
Currently, Red Hat supports the kn-source-kafka plugin and the kn-event plugin.
3.1. Building events by using the kn-event plugin Copia collegamentoCollegamento copiato negli appunti!
You can use the builder-like interface of the kn event build command to build an event. You can then send that event at a later time or use it in another context.
Prerequisites
-
You have installed the Knative (
kn) CLI.
Procedure
Build an event:
kn event build --field <field-name>=<value> --type <type-name> --id <id> --output <format>
$ kn event build --field <field-name>=<value> --type <type-name> --id <id> --output <format>Copy to Clipboard Copied! Toggle word wrap Toggle overflow where:
-
The
--fieldflag adds data to the event as a field-value pair. You can use it multiple times. -
The
--typeflag enables you to specify a string that designates the type of the event. -
The
--idflag specifies the ID of the event. You can use the
jsonoryamlarguments with the--outputflag to change the output format of the event.All of these flags are optional.
Building a simple event
kn event build -o yaml
$ kn event build -o yamlCopy to Clipboard Copied! Toggle word wrap Toggle overflow Resultant event in the YAML format
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Building a sample transaction event
Copy to Clipboard Copied! Toggle word wrap Toggle overflow Resultant event in the JSON format
Copy to Clipboard Copied! Toggle word wrap Toggle overflow
-
The
3.2. Sending events by using the kn-event plugin Copia collegamentoCollegamento copiato negli appunti!
You can use the kn event send command to send an event. The events can be sent either to publicly available addresses or to addressable resources inside a cluster, such as Kubernetes services, as well as Knative services, brokers, and channels. The command uses the same builder-like interface as the kn event build command.
Prerequisites
-
You have installed the Knative (
kn) CLI.
Procedure
Send an event:
Copy to Clipboard Copied! Toggle word wrap Toggle overflow where:
-
The
--fieldflag adds data to the event as a field-value pair. You can use it multiple times. -
The
--typeflag enables you to specify a string that designates the type of the event. -
The
--idflag specifies the ID of the event. -
The
--toflag specifies the destination of the event. The
--namespaceflag specifies the namespace. If omitted, the namespace is taken from the current context.All of these flags are optional, except for the destination specification.
-
The
You can use the following destination formats for the --to flag:
-
--to broker:<broker>: Specifies a broker -
--to channel:<channel>: Specifies a channel -
--to ksvc:<service>or--to <service>: Specifies a Knative service in the current namespace -
--to ksvc:<service>:<namespace>: Specifies a Knative service in another namespace -
--to svc:<service>:<namespace>: Specifies a Kubernetes service in another namespace -
--to special.eventing.dev/v1alpha1/channels:<channel>: SpecifiesGroupVersionResourceofv1alpha1channel -
--to https://example.receiver.uri: Specifies an HTTP URL
If you do not provide a prefix, the destination defaults to a Knative service in the current namespace.
Sending an event to a URL
Sending and event to an in-cluster resource