Skip to content

Commit 1ab5989

Browse files
authored
Merge pull request #31878 from abrennan89/SRVOCF-278
[srvls] [SRVOCF-264] Add tech preview functions docs
2 parents 794d2c0 + 0bfa183 commit 1ab5989

11 files changed

+253
-0
lines changed

_topic_map.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2931,6 +2931,16 @@ Topics:
29312931
# Knative Kafka
29322932
- Name: Using Apache Kafka with OpenShift Serverless
29332933
File: serverless-kafka
2934+
# Functions - uncomment at tech preview
2935+
#- Name: Functions
2936+
# Dir: functions
2937+
# Topics:
2938+
# - Name: About Functions
2939+
# File: serverless-functions-about
2940+
# - Name: Setting up Functions
2941+
# File: serverless-functions-setup
2942+
# - Name: Getting started with Functions
2943+
# File: serverless-functions-getting-started
29342944
# Networking
29352945
- Name: Networking
29362946
Dir: networking
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * serverless/serverless-functions-getting-started.adoc
4+
5+
[id="serverless-build-func-kn_{context}"]
6+
= Building functions
7+
8+
Before you can run a function, you must build the function project by using the `kn func build` command. The build command reads the `func.yaml` file from the function project directory to determine the image name and registry.
9+
10+
.Example `func.yaml`
11+
[source,yaml]
12+
----
13+
name: fn.example.io
14+
namespace: default
15+
runtime: node
16+
image: <image_from_registry>
17+
imageDigest: ""
18+
trigger: http
19+
builder: default
20+
builderMap:
21+
default: quay.io/boson/faas-nodejs-builder
22+
envVars: {}
23+
----
24+
25+
If the image name and registry are not set in the `func.yaml` file, you must either specify the registry flag, `-r` when using the `kn func build` command, or you are prompted to provide a registry value in the terminal when building a function. An image name is then derived from the registry value that you have provided.
26+
27+
.Example command using the `-r` registry flag
28+
[source,terminal]
29+
----
30+
$ kn func build [-i <image> -r <registry> -p <path>]
31+
----
32+
33+
.Example output
34+
[source,terminal]
35+
----
36+
Building function image
37+
Function image has been built, image: quay.io/username/fn.example.io:latest
38+
----
39+
40+
This command creates an OCI container image that can be run locally on your computer, or on a Kubernetes cluster.
41+
42+
.Example using the registy prompt
43+
[source,terminal]
44+
----
45+
$ kn func build
46+
A registry for function images is required (e.g. 'quay.io/boson').
47+
48+
Registry for function images: quay.io/username
49+
Building function image
50+
Function image has been built, image: quay.io/username/fn.example.io:latest
51+
----
52+
53+
The values for image and registry are persisted to the `func.yaml` file, so that subsequent invocations do not require the user to specify these again.
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * serverless/serverless-functions-getting-started.adoc
4+
5+
[id="serverless-create-func-kn_{context}"]
6+
= Creating functions
7+
8+
You can create a basic serverless function using the `kn` CLI.
9+
10+
You can specify the runtime, trigger, image, and namespace as flags on the command line, or use the `-c` flag to start the interactive experience using the CLI prompt.
11+
12+
The values provided for image and registry are persisted to the `func.yaml` file, so that subsequent invocations do not require the user to specify these again.
13+
14+
.Example `func.yaml`
15+
[source,yaml]
16+
----
17+
name: fn.example.io
18+
namespace: default
19+
runtime: node
20+
image: <image_from_registry>
21+
imageDigest: ""
22+
trigger: http
23+
builder: default
24+
builderMap:
25+
default: quay.io/boson/faas-nodejs-builder
26+
envVars: {}
27+
----
28+
29+
.Procedure
30+
31+
* Create a {FunctionsProductShortName} project:
32+
+
33+
[source,terminal]
34+
----
35+
$ kn func create <path> -r <registry> -l <runtime> -t <trigger> -i <image> -n <namespace>
36+
----
37+
+
38+
If the image is unspecified, you are prompted for a registry name. The image name is derived from this registry and the function name.
39+
+
40+
.Example command
41+
[source,terminal]
42+
----
43+
$ kn func create functions/fn.example.io
44+
----
45+
+
46+
.Example output
47+
[source,terminal]
48+
----
49+
Project path: /home/user/functions/fn.example.io
50+
Function name: fn.example.io
51+
Runtime: node
52+
Trigger: http
53+
----
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * serverless/serverless-functions-getting-started.adoc
4+
5+
[id="serverless-deploy-func-kn_{context}"]
6+
= Deploying functions
7+
8+
You can deploy a function to your cluster as a Knative service by using the `kn func deploy` command.
9+
10+
If the targeted function is already deployed, it is updated with a new container image that is pushed to a container image registry, and the Knative service is updated.
11+
12+
.Prerequisites
13+
14+
* You must have already initialized the function that you want to deploy.
15+
16+
.Procedure
17+
18+
* Deploy a function:
19+
+
20+
[source,terminal]
21+
----
22+
$ kn func deploy [-n <namespace> -p <path> -i <image> -r <registry>]
23+
----
24+
+
25+
.Example output
26+
[source,terminal]
27+
----
28+
Function deployed at: http://func.example.com
29+
----
30+
** If no `namespace` is specified, the function is deployed in the current namespace.
31+
** The function is deployed from the current directory, unless a `path` is specified.
32+
** The Knative service name is derived from the project name, and cannot be changed using this command.

modules/serverless-document-attributes.adoc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
:ServerlessProductName: OpenShift Serverless
1111
:ServerlessProductShortName: Serverless
1212
:ServerlessOperatorName: OpenShift Serverless Operator
13+
:FunctionsProductName: OpenShift Serverless Functions
14+
:FunctionsProductShortName: Functions
1315
//
1416
// Documentation publishing attributes used in the master-docinfo.xml file
1517
// Note that the DocInfoProductName generates the URL for the product page.
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Module included in the following assemblies:
2+
//
3+
// * serverless/serverless-functions-setup.adoc
4+
5+
[id="serverless-functions-podman_{context}"]
6+
= Using podman
7+
8+
If you are using podman, you must run the following commands before getting started with {FunctionsProductName}:
9+
10+
. Start the podman service that listens on port `1234`:
11+
+
12+
[source,terminal]
13+
----
14+
$ podman system service --time=0 tcp:0.0.0.0:1234 & # let run in background or another terminal
15+
----
16+
17+
. Establish the environment variable that is used to build a function:
18+
+
19+
[source,terminal]
20+
----
21+
$ export DOCKER_HOST=tcp://127.0.0.1:1234
22+
----
23+
+
24+
[source,terminal]
25+
----
26+
$ func build -v
27+
----

serverless/functions/images

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../images

serverless/functions/modules

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
../modules
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
include::modules/serverless-document-attributes.adoc[]
2+
[id="serverless-functions-about"]
3+
= About {FunctionsProductShortName}
4+
:context: serverless-functions-about
5+
include::modules/common-attributes.adoc[]
6+
7+
toc::[]
8+
9+
:FeatureName: {FunctionsProductName}
10+
include::modules/technology-preview.adoc[leveloffset=+2]
11+
12+
{FunctionsProductName} enables developers to create and deploy stateless, event-driven functions as a Knative service on {product-title}.
13+
14+
The `kn func` CLI is provided as a plug-in for the Knative `kn` CLI. {FunctionsProductName} uses the link:https://buildpacks.io/[CNCF Buildpack API] to create container images. Once a container image has been created, you can use the `kn func` CLI to deploy the container image as a Knative service on the cluster.
15+
16+
[id="serverless-functions-about-runtimes"]
17+
== Supported runtimes
18+
19+
{FunctionsProductName} provides templates that can be used to create basic functions for the following runtimes:
20+
21+
// add xref links to docs once added
22+
* Node.js
23+
* Python
24+
* Golang
25+
* Quarkus
26+
//* SpringBoot - TBC
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
include::modules/serverless-document-attributes.adoc[]
2+
[id="serverless-functions-getting-started"]
3+
= Getting started with {FunctionsProductShortName}
4+
:context: serverless-functions-getting-started
5+
include::modules/common-attributes.adoc[]
6+
7+
toc::[]
8+
9+
:FeatureName: {FunctionsProductName}
10+
include::modules/technology-preview.adoc[leveloffset=+2]
11+
12+
This guide explains how you can create and manage a function on an {ServerlessProductName} installation by using the `kn` CLI.
13+
// TODO: add info about developer console at 4.8 when this is supported.
14+
15+
[id="prerequisites_serverless-functions-getting-started]
16+
== Prerequisites
17+
18+
Before you can complete the following procedures, you must ensure that you have completed all of the prerequisite tasks in xref:../../serverless/functions/serverless-functions-setup.adoc#serverless-functions-setup[Setting up {FunctionsProductShortName}].
19+
20+
include::modules/serverless-create-func-kn.adoc[leveloffset=+1]
21+
include::modules/serverless-build-func-kn.adoc[leveloffset=+1]
22+
include::modules/serverless-deploy-func-kn.adoc[leveloffset=+1]

0 commit comments

Comments
 (0)