Skip to content

Commit 8bd0d65

Browse files
authored
Merge pull request #45033 from rh-max/srvls-change-emit-to-invoke
[SRVOCF-384] Change `kn func emit` to `kn func invoke`
2 parents 43df434 + eaccf5e commit 8bd0d65

9 files changed

+171
-130
lines changed

modules/serverless-functions-using-integrated-registry.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ $ kn func build -r $(oc get route -n openshift-image-registry)/my-namespace
3131
$ kn func deploy -r $(oc get route -n openshift-image-registry)/my-namespace
3232
----
3333
+
34-
You can verify that the function deployed successfully by emitting a test event to it.
34+
You can verify that the function deployed successfully by invoking it with a test event.

modules/serverless-kn-func-emit-reference.adoc

Lines changed: 0 additions & 96 deletions
This file was deleted.

modules/serverless-kn-func-emit.adoc

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 136 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * serverless/reference/kn-func-ref.adoc
4+
5+
:_content-type: REFERENCE
6+
[id="serverless-kn-func-invoke-reference_{context}"]
7+
= kn func invoke optional parameters
8+
9+
You can specify optional parameters for the request by using the following `kn func invoke` CLI command flags.
10+
11+
[options="header",cols="1,3"]
12+
|===
13+
| Flags | Description
14+
| `-t`, `--target` | Specifies the target instance of the invoked function, for example, `local` or `remote` or `https://staging.example.com/`. The default target is `local`.
15+
| `-f`, `--format` | Specifies the format of the message, for example, `cloudevent` or `http`.
16+
| `--id` | Specifies a unique string identifier for the request.
17+
| `-n`, `--namespace` | Specifies the namespace on the cluster.
18+
| `--source` | Specifies sender name for the request. This corresponds to the CloudEvent `source` attribute.
19+
| `--type` | Specifies the type of request, for example, `boson.fn`. This corresponds to the CloudEvent `type` attribute.
20+
| `--data` | Specifies content for the request. For CloudEvent requests, this is the CloudEvent `data` attribute.
21+
| `--file` | Specifies path to a local file containing data to be sent.
22+
| `--content-type` | Specifies the MIME content type for the request.
23+
| `-p`, `--path` | Specifies path to the project directory.
24+
| `-c`, `--confirm` | Enables prompting to interactively confirm all options.
25+
| `-v`, `--verbose` | Enables printing verbose output.
26+
| `-h`, `--help` | Prints information on usage of `kn func invoke`.
27+
|===
28+
29+
[id="serverless-kn-func-invoke-main-parameters_{context}"]
30+
== Main parameters
31+
32+
The following parameters define the main properties of the `kn func invoke` command:
33+
34+
Event target (`-t`, `--target`):: The target instance of the invoked function. Accepts the `local` value for a locally deployed function, the `remote` value for a remotely deployed function, or a URL for a function deployed to an arbitrary endpoint. If a target is not specified, it defaults to `local`.
35+
Event message format (`-f`, `--format`):: The message format for the event, such as `http` or `cloudevent`. This defaults to the format of the template that was used when creating the function.
36+
Event type (`--type`):: The type of event that is sent. You can find information about the `type` parameter that is set in the documentation for each event producer. For example, the API server source might set the `type` parameter of produced events as `dev.knative.apiserver.resource.update`.
37+
Event source (`--source`):: The unique event source that produced the event. This might be a URI for the event source, for example `https://10.96.0.1/`, or the name of the event source.
38+
Event ID (`--id`):: A random, unique ID that is created by the event producer.
39+
Event data (`--data`):: Allows you to specify a `data` value for the event sent by the `kn func invoke` command. For example, you can specify a `--data` value such as `"Hello World"` so that the event contains this data string. By default, no data is included in the events created by `kn func invoke`.
40+
+
41+
[NOTE]
42+
====
43+
Functions that have been deployed to a cluster can respond to events from an existing event source that provides values for properties such as `source` and `type`. These events often have a `data` value in JSON format, which captures the domain specific context of the event. By using the CLI flags noted in this document, developers can simulate those events for local testing.
44+
====
45+
+
46+
You can also send event data using the `--file` flag to provide a local file containing data for the event. In this case, specify the content type using `--content-type`.
47+
Data content type (`--content-type`):: If you are using the `--data` flag to add data for events, you can use the `--content-type` flag to specify what type of data is carried by the event. In the previous example, the data is plain text, so you might specify `kn func invoke --data "Hello world!" --content-type "text/plain"`.
48+
49+
[id="serverless-kn-func-invoke-example-commands_{context}"]
50+
== Example commands
51+
52+
This is the general invocation of the `kn func invoke` command:
53+
54+
[source,terminal]
55+
----
56+
$ kn func invoke --type <event_type> --source <event_source> --data <event_data> --content-type <content_type> --id <event_ID> --format <format> --namespace <namespace>
57+
----
58+
59+
For example, to send a "Hello world!" event, you can run:
60+
61+
[source,terminal]
62+
----
63+
$ kn func invoke --type ping --source example-ping --data "Hello world!" --content-type "text/plain" --id example-ID --format http --namespace my-ns
64+
----
65+
66+
[id="serverless-kn-func-invoke-example-commands-specifying-file-with-data_{context}"]
67+
=== Specifying the file with data
68+
69+
To specify the file on disk that contains the event data, use the `--file` and `--content-type` flags:
70+
71+
[source,terminal]
72+
----
73+
$ kn func invoke --file <path> --content-type <content-type>
74+
----
75+
76+
For example, to send JSON data stored in the `test.json` file, use this command:
77+
78+
[source,terminal]
79+
----
80+
$ kn func invoke --file ./test.json --content-type application/json
81+
----
82+
83+
[id="serverless-kn-func-invoke-example-commands-specifying-function-project_{context}"]
84+
=== Specifying the function project
85+
86+
You can specify a path to the function project by using the `--path` flag:
87+
88+
[source,terminal]
89+
----
90+
$ kn func invoke --path <path_to_function>
91+
----
92+
93+
For example, to use the function project located in the `./example/example-function` directory, use this command:
94+
95+
[source,terminal]
96+
----
97+
$ kn func invoke --path ./example/example-function
98+
----
99+
100+
[id="serverless-kn-func-invoke-example-commands-specifying-where-function-is-deployed_{context}"]
101+
=== Specifying where the target function is deployed
102+
103+
By default, `kn func invoke` targets the local deployment of the function:
104+
105+
[source,terminal]
106+
----
107+
$ kn func invoke
108+
----
109+
110+
To use a different deployment, use the `--target` flag:
111+
112+
[source,terminal]
113+
----
114+
$ kn func invoke --target <target>
115+
----
116+
117+
For example, to use the function deployed on the cluster, use the `--target remote` flag:
118+
119+
[source,terminal]
120+
----
121+
$ kn func invoke --target remote
122+
----
123+
124+
To use the function deployed at an arbitrary URL, use the `--target <URL>` flag:
125+
126+
[source,terminal]
127+
----
128+
$ kn func invoke --target "https://my-event-broker.example.com"
129+
----
130+
131+
You can explicitly target the local deployment. In this case, if the function is not running locally, the command fails:
132+
133+
[source,terminal]
134+
----
135+
$ kn func invoke --target local
136+
----
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * serverless/functions/serverless-functions-getting-started.adoc
4+
// * serverless/reference/kn-func-ref.adoc
5+
6+
:_content-type: REFERENCE
7+
[id="serverless-kn-func-invoke_{context}"]
8+
= Invoking a deployed function with a test event
9+
10+
You can use the `kn func invoke` CLI command to send a test request to invoke a function either locally or on your {product-title} cluster. This command can be used to test that a function is working and able to receive events correctly.
11+
12+
.Example command
13+
[source,terminal]
14+
----
15+
$ kn func invoke
16+
----
17+
18+
The `kn func invoke` command executes on the local directory by default, and assumes that this directory is a function project.

modules/serverless-nodejs-context-object-reference.adoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,12 @@ function handle(context) {
2121
}
2222
----
2323

24-
You can access the function by using the `kn func emit` command to invoke it:
24+
You can access the function by using the `kn func invoke` command:
2525

2626
.Example command
2727
[source,terminal]
2828
----
29-
$ kn func emit --sink 'http://example.function.com'
29+
$ kn func invoke --target 'http://example.function.com'
3030
----
3131

3232
.Example output
@@ -53,12 +53,12 @@ function handle(context) {
5353
}
5454
----
5555

56-
You can access the function by using the `curl` command to invoke it:
56+
You can access the function by using the `kn func invoke` command:
5757

5858
.Example command
5959
[source,terminal]
6060
----
61-
$ curl http://example.com?name=tiger
61+
$ kn func invoke --target 'http://example.com?name=tiger'
6262
----
6363

6464
.Example output
@@ -86,7 +86,7 @@ You can access the function by using the `curl` command to invoke it:
8686
.Example command
8787
[source,terminal]
8888
----
89-
$ kn func emit -d '{"Hello": "world"}'
89+
$ kn func invoke -d '{"Hello": "world"}'
9090
----
9191

9292
.Example output
@@ -108,12 +108,12 @@ function handle(context) {
108108
}
109109
----
110110

111-
You can access the function by using the `kn func emit` command to invoke it:
111+
You can access the function by using the `kn func invoke` command:
112112

113113
.Example command
114114
[source,terminal]
115115
----
116-
$ kn func emit --sink 'http://example.function.com'
116+
$ kn func invoke --target 'http://example.function.com'
117117
----
118118

119119
.Example output

modules/serverless-typescript-context-object-reference.adoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ export function handle(context: Context): string {
2727
}
2828
----
2929

30-
You can access the function by using the `kn func emit` command to invoke it:
30+
You can access the function by using the `kn func invoke` command:
3131

3232
.Example command
3333
[source,terminal]
3434
----
35-
$ kn func emit --sink 'http://example.function.com'
35+
$ kn func invoke --target 'http://example.function.com'
3636
----
3737

3838
.Example output
@@ -63,12 +63,12 @@ export function handle(context: Context): string {
6363
6464
----
6565

66-
You can access the function by using the `kn func emit` command to invoke it:
66+
You can access the function by using the `kn func invoke` command:
6767

6868
.Example command
6969
[source,terminal]
7070
----
71-
$ kn func emit --sink 'http://example.function.com' --data '{"name": "tiger"}'
71+
$ kn func invoke --target 'http://example.function.com' --data '{"name": "tiger"}'
7272
----
7373

7474
.Example output
@@ -97,12 +97,12 @@ export function handle(context: Context): string {
9797
}
9898
----
9999

100-
You can access the function by using the `kn func emit` command to invoke it:
100+
You can access the function by using the `kn func invoke` command:
101101

102102
.Example command
103103
[source,terminal]
104104
----
105-
$ kn func emit --sink 'http://example.function.com' --data '{"hello": "world"}'
105+
$ kn func invoke --target 'http://example.function.com' --data '{"hello": "world"}'
106106
----
107107

108108
.Example output

serverless/cli_tools/kn-func-ref.adoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,6 @@ include::modules/serverless-build-func-kn.adoc[leveloffset=+1]
1111
include::modules/serverless-deploy-func-kn.adoc[leveloffset=+1]
1212
include::modules/functions-list-kn.adoc[leveloffset=+1]
1313
include::modules/describe-function-kn.adoc[leveloffset=+1]
14-
include::modules/serverless-kn-func-emit.adoc[leveloffset=+1]
15-
include::modules/serverless-kn-func-emit-reference.adoc[leveloffset=+2]
14+
include::modules/serverless-kn-func-invoke.adoc[leveloffset=+1]
15+
include::modules/serverless-kn-func-invoke-reference.adoc[leveloffset=+2]
1616
include::modules/delete-function-kn.adoc[leveloffset=+1]

serverless/functions/serverless-functions-getting-started.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Before you can complete the following procedures, you must ensure that you have
1919
include::modules/serverless-create-func-kn.adoc[leveloffset=+1]
2020
include::modules/serverless-build-func-kn.adoc[leveloffset=+1]
2121
include::modules/serverless-deploy-func-kn.adoc[leveloffset=+1]
22-
include::modules/serverless-kn-func-emit.adoc[leveloffset=+1]
22+
include::modules/serverless-kn-func-invoke.adoc[leveloffset=+1]
2323
include::modules/serverless-functions-using-integrated-registry.adoc[leveloffset=+1]
2424

2525
ifdef::openshift-enterprise[]

0 commit comments

Comments
 (0)