kn-plugin-event
is a plugin of Knative Client, for managing cloud events from
command line.
With this plugin, you can build and send the cloud events to publicly available addresses (URLs) or to Addressable (Kubernetes service, Knative service, broker, channels, etc) inside of Kubernetes cluster.
You could use build
subcommand to create an event with a help of convenient
builder-like interface. It may be helpful to send that even later or use it in
other context.
$ kn event build -o yaml
data: {}
datacontenttype: application/json
id: 81a402a2-9c29-4c27-b8ed-246a253c9e58
source: kn-event/v0.4.0
specversion: "1.0"
time: "2021-10-15T10:42:57.713226203Z"
type: dev.knative.cli.plugin.event.generic
$ kn event build \
--field operation.type=local-wire-transfer \
--field operation.amount=2345.40 \
--field operation.from=87656231 \
--field operation.to=2344121 \
--field automated=true \
--field signature='FGzCPLvYWdEgsdpb3qXkaVp7Da0=' \
--type org.example.bank.bar \
--id $(head -c 10 < /dev/urandom | base64 -w 0) \
--output json
{
"specversion": "1.0",
"id": "RjtL8UH66X+UJg==",
"source": "kn-event/v0.4.0",
"type": "org.example.bank.bar",
"datacontenttype": "application/json",
"time": "2021-10-15T10:43:23.113187943Z",
"data": {
"automated": true,
"operation": {
"amount": "2345.40",
"from": 87656231,
"to": 2344121,
"type": "local-wire-transfer"
},
"signature": "FGzCPLvYWdEgsdpb3qXkaVp7Da0="
}
}
To send an event, you should use the send
subcommand. The send
command uses
the same builder-like interface as the build
command. You can send an event to
the public address of your application or to a supported in-cluster resource by
using the --to
option.
To send an event to a public address, you should pass the address to the --to
option:
$ kn event send \
--field player.id=6354aa60-ddb1-452e-8c13-24893667de20 \
--field player.game=2345 \
--field points=456 \
--type org.example.gaming.foo \
--to http://ce-api.foo.example.org/
NOTE: All arguments, except
--to
are optional. Usekn event send --help
to see full usage information.
Sending events to the in-cluster resources is done with a companion Job
that is deployed on your cluster. This allows kn-event
to send your events to
resources that are not publicly accessible.
Send an event to a Knative service showcase
in current namespace:
$ kn event send \
--type org.example.kn.ping \
--id $(uuidgen) \
--field event.data=98765 \
--to showcase
To send the event to the broker named foo
in my-ns
namespace:
$ kn event send --to broker:foo:my-ns
NOTE: The
--to
option follows the Kn sink format. Usekn event send --help
to see full format description.
You can download a pre-built version of kn-plugin-event
from
our release page
. Choose the one that fits your platform.
When the download is ready, you should be ready to use kn-plugin-event
as a
standalone binary. Check the available commands with:
kn-event-<OS>-<ARCH> --help
If you'd like to use the plugin with kn
CLI, install the plugin by simply
copying the executable file under kn
plugins directory as:
$ mkdir -p ~/.config/kn/plugins
$ cp build/_output/bin/kn-event-<OS>-<ARCH> \
~/.config/kn/plugins/kn-event
Check if plugin is loaded
$ kn -h
Run it
$ kn event -h
If you'd like to build the plugin yourself, you will need to have
Golang installed on your machine. Check the go.mod
file
for current minimum version.
To build the plugin, just invoke the following script:
$ ./mage
Project will check, test and build binaries for various platforms. You'll get an
executable plugin binary named kn-event-<OS>-<ARCH>
in build/_output/bin
dir.
You could list all available build targets with:
$ ./mage -l
To update dependencies, please utilize the standard hack/update-deps.sh
script. It's also needed to run this script if you are doing any changes to Go
libraries. Read more about it at knative/hack
repository.