|
| 1 | +--- |
| 2 | +title: "BaaS Integration" |
| 3 | +linkTitle: "BaaS Integration" |
| 4 | +weight: 3350 |
| 5 | +description: |
| 6 | +--- |
| 7 | + |
| 8 | +One of the unique features of OpenFunction is its simple integration with various backend services (BaaS) through [Dapr](https://docs.dapr.io/concepts/components-concept/). Currently, OpenFunction supports Dapr [pub/sub](https://docs.dapr.io/reference/components-reference/supported-pubsub/) and [bindings](https://docs.dapr.io/reference/components-reference/supported-bindings/) building blocks, and more will be added in the future. |
| 9 | + |
| 10 | +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: |
| 11 | + |
| 12 | +- The entire function instance's launch time is slowed down by the launching of the dapr sidecar container. |
| 13 | +- The dapr sidecar container may consume more resources than the function container itself. |
| 14 | + |
| 15 | +To address the problems above, OpenFunction introduces the `Dapr Standalone Mode` in v0.8.0. |
| 16 | + |
| 17 | +## Dapr Standalone Mode |
| 18 | + |
| 19 | +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. |
| 20 | + |
| 21 | +<div align=center><img width="100%" height="100%" src=/images/docs/en/concepts/function/dapr_proxy.png/></div> |
| 22 | + |
| 23 | +## Choose the appropriate Dapr Service Mode |
| 24 | + |
| 25 | +So now you've 2 options to integrate with BaaS: |
| 26 | + |
| 27 | +- `Dapr Sidecar Mode` |
| 28 | +- `Dapr Standalone Mode` |
| 29 | + |
| 30 | +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`. |
| 31 | + |
| 32 | +You can control how to integrate with BaaS with 2 flags, both can be set in function's `serving.spec.annotations`: |
| 33 | + |
| 34 | +- `openfunction.io/enable-dapr` can be set to `true` or `false` |
| 35 | +- `openfunction.io/dapr-service-mode` can be set to `standalone` or `sidecar` |
| 36 | +- When `openfunction.io/enable-dapr` is set to `true`, users can choose the `Dapr Service Mode` by setting `openfunction.io/dapr-service-mode` to `standalone` or `sidecar`. |
| 37 | +- When `openfunction.io/enable-dapr` is set to `false`, the value of `openfunction.io/dapr-service-mode` will be ignored and neither `Dapr Sidecar` nor `Dapr Proxy Service` will be launched. |
| 38 | + |
| 39 | +There're default values for both of these two flags if they're not set. |
| 40 | + |
| 41 | +- The value of `openfunction.io/enable-dapr` will be set to `true` if it's not defined in `serving.spec.annotations` and the function definition contains either `serving.spec.inputs` or `serving.spec.outputs`. Otherwise it will be set to `false`. |
| 42 | +- The default value of `openfunction.io/dapr-service-mode` is `standalone` if not set. |
| 43 | + |
| 44 | +Below you can find a function example to set these two flags: |
| 45 | + |
| 46 | +```yaml |
| 47 | +apiVersion: core.openfunction.io/v1beta1 |
| 48 | +kind: Function |
| 49 | +metadata: |
| 50 | + name: cron-input-kafka-output |
| 51 | +spec: |
| 52 | + version: "v2.0.0" |
| 53 | + image: openfunctiondev/cron-input-kafka-output:v1 |
| 54 | + imageCredentials: |
| 55 | + name: push-secret |
| 56 | + build: |
| 57 | + builder: openfunction/builder-go:latest |
| 58 | + env: |
| 59 | + FUNC_NAME: "HandleCronInput" |
| 60 | + FUNC_CLEAR_SOURCE: "true" |
| 61 | + srcRepo: |
| 62 | + url: "https://github.com/OpenFunction/samples.git" |
| 63 | + sourceSubPath: "functions/async/bindings/cron-input-kafka-output" |
| 64 | + revision: "main" |
| 65 | + serving: |
| 66 | + annotations: |
| 67 | + openfunction.io/enable-dapr: "true" |
| 68 | + openfunction.io/dapr-service-mode: "standalone" |
| 69 | + template: |
| 70 | + containers: |
| 71 | + - name: function # DO NOT change this |
| 72 | + imagePullPolicy: IfNotPresent |
| 73 | + runtime: "async" |
| 74 | + inputs: |
| 75 | + - name: cron |
| 76 | + component: cron |
| 77 | + outputs: |
| 78 | + - name: sample |
| 79 | + component: kafka-server |
| 80 | + operation: "create" |
| 81 | + bindings: |
| 82 | + cron: |
| 83 | + type: bindings.cron |
| 84 | + version: v1 |
| 85 | + metadata: |
| 86 | + - name: schedule |
| 87 | + value: "@every 2s" |
| 88 | + kafka-server: |
| 89 | + type: bindings.kafka |
| 90 | + version: v1 |
| 91 | + metadata: |
| 92 | + - name: brokers |
| 93 | + value: "kafka-server-kafka-brokers:9092" |
| 94 | + - name: topics |
| 95 | + value: "sample-topic" |
| 96 | + - name: consumerGroup |
| 97 | + value: "bindings-with-output" |
| 98 | + - name: publishTopic |
| 99 | + value: "sample-topic" |
| 100 | + - name: authRequired |
| 101 | + value: "false" |
| 102 | +``` |
0 commit comments