BaaS Integration
One of the unique features of OpenFunction is its simple integration with various backend services (BaaS) through Dapr. Currently, OpenFunction supports Dapr pub/sub and bindings building blocks, and more will be added in the future.
In OpenFunction v0.7.0 and versions prior to v0.7.0, OpenFunction integrates with BaaS by injecting a dapr sidecar container into each function instance’s pod, which leads to the following problems:
- The entire function instance’s launch time is slowed down by the launching of the dapr sidecar container.
- The dapr sidecar container may consume more resources than the function container itself.
To address the problems above, OpenFunction introduces the Dapr Standalone Mode
in v0.8.0.
Dapr Standalone Mode
In Dapr standalone mode, one Dapr Proxy service
will be created for each function which is then shared by all instances of this function. This way, there is no need to launch a seperate Dapr sidecar container for each function instance anymore which reduces the function launching time significantly.
Choose the appropriate Dapr Service Mode
So now you’ve 2 options to integrate with BaaS:
Dapr Sidecar Mode
Dapr Standalone Mode
You can choose the appropriate Dapr Service Mode for your functions. The Dapr Standalone Mode
is the recommened and default mode. You can use Dapr Sidecar Mode
if your function doesn’t scale frequently or you’ve difficulty to use the Dapr Standalone Mode
.
You can control how to integrate with BaaS with 2 flags, both can be set in function’s spec.serving.annotations
:
openfunction.io/enable-dapr
can be set totrue
orfalse
openfunction.io/dapr-service-mode
can be set tostandalone
orsidecar
- When
openfunction.io/enable-dapr
is set totrue
, users can choose theDapr Service Mode
by settingopenfunction.io/dapr-service-mode
tostandalone
orsidecar
. - When
openfunction.io/enable-dapr
is set tofalse
, the value ofopenfunction.io/dapr-service-mode
will be ignored and neitherDapr Sidecar
norDapr Proxy Service
will be launched.
There’re default values for both of these two flags if they’re not set.
- The value of
openfunction.io/enable-dapr
will be set totrue
if it’s not defined inspec.serving.annotations
and the function definition contains eitherspec.serving.inputs
orspec.serving.outputs
. Otherwise it will be set tofalse
. - The default value of
openfunction.io/dapr-service-mode
isstandalone
if not set.
Below you can find a function example to set these two flags:
apiVersion: core.openfunction.io/v1beta2
kind: Function
metadata:
name: cron-input-kafka-output
spec:
version: "v2.0.0"
image: openfunctiondev/cron-input-kafka-output:v1
imageCredentials:
name: push-secret
build:
builder: openfunction/builder-go:latest
env:
FUNC_NAME: "HandleCronInput"
FUNC_CLEAR_SOURCE: "true"
srcRepo:
url: "https://github.com/OpenFunction/samples.git"
sourceSubPath: "functions/async/bindings/cron-input-kafka-output"
revision: "main"
serving:
annotations:
openfunction.io/enable-dapr: "true"
openfunction.io/dapr-service-mode: "standalone"
template:
containers:
- name: function # DO NOT change this
imagePullPolicy: IfNotPresent
triggers:
dapr:
- name: cron
type: bindings.cron
outputs:
- dapr:
component: kafka-server
operation: "create"
bindings:
cron:
type: bindings.cron
version: v1
metadata:
- name: schedule
value: "@every 2s"
kafka-server:
type: bindings.kafka
version: v1
metadata:
- name: brokers
value: "kafka-server-kafka-brokers:9092"
- name: topics
value: "sample-topic"
- name: consumerGroup
value: "bindings-with-output"
- name: publishTopic
value: "sample-topic"
- name: authRequired
value: "false"