diff --git a/README.md b/README.md index b987c886..88e168fc 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # OpenFunction Website - + [![Netlify Status](https://api.netlify.com/api/v1/badges/ecf7df22-21fe-4e32-8cae-fc62fb20dff5/deploy-status)](https://app.netlify.com/sites/openfunction-dev/deploys) -openfunction.dev is OpenFunction's website which is built with [Hugo](https://gohugo.io/) and [Hugo template Docsy](https://github.com/google/docsy). +openfunction.dev is OpenFunction's website which is built with [Hugo](https://gohugo.io/) and [Hugo template Docsy](https://github.com/google/docsy). ## Contribute @@ -50,4 +50,4 @@ Open a [pull request (PR)](https://help.github.com/en/desktop/contributing-to-pr ```bash git commit -s -m "xxx" -``` \ No newline at end of file +``` diff --git a/content/en/_index.html b/content/en/_index.html index 863ae0cb..dcd4e8e5 100644 --- a/content/en/_index.html +++ b/content/en/_index.html @@ -23,7 +23,7 @@ {{% blocks/section color="white" %}}
-OpenFunction Architecture +OpenFunction Architecture
diff --git a/content/en/blog/releases/release_v1.0.0.md b/content/en/blog/releases/release_v1.0.0.md index 6a38ee99..1e362839 100644 --- a/content/en/blog/releases/release_v1.0.0.md +++ b/content/en/blog/releases/release_v1.0.0.md @@ -6,7 +6,7 @@ weight: 92 --- -[OpenFunction](https://github.com/OpenFunction/OpenFunction) is a cloud-native open-source FaaS (Function as a Service) platform aiming to let you focus on your business logic only. Today, we are thrilled to announce the general availability of OpenFunction 1.1.0. +[OpenFunction](https://github.com/OpenFunction/OpenFunction) is a cloud-native open-source FaaS (Function as a Service) platform aiming to let you focus on your business logic only. Today, we are thrilled to announce the general availability of OpenFunction 1.0.0. In this update, we have continued our commitment to providing developers with more flexible and powerful tools, and have added some new feature. This release integrates WasmEdge to support Wasm functions; we have also enhanced the CI/CD functionality of OpenFunction to provide relatively complete end-to-end CI/CD functionality; and we have added the ability to build an image of a function or application directly from local code in this release, making it easier for developers to publish and deploy their code. diff --git a/content/en/blog/releases/release_v1.1.0.md b/content/en/blog/releases/release_v1.1.0.md new file mode 100644 index 00000000..42c567b3 --- /dev/null +++ b/content/en/blog/releases/release_v1.1.0.md @@ -0,0 +1,100 @@ +--- +title: "Announcing OpenFunction 1.1.0: Support Dapr State Management and Refactor Function Triggers" +linkTitle: "Release v1.1.0" +date: 2023-06-12 +weight: 92 + +--- + +OpenFunction is a cloud-native open-source FaaS (Function as a Service) platform aiming to let you focus on your business logic only. Today, we are thrilled to announce the general availability of OpenFunction 1.1.0. + +In this release, we have added the v1beta2 API and support Dapr State management. In addition, we enhanced some features and fixed bugs, making OpenFunction more stable and easy to use. + +The following introduces the major updates. + +## Add the v1beta2 API + +In this release, we have added the v1beta2 API. The v1beta1 API has been deprecated and will be removed. You can learn more about the v1beta2 API from this [proposal](https://github.com/OpenFunction/OpenFunction/blob/main/docs/proposals/20230330-support-dapr-state-management.md). + +### Support Dapr state management + +Previously, OpenFunction supports the pub/sub and bindings building blocks, and state management is a building block that is useful for stateful functions. With the use of state store components, you can build functions with persistent state, allowing them to save and restore their own states. + +You can define state stores in Function CR, and OpenFunction will manage the corresponding Dapr components. + +The functions can use the encapsulated state management API of Dapr to save, read, and query key/value pairs in the defined state storage. + +## Refactor function triggers + +Previously, we use `runtime: knative` and `runtime: async` to distinguish sync and async functions, which is sort of difficult. Actually the difference between sync and async functions lies in the trigger type: + +- Sync functions are triggered by `HTTP` events, which are defined by specifying `runtime: knative`. + +- Async functions are triggered by events from components of `Dapr bindings` or `Dapr pubsub`. `runtime: async` and `inputs` have to be used together to specify triggers for async functions. + +Now we use `triggers` to replace `runtime` and `inputs`. + +`HTTP Trigger` triggers a function with an HTTP request. You can define an `HTTP Trigger` for a function like this: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + triggers: + http: + port: 8080 + route: + rules: + - matches: + - path: + type: PathPrefix + value: /echo +``` + +`Dapr Trigger` triggers a function with events from `Dapr bindings` or `Dapr pubsub`. You can define a function with `Dapr Trigger` like this: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler + namespace: default +spec: + serving: + bindings: + kafka-receiver: + metadata: + - name: brokers + value: kafka-server-kafka-brokers:9092 + - name: authRequired + value: "false" + - name: publishTopic + value: logs + - name: topics + value: logs + - name: consumerGroup + value: logs-handler + type: bindings.kafka + version: v1 + triggers: + dapr: + - name: kafka-receiver + type: bindings.kafka +``` + +## Other enhancements + +- Delete the `lastTransitionTime` field from the gateway status to prevent frequent triggering of reconcile. +- Allow to set scopes when creating Dapr components. +- Support the ability to set cache images to improve build performance when using OpenFunction strategies. +- Support the ability to set bash images of OpenFunction strategies. + +These are the main feature changes in OpenFunction v1.1.0 and we would like to thank all contributors for your contributions. If you are looking for an efficient and flexible cloud-native function development platform, OpenFunction v1.1.0 is the perfect choice for you. + +For more details and documentation, please visit our website and GitHub repo. + +- [Official Website](https://openfunction.dev/): https://openfunction.dev/ +- [Github](https://github.com/OpenFunction/OpenFunction/releases/tag/v1.1.0):https://github.com/OpenFunction/OpenFunction/releases/tag/v1.1.0 \ No newline at end of file diff --git a/content/en/blog/releases/release_v1.2.0.md b/content/en/blog/releases/release_v1.2.0.md new file mode 100644 index 00000000..6b0388b0 --- /dev/null +++ b/content/en/blog/releases/release_v1.2.0.md @@ -0,0 +1,43 @@ +--- +title: "OpenFunction 1.2.0: integrating KEDA http-addon as a synchronous function runtime" +linkTitle: "Release v1.2.0" +date: 2023-11-01 +weight: 92 + +--- + +[OpenFunction](https://github.com/OpenFunction/OpenFunction) is an open-source cloud-native FaaS (Function as a Service) platform designed to help developers focus on their business logic. We are thrilled to announce another important update for OpenFunction, the release of version v1.2.0! + +In this update, we continue to strive to provide developers with more flexible and powerful tools, and have added some new features. This version integrates KEDA http-addon as a synchronous function runtime, supports adding environment variables when enabling SkyWalking tracing, and supports recording build time. Additionally, several components have been upgraded and multiple bugs have been fixed. + +Here are the main highlights of this version update: + +## integrating KEDA http-addon as a synchronous function runtime + +KEDA http-addon is an additional component of KEDA that automatically scales HTTP servers based on changes in HTTP traffic, including scaling from zero to handle traffic and scaling down to zero when there is no traffic. + +The working principle of KEDA http-addon is that it creates a component called Interceptor in the Kubernetes cluster to receive all HTTP requests and forward them to the target application. At the same time, it reports the length of the request queue to a component called External Scaler, which triggers KEDA's automatic scaling mechanism. This allows your HTTP application to dynamically adjust the number of replicas based on the actual traffic demand. + +In OpenFunction version v1.2.0, we have integrated KEDA http-addon as an option for synchronous function runtime. This means that you can use OpenFunction to create and manage HTTP-based functions and leverage the capabilities of KEDA http-addon for efficient and flexible elastic scaling. To deploy and run your HTTP functions, you simply need to specify the value of `serving.triggers[*].http.engine` as "keda" when creating the Function resource and configure the relevant parameters of `keda.httpScaledObject` in `serving.scaleOptions`. + +## Support for recording events when the states of Function, Builder, and Serving change + +Events are an important resource type in Kubernetes that can record important or interesting occurrences within a cluster. Events can help users and developers understand changes in the state of resources within the cluster and handle any abnormalities accordingly. + +In OpenFunction version v1.2.0, we support recording events when the states of Function, Builder, and Serving change. This allows you to gain more information about what happens during the function building and running processes by reviewing the events. For example, you can see events such as the start, end, or failure of function building, as well as events related to the creation, update, or deletion of function runtimes. + +## Other improvements and optimizations + +In addition to the major changes mentioned above, this version also includes the following modifications and enhancements: + +* Upgraded KEDA to v2.10.1 and HPA (Horizontal Pod Autoscaler) API version to v2, improving stability and compatibility. +* Added support for recording build time, allowing you to track the duration of function builds. +* Adjusted the CI (Continuous Integration) process and fixed some minor issues. +* Fixed a bug in the keda http-addon runtime that caused functions to not run properly. +* Upgraded several components in the charts, including keda, dapr, and contour, to ensure the use of the latest versions and features. +* These are the main functional changes in OpenFunction v1.2.0. We would like to express our sincere gratitude to all contributors for their participation and contributions. + +To learn more about OpenFunction and this version update, please visit our official website and GitHub page. + +- [Official Website](https://openfunction.dev/):https://openfunction.dev/ +- [Github](https://github.com/OpenFunction/OpenFunction/releases/tag/v1.2.0):https://github.com/OpenFunction/OpenFunction/releases/tag/v1.2.0 \ No newline at end of file diff --git a/content/en/docs/_index.md b/content/en/docs/_index.md index 69aa24a3..88af2f02 100644 --- a/content/en/docs/_index.md +++ b/content/en/docs/_index.md @@ -1,5 +1,5 @@ --- -title: "v1.0 (preview)" +title: "v1.2 (latest)" linkTitle: "Docs" weight: 20 --- diff --git a/content/en/docs/best-practices/interact-with-dapr-output-binding.md b/content/en/docs/best-practices/interact-with-dapr-output-binding.md index ef479422..19887033 100644 --- a/content/en/docs/best-practices/interact-with-dapr-output-binding.md +++ b/content/en/docs/best-practices/interact-with-dapr-output-binding.md @@ -40,7 +40,7 @@ The following diagram illustrates the relationship between these functions. namespace: default spec: kafka: - version: 3.1.0 + version: 3.3.1 replicas: 1 listeners: - name: plain @@ -114,7 +114,7 @@ The following diagram illustrates the relationship between these functions. 1. Use the following example YAML file to create a manifest `kafka-input.yaml` and modify the value of `spec.image` to set your own image registry address. The field `spec.serving.inputs` defines an input source that points to a Dapr component of the Kafka server. It means that the `kafka-input` function will be driven by events in the topic `sample-topic` of the Kafka server. ```yaml - apiVersion: core.openfunction.io/v1beta1 + apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: kafka-input @@ -133,15 +133,19 @@ The following diagram illustrates the relationship between these functions. sourceSubPath: "functions/async/bindings/kafka-input" revision: "main" serving: - runtime: async scaleOptions: minReplicas: 0 maxReplicas: 10 keda: + triggers: + - type: kafka + metadata: + topic: sample-topic + bootstrapServers: kafka-server-kafka-brokers.default.svc:9092 + consumerGroup: kafka-input + lagThreshold: "20" scaledObject: pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 cooldownPeriod: 60 advanced: horizontalPodAutoscalerConfig: @@ -154,16 +158,11 @@ The following diagram illustrates the relationship between these functions. periodSeconds: 15 scaleUp: stabilizationWindowSeconds: 0 + triggers: - - type: kafka - metadata: - topic: sample-topic - bootstrapServers: kafka-server-kafka-brokers.default.svc:9092 - consumerGroup: kafka-input - lagThreshold: "20" - inputs: - - name: greeting - component: target-topic + dapr: + - name: target-topic + type: bindings.kafka bindings: target-topic: type: bindings.kafka @@ -192,26 +191,17 @@ The following diagram illustrates the relationship between these functions. ``` 3. Use the following example YAML file to create a manifest `function-front.yaml` and modify the value of `spec.image` to set your own image registry address. - - ```yaml - apiVersion: core.openfunction.io/v1beta1 + +```yaml + apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-front - annotations: - plugins: | - pre: - - plugin-custom - - plugin-example - post: - - plugin-custom - - plugin-example spec: version: "v1.0.0" image: "/sample-knative-dapr:latest" imageCredentials: name: push-secret - port: 8080 # Default to 8080 build: builder: openfunction/builder-go:latest env: @@ -222,14 +212,20 @@ The following diagram illustrates the relationship between these functions. sourceSubPath: "functions/knative/with-output-binding" revision: "main" serving: + hooks: + pre: + - plugin-custom + - plugin-example + post: + - plugin-example + - plugin-custom scaleOptions: minReplicas: 0 maxReplicas: 5 - runtime: knative outputs: - - name: target - component: kafka-server - operation: "create" + - dapr: + name: kafka-server + operation: "create" bindings: kafka-server: type: bindings.kafka @@ -249,8 +245,8 @@ The following diagram illustrates the relationship between these functions. containers: - name: function imagePullPolicy: Always - ``` - + ``` + {{% alert title="Note" color="success" %}} `metadata.plugins.pre` defines the order of plugins that need to be called before the user function is executed. `metadata.plugins.post` defines the order of plugins that need to be called after the user function is executed. For more information about the logic of these two plugins and the effect of the plugins after they are executed, see [Plugin mechanism](https://github.com/OpenFunction/samples/blob/main/functions-framework/README.md#plugin-mechanism). diff --git a/content/en/docs/best-practices/logs-handler-function.md b/content/en/docs/best-practices/logs-handler-function.md index de4f94f4..e07a5ed4 100644 --- a/content/en/docs/best-practices/logs-handler-function.md +++ b/content/en/docs/best-practices/logs-handler-function.md @@ -38,7 +38,7 @@ This document uses an asynchronous function to analyze the log stream in Kafka t namespace: default spec: kafka: - version: 3.1.0 + version: 3.3.1 replicas: 1 listeners: - name: plain @@ -111,87 +111,89 @@ This document uses an asynchronous function to analyze the log stream in Kafka t 1. Use the following example YAML file to create a manifest `logs-handler-function.yaml` and modify the value of `spec.image` to set your own image registry address. - ```yaml - apiVersion: core.openfunction.io/v1beta1 +```yaml + apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: logs-async-handler + namespace: default spec: - version: "v2.0.0" - image: /logs-async-handler:latest - imageCredentials: - name: push-secret build: builder: openfunction/builder-go:latest env: - FUNC_NAME: "LogsHandler" FUNC_CLEAR_SOURCE: "true" - # Use FUNC_GOPROXY to set the goproxy - # FUNC_GOPROXY: "https://goproxy.cn" + FUNC_NAME: LogsHandler srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "functions/async/logs-handler-function/" - revision: "main" + revision: main + sourceSubPath: functions/async/logs-handler-function/ + url: https://github.com/OpenFunction/samples.git + image: openfunctiondev/logs-async-handler:v1 + imageCredentials: + name: push-secret serving: - runtime: "async" - scaleOptions: - keda: - scaledObject: - pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 - cooldownPeriod: 60 - advanced: - horizontalPodAutoscalerConfig: - behavior: - scaleDown: - stabilizationWindowSeconds: 45 - policies: - - type: Percent - value: 50 - periodSeconds: 15 - scaleUp: - stabilizationWindowSeconds: 0 - triggers: - - type: kafka - metadata: - topic: logs - bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092 - consumerGroup: logs-handler - lagThreshold: "20" - template: - containers: - - name: function - imagePullPolicy: Always - inputs: - - name: kafka - component: kafka-receiver - outputs: - - name: notify - component: notification-manager - operation: "post" bindings: kafka-receiver: - type: bindings.kafka - version: v1 metadata: - name: brokers - value: "kafka-server-kafka-brokers:9092" + value: kafka-server-kafka-brokers:9092 - name: authRequired value: "false" - name: publishTopic - value: "logs" + value: logs - name: topics - value: "logs" + value: logs - name: consumerGroup - value: "logs-handler" - notification-manager: - type: bindings.http + value: logs-handler + type: bindings.kafka version: v1 + notification-manager: metadata: - name: url value: http://notification-manager-svc.kubesphere-monitoring-system.svc.cluster.local:19093/api/v2/alerts - ``` + type: bindings.http + version: v1 + outputs: + - dapr: + name: notification-manager + operation: post + type: bindings.http + scaleOptions: + keda: + scaledObject: + advanced: + horizontalPodAutoscalerConfig: + behavior: + scaleDown: + policies: + - periodSeconds: 15 + type: Percent + value: 50 + stabilizationWindowSeconds: 45 + scaleUp: + stabilizationWindowSeconds: 0 + cooldownPeriod: 60 + pollingInterval: 15 + triggers: + - metadata: + bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092 + consumerGroup: logs-handler + lagThreshold: "20" + topic: logs + type: kafka + maxReplicas: 10 + minReplicas: 0 + template: + containers: + - imagePullPolicy: IfNotPresent + name: function + triggers: + dapr: + - name: kafka-receiver + type: bindings.kafka + workloadType: Deployment + version: v2.0.0 + workloadRuntime: OCIContainer +``` 2. Run the following command to create the function `logs-async-handler`. diff --git a/content/en/docs/best-practices/skywalking-solution-for-openfunction.md b/content/en/docs/best-practices/skywalking-solution-for-openfunction.md index 389ae1e6..5ece91ef 100644 --- a/content/en/docs/best-practices/skywalking-solution-for-openfunction.md +++ b/content/en/docs/best-practices/skywalking-solution-for-openfunction.md @@ -72,7 +72,7 @@ This document uses `skywalking-oap.default:11800` as an example of the skywalkin ```yaml data: - plugins.tracing: | + tracing: | enabled: true provider: name: "skywalking" @@ -94,20 +94,21 @@ To enable tracing configuration in the function-level, add the field `plugins.tr ```yaml metadata: name: tracing-function - annotations: - plugins.tracing: | - enabled: true - provider: - name: "skywalking" - oapServer: "skywalking-oap:11800" - tags: - func: tracing-function - layer: faas - tag1: value1 - tag2: value2 - baggage: - key: "key1" - value: "value1" +spec: + serving: + tracing: + enabled: true + provider: + name: "skywalking" + oapServer: "skywalking-oap:11800" + tags: + func: tracing-function + layer: faas + tag1: value1 + tag2: value2 + baggage: + key: "key1" + value: "value1" ``` It is recommended that you use the global tracing configuration, or you have to add function-level tracing configuration for every function you create. diff --git a/content/en/docs/concepts/Events/event-bus-and-trigger.md b/content/en/docs/concepts/Events/event-bus-and-trigger.md index 5d7c3ee6..229023c4 100644 --- a/content/en/docs/concepts/Events/event-bus-and-trigger.md +++ b/content/en/docs/concepts/Events/event-bus-and-trigger.md @@ -27,16 +27,14 @@ helm install stan nats/stan --set stan.nats.url=nats://nats:4222 1. Use the following content to create a configuration file (for example, `openfuncasync-function.yaml`) for the target function, which is triggered by the Trigger CRD and prints the received message. ```yaml - apiVersion: core.openfunction.io/v1beta1 + apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: trigger-target spec: version: "v1.0.0" image: openfunctiondev/v1beta1-trigger-target:latest - port: 8080 serving: - runtime: "async" scaleOptions: keda: scaledObject: @@ -44,18 +42,18 @@ helm install stan nats/stan --set stan.nats.url=nats://nats:4222 minReplicaCount: 0 maxReplicaCount: 10 cooldownPeriod: 30 + triggers: + - type: stan + metadata: + natsServerMonitoringEndpoint: "stan.default.svc.cluster.local:8222" + queueGroup: "grp1" + durableName: "ImDurable" + subject: "metrics" + lagThreshold: "10" triggers: - - type: stan - metadata: - natsServerMonitoringEndpoint: "stan.default.svc.cluster.local:8222" - queueGroup: "grp1" - durableName: "ImDurable" - subject: "metrics" - lagThreshold: "10" - inputs: - - name: autoscaling-pubsub - component: eventbus - topic: metrics + dapr: + - name: eventbus + topic: metrics pubsub: eventbus: type: pubsub.natsstreaming @@ -233,7 +231,7 @@ helm install stan nats/stan --set stan.nats.url=nats://nats:4222 1. Use the following content to create an event producer configuration file (for example, `events-producer.yaml`). ```yaml - apiVersion: core.openfunction.io/v1beta1 + apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: events-producer @@ -245,14 +243,14 @@ helm install stan nats/stan --set stan.nats.url=nats://nats:4222 containers: - name: function imagePullPolicy: Always - runtime: "async" - inputs: - - name: cron - component: cron + triggers: + dapr: + - name: cron + type: bindings.cron outputs: - - name: target - component: kafka-server - operation: "create" + - dapr: + name: kafka-server + operation: "create" bindings: cron: type: bindings.cron diff --git a/content/en/docs/concepts/Events/event-source.md b/content/en/docs/concepts/Events/event-source.md index 19824c85..ffd1f929 100644 --- a/content/en/docs/concepts/Events/event-source.md +++ b/content/en/docs/concepts/Events/event-source.md @@ -14,20 +14,21 @@ In this example, an EventSource is defined for synchronous invocation to use the Use the following content to create a function as the EventSource Sink. For more information about how to create a function, see [Create sync functions](../../../getting-started/quickstarts/sync-functions). ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: sink spec: version: "v1.0.0" image: "openfunction/sink-sample:latest" - port: 8080 serving: - runtime: "knative" template: containers: - name: function imagePullPolicy: Always + triggers: + http: + port: 8080 ``` After the function is created, run the following command to get the URL of the function. @@ -63,7 +64,7 @@ sink Skipped Running serving-4x5wh https://openfunctio namespace: default spec: kafka: - version: 3.1.0 + version: 3.3.1 replicas: 1 listeners: - name: plain diff --git a/content/en/docs/concepts/baas_integration.md b/content/en/docs/concepts/baas_integration.md index bc37a6cf..ccf9e3af 100644 --- a/content/en/docs/concepts/baas_integration.md +++ b/content/en/docs/concepts/baas_integration.md @@ -44,7 +44,7 @@ There're default values for both of these two flags if they're not set. Below you can find a function example to set these two flags: ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: cron-input-kafka-output @@ -70,14 +70,14 @@ spec: containers: - name: function # DO NOT change this imagePullPolicy: IfNotPresent - runtime: "async" - inputs: - - name: cron - component: cron + triggers: + dapr: + - name: cron + type: bindings.cron outputs: - - name: sample - component: kafka-server - operation: "create" + - dapr: + component: kafka-server + operation: "create" bindings: cron: type: bindings.cron diff --git a/content/en/docs/concepts/build_strategy.md b/content/en/docs/concepts/build_strategy.md new file mode 100644 index 00000000..d8ee56b1 --- /dev/null +++ b/content/en/docs/concepts/build_strategy.md @@ -0,0 +1,127 @@ +--- +title: "Build Strategy" +linkTitle: "Build Strategy" +weight: 3120 +description: +--- + +Build Strategy is used to control the build process. There are two types of strategies, `ClusterBuildStrategy` and `BuildStrategy`. +Both strategies define a group of steps necessary to control the application build process. + +`ClusterBuildStrategy` is cluster-wide, while `BuildStrategy` is namespaced. + +There are 4 built-in `ClusterBuildStrategy` in OpenFunction, you can find more details in the following sections. + +## openfunction + +The `openfunction` ClusterBuildStrategy uses [Buildpacks](https://buildpacks.io/docs/) to build function images which is the default build strategy. + +The following are the parameters of the `openfunction` ClusterBuildStrategy: + +| Name | Type | Describe | +| --- | --- | --- | +| RUN_IMAGE | string | Reference to a run image to use | +| CACHE_IMAGE | string | Cache Image is a way to preserve cache layers across different builds, which can improve build performance when building functions or applications with lots of dependencies like Java functions. | +| BASH_IMAGE | string | The bash image that the strategy used. | +| ENV_VARS | string | Environment variables to set during _build-time_. The formate is `key1=value1,key2=value2`. | + +Users can set these parameters like this: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler +spec: + build: + shipwright: + params: + RUN_IMAGE: "" + ENV_VARS: "" +``` + +## buildah + +The `buildah` ClusterBuildStrategy uses [buildah](https://buildah.io/) to build application images. + +To use `buildah` ClusterBuildStrategy, you can define a `Function` like this: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: sample-go-app + namespace: default +spec: + build: + builder: openfunction/buildah:v1.23.1 + dockerfile: Dockerfile + shipwright: + strategy: + kind: ClusterBuildStrategy + name: buildah +``` + +The following are the parameters of the `buildah` ClusterBuildStrategy: + +| Name | Type | Describe | Default | +| --- | --- | --- | --- | +| registry-search | string | The registries for searching short name images such as `golang:latest`, separated by commas. | docker.io,quay.io | +| registry-insecure | string | The fully-qualified name of insecure registries. An insecure registry is a registry that does not have a valid SSL certificate or only supports HTTP. | +| registry-block | string | The registries that need to block pull access. | "" | + +## kaniko + +The `kaniko` ClusterBuildStrategy uses [kaniko](https://github.com/GoogleContainerTools/kaniko) to build application images. + +To use `kaniko` ClusterBuildStrategy, you can define a `Function` like this: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-kaniko + namespace: default +spec: + build: + builder: openfunction/kaniko-executor:v1.7.0 + dockerfile: Dockerfile + shipwright: + strategy: + kind: ClusterBuildStrategy + name: kaniko +``` + +## ko + +The `ko` ClusterBuildStrategy uses [ko](https://github.com/ko-build/ko) to build `Go` application images. + +To use `ko` ClusterBuildStrategy, you can define a `Function` like this: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-ko + namespace: default +spec: + build: + builder: golang:1.17 + dockerfile: Dockerfile + shipwright: + strategy: + kind: ClusterBuildStrategy + name: ko +``` + +The following are the parameters of `ko` ClusterBuildStrategy: + +| Name | Type | Describe | Default | +| --- | --- | --- | --- | +| go-flags | string | Value for the GOFLAGS environment variable. | "" | +| ko-version | string | Version of ko, must be either 'latest', or a release name from https://github.com/google/ko/releases. | "" | +| package-directory | string | The directory inside the context directory containing the main package. | "." | + +## Custom Strategy + +Users can customize their own strategy. To customize strategy, you can refer to [this](https://github.com/shipwright-io/build/blob/main/docs/buildstrategies.md). \ No newline at end of file diff --git a/content/en/docs/concepts/cicd.md b/content/en/docs/concepts/cicd.md index 436795cd..57cb228d 100644 --- a/content/en/docs/concepts/cicd.md +++ b/content/en/docs/concepts/cicd.md @@ -39,7 +39,7 @@ kubectl apply -f https://raw.githubusercontent.com/OpenFunction/revision-control To detect source code or image changes, you'll need to add revision controller switch and params like below to a function's annotation. ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: annotations: diff --git a/content/en/docs/concepts/function.md b/content/en/docs/concepts/function.md index d922901d..4330b234 100644 --- a/content/en/docs/concepts/function.md +++ b/content/en/docs/concepts/function.md @@ -20,7 +20,7 @@ Once a function is created, it will controll the lifecycle of `Build` and `Servi - `Serving` can be defined without `Build`, the function will use a previously built function image for serving. -
+
## Build diff --git a/content/en/docs/concepts/function_build.md b/content/en/docs/concepts/function_build.md index aeff45f5..2361b1a5 100644 --- a/content/en/docs/concepts/function_build.md +++ b/content/en/docs/concepts/function_build.md @@ -18,7 +18,7 @@ You can build a function image by simply adding a build section in the `Function If there is a serving section defined as well, the function will be launched as soon as the build completes. ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: logs-async-handler @@ -70,7 +70,7 @@ docker push /sample-source-code:latest Unlike defining the `spec.build.srcRepo.url` field for the git repo method, you'll need to define the `spec.build.srcRepo.bundleContainer.image` field instead. ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: logs-async-handler diff --git a/content/en/docs/concepts/function_io.md b/content/en/docs/concepts/function_io.md deleted file mode 100644 index 8a4f93f1..00000000 --- a/content/en/docs/concepts/function_io.md +++ /dev/null @@ -1,127 +0,0 @@ ---- -title: "Function Inputs and Outputs" -linkTitle: "Function Inputs and Outputs" -weight: 3200 -description: ---- -Functions usually have inputs and outputs. -## Function Inputs - -For a sync function, the input is always the payload of the HTTP request. - -For an async function, the input data comes from: -- Any [Dapr Input Binding components](https://docs.dapr.io/reference/components-reference/supported-bindings/) of the [Dapr Bindings Building Block](https://docs.dapr.io/developing-applications/building-blocks/bindings/bindings-overview/) -- Any [Dapr Pub/sub brokers components](https://docs.dapr.io/reference/components-reference/supported-pubsub/) of the [Dapr Pub/sub Building Block](https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/) - -## Function Outputs - -For a sync function, the output can be sent through the HTTP response. - -Both sync functions and async functions can send outputs to Dapr components including: -- Any [Dapr Output Binding components](https://docs.dapr.io/reference/components-reference/supported-bindings/) of the [Dapr Bindings Building Block](https://docs.dapr.io/developing-applications/building-blocks/bindings/bindings-overview/) -- Any [Dapr Pub/sub brokers components](https://docs.dapr.io/reference/components-reference/supported-pubsub/) of the [Dapr Pub/sub Building Block](https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/) - -For example, [here](https://github.com/OpenFunction/samples/blob/main/functions/async/bindings/cron-input-kafka-output) you can find an async function with a cron input binding and a Kafka output binding: - -```yaml -apiVersion: core.openfunction.io/v1beta1 -kind: Function -metadata: - name: cron-input-kafka-output -spec: - ... - serving: - ... - runtime: "async" - inputs: - - name: cron - component: cron - outputs: - - name: sample - 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" -``` - -[Here](https://github.com/OpenFunction/samples/tree/main/functions/async/pubsub/subscriber) is another async function example that use a Kafka Pub/sub component as input. - -```yaml -apiVersion: core.openfunction.io/v1beta1 -kind: Function -metadata: - name: autoscaling-subscriber -spec: - ... - serving: - ... - runtime: "async" - inputs: - - name: producer - component: kafka-server - topic: "sample-topic" - pubsub: - kafka-server: - type: pubsub.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-server-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: allowedTopics - value: "sample-topic" - - name: consumerID - value: "autoscaling-subscriber" -``` - -Sync functions can also send output to Dapr output binding components or Pub/sub components, [here](https://github.com/OpenFunction/samples/tree/main/functions/knative/with-output-binding) is an example: - -```yaml -apiVersion: core.openfunction.io/v1beta1 -kind: Function -metadata: - name: function-front -spec: - serving: - ... - runtime: knative - outputs: - - name: target - component: kafka-server - operation: "create" - bindings: - kafka-server: - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-server-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: publishTopic - value: "sample-topic" - - name: topics - value: "sample-topic" - - name: consumerGroup - value: "function-front" -``` diff --git a/content/en/docs/concepts/function_output.md b/content/en/docs/concepts/function_output.md new file mode 100644 index 00000000..9474c922 --- /dev/null +++ b/content/en/docs/concepts/function_output.md @@ -0,0 +1,78 @@ +--- +title: "Function Outputs" +linkTitle: "Function Outputs" +weight: 3210 +description: +--- + +## Function Outputs + +Output is a component that the function can send data to, include: + +- Any [Dapr Output Binding components](https://docs.dapr.io/reference/components-reference/supported-bindings/) of the [Dapr Bindings Building Block](https://docs.dapr.io/developing-applications/building-blocks/bindings/bindings-overview/) +- Any [Dapr Pub/sub brokers components](https://docs.dapr.io/reference/components-reference/supported-pubsub/) of the [Dapr Pub/sub Building Block](https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/) + +For example, [here](https://github.com/OpenFunction/samples/blob/main/functions/async/bindings/cron-input-kafka-output) you can find an async function with a cron input binding and a Kafka output binding: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: cron-input-kafka-output +spec: + ... + serving: + ... + outputs: + - dapr: + name: kafka-server + type: bindings.kafka + operation: "create" + bindings: + 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" +``` + +[Here](https://github.com/OpenFunction/samples/tree/main/functions/async/pubsub/subscriber) is another async function example that use a Kafka Pub/sub component as input. + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: autoscaling-subscriber +spec: + ... + serving: + ... + runtime: "async" + outputs: + - dapr: + name: kafka-server + type: pubsub.kafka + topic: "sample-topic" + pubsub: + kafka-server: + type: pubsub.kafka + version: v1 + metadata: + - name: brokers + value: "kafka-server-kafka-brokers:9092" + - name: authRequired + value: "false" + - name: allowedTopics + value: "sample-topic" + - name: consumerID + value: "autoscaling-subscriber" +``` diff --git a/content/en/docs/concepts/function_scaling_trigger.md b/content/en/docs/concepts/function_scaling.md similarity index 79% rename from content/en/docs/concepts/function_scaling_trigger.md rename to content/en/docs/concepts/function_scaling.md index 41a38a9f..bbd69dc4 100644 --- a/content/en/docs/concepts/function_scaling_trigger.md +++ b/content/en/docs/concepts/function_scaling.md @@ -1,7 +1,7 @@ --- -title: "Function Scaling and Triggers" -linkTitle: "Function Scaling and Triggers" -weight: 3210 +title: "Function Scaling" +linkTitle: "Function Scaling" +weight: 3220 description: --- @@ -14,7 +14,7 @@ OpenFunction defines function scaling in `ScaleOptions` and defines triggers to You can define unified function scale options for sync and async functions like below which will be valid for both sync and async functions: ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample @@ -30,18 +30,18 @@ Usually simply defining `minReplicas` and `maxReplicas` is not enough for async > You can find more details of async function scale options in [KEDA ScaleObject Spec](https://keda.sh/docs/2.7/concepts/scaling-deployments/#scaledobject-spec) and [KEDA ScaledJob Spec](https://keda.sh/docs/2.7/concepts/scaling-jobs/#scaledjob-spec). ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample spec: serving: scaleOptions: + minReplicas: 0 + maxReplicas: 10 keda: scaledObject: pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 cooldownPeriod: 60 advanced: horizontalPodAutoscalerConfig: @@ -61,7 +61,7 @@ You can also set advanced scale options for Knative sync functions too which wil > You can find more details of the Knative sync function scale options [here](https://knative.dev/docs/serving/autoscaling/scale-bounds/#scale-down-delay) ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample @@ -69,8 +69,6 @@ spec: serving: scaleOptions: knative: - autoscaling.knative.dev/min-scale: "0" - autoscaling.knative.dev/max-scale: "10" autoscaling.knative.dev/initial-scale: "1" autoscaling.knative.dev/scale-down-delay: "0" autoscaling.knative.dev/window: "60s" @@ -79,25 +77,26 @@ spec: autoscaling.knative.dev/target: "100" ``` -## Triggers +### Triggers Triggers define how to activate function scaling for async functions. You can use triggers defined in all [KEDA scalers](https://keda.sh/docs/2.7/scalers/) as OpenFunction's trigger spec. > Sync functions' scaling is activated by various options of HTTP requests which are already defined in the previous ScaleOption section. ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample spec: serving: - runtime: "async" - triggers: - - type: kafka - metadata: - topic: logs - bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092 - consumerGroup: logs-handler - lagThreshold: "20" + scaleOptions: + keda: + triggers: + - type: kafka + metadata: + topic: logs + bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092 + consumerGroup: logs-handler + lagThreshold: "20" ``` \ No newline at end of file diff --git a/content/en/docs/concepts/function_trigger.md b/content/en/docs/concepts/function_trigger.md new file mode 100644 index 00000000..992e7548 --- /dev/null +++ b/content/en/docs/concepts/function_trigger.md @@ -0,0 +1,84 @@ +--- +title: "Function Trigger" +linkTitle: "Function Trigger" +weight: 3200 +description: +--- +Function `Triggers` are used to define how to trigger a function. Currently, there are two kinds of triggers: `HTTP Trigger`, and `Dapr Trigger`. The default trigger is `HTTP trigger`. + +## HTTP Trigger + +`HTTP Trigger` triggers a function with an HTTP request. You can define an `HTTP Trigger` for a function like this: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + triggers: + http: + port: 8080 + route: + rules: + - matches: + - path: + type: PathPrefix + value: /echo +``` + +## Dapr Trigger + +`Dapr Trigger` triggers a function with events from `Dapr bindings` or `Dapr pubsub`. You can define a function with `Dapr Trigger` like this: + + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler + namespace: default +spec: + serving: + bindings: + kafka-receiver: + metadata: + - name: brokers + value: kafka-server-kafka-brokers:9092 + - name: authRequired + value: "false" + - name: publishTopic + value: logs + - name: topics + value: logs + - name: consumerGroup + value: logs-handler + type: bindings.kafka + version: v1 + triggers: + dapr: + - name: kafka-receiver + type: bindings.kafka +``` + +## Function Inputs + +`Input` is where a function can get extra input data from, `Dapr State Stores` is supported as `Input` currently. + +You can define function input like this: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler + namespace: default +spec: + serving: + triggers: + inputs: + - dapr: + name: mysql + type: state.mysql +``` \ No newline at end of file diff --git a/content/en/docs/concepts/networking/function-entrypoints.md b/content/en/docs/concepts/networking/function-entrypoints.md index 1a7c0d31..0f7f3dcc 100644 --- a/content/en/docs/concepts/networking/function-entrypoints.md +++ b/content/en/docs/concepts/networking/function-entrypoints.md @@ -73,9 +73,7 @@ To access a sync function by the external address, you'll need to configure DNS state: Skipped route: conditions: - - lastTransitionTime: "2022-08-20T11:03:14Z" - message: Valid HTTPRoute - observedGeneration: 13 + - message: Valid HTTPRoute reason: Valid status: "True" type: Accepted @@ -126,9 +124,7 @@ To access a sync function by the external address, you'll need to configure DNS state: Skipped route: conditions: - - lastTransitionTime: "2022-08-20T13:07:17Z" - message: Valid HTTPRoute - observedGeneration: 14 + - message: Valid HTTPRoute reason: Valid status: "True" type: Accepted diff --git a/content/en/docs/concepts/networking/gateway.md b/content/en/docs/concepts/networking/gateway.md index e8001ff3..662ddf51 100644 --- a/content/en/docs/concepts/networking/gateway.md +++ b/content/en/docs/concepts/networking/gateway.md @@ -26,24 +26,18 @@ After an `OpenFunction Gateway` is deployed, you'll be able to find the status o ```yaml status: conditions: - - lastTransitionTime: "2022-08-04T10:20:57Z" - message: Gateway is scheduled - observedGeneration: 2 + - message: Gateway is scheduled reason: Scheduled status: "True" type: Scheduled - - lastTransitionTime: "2022-08-04T10:20:57Z" - message: Valid Gateway - observedGeneration: 2 + - message: Valid Gateway reason: Valid status: "True" type: Ready listeners: - attachedRoutes: 0 conditions: - - lastTransitionTime: "2022-08-04T10:20:57Z" - message: Valid listener - observedGeneration: 2 + - message: Valid listener reason: Ready status: "True" type: Ready @@ -53,9 +47,7 @@ status: kind: HTTPRoute - attachedRoutes: 0 conditions: - - lastTransitionTime: "2022-08-04T10:20:57Z" - message: Valid listener - observedGeneration: 2 + - message: Valid listener reason: Ready status: "True" type: Ready diff --git a/content/en/docs/concepts/networking/route.md b/content/en/docs/concepts/networking/route.md index f440cd1d..21ec252d 100644 --- a/content/en/docs/concepts/networking/route.md +++ b/content/en/docs/concepts/networking/route.md @@ -35,9 +35,7 @@ status: state: Skipped route: conditions: - - lastTransitionTime: "2022-08-04T10:43:29Z" - message: Valid HTTPRoute - observedGeneration: 1 + - message: Valid HTTPRoute reason: Valid status: "True" type: Accepted @@ -75,24 +73,24 @@ If `route.rules` is not defined, `route.rules` will be generated based on path o ```shell kubectl apply -f - < Before you creating any functions, make sure you've installed all the [prerequisites](../prerequisites) -Sync functions are funtions whose inputs are payloads of HTTP requests, and the output or response are sent to the waiting client immediately after the function logic finishes processing the inputs payload. Below you can find some sync function examples in different languages: +Sync functions are functions whose inputs are payloads of HTTP requests, and the output or response are sent to the waiting client immediately after the function logic finishes processing the inputs payload. Below you can find some sync function examples in different languages: | | Sync Functions | |-----------|----------------| diff --git a/content/en/docs/getting-started/installation.md b/content/en/docs/getting-started/installation.md index 1b9ed6f3..1d18f543 100644 --- a/content/en/docs/getting-started/installation.md +++ b/content/en/docs/getting-started/installation.md @@ -13,19 +13,12 @@ This document describes how to install OpenFunction. - You need to ensure your Kubernetes version meets the requirements described in the following compatibility matrix. -| OpenFunction Version | Kubernetes 1.20 | Kubernetes 1.21 | Kubernetes 1.22 | Kubernetes 1.23 | Kubernetes 1.24 | Kubernetes 1.25 | +| OpenFunction Version | Kubernetes 1.21 | Kubernetes 1.22 | Kubernetes 1.23 | Kubernetes 1.24 | Kubernetes 1.25 | Kubernetes 1.26+ | |----------------------|-----------------|-----------------|-----------------|-----------------|-----------------|-----------------| -| HEAD | N/A | √ | √ | √ | √ | √ | -| v1.0.x | N/A | √ | √ | √ | √ | √ | -| v0.8.x | √ | √ | √ | √ | √ | √* | -| v0.7.0 | √ | √ | √ | √ | √ | N/A | - -{{% alert title="Note" color="success" %}} - -OpenFunction supports Kubernetes 1.25 starting from v0.8.1 - -{{% /alert %}} - +| HEAD | N/A | N/A | √ | √ | √ | √ | +| v1.2 | N/A | N/A | √ | √ | √ | √ | +| v1.1.x | √ | √ | √ | √ | √ | N/A | +| v1.0.x | √ | √ | √ | √ | √ | N/A | ## Install OpenFunction diff --git a/content/en/docs/introduction.md b/content/en/docs/introduction.md index 61ba2299..82e66a4f 100644 --- a/content/en/docs/introduction.md +++ b/content/en/docs/introduction.md @@ -13,7 +13,7 @@ OpenFunction is a cloud-native open source FaaS (Function as a Service) platform ## Architecture and Design -
+
## Core Features diff --git a/content/en/docs/operations/networking/switch-gateway.md b/content/en/docs/operations/networking/switch-gateway.md index 5c643455..9040c3a4 100644 --- a/content/en/docs/operations/networking/switch-gateway.md +++ b/content/en/docs/operations/networking/switch-gateway.md @@ -68,23 +68,23 @@ EOF ```shell kubectl apply -f - < - Learn how to use the CLI of OpenFunction. ---- - -This document describes how to use the CLI of OpenFunction. - -## Overview - -ofn is the command-line interface for OpenFunction. It helps you install and manage OpenFuntion. - -The following table describes the main commands supported by ofn. - -| Command | Description | -| ------------- | ------------------------------------------------------------ | -| `init` | Provides management for the framework of OpenFunction. | -| `create` | Creates a function from a file or stdin. | -| `apply` | Applies a function from a file or stdin. | -| `demo` | Creates a [kind cluster](https://kind.sigs.k8s.io/) to install OpenFunction and run its demo. | -| `get` | Prints a table of the most important information about the specified function. | -| `get builder` | Prints important information about the Builder. | -| `get serving` | Prints important information about the Serving. | -| `delete` | Deletes the specified function. | - -## `ofn demo` Parameters - -The following table describes parameters available for the `ofn demo` command. - -| Parameter | Description | -| ------------ | ------------------------------------------------------------ | -| --auto-prune | For removing the demo kind cluster. To keep the demo kind cluster, run `ofn demo --auto-prune=false`, and you can delete the demo kind cluster by running `kind delete cluster --name openfunction`. | -| --verbose | For displaying detailed information. | -| --region-cn | For users who have limited access to gcr.io or github.com. | - diff --git a/content/en/docs/reference/component-reference/function-spec.md b/content/en/docs/reference/component-reference/function-spec.md index d0d723d4..79f9e1b5 100644 --- a/content/en/docs/reference/component-reference/function-spec.md +++ b/content/en/docs/reference/component-reference/function-spec.md @@ -8,162 +8,270 @@ description: > This document describes the specifications of the Function CRD. -## Function - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **apiVersion** *string* | core.openfunction.io/v1alpha2 | -| **kind** *string* | Function | -| **metadata** *[v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta)* | *(Optional)* Refer to [v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta) | -| **spec** *[FunctionSpec](#functionspec)* | Refer to [FunctionSpec](#functionspec) | -| **status** *FunctionStatus* | Refer to FunctionStatus | - -### FunctionSpec - -*Belong to [Function](#function)*. - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **version** *string* | *(Optional)* Function version, e.g. `v1.0.0` | -| **image** *string* | Image upload path, e.g. `demorepo/demofunction:v1` | -| **imageCredentials** *[v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference)* | *(Optional)* Credentials for accessing the image repository, refer to [v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference) | -| **port** *int32* | *(Optional)* The port the function is listening on, e.g. `8080` | -| **build** *[BuildImpl](#buildimpl)* | *(Optional)* Builder specification for the function, see [BuildImpl](#buildimpl) | -| **serving** *[ServingImpl](#servingimpl)* | *(Optional)* Serving specification for the function, see [ServingImpl](#servingimpl) | - -### BuildImpl - -*Belong to [FunctionSpec](#functionspec)*. - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **builder** *string* | Name of the Builder | -| **builderCredentials** *[v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference)* | *(Optional)* Credentials for accessing the image repository, refer to [v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference) | -| **shipwright** *[ShipwrightEngine](#shipwrightengine)* | *(Optional)* Specification of the Shipwright engine, refer to [ShipwrightEngine](#shipwrightengine) | -| **params** *map[string]string* | *(Optional)* Parameters passed to Shipwright | -| **env** map[string]string | *(Optional)* Parameters passed to the buildpacks builder | -| **srcRepo** *[GitRepo](#gitrepo)* | The configuration of the source code repository, refer to [GitRepo](#gitrepo) | -| **dockerfile** *string* | *(Optional)* Path to the Dockerfile instructing Shipwright when using the Dockerfile to build images | - -### ShipwrightEngine - -*Belong to [BuildImpl](#buildimpl)*. - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **strategy** *[Strategy](#strategy)* | *(Optional)* Index of image build strategy, refer to [Strategy](#strategy) | -| **timeout** *[v1.Duration](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration)* | *(Optional)* Build timeout, refer to [v1.Duration](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration) | - -### Strategy - -*Belong to [ShipwrightEngine](#shipwrightengine)*. - -| Field | Description | -| --------------- | ------------------------------------------------------------ | -| **name** string | Name of the strategy | -| **kind** string | *(Optional)* Kind of the build strategy, which defaults to "BuildStrategy" or optional "ClusterBuildStrategy" | - -### GitRepo - -*Belong to [BuildImpl](#buildimpl)*. - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **url** *string* | Source code repository address | -| **revision** *string* | *(Optional)* Referenceable instances in the repository, such as commit ID and branch name. | -| **sourceSubPath** *string* | *(Optional)* The directory of the function in the repository, e.g. `functions/function-a/` | -| **credentials** *[v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference)* | *(Optional)* Repository access credentials, refer to [v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference) | - -### ServingImpl - -*Belong to [FunctionSpec](#functionspec)*. - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **runtime** *string* | Type of load runtime, optional: `Knative`, `OpenFuncAsync` | -| **params** *map[string]string* | *(Optional)* Parameters passed to the workloads | -| **openFuncAsync** *[OpenFuncAsyncRuntime](#openfuncasyncruntime)* | *(Optional)* Used to define the configuration of OpenFuncAsync when the runtime is OpenFuncAsync, see [OpenFuncAsyncRuntime](#openfuncasyncruntime) | -| **template** *[v1.PodSpec](https://pkg.go.dev/k8s.io/api/core/v1#PodSpec)* | *(Optional)* Template for the definition of Pods in the workloads, refer to [v1.PodSpec](https://pkg.go.dev/k8s.io/api/core/v1#PodSpec) | - -### OpenFuncAsyncRuntime - -*Belong to [ServingImpl](#servingimpl)*. - -| Field | Description | -| ------------------------ | ------------------------------------------------------------ | -| **dapr** *[Dapr](#dapr)* | *(Optional)* Definition of Dapr components, see [Dapr](#dapr) | -| **keda** *[Keda](#keda)* | *(Optional)* Definition of Keda, see [Keda](#keda) | - -### Dapr - -*Belong to [OpenFuncAsyncRuntime](#openfuncasyncruntime)*. - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **annotations** *map[string]string* | *(Optional)* Annotations for Dapr components, see [Dapr documentation](https://docs.dapr.io/reference/arguments-annotations-overview/) | -| **components** *map\[string][componentsv1alpha1.ComponentSpec](https://docs.dapr.io/reference/components-reference/)* | *(Optional)* Dapr Components Spec map, with key being component's name and value being [componentsv1alpha1.ComponentSpec](https://docs.dapr.io/reference/components-reference/) | -| **inputs** *\[][DaprIO](#daprio)* | *(Optional)* The definition of the inputs of the function, see [DaprIO](#daprio) | -| **outputs** *\[][DaprIO](#daprio)* | *(Optional)* The definition of the outputs of the function, see [DaprIO](#daprio) | - -### DaprIO - -*Belong to [Dapr](#dapr)*. - -| Field | Description | -| ------------------------------ | ------------------------------------------------------------ | -| **name** *string* | Name of the input and output of the function. Consistent with the name of [DaprComponent](#daprcomponent) means associated | -| **component** *string* | Indicates the name of components | -| **type** *string* | Type of Dapr component, optional: `bindings`, `pubsub` | -| **topic** *string* | *(Optional)* When the **type** is `pubsub`, you need to set the topic | -| **operation** *string* | *(Optional)* Operation field tells the Dapr component which operation it should perform, refer to [Dapr docs](https://docs.dapr.io/reference/components-reference/supported-bindings/kafka/#binding-support) | -| **params** *map[string]string* | *(Optional)* Parameters passed to Dapr | - -### Keda - -*Belong to [OpenFuncAsyncRuntime](#openfuncasyncruntime)*. - -| Field | Description | -| -------------------------------------------------------- | ------------------------------------------------------------ | -| **scaledObject** *[KedaScaledObject](#kedascaledobject)* | Definition of KEDA scalable objects (Deployments), refer to [KedaScaledObject](#kedascaledobject) | -| **scaledJob** *[KedaScaledJob](#kedascaledjob)* | Definition of KEDA scalable jobs, refer to [KedaScaledJob](#kedascaledjob) | - -### KedaScaledObject - -*Belong to [Keda](#keda)*. - -{{% alert title="Note" color="success" %}} - -For more information, see [Scaling Deployments, StatefulSets & Custom Resources](https://keda.sh/docs/2.4/concepts/scaling-deployments/). - -{{% /alert %}} - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **workloadType** *string* | How to run the function, known values are `Deployment` or `StatefulSet`, which defaults to `Deployment`. | -| **pollingInterval** *int32* | *(Optional)* The `pollingInterval` is in seconds. This is the interval in which KEDA checks the triggers for the queue length or the stream lag. It defaults to `30` seconds. | -| **cooldownPeriod** *int32* | *(Optional)* The `cooldownPeriod` is in seconds, and it is the period of time to wait after the last trigger activated before scaling back down to 0. It defaults to `300` seconds. | -| **minReplicaCount** *int32* | *(Optional)* Minimum number of replicas which KEDA will scale the resource down to. By default, it scales to `0`. | -| **maxReplicaCount** *int32* | *(Optional)* This setting is passed to the HPA definition that KEDA will create for a given resource. | -| **advanced** *[kedav1alpha1.AdvancedConfig](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#AdvancedConfig)* | *(Optional)* This property specifies whether the target resource (for example, `Deployment` and `StatefulSet`) should be scaled back to original replicas count after the `ScaledObject` is deleted. Default behavior is to keep the replica count at the same number as it is in the moment of `ScaledObject` deletion. Refer to [kedav1alpha1.AdvancedConfig](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#AdvancedConfig). | -| **triggers** *\[][kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers)* | Event sources that trigger dynamic scaling of workloads. Refer to [kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers). | - -### KedaScaledJob - -*Belong to [Keda](#keda)*. - -{{% alert title="Note" color="success" %}} - -For more information, see [Scaling Jobs](https://keda.sh/docs/2.4/concepts/scaling-jobs/). - -{{% /alert %}} - -| Field | Description | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **restartPolicy** *[v1.RestartPolicy](https://pkg.go.dev/k8s.io/api/core/v1#RestartPolicy)* | Restart policy for all containers within the pod. Value options are `OnFailure` or `Never`. It defaults to `Never`. | -| **pollingInterval** *int32* | *(Optional)* The `pollingInterval` is in seconds. This is the interval in which KEDA checks the triggers for the queue length or the stream lag. It defaults to `30` seconds. | -| **successfulJobsHistoryLimit** *int32* | *(Optional)* How many completed jobs should be kept. It defaults to `100`. | -| **failedJobsHistoryLimit** *int32* | *(Optional)* How many failed jobs should be kept. It defaults to `100`. | -| **maxReplicaCount** *int32* | *(Optional)* The max number of pods that is created within a single polling period. | -| **scalingStrategy** *[kedav1alpha1.ScalingStrategy](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScalingStrategy)* | *(Optional)* Select a scaling strategy. Value options are `default`, `custom`, or `accurate`. The default value is `default`. Refer to [kedav1alpha1.ScalingStrategy](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScalingStrategy). | -| **triggers** *\[][kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers)* | Event sources that trigger dynamic scaling of workloads, refer to [kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers). | +## Function.spec + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **image** | string | Image upload path, e.g. demorepo/demofunction:v1 | true | +| [build](#functionspecbuild) | object | Builder specification for the function | false | +| **imageCredentials** | object | Credentials for accessing the image repository, refer to v1.LocalObjectReference | false | +| [serving](#functionspecserving) | object | Serving specification for the function | false | +| **version** | string | Function version, e.g. v1.0.0 | false | +| **workloadRuntime** | string | WorkloadRuntime for Function. Know values: OCIContainer and WasmEdge.Default: OCIContainer | false | + +### Function.spec.build +[↩ Parent](#functionspec) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| [srcRepo](#functionspecbuildsrcrepo) | object | The configuration of the source code repository | true | +| **builder** | string | Name of the Builder | false | +| **builderCredentials** | object | Credentials for accessing the image repository, refer to [v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference) | false | +| **builderMaxAge** | string | The maximum time of finished builders to retain. | false | +| **dockerfile** | string | Path to the Dockerfile instructing Shipwright when using the Dockerfile to build images | false | +| **env** | map[string]string | Environment variables passed to the buildpacks builder | false | +| **failedBuildsHistoryLimit** | integer | The number of failed builders to retain. Default is 1. | false | +| [shipwright](#functionspecbuildshipwright) | object | Specification of the Shipwright engine | false | +| **successfulBuildsHistoryLimit** | integer | The number of successful finished builders to retain. Default is 0. | false | +| **timeout** | string | The maximum time for the builder to build the image | false | + +### Function.spec.build.srcRepo +[↩ Parent](#functionspecbuild) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| [bundleContainer](#functionspecbuildsrcrepobundlecontainer) | object | BundleContainer describes the source code bundle container to pull | false | +| **credentials** | object | Repository access credentials, refer to v1.LocalObjectReference | false | +| **revision** | string | Referencable instances in the repository, such as commit ID and branch name. | false | +| **sourceSubPath** | string | The directory of the function in the repository, e.g. functions/function-a/ | false | +| **url** | string | Source code repository address | false | + +### Function.spec.build.srcRepo.bundleContainer +[↩ Parent](#functionspecbuildsrcrepo) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **image** | string | The bundleContainer image name | true | + +### Function.spec.build.shipwright +[↩ Parent](#functionspecbuild) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **params** | []object | Parameters for the build strategy | false | +| [strategy](../../../concepts/build_strategy) | object | Strategy references the BuildStrategy to use to build the image | false | +| **timeout** | string | The maximum amount of time the shipwright Build should take to execute | false | + +### Function.spec.serving +[↩ Parent](#functionspec) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **annotations** | map[string]string | Annotations that will be added to the workload | false | +| **bindings** | map[string]object | [Dapr bindings](https://docs.dapr.io/developing-applications/building-blocks/bindings/) that the function needs to create and use. | false | +| [hooks](#functionspecservinghooks) | object | Hooks that will be executed before or after the function execution | false | +| **labels** | map[string]string | Labels that will be added to the workload | false | +| [outputs](#functionspecservingoutputsindex) | []object | The outputs which the function will send data to | false | +| **params** | map[string]string | Parameters required by the function, will be passed to the function as environment variables | false | +| **pubsub** | map[string]object | [Dapr pubsub](https://docs.dapr.io/developing-applications/building-blocks/pubsub/) that the function needs to create and use | false | +| [scaleOptions](#functionspecservingscaleoptions) | object | Configuration of auto scaling. | false | +| [states](#functionspecservingstateskey) | map[string]object | Dapr state store that the function needs to create and use | false | +| **template** | object | Template is a pod template which allows modifying operator generated pod template. | false | +| **timeout** | string | Timeout defines the maximum amount of time the Serving should take to execute before the Serving is running | false | +| [tracing](#functionspecservingtracing) | object | Configuration of tracing | false | +| **triggers** | object | Triggers used to trigger the function. Refer to [Function Trigger](../../../concepts/function_trigger). | true | +| **workloadType** | string | The type of workload used to run the function, known values are: Deployment, StatefulSet and Job | false | + +### Function.spec.serving.hooks +[↩ Parent](#functionspecserving) + + + + + + + + + + + + + + + + + + + + + + + + + + +
NameTypeDescriptionRequired
policystring + There are two kind of hooks, global hooks and private hooks, the global hooks define in the config file of OpenFunction Controller, + the private hooks define in the Function. Policy is the relationship between the global hooks and the private hooks of the function. Known values are: +
+   Append: All hooks will be executed, the private pre hooks will execute after the global pre hooks , and the private post hooks will execute before the global post hooks. this is the default policy.
+   Override: Only execute the private hooks.
+
false
post[]string + The hooks will be executed after the function execution + false
pre[]string + The hooks will be executed before the function execution + false
+ +### Function.spec.serving.outputs[index] +[↩ Parent](#functionspecserving) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| [dapr](#functionspecservingoutputsindexdapr) | object | Dapr output, refer to a exist component or a component defined in bindings or pubsub | false | + +### Function.spec.serving.outputs[index].dapr +[↩ Parent](#functionspecservingoutputsindex) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **name** | string | The name of the dapr component | true | +| **metadata** | map[string]string | Metadata passed to Dapr | false | +| **operation** | string | Operation field tells the Dapr component which operation it should perform, refer to [Dapr docs](https://docs.dapr.io/reference/components-reference/supported-bindings/kafka/#binding-support) | false | +| **topic** | string | When the type is pubsub, you need to set the topic | false | +| **type** | string | Type of Dapr component, such as: bindings.kafka, pubsub.rocketmq | false | + +### Function.spec.serving.scaleOptions +[↩ Parent](#functionspecserving) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| [keda](#functionspecservingscaleoptionskeda) | object | Configuration about keda autoscaling | false | +| **knative** | map[string]string | Knative autiscaling annotations. Refer to [Knative autoscaling](https://knative.dev/docs/serving/autoscaling/). | false | +| **maxReplicas** | integer | Minimum number of replicas which will scale the resource down to. By default, it scales to 0. | false | +| **minReplicas** | integer | Maximum number of replicas which will scale the resource up to. | false | + +### Function.spec.serving.scaleOptions.keda +[↩ Parent](#functionspecservingscaleoptions) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| [scaledJob](#functionspecservingscaleoptionskedascaledjob) | object | Scale options for job | false | +| [scaledObject](#functionspecservingscaleoptionskedascaledobject) | object | Scale options for deployment and statefulset | false | +| **triggers** | []object | Event sources that trigger dynamic scaling of workloads. Refer to [kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers). | false | + +### Function.spec.serving.scaleOptions.keda.scaledJob +[↩ Parent](#functionspecservingscaleoptionskeda) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **failedJobsHistoryLimit** | integer | How many failed jobs should be kept. It defaults to 100. | false | +| **pollingInterval** | integer | The pollingInterval is in seconds. This is the interval in which KEDA checks the triggers for the queue length or the stream lag. It defaults to 30 seconds. | false | +| **restartPolicy** | string | Restart policy for all containers within the pod. Value options are OnFailure or Never. It defaults to Never. | false | +| **scalingStrategy** | object | Select a scaling strategy. Value options are default, custom, or accurate. The default value is default. Refer to kedav1alpha1.ScalingStrategy | false | +| **successfulJobsHistoryLimit** | integer | How many completed jobs should be kept. It defaults to 100. | false | + +### Function.spec.serving.scaleOptions.keda.scaledObject +[↩ Parent](#functionspecservingscaleoptionskeda) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **advanced** | object | This property specifies whether the target resource (for example, Deployment and StatefulSet) should be scaled back to original replicas count after the ScaledObject is deleted. Default behavior is to keep the replica count at the same number as it is in the moment of ScaledObject deletion. Refer to [kedav1alpha1.AdvancedConfig](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#AdvancedConfig). | false | +| **cooldownPeriod** | integer | The cooldownPeriod is in seconds, and it is the period of time to wait after the last trigger activated before scaling back down to 0. It defaults to 300 seconds. | false | +| **pollingInterval** | integer | The pollingInterval is in seconds. This is the interval in which KEDA checks the triggers for the queue length or the stream lag. It defaults to 30 seconds. | false | + +### Function.spec.serving.states[key] +[↩ Parent](#functionspecserving) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **spec** | object | Dapr state stroe component spec. Refer to [Dapr docs](https://docs.dapr.io/developing-applications/building-blocks/state-management/). | false | + +### Function.spec.serving.tracing +[↩ Parent](#functionspecserving) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **baggage** | map[string]string | Baggage is contextual information that passed between spans. It is a key-value store that resides alongside span context in a trace, making values available to any span created within that trace. | true | +| **enabled** | boolean | Wether to enable tracing | true | +| [provider](#functionspecservingtracingprovider) | object | The tracing implementation used to create and send span | true | +| **tags** | map[string]string | The tag that needs to be added to the spans | false | + +### Function.spec.serving.tracing.provider +[↩ Parent](#functionspecservingtracing) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **name** | string | Tracing provider name, known values are skywalking and opentelemetry | true | +| [exporter](#functionspecservingtracingproviderexporter) | object | Service to collect span for opentelemetry | false | +| **oapServer** | string | The skywalking server url | false | + +### Function.spec.serving.tracing.provider.exporter +[↩ Parent](#functionspecservingtracingprovider) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **endpoint** | string | The exporter url | true | +| **name** | string | The exporter name, known values are otlp, jaeger, and zipkin | true | +| **compression** | string | The compression type to use on OTLP trace requests. Options include gzip. By default no compression will be used. | false | +| **headers** | string | Key-value pairs separated by commas to pass as request headers on OTLP trace requests. | false | +| **protocol** | string | The transport protocol to use on OTLP trace requests. Options include grpc and http/protobuf. Default is grpc. | false | +| **timeout** | string | The maximum waiting time, in milliseconds, allowed to send each OTLP trace batch. Default is 10000. | false | + +### Function.spec.serving.triggers +[↩ Parent](#functionspecserving) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| [dapr](#functionspecservingtriggersdaprindex) | []object | List of dapr triggers, refer to dapr bindings or pusub components | false | +| [http](#functionspecservingtriggershttp) | object | The http trigger | false | +| [inputs](#functionspecservingtriggersinputsindex) | []object | A list of components that the function can get data from | false | + +### Function.spec.serving.triggers.dapr[index] +[↩ Parent](#functionspecservingtriggers) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **name** | string | The dapr component name | true | +| **topic** | string | When the component type is pubsub, you need to set the topic | false | +| **type** | string | Type of Dapr component, such as: bindings.kafka, pubsub.rocketmq | false | + +### Function.spec.serving.triggers.http +[↩ Parent](#functionspecservingtriggers) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **port** | integer | The port the function is listening on, e.g. 8080 | false | +| [route](#functionspecservingtriggershttproute) | object | Route defines how traffic from the Gateway listener is routed to a function. | false | + +### Function.spec.serving.triggers.http.route +[↩ Parent](#functionspecservingtriggershttp) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| [gatewayRef](#functionspecservingtriggershttproutegatewayref) | object | GatewayRef references the Gateway resources that a Route wants | false | +| **hostnames** | []string | Hostnames defines a set of hostname that should match against the HTTP Host header to select a HTTPRoute to process the request. | false | +| **rules** | []object | Rules are a list of HTTP matchers, filters and actions. Refer to [HTTPRouteRule](https://gateway-api.sigs.k8s.io/v1alpha2/references/spec/#gateway.networking.k8s.io/v1beta1.HTTPRouteRule). | false | + +### Function.spec.serving.triggers.http.route.gatewayRef +[↩ Parent](#functionspecservingtriggershttproute) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **name** | string | The name of the gateway | true | +| **namespace** | string | The namespace of the gateway | true | + +### Function.spec.serving.triggers.inputs[index] +[↩ Parent](#functionspecservingtriggers) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| [dapr](#functionspecservingtriggersinputsindexdapr) | object | A dapr component that function can get data from. Now just support dapr state store | true | + +### Function.spec.serving.triggers.inputs[index].dapr +[↩ Parent](#functionspecservingtriggersinputsindex) + +| Name | Type | Description | Required | +| --- | --- | --- | --- | +| **name** | string | The dapr component name, maybe a exist component or a component defined in state | true | +| **type** | string | The dapr component type, such as state.redis | false | diff --git a/content/en/docs/reference/faq.md b/content/en/docs/reference/faq.md index 82b39234..5f81e4dd 100644 --- a/content/en/docs/reference/faq.md +++ b/content/en/docs/reference/faq.md @@ -142,7 +142,7 @@ You can refer to the `Global(ConfigMap)` and `Global(Operator)` sections of this And for `Per Revision` you can configure it like [this](../../concepts/function_scaling_trigger/). ```yaml -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample @@ -150,8 +150,7 @@ spec: serving: scaleOptions: knative: - autoscaling: - target: "200" + autoscaling.knative.dev/target: "200" ``` #### Hard limit @@ -176,7 +175,7 @@ spec: autoscaling.knative.dev/: "value" # Configuration in OpenFunction (recommended) -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample @@ -184,11 +183,10 @@ spec: serving: scaleOptions: knative: - autoscaling: : "value" # Alternative approach -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample @@ -218,7 +216,7 @@ spec: dapr.io/app-max-concurrency: "value" # Configuration in OpenFunction (recommended) -apiVersion: core.openfunction.io/v1beta1 +apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-sample @@ -524,7 +522,7 @@ A: Let's take [Java functions](https://github.com/OpenFunction/samples/tree/main - Modify `functions/knative/java/hello-world/function-sample.yaml` according to your environment: ```yaml - apiVersion: core.openfunction.io/v1beta1 + apiVersion: core.openfunction.io/v1beta2 kind: Function metadata: name: function-http-java @@ -533,7 +531,6 @@ A: Let's take [Java functions](https://github.com/OpenFunction/samples/tree/main image: "/sample-java-func:v1" imageCredentials: name: push-secret - port: 8080 # default to 8080 build: builder: /builder-java:v2-18 params: @@ -552,7 +549,9 @@ A: Let's take [Java functions](https://github.com/OpenFunction/samples/tree/main containers: - name: function # DO NOT change this imagePullPolicy: IfNotPresent - runtime: "knative" + triggers: + http: + port: 8080 ``` > If your private mirror repository is insecure, please refer to [Use private image repository in an insecure way](https://openfunction.dev/docs/reference/faq/#q-how-to-use-private-image-repositories-in-openfunction) diff --git a/content/en/openfunction-0.5-architecture.svg b/content/en/openfunction-0.5-architecture.svg deleted file mode 100644 index e4bb9381..00000000 --- a/content/en/openfunction-0.5-architecture.svg +++ /dev/null @@ -1,287 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/content/zh/OpenFunction-architecture.png b/content/zh/OpenFunction-architecture.png deleted file mode 100644 index 3573d1ac..00000000 Binary files a/content/zh/OpenFunction-architecture.png and /dev/null differ diff --git a/content/zh/_index.html b/content/zh/_index.html index 817c64bd..f02668c4 100644 --- a/content/zh/_index.html +++ b/content/zh/_index.html @@ -8,7 +8,7 @@ Welcome to OpenFunction
- + 阅读文档 @@ -23,7 +23,7 @@ {{% blocks/section color="white" %}}
-OpenFunction Architecture +OpenFunction Architecture
@@ -62,4 +62,4 @@

期待您的贡献!

在 [GitHub ](https://github.com/OpenFunction/OpenFunction) 上关注我们,并通过提交 [Pull Request](https://github.com/OpenFunction/OpenFunction/pulls) 开启您的 OpenFunction 旅程。 -{{% /blocks/lead %}} \ No newline at end of file +{{% /blocks/lead %}} diff --git a/content/zh/blog/releases/release_v1.0.0.md b/content/zh/blog/releases/release_v1.0.0.md index 618cc7ea..cb585cd8 100644 --- a/content/zh/blog/releases/release_v1.0.0.md +++ b/content/zh/blog/releases/release_v1.0.0.md @@ -84,7 +84,7 @@ EOF ## 从本地源代码构建函数 -目前,OpenFunction v1.0.0 支持根据本地的源代码构建函数或应用。只需要将本地源代码打包到容器镜像中,并将此镜像推送到容器注册表即可完成构建。以下为操作方法。 +目前,OpenFunction v1.0.0 支持根据本地的源代码构建函数或应用。只需要将本地源代码打包到容器镜像中,并将此镜像推送到容器镜像仓库即可完成构建。以下为操作方法。 假设你的源代码在 `samples` 目录中,你可以根据以下 `Dockerfile` 来构建包含源代码的镜像。 diff --git a/content/zh/blog/releases/release_v1.1.0.md b/content/zh/blog/releases/release_v1.1.0.md new file mode 100644 index 00000000..dbc15eea --- /dev/null +++ b/content/zh/blog/releases/release_v1.1.0.md @@ -0,0 +1,98 @@ +--- +title: "OpenFunction v1.1.0 发布:支持 Dapr 状态管理,重构函数触发器" +linkTitle: "Release v1.1.0" +date: 2023-06-12 +weight: 92 +--- + +[OpenFunction](https://github.com/OpenFunction/OpenFunction) 是一个开源的云原生 FaaS(Function as a Service,函数即服务)平台,旨在帮助开发者专注于业务逻辑的研发。在过去的几个月里,OpenFunction 社区一直在努力工作,为 OpenFunction 1.1.0 版本的发布做准备。今天,我们非常高兴地宣布 OpenFunction 1.1.0 已经发布了!感谢社区各位小伙伴的贡献和反馈! + +OpenFunction 1.1.0 版本带来了两个新的功能:新增 v1beta2 API,支持 Dapr 状态管理。此外,该版本还有多项强化(重构函数触发器等)及 bug 修复,使 OpenFunction 更加稳定和易用。 + +以下是本次版本更新的主要内容: + +## 新增 v1beta2 API + +在此版本中,我们新增了 v1beta2 API,原 v1beta1 API 已弃用,将来会被删除。v1beta2 中有不少重构,你可以在这个 [proposal](https://github.com/OpenFunction/OpenFunction/blob/main/docs/proposals/20230330-support-dapr-state-management.md) 中了解更多细节。 + +## 支持 Dapr 状态管理 + +之前,OpenFunction 支持 Dapr 发布/订阅和绑定构建块,状态管理也是有用的构建块之一,它对于具有状态的函数非常有用。使用状态存储组件,您可以构建具有持久状态的函数,这些函数可以保存和恢复它们的状态。 + +现在你可以在 Function CR 中定义状态存储,OpenFunction 将管理相应的 Dapr 组件。 + +你的函数可以使用简单封装的 Dapr 的状态管理 API 来保存、读取和查询定义的状态存储中的键/值对。 + +## 重构函数触发器 + +之前,我们使用 `runtime: knative` 和 `runtime: async` 来区分同步和异步函数,这会增加学习曲线。实际上,同步和异步函数之间的区别在于触发类型: + +- 同步函数由 HTTP 事件触发,这可以通过指定 `runtime: knative` 来定义。 +- 异步函数由 Dapr 绑定组件或 Dapr 发布者事件触发。要指定异步函数的触发器,必须同时使用 `runtime: async` 和 `inputs`。 + +因此,我们可以使用 `triggers` 来替代 `runtime` 和 `inputs`。 + +`HTTP Trigger` 通过 HTTP 请求触发一个函数。您可以这样定义一个 `HTTP Trigger`: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + triggers: + http: + port: 8080 + route: + rules: + - matches: + - path: + type: PathPrefix + value: /echo +``` + +`Dapr Trigger` 使用 `Dapr bindings` 或 `Dapr pubsub` 的事件触发一个函数。你可以用 `Dapr Trigger` 定义一个函数: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler + namespace: default +spec: + serving: + bindings: + kafka-receiver: + metadata: + - name: brokers + value: kafka-server-kafka-brokers:9092 + - name: authRequired + value: "false" + - name: publishTopic + value: logs + - name: topics + value: logs + - name: consumerGroup + value: logs-handler + type: bindings.kafka + version: v1 + triggers: + dapr: + - name: kafka-receiver + type: bindings.kafka +``` + +## 其他改进和优化 + +- 从网关状态中删除 lastTransitionTime 字段,以防止频繁触发 reconcile。 +- 允许在创建 Dapr 组件时设置作用域。 +- 使用 OpenFunction 策略时,支持设置缓存镜像以提高构建性能。 +- 支持设置 OpenFunction 构建策略的 bash 镜像。 + +以上就是 OpenFunction v1.1.0 的主要功能变化,在此十分感谢各位贡献者的参与和贡献。如果您正在寻找一款高效、灵活的云原生函数开发平台,那么 OpenFunction v1.1.0 绝对不容错过。 + +了解更多关于 OpenFunction 和本次版本更新的信息,欢迎访问我们的官方网站和 Github 页面。 + +- [官网](https://openfunction.dev/):https://openfunction.dev/ +- [Github](https://github.com/OpenFunction/OpenFunction/releases/tag/v1.1.0):https://github.com/OpenFunction/OpenFunction/releases/tag/v1.1.0 \ No newline at end of file diff --git a/content/zh/blog/releases/release_v1.2.0.md b/content/zh/blog/releases/release_v1.2.0.md new file mode 100644 index 00000000..6dfc2d5e --- /dev/null +++ b/content/zh/blog/releases/release_v1.2.0.md @@ -0,0 +1,49 @@ +--- +title: "OpenFunction v1.2.0 发布:集成 KEDA http-addon 作为同步函数运行时" +linkTitle: "Release v1.2.0" +date: 2023-11-01 +weight: 92 +--- + +[OpenFunction](https://github.com/OpenFunction/OpenFunction) 是一个开源的云原生 FaaS(Function as a Service,函数即服务)平台,旨在帮助开发者专注于业务逻辑的研发。我们非常高兴地宣布 OpenFunction 又迎来了一次重要的更新,即 v1.2.0 版本的发布! + +本次更新中,我们继续致力于为开发者们提供更加灵活和强大的工具,并在此基础上加入了一些新的功能点。该版本集成了 KEDA http-addon 作为同步函数运行时;支持在启用 SkyWalking 跟踪时添加环境变量;支持记录构建时间等。此外,还升级了部分组件及修复了多项 bug。 + +以下是该版本更新的主要内容: + +## 集成 KEDA http-addon 作为同步函数运行时 + +KEDA http-addon 是一个 KEDA 的附加组件,它可以根据 HTTP 流量的变化自动地调整 HTTP 服务器的规模(包括从零开始扩容和缩容到零)。 + +KEDA http-addon 的工作原理是,它会在 Kubernetes 集群中创建一个名为 Interceptor 的组件,用来接收所有的 HTTP 请求,并将请求转发给目标应用。同时,它会将请求队列的长度报告给一个名为 External Scaler 的组件,用来触发 KEDA 的自动扩缩容机制。这样,你的 HTTP 应用就可以根据实际的流量需求动态地调整副本数。 + +在 OpenFunction v1.2.0 版本中,我们集成了 KEDA http-addon 作为同步函数运行时的一种选择。这意味着,你可以使用 OpenFunction 来创建和管理基于 HTTP 的函数,并利用 KEDA http-addon 的能力来实现高效且灵活的弹性伸缩。你只需在创建 Function 资源时指定 `serving.triggers[*].http.engine` 的值为 keda ,并且在 `serving.scaleOptions` 中配置 `keda.httpScaledObject` 相关参数,就可以部署和运行你的 HTTP 函数了。 + +## 支持在启用 SkyWalking 跟踪时添加环境变量 + +SkyWalking 是一个开源的应用性能监控(APM)系统,它可以帮助你观察和分析你的应用在不同环境中的运行状况。OpenFunction 支持在部署函数时启用 SkyWalking 跟踪,以便你可以更好地理解和优化你的函数性能。 + +在 OpenFunction v1.2.0 版本中,我们增加了一个新的功能,即支持在启用 SkyWalking 跟踪时添加环境变量。这样,你可以在创建 Function 资源时指定一些自定义的环境变量来控制 SkyWalking 的一些配置参数。这些环境变量会被传递给函数容器,并影响 SkyWalking 的采集和上报行为。 + +## 当 Function、Builder 和 Serving 状态变化时支持记录事件 + +事件(Event)是 Kubernetes 中一种重要的资源类型,它可以记录集群中发生的一些重要或者有趣的事情。事件可以帮助用户和开发者了解集群中资源的状态变化和异常情况,并采取相应的措施。 + +在 OpenFunction v1.2.0 版本中,我们支持当 Function、Builder 和 Serving 状态变化时记录事件。这样,你可以通过查看事件来获取更多关于函数构建和运行过程中发生的事情的信息。例如,你可以看到函数构建开始、结束、失败等事件;函数运行时创建、更新、删除等事件。 + +## 其他的改进和优化 + +除了上述的主要变化,该版本还有以下更改和增强: + +- 升级了 KEDA 到 v2.10.1 ,HPA(自动伸缩)API 版本到 v2 ,提高了稳定性和兼容性 +- 支持记录构建时间,以便你可以了解函数构建的耗时情况 +- 调整了 CI 流程,修复了一些小问题 +- 修复了一个在 keda http-addon 运行时中的 bug ,该 bug 会导致函数无法正常运行 +- 升级了 charts 中的一些组件,包括 keda ,dapr 和 contour ,以保持最新的版本和功能 + +以上就是 OpenFunction v1.2.0 的主要功能变化,在此十分感谢各位贡献者的参与和贡献。 + +了解更多关于 OpenFunction 和本次版本更新的信息,欢迎访问我们的官方网站和 Github 页面。 + +- [官网](https://openfunction.dev/):https://openfunction.dev/ +- [Github](https://github.com/OpenFunction/OpenFunction/releases/tag/v1.2.0):https://github.com/OpenFunction/OpenFunction/releases/tag/v1.2.0 \ No newline at end of file diff --git a/content/zh/docs/_index.md b/content/zh/docs/_index.md index ce40b4aa..7b018ffa 100644 --- a/content/zh/docs/_index.md +++ b/content/zh/docs/_index.md @@ -1,14 +1,13 @@ --- -title: "欢迎访问 OpenFunction" +title: "v1.2 (latest)" linkTitle: "文档" weight: 20 --- -[OpenFunction](https://github.com/OpenFunction/OpenFunction.git) 是一个云原生、开源的 FaaS(函数即服务)框架,旨在让开发人员专注于他们的开发意图,而不必关心底层运行环境和基础设施。用户只需提交一段代码,就可以生成事件驱动的、动态伸缩的 Serverless 工作负载。 -{{% alert title="Note" color="success" %}} +欢迎来到 OpenFunction 的文档站点! -当前版本:**v0.4.0** +{{% alert title="什么是 OpenFunction?" color="success" %}} -OpenFunction 在 [github.com/OpenFunction/samples](https://github.com/OpenFunction/samples.git) 上提供了一些案例,供开发者实践、上手。 +[OpenFunction](https://github.com/OpenFunction/OpenFunction.git) 是一个云原生的开源 FaaS(函数即服务)平台,旨在让用户专注于业务逻辑,而不必担心底层的运行环境和基础设施。用户只需要以函数的形式提交与业务相关的源代码。 {{% /alert %}} \ No newline at end of file diff --git a/content/zh/docs/best-practices/_index.md b/content/zh/docs/best-practices/_index.md index c43ac3d0..fe0b61ba 100644 --- a/content/zh/docs/best-practices/_index.md +++ b/content/zh/docs/best-practices/_index.md @@ -2,6 +2,6 @@ title: "最佳实践" linkTitle: "最佳实践" weight: 5000 -description: > - 了解使用 OpenFunction 的最佳实践。 +description: --- +要获取更多使用 OpenFunction 的示例,请参考 [示例仓库](https://github.com/OpenFunction/samples),例如 [基于队列深度的服务自动扩展](https://github.com/OpenFunction/samples/blob/main/functions/async/pubsub/README.md)。 diff --git a/content/zh/docs/best-practices/interact-with-dapr-output-binding.md b/content/zh/docs/best-practices/interact-with-dapr-output-binding.md new file mode 100644 index 00000000..89ce323c --- /dev/null +++ b/content/zh/docs/best-practices/interact-with-dapr-output-binding.md @@ -0,0 +1,346 @@ +--- +title: "创建一个基于 Knative 的函数以通过 Dapr 组件与中间件交互" +linkTitle: "创建一个基于 Knative 的函数以通过 Dapr 组件与中间件交互" +weight: 5200 +description: > + 了解如何创建一个基于 Knative 的函数,通过 Dapr 组件与中间件交互。 +--- + +本文档描述了如何创建一个基于 Knative 的函数,通过 Dapr 组件与中间件交互。 + +## 概述 + +与异步函数类似,基于 Knative 运行时的函数可以通过 Dapr 组件与中间件交互。本文档使用两个函数,`function-front` 和 `kafka-input`,进行演示。 + +以下图表说明了这些函数之间的关系。 + +![](/images/docs/en/best-practices/interact-with-dapr-output-binding/knative-dapr.png) + +## 先决条件 + +- 您已经[安装了 OpenFunction](../../getting-started/installation/)。 +- 您已经[创建了一个 secret](../../getting-started/quickstarts/prerequisites/)。 + +## 创建 Kafka 服务器和主题 + +1. 运行以下命令,在默认命名空间中安装 [strimzi-kafka-operator](https://github.com/strimzi/strimzi-kafka-operator)。 + + ```shell + helm repo add strimzi https://strimzi.io/charts/ + helm install kafka-operator -n default strimzi/strimzi-kafka-operator + ``` + +2. 使用以下内容创建一个文件 `kafka.yaml`。 + + ```yaml + apiVersion: kafka.strimzi.io/v1beta2 + kind: Kafka + metadata: + name: kafka-server + namespace: default + spec: + kafka: + version: 3.3.1 + replicas: 1 + listeners: + - name: plain + port: 9092 + type: internal + tls: false + - name: tls + port: 9093 + type: internal + tls: true + config: + offsets.topic.replication.factor: 1 + transaction.state.log.replication.factor: 1 + transaction.state.log.min.isr: 1 + default.replication.factor: 1 + min.insync.replicas: 1 + inter.broker.protocol.version: "3.1" + storage: + type: ephemeral + zookeeper: + replicas: 1 + storage: + type: ephemeral + entityOperator: + topicOperator: {} + userOperator: {} + --- + apiVersion: kafka.strimzi.io/v1beta2 + kind: KafkaTopic + metadata: + name: sample-topic + namespace: default + labels: + strimzi.io/cluster: kafka-server + spec: + partitions: 10 + replicas: 1 + config: + retention.ms: 7200000 + segment.bytes: 1073741824 + ``` + +3. 运行以下命令,在默认命名空间中部署一个名为 `kafka-server` 的 1 副本 Kafka 服务器和一个名为 `sample-topic` 的 1 副本 Kafka 主题。 + + ```shell + kubectl apply -f kafka.yaml + ``` + +4. 运行以下命令,检查 pod 状态,等待 Kafka 和 Zookeeper 启动并运行。 + + ```shell + $ kubectl get po + NAME READY STATUS RESTARTS AGE + kafka-server-entity-operator-568957ff84-nmtlw 3/3 Running 0 8m42s + kafka-server-kafka-0 1/1 Running 0 9m13s + kafka-server-zookeeper-0 1/1 Running 0 9m46s + strimzi-cluster-operator-687fdd6f77-cwmgm 1/1 Running 0 11m + ``` + +5. 运行以下命令,查看 Kafka 集群的元数据。 + + ```shell + # 启动一个实用工具 pod。 + $ kubectl run utils --image=arunvelsriram/utils -i --tty --rm + # 检查 Kafka 集群的元数据。 + $ kafkacat -L -b kafka-server-kafka-brokers:9092 + ``` + +## 创建函数 + +1. 使用以下示例 YAML 文件创建一个清单 `kafka-input.yaml`,并修改 `spec.image` 的值以设置您自己的镜像仓库地址。字段 `spec.serving.inputs` 定义了一个指向 Kafka 服务器的 Dapr 组件的输入源。这意味着 `kafka-input` 函数将由 Kafka 服务器的主题 `sample-topic` 中的事件驱动。 + + ```yaml + apiVersion: core.openfunction.io/v1beta2 + kind: Function + metadata: + name: kafka-input + spec: + version: "v1.0.0" + image: /kafka-input:latest + imageCredentials: + name: push-secret + build: + builder: openfunction/builder-go:latest + env: + FUNC_NAME: "HandleKafkaInput" + FUNC_CLEAR_SOURCE: "true" + srcRepo: + url: "https://github.com/OpenFunction/samples.git" + sourceSubPath: "functions/async/bindings/kafka-input" + revision: "main" + serving: + scaleOptions: + minReplicas: 0 + maxReplicas: 10 + keda: + triggers: + - type: kafka + metadata: + topic: sample-topic + bootstrapServers: kafka-server-kafka-brokers.default.svc:9092 + consumerGroup: kafka-input + lagThreshold: "20" + scaledObject: + pollingInterval: 15 + cooldownPeriod: 60 + advanced: + horizontalPodAutoscalerConfig: + behavior: + scaleDown: + stabilizationWindowSeconds: 45 + policies: + - type: Percent + value: 50 + periodSeconds: 15 + scaleUp: + stabilizationWindowSeconds: 0 + + triggers: + dapr: + - name: target-topic + type: bindings.kafka + bindings: + target-topic: + type: bindings.kafka + version: v1 + metadata: + - name: brokers + value: "kafka-server-kafka-brokers:9092" + - name: topics + value: "sample-topic" + - name: consumerGroup + value: "kafka-input" + - name: publishTopic + value: "sample-topic" + - name: authRequired + value: "false" + template: + containers: + - name: function + imagePullPolicy: Always + ``` + +2. 运行以下命令创建函数 `kafka-input`。 + + ```shell + kubectl apply -f kafka-input.yaml + ``` + +3. 使用以下示例 YAML 文件创建一个清单 `function-front.yaml`,并修改 `spec.image` 的值以设置您自己的镜像仓库地址。 + + ```yaml + apiVersion: core.openfunction.io/v1beta2 + kind: Function + metadata: + name: function-front + spec: + version: "v1.0.0" + image: "/sample-knative-dapr:latest" + imageCredentials: + name: push-secret + build: + builder: openfunction/builder-go:latest + env: + FUNC_NAME: "ForwardToKafka" + FUNC_CLEAR_SOURCE: "true" + srcRepo: + url: "https://github.com/OpenFunction/samples.git" + sourceSubPath: "functions/knative/with-output-binding" + revision: "main" + serving: + hooks: + pre: + - plugin-custom + - plugin-example + post: + - plugin-example + - plugin-custom + scaleOptions: + minReplicas: 0 + maxReplicas: 5 + outputs: + - dapr: + name: kafka-server + operation: "create" + bindings: + kafka-server: + type: bindings.kafka + version: v1 + metadata: + - name: brokers + value: "kafka-server-kafka-brokers:9092" + - name: authRequired + value: "false" + - name: publishTopic + value: "sample-topic" + - name: topics + value: "sample-topic" + - name: consumerGroup + value: "function-front" + template: + containers: + - name: function + imagePullPolicy: Always + ``` + + + {{% alert title="注意" color="success" %}} + + `metadata.plugins.pre` 定义了在执行用户函数之前需要调用的插件的顺序。`metadata.plugins.post` 定义了在执行用户函数之后需要调用的插件的顺序。有关这两个插件的逻辑以及执行插件后的效果的更多信息,请参阅 [插件机制](https://github.com/OpenFunction/samples/blob/main/functions-framework/README.md#plugin-mechanism)。 + + {{% /alert %}} + +4. 在清单中,`spec.serving.outputs` 定义了一个指向 Kafka 服务器的 Dapr 组件的输出。这使您可以在 `function-front` 函数中向输出 `target` 发送自定义内容。 + + ```go + func Sender(ctx ofctx.Context, in []byte) (ofctx.Out, error) { + ... + _, err := ctx.Send("target", greeting) + ... + } + ``` + +5. 运行以下命令创建函数 `function-front`。 + + ```shell + kubectl apply -f function-front.yaml + ``` + +## 检查结果 + +1. 运行以下命令查看函数的状态。 + + ```shell + $ kubectl get functions.core.openfunction.io + + NAME BUILDSTATE SERVINGSTATE BUILDER SERVING URL AGE + function-front Succeeded Running builder-bhbtk serving-vc6jw https://openfunction.io/default/function-front 2m41s + kafka-input Succeeded Running builder-dprfd serving-75vrt 2m21s + ``` + + {{% alert title="注意" color="success" %}} + + `URL`,由 OpenFunction Domain 提供,是可以访问的地址。要通过此 URL 地址访问函数,您需要确保 DNS 可以解析此地址。 + + {{% /alert %}} + +2. 运行以下命令在集群中创建一个用于访问函数的 pod。 + + ```shell + kubectl run curl --image=radial/busyboxplus:curl -i --tty --rm + ``` + +3. 运行以下命令通过 `URL` 访问函数。 + + ```shell + [ root@curl:/ ]$ curl -d '{"message":"Awesome OpenFunction!"}' -H "Content-Type: application/json" -X POST http://openfunction.io.svc.cluster.local/default/function-front + ``` + +4. 运行以下命令查看 `function-front` 的日志。 + + ```shell + kubectl logs -f \ + $(kubectl get po -l \ + openfunction.io/serving=$(kubectl get functions function-front -o jsonpath='{.status.serving.resourceRef}') \ + -o jsonpath='{.items[0].metadata.name}') \ + function + ``` + + 输出如下所示。 + + ```shell + dapr client initializing for: 127.0.0.1:50001 + I0125 06:51:55.584973 1 framework.go:107] Plugins for pre-hook stage: + I0125 06:51:55.585044 1 framework.go:110] - plugin-custom + I0125 06:51:55.585052 1 framework.go:110] - plugin-example + I0125 06:51:55.585057 1 framework.go:115] Plugins for post-hook stage: + I0125 06:51:55.585062 1 framework.go:118] - plugin-custom + I0125 06:51:55.585067 1 framework.go:118] - plugin-example + I0125 06:51:55.585179 1 knative.go:46] Knative Function serving http: listening on port 8080 + 2022/01/25 06:52:02 http - Data: {"message":"Awesome OpenFunction!"} + I0125 06:52:02.246450 1 plugin-example.go:83] the sum is: 2 + ``` + +5. 运行以下命令查看 `kafka-input` 的日志。 + + ```shell + kubectl logs -f \ + $(kubectl get po -l \ + openfunction.io/serving=$(kubectl get functions kafka-input -o jsonpath='{.status.serving.resourceRef}') \ + -o jsonpath='{.items[0].metadata.name}') \ + function + ``` + + 输出如下所示。 + + ```shell + dapr client initializing for: 127.0.0.1:50001 + I0125 06:35:28.332381 1 framework.go:107] Plugins for pre-hook stage: + I0125 06:35:28.332863 1 framework.go:115] Plugins for post-hook stage: + I0125 06:35:28.333749 1 async.go:39] Async Function serving grpc: listening on port 8080 + message from Kafka '{Awesome OpenFunction!}' + ``` diff --git a/content/zh/docs/best-practices/logs-handler-function.md b/content/zh/docs/best-practices/logs-handler-function.md new file mode 100644 index 00000000..ee01d1ae --- /dev/null +++ b/content/zh/docs/best-practices/logs-handler-function.md @@ -0,0 +1,204 @@ +--- +title: "Elastic 日志告警" +linkTitle: "Elastic 日志告警" +weight: 5400 +description: > + 学习如何创建一个异步函数来查找错误日志。 +--- + +本文档描述了如何创建一个异步函数来查找错误日志。 + +## 概述 + +本文档使用一个异步函数来分析 Kafka 中的日志流,以找出错误日志。异步函数将然后向 Slack 发送告警。以下图表说明了整个工作流程。 + +![](/images/docs/en/best-practices/logs-handler-function/elastic-log-processing.png) + +## 先决条件 + +- 您已经[安装了 OpenFunction](../../getting-started/installation/)。 +- 您已经[创建了一个 secret](../../getting-started/quickstarts/prerequisites/)。 + +## 创建 Kafka 服务器和主题 + +1. 运行以下命令在默认命名空间中安装 [strimzi-kafka-operator](https://github.com/strimzi/strimzi-kafka-operator)。 + + ```shell + helm repo add strimzi https://strimzi.io/charts/ + helm install kafka-operator -n default strimzi/strimzi-kafka-operator + ``` + +2. 使用以下内容创建一个文件 `kafka.yaml`。 + + ```yaml + apiVersion: kafka.strimzi.io/v1beta2 + kind: Kafka + metadata: + name: kafka-logs-receiver + namespace: default + spec: + kafka: + version: 3.3.1 + replicas: 1 + listeners: + - name: plain + port: 9092 + type: internal + tls: false + - name: tls + port: 9093 + type: internal + tls: true + config: + offsets.topic.replication.factor: 1 + transaction.state.log.replication.factor: 1 + transaction.state.log.min.isr: 1 + default.replication.factor: 1 + min.insync.replicas: 1 + inter.broker.protocol.version: "3.1" + storage: + type: ephemeral + zookeeper: + replicas: 1 + storage: + type: ephemeral + entityOperator: + topicOperator: {} + userOperator: {} + --- + apiVersion: kafka.strimzi.io/v1beta2 + kind: KafkaTopic + metadata: + name: logs + namespace: default + labels: + strimzi.io/cluster: kafka-logs-receiver + spec: + partitions: 10 + replicas: 1 + config: + retention.ms: 7200000 + segment.bytes: 1073741824 + ``` + +3. 运行以下命令在默认命名空间中部署一个名为 `kafka-logs-receiver` 的 1 副本 Kafka 服务器和一个名为 `logs` 的 1 副本 Kafka 主题。 + + ```shell + kubectl apply -f kafka.yaml + ``` + +4. 运行以下命令检查 pod 状态,等待 Kafka 和 Zookeeper 启动并运行。 + + ```shell + $ kubectl get po + NAME READY STATUS RESTARTS AGE + kafka-logs-receiver-entity-operator-57dc457ccc-tlqqs 3/3 Running 0 8m42s + kafka-logs-receiver-kafka-0 1/1 Running 0 9m13s + kafka-logs-receiver-zookeeper-0 1/1 Running 0 9m46s + strimzi-cluster-operator-687fdd6f77-cwmgm 1/1 Running 0 11m + ``` + +5. 运行以下命令查看 Kafka 集群的元数据。 + + ```shell + # 启动一个实用工具 pod。 + $ kubectl run utils --image=arunvelsriram/utils -i --tty --rm + # 检查 Kafka 集群的元数据。 + $ kafkacat -L -b kafka-logs-receiver-kafka-brokers:9092 + ``` + +## 创建日志处理函数 + +1. 使用以下示例 YAML 文件创建一个清单 `logs-handler-function.yaml`,并修改 `spec.image` 的值以设置您自己的镜像仓库地址。 + +```yaml + apiVersion: core.openfunction.io/v1beta2 + kind: Function + metadata: + name: logs-async-handler + namespace: default + spec: + build: + builder: openfunction/builder-go:latest + env: + FUNC_CLEAR_SOURCE: "true" + FUNC_NAME: LogsHandler + srcRepo: + revision: main + sourceSubPath: functions/async/logs-handler-function/ + url: https://github.com/OpenFunction/samples.git + image: openfunctiondev/logs-async-handler:v1 + imageCredentials: + name: push-secret + serving: + bindings: + kafka-receiver: + metadata: + - name: brokers + value: kafka-server-kafka-brokers:9092 + - name: authRequired + value: "false" + - name: publishTopic + value: logs + - name: topics + value: logs + - name: consumerGroup + value: logs-handler + type: bindings.kafka + version: v1 + notification-manager: + metadata: + - name: url + value: http://notification-manager-svc.kubesphere-monitoring-system.svc.cluster.local:19093/api/v2/alerts + type: bindings.http + version: v1 + outputs: + - dapr: + name: notification-manager + operation: post + type: bindings.http + scaleOptions: + keda: + scaledObject: + advanced: + horizontalPodAutoscalerConfig: + behavior: + scaleDown: + policies: + - periodSeconds: 15 + type: Percent + value: 50 + stabilizationWindowSeconds: 45 + scaleUp: + stabilizationWindowSeconds: 0 + cooldownPeriod: 60 + pollingInterval: 15 + triggers: + - metadata: + bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092 + consumerGroup: logs-handler + lagThreshold: "20" + topic: logs + type: kafka + maxReplicas: 10 + minReplicas: 0 + template: + containers: + - imagePullPolicy: IfNotPresent + name: function + triggers: + dapr: + - name: kafka-receiver + type: bindings.kafka + workloadType: Deployment + version: v2.0.0 + workloadRuntime: OCIContainer +``` + +2. 运行以下命令创建函数 `logs-async-handler`。 + + ```shell + kubectl apply -f logs-handler-function.yaml + ``` + +3. 日志处理函数将由 Kafka 中 logs 主题的消息触发。 diff --git a/content/zh/docs/concepts/Events/_index.md b/content/zh/docs/concepts/Events/_index.md new file mode 100644 index 00000000..a277a45b --- /dev/null +++ b/content/zh/docs/concepts/Events/_index.md @@ -0,0 +1,7 @@ +--- +title: "OpenFunction 事件" +linkTitle: "OpenFunction 事件" +weight: 4500 +description: +--- + diff --git a/content/zh/docs/concepts/Events/clustereventbus.md b/content/zh/docs/concepts/Events/clustereventbus.md new file mode 100644 index 00000000..d51f6b62 --- /dev/null +++ b/content/zh/docs/concepts/Events/clustereventbus.md @@ -0,0 +1,52 @@ +--- +title: "使用 ClusterEventBus" +linkTitle: "使用 ClusterEventBus" +weight: 4540 +description: +--- + +本文档描述了如何使用 ClusterEventBus。 + +## 先决条件 + +您已完成 [使用 EventBus 和 Trigger](../event-bus-and-trigger) 中描述的步骤。 + +## 使用 ClusterEventBus + +1. 使用以下内容创建一个 ClusterEventBus 配置文件(例如,`clustereventbus.yaml`)。 + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: ClusterEventBus + metadata: + name: default + spec: + natsStreaming: + natsURL: "nats://nats.default:4222" + natsStreamingClusterID: "stan" + subscriptionType: "queue" + durableSubscriptionName: "ImDurable" + ``` + +2. 运行以下命令删除 EventBus。 + + ```shell + kubectl delete eventbus.events.openfunction.io default + ``` + +3. 运行以下命令应用配置文件。 + + ```shell + kubectl apply -f clustereventbus.yaml + ``` + +4. 运行以下命令检查结果。 + + ```shell + $ kubectl get eventbus.events.openfunction.io + No resources found in default namespace. + + $ kubectl get clustereventbus.events.openfunction.io + NAME AGE + default 21s + ``` \ No newline at end of file diff --git a/content/zh/docs/concepts/Events/event-bus-and-trigger.md b/content/zh/docs/concepts/Events/event-bus-and-trigger.md new file mode 100644 index 00000000..ffc11d62 --- /dev/null +++ b/content/zh/docs/concepts/Events/event-bus-and-trigger.md @@ -0,0 +1,293 @@ +--- +title: "使用 EventBus 和 Trigger" +linkTitle: "使用 EventBus 和 Trigger" +weight: 4520 +description: +--- + +本文档提供了一个示例,说明如何使用 EventBus 和 Trigger。 + +## 先决条件 + +- 您需要创建一个作为目标函数的函数以被触发。有关更多详细信息,请参见 [创建函数](../event-source#create-a-function)。 +- 您需要创建一个 Kafka 集群。有关更多详细信息,请参见 [创建 Kafka 集群](../event-source#create-a-kafka-cluster)。 + +## 部署 NATS 流服务器 + +运行以下命令部署 NATS 流服务器。本文档使用 `nats://nats.default:4222` 作为 NATS 流服务器的访问地址,`stan` 作为集群 ID。有关更多信息,请参见 [NATS Streaming (STAN)](https://github.com/nats-io/k8s/tree/main/helm/charts/stan#tldr)。 + +```shell +helm repo add nats https://nats-io.github.io/k8s/helm/charts/ +helm install nats nats/nats +helm install stan nats/stan --set stan.nats.url=nats://nats:4222 +``` + +## 创建 OpenFuncAsync 运行时函数 + +1. 使用以下内容创建目标函数的配置文件(例如,`openfuncasync-function.yaml`),该函数由 Trigger CRD 触发并打印接收到的消息。 + + ```yaml + apiVersion: core.openfunction.io/v1beta2 + kind: Function + metadata: + name: trigger-target + spec: + version: "v1.0.0" + image: openfunctiondev/v1beta1-trigger-target:latest + serving: + scaleOptions: + keda: + scaledObject: + pollingInterval: 15 + minReplicaCount: 0 + maxReplicaCount: 10 + cooldownPeriod: 30 + triggers: + - type: stan + metadata: + natsServerMonitoringEndpoint: "stan.default.svc.cluster.local:8222" + queueGroup: "grp1" + durableName: "ImDurable" + subject: "metrics" + lagThreshold: "10" + triggers: + dapr: + - name: eventbus + topic: metrics + pubsub: + eventbus: + type: pubsub.natsstreaming + version: v1 + metadata: + - name: natsURL + value: "nats://nats.default:4222" + - name: natsStreamingClusterID + value: "stan" + - name: subscriptionType + value: "queue" + - name: durableSubscriptionName + value: "ImDurable" + - name: consumerID + value: "grp1" + ``` + +2. 运行以下命令应用配置文件。 + + ```shell + kubectl apply -f openfuncasync-function.yaml + ``` + +## 创建 EventBus 和 EventSource + +1. 使用以下内容创建 EventBus 的配置文件(例如,`eventbus.yaml`)。 + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: EventBus + metadata: + name: default + spec: + natsStreaming: + natsURL: "nats://nats.default:4222" + natsStreamingClusterID: "stan" + subscriptionType: "queue" + durableSubscriptionName: "ImDurable" + ``` + +2. 使用以下内容创建 EventSource 的配置文件(例如,`eventsource.yaml`)。 + + {{% alert title="注意" color="success" %}} + + 通过 `spec.eventBus` 设置事件总线的名称。 + + {{% /alert %}} + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: EventSource + metadata: + name: my-eventsource + spec: + logLevel: "2" + eventBus: "default" + kafka: + sample-two: + brokers: "kafka-server-kafka-brokers.default.svc.cluster.local:9092" + topic: "events-sample" + authRequired: false + ``` + +3. 运行以下命令应用这些配置文件。 + + ```shell + kubectl apply -f eventbus.yaml + kubectl apply -f eventsource.yaml + ``` + +4. 运行以下命令检查结果。 + + ```shell + $ kubectl get eventsources.events.openfunction.io + NAME EVENTBUS SINK STATUS + my-eventsource default Ready + + $ kubectl get eventbus.events.openfunction.io + NAME AGE + default 62m + + $ kubectl get components + NAME AGE + serving-9689d-component-ebfes-my-eventsource-cmcbw 46m + serving-9689d-component-esc-kafka-sample-two-l99cg 46m + serving-dxrhd-component-eventbus-t65q7 13m + serving-zwlj4-component-ebft-my-trigger-4925n 100s + ``` + + {{% alert title="注意" color="success" %}} + + 在使用事件总线的情况下,EventSource 控制器的工作流程描述如下: + + 1. 创建一个名为 `my-eventsource` 的 EventSource 自定义资源。 + 2. 检索并重新组织 EventBus 的配置,包括 EventBus 名称(在此示例中为 `default`)和与 EventBus 关联的 Dapr 组件的名称。 + 3. 创建一个名为 `serving-xxxxx-component-ebfes-my-eventsource-xxxxx` 的 Dapr 组件,使 EventSource 能够与事件总线关联。 + 4. 创建一个名为 `serving-xxxxx-component-esc-kafka-sample-two-xxxxx` 的 Dapr 组件,使 EventSource 能够与事件源关联。 + 5. 创建一个名为 `serving-xxxxx-deployment-v100-xxxxx` 的 Deployment,用于处理事件。 + + {{% /alert %}} + +## 创建 Trigger + +1. 使用以下内容创建 Trigger 的配置文件(例如,`trigger.yaml`)。 + + {{% alert title="注意" color="success" %}} + + - 通过 `spec.eventBus` 设置与 Trigger 关联的事件总线。 + - 通过 `spec.inputs` 设置事件输入源。 + - 这是一个简单的触发器,它从名为 `default` 的 EventBus 中收集事件。当它从 EventSource `my-eventsource` 中检索到一个 `sample-two` 事件时,它触发一个名为 `function-sample-serving-qrdx8-ksvc-fwml8` 的 Knative 服务,并同时将事件发送到事件总线的 `metrics` 主题。 + + {{% /alert %}} + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: Trigger + metadata: + name: my-trigger + spec: + logLevel: "2" + eventBus: "default" + inputs: + inputDemo: + eventSource: "my-eventsource" + event: "sample-two" + subscribers: + - condition: inputDemo + topic: "metrics" + ``` + +2. 运行以下命令应用配置文件。 + + ```shell + kubectl apply -f trigger.yaml + ``` + +3. 运行以下命令检查结果。 + + ```shell + $ kubectl get triggers.events.openfunction.io + NAME EVENTBUS STATUS + my-trigger default Ready + + $ kubectl get eventbus.events.openfunction.io + NAME AGE + default 62m + + $ kubectl get components + NAME AGE + serving-9689d-component-ebfes-my-eventsource-cmcbw 46m + serving-9689d-component-esc-kafka-sample-two-l99cg 46m + serving-dxrhd-component-eventbus-t65q7 13m + serving-zwlj4-component-ebft-my-trigger-4925n 100s + ``` + + {{% alert title="注意" color="success" %}} + + 在使用事件总线的情况下,Trigger 控制器的工作流程如下: + + 1. 创建一个名为 `my-trigger` 的 Trigger 自定义资源。 + 2. 检索并重新组织 EventBus 的配置,包括 EventBus 名称(在此示例中为 `default`)和与 EventBus 关联的 Dapr 组件的名称。 + 3. 创建一个名为 `serving-xxxxx-component-ebft-my-trigger-xxxxx` 的 Dapr 组件,使 Trigger 能够与事件总线关联。 + 4. 创建一个名为 `serving-xxxxx-deployment-v100-xxxxx` 的 Deployment,用于处理触发任务。 + + {{% /alert %}} + +## 创建事件生产者 + +1. 使用以下内容创建事件生产者配置文件(例如,`events-producer.yaml`)。 + + ```yaml + apiVersion: core.openfunction.io/v1beta2 + kind: Function + metadata: + name: events-producer + spec: + version: "v1.0.0" + image: openfunctiondev/v1beta1-bindings:latest + serving: + template: + containers: + - name: function + imagePullPolicy: Always + triggers: + dapr: + - name: cron + type: bindings.cron + outputs: + - dapr: + name: 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: "events-sample" + - name: consumerGroup + value: "bindings-with-output" + - name: publishTopic + value: "events-sample" + - name: authRequired + value: "false" + ``` + +2. 运行以下命令应用配置文件。 + + ```shell + kubectl apply -f events-producer.yaml + ``` + +3. 运行以下命令观察目标异步函数的变化。 + + ```shell + $ kubectl get functions.core.openfunction.io + NAME BUILDSTATE SERVINGSTATE BUILDER SERVING URL AGE + trigger-target Skipped Running serving-dxrhd 20m + + $ kubectl get po --watch + NAME READY STATUS RESTARTS AGE + serving-dxrhd-deployment-v100-xmrkq-785cb5f99-6hclm 0/2 Pending 0 0s + serving-dxrhd-deployment-v100-xmrkq-785cb5f99-6hclm 0/2 Pending 0 0s + serving-dxrhd-deployment-v100-xmrkq-785cb5f99-6hclm 0/2 ContainerCreating 0 0s + serving-dxrhd-deployment-v100-xmrkq-785cb5f99-6hclm 0/2 ContainerCreating 0 2s + serving-dxrhd-deployment-v100-xmrkq-785cb5f99-6hclm 1/2 Running 0 4s + serving-dxrhd-deployment-v100-xmrkq-785cb5f99-6hclm 1/2 Running 0 4s + serving-dxrhd-deployment-v100-xmrkq-785cb5f99-6hclm 2/2 Running 0 4s + ``` \ No newline at end of file diff --git a/content/zh/docs/concepts/Events/event-source.md b/content/zh/docs/concepts/Events/event-source.md new file mode 100644 index 00000000..01c126f1 --- /dev/null +++ b/content/zh/docs/concepts/Events/event-source.md @@ -0,0 +1,269 @@ +--- +title: "使用 EventSource" +linkTitle: "使用 EventSource" +weight: 4510 +description: +--- + +本文档提供了一个示例,说明如何使用事件源触发同步函数。 + +在此示例中,定义了一个 EventSource,用于同步调用,使用事件源(一个 Kafka 服务器)作为函数(一个 Knative 服务)的输入绑定。当事件源生成事件时,它将通过 `spec.sink` 配置调用函数并获取同步返回。 + +## 创建函数 + +使用以下内容创建一个函数作为 EventSource Sink。有关如何创建函数的更多信息,请参见 [创建同步函数](../../../getting-started/quickstarts/sync-functions)。 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: sink +spec: + version: "v1.0.0" + image: "openfunction/sink-sample:latest" + serving: + template: + containers: + - name: function + imagePullPolicy: Always + triggers: + http: + port: 8080 +``` + +创建函数后,运行以下命令获取函数的 URL。 + +{{% alert title="注意" color="success" %}} + +在函数的 URL 中,`openfunction` 是 Kubernetes 服务的名称,`io` 是运行 Kubernetes 服务的命名空间。有关更多信息,请参见 [服务的命名空间](https://kubernetes.io/docs/concepts/services-networking/dns-pod-service/#namespaces-of-services)。 + +{{% /alert %}} + +```shell +$ kubectl get functions.core.openfunction.io +NAME BUILDSTATE SERVINGSTATE BUILDER SERVING URL AGE +sink Skipped Running serving-4x5wh https://openfunction.io/default/sink 13s +``` + +## 创建 Kafka 集群 + +1. 运行以下命令在默认命名空间中安装 [strimzi-kafka-operator](https://github.com/strimzi/strimzi-kafka-operator)。 + + ```shell + helm repo add strimzi https://strimzi.io/charts/ + helm install kafka-operator -n default strimzi/strimzi-kafka-operator + ``` + +2. 使用以下内容创建一个文件 `kafka.yaml`。 + + ```yaml + apiVersion: kafka.strimzi.io/v1beta2 + kind: Kafka + metadata: + name: kafka-server + namespace: default + spec: + kafka: + version: 3.3.1 + replicas: 1 + listeners: + - name: plain + port: 9092 + type: internal + tls: false + - name: tls + port: 9093 + type: internal + tls: true + config: + offsets.topic.replication.factor: 1 + transaction.state.log.replication.factor: 1 + transaction.state.log.min.isr: 1 + default.replication.factor: 1 + min.insync.replicas: 1 + inter.broker.protocol.version: "3.1" + storage: + type: ephemeral + zookeeper: + replicas: 1 + storage: + type: ephemeral + entityOperator: + topicOperator: {} + userOperator: {} + --- + apiVersion: kafka.strimzi.io/v1beta2 + kind: KafkaTopic + metadata: + name: events-sample + namespace: default + labels: + strimzi.io/cluster: kafka-server + spec: + partitions: 10 + replicas: 1 + config: + retention.ms: 7200000 + segment.bytes: 1073741824 + ``` + +3. 运行以下命令在默认命名空间中部署一个名为 `kafka-server` 的 1-replica Kafka 服务器和一个名为 `events-sample` 的 1-replica Kafka 主题。此命令创建的 Kafka 和 Zookeeper 集群的存储类型为 **ephemeral**,并使用 emptyDir 进行演示。 + + ```shell + kubectl apply -f kafka.yaml + ``` + +4. 运行以下命令检查 pod 状态,并等待 Kafka 和 Zookeeper 启动并运行。 + + ```shell + $ kubectl get po + NAME READY STATUS RESTARTS AGE + kafka-server-entity-operator-568957ff84-nmtlw 3/3 Running 0 8m42s + kafka-server-kafka-0 1/1 Running 0 9m13s + kafka-server-zookeeper-0 1/1 Running 0 9m46s + strimzi-cluster-operator-687fdd6f77-cwmgm 1/1 Running 0 11m + ``` + +5. 运行以下命令查看 Kafka 集群的元数据。 + + ```shell + kafkacat -L -b kafka-server-kafka-brokers:9092 + ``` + +## 触发同步函数 + +### 创建 EventSource + +1. 使用以下内容创建一个 EventSource 配置文件(例如,`eventsource-sink.yaml`)。 + + {{% alert title="注意" color="success" %}} + + - 以下示例定义了一个名为 `my-eventsource` 的事件源,并将指定 Kafka 服务器生成的事件标记为 `sample-one` 事件。 + - `spec.sink` 引用了在先决条件中创建的目标函数(Knative 服务)。 + + {{% /alert %}} + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: EventSource + metadata: + name: my-eventsource + spec: + logLevel: "2" + kafka: + sample-one: + brokers: "kafka-server-kafka-brokers.default.svc.cluster.local:9092" + topic: "events-sample" + authRequired: false + sink: + uri: "http://openfunction.io.svc.cluster.local/default/sink" + ``` + +2. 运行以下命令应用配置文件。 + + ```shell + kubectl apply -f eventsource-sink.yaml + ``` + +3. 运行以下命令检查结果。 + + ```shell + $ kubectl get eventsources.events.openfunction.io + NAME EVENTBUS SINK STATUS + my-eventsource Ready + + $ kubectl get components + NAME AGE + serving-8f6md-component-esc-kafka-sample-one-r527t 68m + serving-8f6md-component-ts-my-eventsource-default-wz8jt 68m + + $ kubectl get deployments.apps + NAME READY UP-TO-DATE AVAILABLE AGE + serving-8f6md-deployment-v100-pg9sd 1/1 1 1 68m + ``` + + {{% alert title="注意" color="success" %}} + + 在此示例中触发同步函数,EventSource 控制器的工作流程描述如下: + + 1. 创建一个名为 `my-eventsource` 的 EventSource 自定义资源。 + 2. 创建一个名为 `serving-xxxxx-component-esc-kafka-sample-one-xxxxx` 的 Dapr 组件,使 EventSource 能够与事件源关联。 + 3. 创建一个名为 `serving-xxxxx-component-ts-my-eventsource-default-xxxxx` 的 Dapr 组件,使 EventSource 能够与 sink 函数关联。 + 4. 创建一个名为 `serving-xxxxx-deployment-v100-xxxxx-xxxxxxxxxx-xxxxx` 的 Deployment,用于处理事件。 + + {{% /alert %}} + +### 创建事件生产者 + +要启动目标函数,需要创建一些事件来触发函数。 + +1. 使用以下内容创建一个事件生产者配置文件(例如,`events-producer.yaml`)。 + + ```yaml + apiVersion: core.openfunction.io/v1beta1 + kind: Function + metadata: + name: events-producer + spec: + version: "v1.0.0" + image: openfunctiondev/v1beta1-bindings:latest + serving: + template: + containers: + - name: function + imagePullPolicy: Always + runtime: "async" + inputs: + - name: cron + component: cron + outputs: + - name: target + 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: "events-sample" + - name: consumerGroup + value: "bindings-with-output" + - name: publishTopic + value: "events-sample" + - name: authRequired + value: "false" + ``` + +2. 运行以下命令应用配置文件。 + + ```shell + kubectl apply -f events-producer.yaml + ``` + +3. 运行以下命令实时检查结果。 + + ```shell + $ kubectl get po --watch + NAME READY STATUS RESTARTS AGE + serving-k6zw8-deployment-v100-fbtdc-dc96c4589-s25dh 0/2 ContainerCreating 0 1s + serving-8f6md-deployment-v100-pg9sd-6666c5577f-4rpdg 2/2 Running 0 23m + serving-k6zw8-deployment-v100-fbtdc-dc96c4589-s25dh 0/2 ContainerCreating 0 1s + serving-k6zw8-deployment-v100-fbtdc-dc96c4589-s25dh 1/2 Running 0 5s + serving-k6zw8-deployment-v100-fbtdc-dc96c4589-s25dh 2/2 Running 0 8s + serving-4x5wh-ksvc-wxbf2-v100-deployment-5c495c84f6-8n6mk 0/2 Pending 0 0s + serving-4x5wh-ksvc-wxbf2-v100-deployment-5c495c84f6-8n6mk 0/2 Pending 0 0s + serving-4x5wh-ksvc-wxbf2-v100-deployment-5c495c84f6-8n6mk 0/2 ContainerCreating 0 0s + serving-4x5wh-ksvc-wxbf2-v100-deployment-5c495c84f6-8n6mk 0/2 ContainerCreating 0 2s + serving-4x5wh-ksvc-wxbf2-v100-deployment-5c495c84f6-8n6mk 1/2 Running 0 4s + serving-4x5wh-ksvc-wxbf2-v100-deployment-5c495c84f6-8n6mk 1/2 Running 0 4s + serving-4x5wh-ksvc-wxbf2-v100-deployment-5c495c84f6-8n6mk 2/2 Running 0 4s + ``` \ No newline at end of file diff --git a/content/zh/docs/concepts/Events/introduction.md b/content/zh/docs/concepts/Events/introduction.md new file mode 100644 index 00000000..2b770b82 --- /dev/null +++ b/content/zh/docs/concepts/Events/introduction.md @@ -0,0 +1,50 @@ +--- +title: "简介" +linkTitle: "简介" +weight: 3400 +description: +--- + +## 概述 + +OpenFunction 事件是 OpenFunction 的事件管理框架。它提供以下核心特性: + +- 支持通过同步和异步调用触发目标函数 +- 用户定义的触发判断逻辑 +- OpenFunction 事件的组件可以由 OpenFunction 本身驱动 + +## 架构 + +以下图示说明了 OpenFunction 事件的架构。 + +![openfunction-events](/images/docs/en/concepts/events/openfunction-events.svg) + +## 概念 + +### EventSource + +EventSource 定义了事件的生产者,例如 Kafka 服务,对象存储服务,甚至是函数。它包含了这些事件生产者的描述和发送这些事件的信息。 + +EventSource 支持以下类型的事件源服务器: + +- Kafka +- Cron(调度器) +- Redis + +### EventBus(ClusterEventBus) + +EventBus 负责聚合事件并使其持久化。它包含了一个通常是消息队列(如 NATS Streaming 和 Kafka)的事件总线 broker 的描述,并为 EventSource 和 Trigger 提供这些配置。 + +EventBus 默认处理命名空间范围内的事件总线适配。对于集群范围,ClusterEventBus 可作为事件总线适配器,并在其他组件无法找到命名空间下的 EventBus 时生效。 + +EventBus 支持以下事件总线 broker: + +- NATS Streaming + +### Trigger + +Trigger 是事件目的的抽象,例如接收到消息时需要做什么。它包含了由您定义的事件的目的,这告诉触发器它应该从哪个 EventSource 获取事件,并根据给定的条件决定是否触发目标函数。 + +## 参考 + +有关更多信息,请参阅 [EventSource 规范](https://openfunction.dev/docs/reference/component-reference/eventsource-spec/eventsource-spec) 和 [EventBus 规范](https://openfunction.dev/docs/reference/component-reference/eventbus-spec/eventbus-spec)。 \ No newline at end of file diff --git a/content/zh/docs/concepts/Events/multisource-in-eventsource.md b/content/zh/docs/concepts/Events/multisource-in-eventsource.md new file mode 100644 index 00000000..b20c7edb --- /dev/null +++ b/content/zh/docs/concepts/Events/multisource-in-eventsource.md @@ -0,0 +1,69 @@ +--- +title: "在一个 EventSource 中使用多个源" +linkTitle: "在一个 EventSource 中使用多个源" +weight: 4530 +description: +--- + +本文档描述了如何在一个 EventSource 中使用多个源。 + +## 先决条件 + +- 您需要创建一个作为目标函数的函数以被触发。有关更多详细信息,请参见 [创建函数](../event-source#create-a-function)。 +- 您需要创建一个 Kafka 集群。有关更多详细信息,请参见 [创建 Kafka 集群](../event-source#create-a-kafka-cluster)。 + +## 在一个 EventSource 中使用多个源 + +1. 使用以下内容创建一个 EventSource 配置文件(例如,`eventsource-multi.yaml`)。 + + {{% alert title="注意" color="success" %}} + + - 以下示例定义了一个名为 `my-eventsource` 的事件源,并将指定 Kafka 服务器生成的事件标记为 `sample-three` 事件。 + - `spec.sink` 引用了目标函数(Knative 服务)。 + - `spec.cron` 的配置是每5秒触发一次在 `spec.sink` 中定义的函数。 + + {{% /alert %}} + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: EventSource + metadata: + name: my-eventsource + spec: + logLevel: "2" + kafka: + sample-three: + brokers: "kafka-server-kafka-brokers.default.svc.cluster.local:9092" + topic: "events-sample" + authRequired: false + cron: + sample-three: + schedule: "@every 5s" + sink: + uri: "http://openfunction.io.svc.cluster.local/default/sink" + ``` + +2. 运行以下命令应用配置文件。 + + ```shell + kubectl apply -f eventsource-multi.yaml + ``` + +3. 运行以下命令观察变化。 + + ```shell + $ kubectl get eventsources.events.openfunction.io + NAME EVENTBUS SINK STATUS + my-eventsource Ready + + $ kubectl get components + NAME AGE + serving-vqfk5-component-esc-cron-sample-three-dzcpv 35s + serving-vqfk5-component-esc-kafka-sample-one-nr9pq 35s + serving-vqfk5-component-ts-my-eventsource-default-q6g6m 35s + + $ kubectl get deployments.apps + NAME READY UP-TO-DATE AVAILABLE AGE + serving-4x5wh-ksvc-wxbf2-v100-deployment 1/1 1 1 3h14m + serving-vqfk5-deployment-v100-vdmvj 1/1 1 1 48s + ``` \ No newline at end of file diff --git a/content/zh/docs/concepts/Events/trigger-conditions.md b/content/zh/docs/concepts/Events/trigger-conditions.md new file mode 100644 index 00000000..3c2a63c5 --- /dev/null +++ b/content/zh/docs/concepts/Events/trigger-conditions.md @@ -0,0 +1,140 @@ +--- +title: "使用带有条件的 Trigger" +linkTitle: "使用带有条件的 Trigger" +weight: 4550 +description: +--- + +本文档描述了如何使用带有条件的触发器。 + +## 先决条件 + +您已完成 [使用 EventBus 和 Trigger](../event-bus-and-trigger) 中描述的步骤。 + +## 使用带有条件的触发器 + +### 创建两个事件源 + +1. 使用以下内容创建一个 EventSource 配置文件(例如,`eventsource-a.yaml`)。 + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: EventSource + metadata: + name: eventsource-a + spec: + logLevel: "2" + eventBus: "default" + kafka: + sample-five: + brokers: "kafka-server-kafka-brokers.default.svc.cluster.local:9092" + topic: "events-sample" + authRequired: false + ``` + +2. 使用以下内容创建另一个 EventSource 配置文件(例如,`eventsource-b.yaml`)。 + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: EventSource + metadata: + name: eventsource-b + spec: + logLevel: "2" + eventBus: "default" + cron: + sample-five: + schedule: "@every 5s" + ``` + +3. 运行以下命令应用这两个配置文件。 + + ```shell + kubectl apply -f eventsource-a.yaml + kubectl apply -f eventsource-b.yaml + ``` + +### 创建带有条件的触发器 + +1. 使用以下内容创建一个带有 `condition` 的触发器配置文件(例如,`condition-trigger.yaml`)。 + + ```yaml + apiVersion: events.openfunction.io/v1alpha1 + kind: Trigger + metadata: + name: condition-trigger + spec: + logLevel: "2" + eventBus: "default" + inputs: + eventA: + eventSource: "eventsource-a" + event: "sample-five" + eventB: + eventSource: "eventsource-b" + event: "sample-five" + subscribers: + - condition: eventB + sink: + uri: "http://openfunction.io.svc.cluster.local/default/sink" + - condition: eventA && eventB + topic: "metrics" + ``` + + {{% alert title="注意" color="success" %}} + + 在这个例子中,定义了两个输入源和两个订阅者,它们的触发关系描述如下: + + - 当接收到输入 `eventB` 时,将输入事件发送到 Knative 服务。 + - 当接收到输入 `eventB` 和输入 `eventA` 时,将输入事件同时发送到事件总线的 `metrics` 主题和 Knative 服务。 + + {{% /alert %}} + +2. 运行以下命令应用配置文件。 + + ```shell + kubectl apply -f condition-trigger.yaml + ``` + +3. 运行以下命令检查结果。 + + ```shell + $ kubectl get eventsources.events.openfunction.io + NAME EVENTBUS SINK STATUS + eventsource-a default Ready + eventsource-b default Ready + + $ kubectl get triggers.events.openfunction.io + NAME EVENTBUS STATUS + condition-trigger default Ready + + $ kubectl get eventbus.events.openfunction.io + NAME AGE + default 12s + ``` + +4. 运行以下命令,您可以从输出中看到,由于事件源 `eventsource-b` 是一个 cron 任务,所以触发器中的 `eventB` 条件匹配,触发了 Knative 服务。 + + ```shell + $ kubectl get functions.core.openfunction.io + NAME BUILDSTATE SERVINGSTATE BUILDER SERVING URL AGE + sink Skipped Running serving-4x5wh https://openfunction.io/default/sink 3h25m + + $ kubectl get po + NAME READY STATUS RESTARTS AGE + serving-4x5wh-ksvc-wxbf2-v100-deployment-5c495c84f6-k2jdg 2/2 Running 0 46s + ``` + +5. 参考 [创建事件生产者](../event-bus-and-trigger#create-an-event-producer) 创建一个事件生产者。 + +6. 运行以下命令,您可以从输出中看到,触发器中的 `eventA && eventB` 条件匹配,事件同时发送到事件总线的 `metrics` 主题。触发了 OpenFuncAsync 函数。 + + ```shell + $ kubectl get functions.core.openfunction.io + NAME BUILDSTATE SERVINGSTATE BUILDER SERVING URL AGE + trigger-target Skipped Running serving-7hghp 103s + + $ kubectl get po + NAME READY STATUS RESTARTS AGE + serving-7hghp-deployment-v100-z8wrf-946b4854d-svf55 2/2 Running 0 18s + ``` \ No newline at end of file diff --git a/content/zh/docs/concepts/_index.md b/content/zh/docs/concepts/_index.md index 8245c2e0..4c6f7746 100644 --- a/content/zh/docs/concepts/_index.md +++ b/content/zh/docs/concepts/_index.md @@ -1,7 +1,7 @@ --- title: "概念术语" linkTitle: "概念术语" -weight: 10 -description: > - 向您介绍 OpenFunction 中的概念 +weight: 3000 +description: --- + diff --git a/content/zh/docs/concepts/baas_integration.md b/content/zh/docs/concepts/baas_integration.md new file mode 100644 index 00000000..b27d3826 --- /dev/null +++ b/content/zh/docs/concepts/baas_integration.md @@ -0,0 +1,102 @@ +--- +title: "BaaS 集成" +linkTitle: "BaaS 集成" +weight: 3350 +description: +--- + +OpenFunction 的一个独特特性是它可以通过 [Dapr](https://docs.dapr.io/concepts/components-concept/) 简单地集成各种后端服务 (BaaS)。目前,OpenFunction 支持 Dapr 的 [pub/sub](https://docs.dapr.io/reference/components-reference/supported-pubsub/) 和 [bindings](https://docs.dapr.io/reference/components-reference/supported-bindings/) 构建块,未来将会添加更多。 + +在 OpenFunction v0.7.0 及之前的版本中,OpenFunction 通过在每个函数实例的 pod 中注入一个 dapr sidecar 容器来集成 BaaS,这导致了以下问题: + +- dapr sidecar 容器的启动拖慢了整个函数实例的启动时间。 +- dapr sidecar 容器可能消耗的资源比函数容器本身还要多。 + +为了解决上述问题,OpenFunction 在 v0.8.0 中引入了 `Dapr 独立模式`。 + +## Dapr 独立模式 + +在 Dapr 独立模式中,每个函数都会创建一个 `Dapr 代理服务`,然后由该函数的所有实例共享。这样,就不再需要为每个函数实例启动一个单独的 Dapr sidecar 容器,从而大大减少了函数的启动时间。 + +
+ +## 选择适当的 Dapr 服务模式 + +所以现在你有两个选项来集成 BaaS: + +- `Dapr Sidecar 模式` +- `Dapr 独立模式` + +你可以为你的函数选择适当的 Dapr 服务模式。`Dapr 独立模式` 是推荐的和默认的模式。如果你的函数不经常扩展,或者你难以使用 `Dapr 独立模式`,你可以使用 `Dapr Sidecar 模式`。 + +你可以通过设置两个标志来控制如何集成 BaaS,这两个标志都可以在函数的 `spec.serving.annotations` 中设置: + +- `openfunction.io/enable-dapr` 可以设置为 `true` 或 `false` +- `openfunction.io/dapr-service-mode` 可以设置为 `standalone` 或 `sidecar` +- 当 `openfunction.io/enable-dapr` 设置为 `true` 时,用户可以通过将 `openfunction.io/dapr-service-mode` 设置为 `standalone` 或 `sidecar` 来选择 `Dapr 服务模式`。 +- 当 `openfunction.io/enable-dapr` 设置为 `false` 时,`openfunction.io/dapr-service-mode` 的值将被忽略,既不会启动 `Dapr Sidecar`,也不会启动 `Dapr 代理服务`。 + +如果这两个标志没有设置,它们都有默认值。 + +- 如果 `openfunction.io/enable-dapr` 在 `spec.serving.annotations` 中没有定义,并且函数定义包含 `spec.serving.inputs` 或 `spec.serving.outputs`,那么 `openfunction.io/enable-dapr` 的值将被设置为 `true`。否则,它将被设置为 `false`。 +- 如果没有设置 `openfunction.io/dapr-service-mode`,其默认值为 `standalone`。 + +下面你可以找到一个设置这两个标志的函数示例: + +```yaml +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" +``` \ No newline at end of file diff --git a/content/zh/docs/concepts/build_strategy.md b/content/zh/docs/concepts/build_strategy.md new file mode 100644 index 00000000..8866dda0 --- /dev/null +++ b/content/zh/docs/concepts/build_strategy.md @@ -0,0 +1,127 @@ +--- +title: "构建策略" +linkTitle: "构建策略" +weight: 3120 +description: +--- + +构建策略用于控制构建过程。有两种类型的策略,`ClusterBuildStrategy` 和 `BuildStrategy`。 +这两种策略都定义了一组步骤,这些步骤是控制应用程序构建过程所必需的。 + +`ClusterBuildStrategy` 是集群范围的,而 `BuildStrategy` 是命名空间范围的。 + +在 OpenFunction 中有 4 种内置的 `ClusterBuildStrategy`,你可以在以下各节中找到更多详细信息。 + +## openfunction + +`openfunction` ClusterBuildStrategy 使用 [Buildpacks](https://buildpacks.io/docs/) 来构建函数镜像,这是默认的构建策略。 + +以下是 `openfunction` ClusterBuildStrategy 的参数: + +| 名称 | 类型 | 描述 | +| --- | --- | --- | +| RUN_IMAGE | string | 使用的运行镜像的引用 | +| CACHE_IMAGE | string | 缓存镜像是一种在不同构建之间保留缓存层的方式,当构建具有大量依赖项的函数或应用程序(如 Java 函数)时,可以提高构建性能。 | +| BASH_IMAGE | string | 策略使用的 bash 镜像。 | +| ENV_VARS | string | 在 _构建时_ 设置的环境变量。格式为 `key1=value1,key2=value2`。 | + +用户可以像这样设置这些参数: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler +spec: + build: + shipwright: + params: + RUN_IMAGE: "" + ENV_VARS: "" +``` + +## buildah + +`buildah` ClusterBuildStrategy 使用 [buildah](https://buildah.io/) 来构建应用程序镜像。 + +要使用 `buildah` ClusterBuildStrategy,你可以定义一个 `Function`,如下所示: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: sample-go-app + namespace: default +spec: + build: + builder: openfunction/buildah:v1.23.1 + dockerfile: Dockerfile + shipwright: + strategy: + kind: ClusterBuildStrategy + name: buildah +``` + +以下是 `buildah` ClusterBuildStrategy 的参数: + +| 名称 | 类型 | 描述 | 默认值 | +| --- | --- | --- | --- | +| registry-search | string | 用于搜索短名称镜像(如 `golang:latest`)的镜像仓库,用逗号分隔。 | docker.io,quay.io | +| registry-insecure | string | 不安全镜像仓库的全名。不安全的镜像仓库是没有有效 SSL 证书或只支持 HTTP 的镜像仓库。 | +| registry-block | string | 需要阻止拉取访问的镜像仓库。 | "" | + +## kaniko + +`kaniko` ClusterBuildStrategy 使用 [kaniko](https://github.com/GoogleContainerTools/kaniko) 来构建应用程序镜像。 + +要使用 `kaniko` ClusterBuildStrategy,你可以定义一个 `Function`,如下所示: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-kaniko + namespace: default +spec: + build: + builder: openfunction/kaniko-executor:v1.7.0 + dockerfile: Dockerfile + shipwright: + strategy: + kind: ClusterBuildStrategy + name: kaniko +``` + +## ko + +`ko` ClusterBuildStrategy 使用 [ko](https://github.com/ko-build/ko) 来构建 `Go` 应用程序镜像。 + +要使用 `ko` ClusterBuildStrategy,你可以定义一个 `Function`,如下所示: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-ko + namespace: default +spec: + build: + builder: golang:1.17 + dockerfile: Dockerfile + shipwright: + strategy: + kind: ClusterBuildStrategy + name: ko +``` + +以下是 `ko` ClusterBuildStrategy 的参数: + +| 名称 | 类型 | 描述 | 默认值 | +| --- | --- | --- | --- | +| go-flags | string | Value for the GOFLAGS environment variable. | "" | +| ko-version | string | Version of ko, must be either 'latest', or a release name from https://github.com/google/ko/releases. | "" | +| package-directory | string | The directory inside the context directory containing the main package. | "." | + +## 自定义策略 + +用户可以自定义他们自己的策略。要自定义策略,你可以参考 [这里](https://github.com/shipwright-io/build/blob/main/docs/buildstrategies.md)。 \ No newline at end of file diff --git a/content/zh/docs/concepts/builder.md b/content/zh/docs/concepts/builder.md deleted file mode 100644 index 526c480b..00000000 --- a/content/zh/docs/concepts/builder.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "Builder" -linkTitle: "Builder" -weight: 15 -description: > - OpenFunction 概念之核心框架资源,函数构建器 Builder ---- - -**Builder** 定义了 OpenFunction 中由源代码生成应用镜像的构建工作。 - -当前,OpenFunction Builder 使用 [Shipwright](#shipwright) 和 [Cloud Native Buildpacks](#cloud-native-buildpacks) 来构建应用镜像。它通过 Shipwright 控制应用镜像的构建过程,包括通过 Cloud Native Buildpacks 获取代码、生成镜像制品和发布镜像。 - -### 支持的构建器 - -- [OpenFunction Builder](https://github.com/OpenFunction/builder) -- [GoogleCloudPlatform Builder](https://github.com/GoogleCloudPlatform/buildpacks) -- [Paketo Builder](https://paketo.io/docs/) - -### Shipwright - -[Shipwright](https://github.com/shipwright-io/build) 是一个可扩展的镜像流水线框架,用于在 Kubernetes 上构建容器镜像。 - -### Cloud Native Buildpacks - -[Cloud Native Buildpacks](https://buildpacks.io/) 是一个 OCI 标准的镜像构建框架,无需 Dockerfile 即可根据自定义步骤(buildpack)将源代码转化为容器镜像制品。 - -### 参考 - -Builder 是一种 [CustomResourceDefinitions(CRD)](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/)。你可以访问 [Builder CRD Spec]({{< ref "../reference/function-spec#buildimpl" >}}) 了解更多信息。 diff --git a/content/zh/docs/concepts/cicd.md b/content/zh/docs/concepts/cicd.md new file mode 100644 index 00000000..4c62007e --- /dev/null +++ b/content/zh/docs/concepts/cicd.md @@ -0,0 +1,77 @@ +--- +title: "CI/CD" +linkTitle: "CI/CD" +weight: 3500 +description: +--- + +## 概述 + +以前,用户可以使用 OpenFunction 将函数或应用程序源代码构建成容器镜像,然后直接将构建的镜像部署到底层的同步/异步 Serverless 运行时,无需用户干预。 + +但是,OpenFunction 无法在函数或应用程序源代码更改时重新构建镜像,然后重新部署它,也无法在此镜像更改时重新部署镜像(当镜像在另一个函数中手动构建和推送时) + +从 v1.0.0 开始,OpenFunction 在一个新的组件 `Revision Controller` 中添加了检测源代码或镜像更改,然后重新构建和/或重新部署新构建的镜像的能力。修订控制器能够: +- 检测 github、gitlab 或 gitee 中的源代码更改,然后在源代码更改时重新构建和重新部署新构建的镜像。 +- 检测包含源代码的捆绑容器镜像(镜像)的更改,然后在捆绑镜像更改时重新构建和重新部署新构建的镜像。 +- 检测函数或应用程序镜像的更改,然后在函数或应用程序镜像更改时重新部署新镜像。 + +## 快速开始 + +### 安装 `Revision Controller` + +你可以在安装 [OpenFunction](https://openfunction.dev/docs/getting-started/installation/#install-openfunction) 时启用 `Revision Controller`,只需在 helm 命令中添加以下标志即可。 + +```shell +--set revisionController.enable=true +``` + +你也可以在 `OpenFunction` 安装后启用 `Revision Controller`: + +```shell +kubectl apply -f https://raw.githubusercontent.com/OpenFunction/revision-controller/release-1.0/deploy/bundle.yaml +``` + +> `Revision Controller` 默认将安装到 `openfunction` 命名空间。如果你想将其安装到另一个命名空间,你可以下载 `bundle.yaml` 并手动更改命名空间。 + +### 检测源代码或镜像更改 + +要检测源代码或镜像更改,你需要将修订控制器开关和参数添加到函数的注解中,如下所示。 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + annotations: + openfunction.io/revision-controller: enable + openfunction.io/revision-controller-params: | + type: source + repo-type: github + polling-interval: 1m + name: function-http-java + namespace: default +spec: + build: + ... + serving: + ... +``` + +#### 注解 + +| 键 | 描述 | +| ---------------------------------------------- | ---------------------------------------------------------------------------------------------- | +| **openfunction.io/revision-controller** | 是否启用修订控制器来检测此函数的源代码或镜像更改,可以设置为 `enable` 或 `disable`。 | +| **openfunction.io/revision-controller-params** | 修订控制器的参数。 | + +#### 参数 + +| 名称 | 描述 | +| --------------------- | ---------------------------------------------------------------------------------------------------------------- | +| **type** | 要检测的更改类型,包括 `source`、`source-image` 和 `image`。 | +| **polling-interval** | 轮询镜像摘要或源代码头的间隔。 | +| **repo-type** | git 仓库的类型,包括 `github`、`gitlab` 和 `gitee`。默认为 `github`。 | +| **base-url** | gitlab 服务器的基本 url。 | +| **auth-type** | gitlab 服务器的认证类型。 | +| **project-id** | gitlab 仓库的项目 id。 | +| **insecure-registry** | 如果镜像仓库不安全,你应该将此设置为 true。 | diff --git a/content/zh/docs/concepts/eventbus.md b/content/zh/docs/concepts/eventbus.md deleted file mode 100644 index 3f6f5277..00000000 --- a/content/zh/docs/concepts/eventbus.md +++ /dev/null @@ -1,21 +0,0 @@ ---- -title: "EventBus(ClusterEventBus)" -linkTitle: "EventBus(ClusterEventBus)" -weight: 30 -description: > - OpenFunction 概念之事件框架资源,事件总线 EventBus(ClusterEventBus) ---- - -**EventBus** 负责聚合事件并持久化事件。 - -**EventBus** 包含对事件总线后端服务的描述(通常是一个消息服务器,如 NATS Streaming、Kafka 等),然后为 **EventSource** 和 **Trigger** 提供这些配置(让它们可以从事件总线中获取事件)。 - -**EventBus** 默认负责 namespace scope 的事件总线适配,同时我们也为 cluster scope 提供了一个事件总线适配器 **ClusterEventBus** ,它将在命名空间中不存在 EventBus 时生效。 - -### 支持的事件总线服务器 - -- [NATS Streaming]({{}}) - -### 参考 - -EventBus 是一种 [CustomResourceDefinitions(CRD)](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/)。你可以访问 [EventBus CRD Spec]({{< ref "../reference/eventbus-spec" >}}) 了解更多信息。 diff --git a/content/zh/docs/concepts/eventsource.md b/content/zh/docs/concepts/eventsource.md deleted file mode 100644 index a1a01b72..00000000 --- a/content/zh/docs/concepts/eventsource.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "EventSource" -linkTitle: "EventSource" -weight: 25 -description: > - OpenFunction 概念之事件框架资源,事件源 EventSource ---- - -**EventSource** 代表一个事件的生产者,如 Kafka 服务器、对象存储服务,也可以是一个应用。它包含这些事件生产者的定义,以便于从这些生产者处获取事件。它同时定义了这些事件将去往何处。 - -### 支持的事件源 - -- [Kafka]({{}}) -- [Cron (scheduler)]({{}}) -- [Redis]({{}}) - -### 参考 - -EventSource 是一种 [CustomResourceDefinitions(CRD)](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/)。你可以访问 [EventSource CRD Spec]({{< ref "../reference/eventsource-spec" >}}) 了解更多信息。 diff --git a/content/zh/docs/concepts/function.md b/content/zh/docs/concepts/function.md index 1055659c..380b8897 100644 --- a/content/zh/docs/concepts/function.md +++ b/content/zh/docs/concepts/function.md @@ -1,16 +1,44 @@ --- -title: "Function" -linkTitle: "Function" -weight: 10 -description: > - OpenFunction 概念之核心框架资源,函数实例 Function +title: "函数定义" +linkTitle: "函数定义" +weight: 3100 +description: --- +## 函数 -**Function** 是直接由使用者定义、控制的资源,它是使用者对其业务应用的一段描述,即用何种原料(源代码)加工成何种制品(应用镜像),最终又将以何种方式运作(工作负载、运行时)。 +`Function`是`Build`和`Serving`的控制平面,也是用户使用OpenFunction的接口。用户无需单独创建`Build`或`Serving`,因为`Function`是定义函数的`Build`和`Serving`的唯一地方。 -在 OpenFunction 中,**Function** 资源会根据配置有序控制 **[Builder]({{}})** 和 **[Serving]({{}})** 资源的协调过程,进而实现使用者函数的生命周期管理。 +一旦创建了函数,它将控制`Build`和`Serving`的生命周期,无需用户干预: -### 参考 +- 如果在函数中定义了`Build`,则一旦部署函数,将创建一个builder自定义资源来构建函数的容器镜像。 -Function 是一种 [CustomResourceDefinitions(CRD)](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/)。你可以访问 [Function CRD Spec]({{< ref "../reference/function-spec" >}}) 了解更多信息。 +- 如果在函数中定义了`Serving`,则将创建一个serving自定义资源来控制函数的服务和自动缩放。 +- `Build`和`Serving`可以一起定义,这意味着首先将构建函数镜像,然后将其用于服务。 + +- 可以定义`Build`而不定义`Serving`,在这种情况下,函数仅用于构建镜像。 + +- 可以定义`Serving`而不定义`Build`,函数将使用先前构建的函数镜像进行服务。 + +
+ +## 构建 + +OpenFunction使用[Shipwright](https://github.com/shipwright-io/build)和[Cloud Native Buildpacks](https://buildpacks.io/)将函数源代码构建成容器镜像。 + +一旦创建了包含`Build`规范的函数,就会创建一个`builder`自定义资源,该资源将使用Shipwright管理构建工具和策略。然后,Shipwright将使用Tekton控制构建容器镜像的过程,包括获取源代码、生成镜像工件和发布镜像。 + +
+ +## 服务 +一旦创建了包含`Serving`规范的函数,就会创建一个`Serving`自定义资源来控制函数的服务阶段。目前,OpenFunction Serving支持两种运行时:Knative同步运行时和OpenFunction异步运行时。 + +## 同步运行时 + +对于同步函数,OpenFunction目前支持使用 Knative Serving 和 KEDA http-addon 作为运行时。 + +## 异步运行时 + +OpenFunction的异步运行时是一个基于[KEDA](https://keda.sh/)和[Dapr](https://dapr.io/)实现的事件驱动运行时。异步函数可以由各种事件类型触发,如消息队列、cronjob和MQTT等。 + +
diff --git a/content/zh/docs/concepts/function_build.md b/content/zh/docs/concepts/function_build.md new file mode 100644 index 00000000..128e62b6 --- /dev/null +++ b/content/zh/docs/concepts/function_build.md @@ -0,0 +1,139 @@ +--- +title: "函数构建" +linkTitle: "函数构建" +weight: 3110 +description: +--- +目前,OpenFunction支持使用[Cloud Native Buildpacks](https://buildpacks.io/)构建函数镜像,无需创建`Dockerfile`。 + +同时,您也可以使用OpenFunction通过`Dockerfile`构建[无服务器应用](../serverless_apps/#build-and-run-a-serverless-application-with-a-dockerfile)。 + +## 通过定义构建部分来构建函数 + +您可以从git仓库的源代码或本地存储的源代码构建函数或应用。 + +### 从git仓库的源代码构建函数 + +您可以通过在`Function`定义中添加一个构建部分来构建函数镜像。如果还定义了服务部分,那么构建完成后将立即启动函数。 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler +spec: + version: "v2.0.0" + image: openfunctiondev/logs-async-handler:v1 + imageCredentials: + name: push-secret + build: + builder: openfunction/builder-go:latest + env: + FUNC_NAME: "LogsHandler" + FUNC_CLEAR_SOURCE: "true" + ## 自定义函数框架版本,目前仅对functions-framework-go有效 + ## 通常情况下,您不需要这样做,因为构建器会自带最新的函数框架 + # FUNC_FRAMEWORK_VERSION: "v0.4.0" + ## 使用FUNC_GOPROXY设置goproxy + # FUNC_GOPROXY: "https://goproxy.cn" + srcRepo: + url: "https://github.com/OpenFunction/samples.git" + sourceSubPath: "functions/async/logs-handler-function/" + revision: "main" +``` + +> 要将函数镜像推送到容器仓库,您需要创建一个包含仓库凭证的秘密,并将该秘密添加到`imageCredentials`。 +> 您可以参考[先决条件](../../getting-started/quickstarts/prerequisites)以获取更多信息。 + +### 从本地源代码构建函数 + +要从本地源代码构建函数或应用,您需要将本地源代码打包成容器镜像,并将此镜像推送到容器仓库。 + +假设您的源代码在`samples`目录中,您可以使用以下`Dockerfile`来构建源代码包镜像。 + +```shell +FROM scratch +WORKDIR / +COPY samples samples/ +``` + +然后,您可以像这样构建源代码包镜像: + +```shell +docker build -t /sample-source-code:latest -f . +docker push /sample-source-code:latest +``` + +建议使用空镜像scratch作为构建源代码包镜像的基础镜像,非空基础镜像可能会导致源代码复制失败。 +与为git仓库方法定义spec.build.srcRepo.url字段不同,您需要定义spec.build.srcRepo.bundleContainer.image字段。 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler +spec: + build: + srcRepo: + bundleContainer: + image: openfunctiondev/sample-source-code:latest + sourceSubPath: "/samples/functions/async/logs-handler-function/" +``` + +sourceSubPath是源代码包镜像中源代码的绝对路径。 + +## 使用pack CLI构建函数 + +通常,直接从本地源代码构建函数镜像是必要的,特别是出于调试目的或用于离线环境。您可以使用pack CLI来实现这一点。 + +Pack是由Cloud Native Buildpacks项目维护的一个工具,用于支持使用buildpacks。它启用了以下功能: + +- 使用buildpacks构建应用。 +- 重新基准使用buildpacks创建的应用镜像。 +- 创建生态系统内使用的各种组件。 + +按照[这里](https://buildpacks.io/docs/tools/pack/)的说明安装`pack` CLI工具。 +您可以在[这里](https://buildpacks.io/docs/tools/pack/cli/pack/)找到更多关于如何使用pack CLI的详细信息。 + +要从本地源代码构建OpenFunction函数镜像,您可以按照以下步骤操作: + +### 下载函数示例 + +```shell +git clone https://github.com/OpenFunction/samples.git +cd samples/functions/knative/hello-world-go +``` + +使用pack CLI构建函数镜像 +```shell +pack build func-helloworld-go --builder openfunction/builder-go:v2.4.0-1.17 --env FUNC_NAME="HelloWorld" --env FUNC_CLEAR_SOURCE=true +``` + +本地启动函数镜像 +```shell +docker run --rm --env="FUNC_CONTEXT={\"name\":\"HelloWorld\",\"version\":\"v1.0.0\",\"port\":\"8080\",\"runtime\":\"Knative\"}" --env="CONTEXT_MODE=self-host" --name func-helloworld-go -p 8080:8080 func-helloworld-go +``` + +访问函数 +```shell +curl http://localhost:8080 +``` + +输出示例: +```shell +hello, world! +``` + +## OpenFunction构建器 + +要使用[Cloud Native Buildpacks](https://buildpacks.io/)构建函数镜像,需要一个构建器镜像。 + +在这里,您可以找到OpenFunction社区维护的流行语言的构建器: + +| | 构建器 | +|-----------|------------------------------------------------------------------------------------------------------------------------------------| +| Go | openfunction/builder-go:v2.4.0 (openfunction/builder-go:latest) | +| Nodejs | openfunction/builder-node:v2-16.15 (openfunction/builder-node:latest) | +| Java | openfunction/builder-java:v2-11, openfunction/builder-java:v2-16, openfunction/builder-java:v2-17, openfunction/builder-java:v2-18 | +| Python | openfunction/gcp-builder:v1 | +| DotNet | openfunction/gcp-builder:v1 | \ No newline at end of file diff --git a/content/zh/docs/concepts/function_output.md b/content/zh/docs/concepts/function_output.md new file mode 100644 index 00000000..27284cf8 --- /dev/null +++ b/content/zh/docs/concepts/function_output.md @@ -0,0 +1,78 @@ +--- +title: "函数输出" +linkTitle: "函数输出" +weight: 3210 +description: +--- + +## 函数输出 + +输出是函数可以发送数据的组件,包括: + +- 任何 [Dapr 输出绑定组件](https://docs.dapr.io/reference/components-reference/supported-bindings/) 的 [Dapr 绑定构建块](https://docs.dapr.io/developing-applications/building-blocks/bindings/bindings-overview/) +- 任何 [Dapr Pub/sub brokers 组件](https://docs.dapr.io/reference/components-reference/supported-pubsub/) 的 [Dapr Pub/sub 构建块](https://docs.dapr.io/developing-applications/building-blocks/pubsub/pubsub-overview/) + +例如,[这里](https://github.com/OpenFunction/samples/blob/main/functions/async/bindings/cron-input-kafka-output) 你可以找到一个带有 cron 输入绑定和 Kafka 输出绑定的异步函数: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: cron-input-kafka-output +spec: + ... + serving: + ... + outputs: + - dapr: + name: kafka-server + type: bindings.kafka + operation: "create" + bindings: + 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" +``` + +[这里](https://github.com/OpenFunction/samples/blob/main/functions/async/bindings/cron-input-kafka-output) 是另一个使用 Kafka Pub/sub 组件作为输入的异步函数示例 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: autoscaling-subscriber +spec: + ... + serving: + ... + runtime: "async" + outputs: + - dapr: + name: kafka-server + type: pubsub.kafka + topic: "sample-topic" + pubsub: + kafka-server: + type: pubsub.kafka + version: v1 + metadata: + - name: brokers + value: "kafka-server-kafka-brokers:9092" + - name: authRequired + value: "false" + - name: allowedTopics + value: "sample-topic" + - name: consumerID + value: "autoscaling-subscriber" +``` diff --git a/content/zh/docs/concepts/function_scaling.md b/content/zh/docs/concepts/function_scaling.md new file mode 100644 index 00000000..e47f9310 --- /dev/null +++ b/content/zh/docs/concepts/function_scaling.md @@ -0,0 +1,102 @@ +--- +title: "函数缩放" +linkTitle: "函数缩放" +weight: 3220 +description: +--- + +缩放是 FaaS 或 Serverless 平台的核心特性之一。 + +OpenFunction 在 `ScaleOptions` 中定义了函数缩放,并在 `Triggers` 中定义了激活函数缩放的触发器。 + +## ScaleOptions + +您可以为同步和异步函数定义统一的函数缩放选项,如下所示,这将对同步和异步函数都有效: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + scaleOptions: + minReplicas: 0 + maxReplicas: 10 +``` + +通常,仅定义 minReplicas 和 maxReplicas 对于异步函数来说是不够的。您可以像下面这样为异步函数定义单独的缩放选项,这将覆盖 minReplicas 和 maxReplicas。 + +您可以在 [KEDA ScaleObject Spec](https://keda.sh/docs/2.7/concepts/scaling-deployments/#scaledobject-spec) 和 [KEDA ScaledJob Spec](https://keda.sh/docs/2.7/concepts/scaling-jobs/#scaledjob-spec) 中找到更多关于异步函数缩放选项的详细信息。 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + scaleOptions: + minReplicas: 0 + maxReplicas: 10 + keda: + scaledObject: + pollingInterval: 15 + cooldownPeriod: 60 + advanced: + horizontalPodAutoscalerConfig: + behavior: + scaleDown: + stabilizationWindowSeconds: 45 + policies: + - type: Percent + value: 50 + periodSeconds: 15 + scaleUp: + stabilizationWindowSeconds: 0 +``` + +您也可以为 Knative 同步函数设置高级缩放选项,这将覆盖 minReplicas 和 maxReplicas。 + +> 您可以在 [这里](https://knative.dev/docs/serving/autoscaling/scale-bounds/#scale-down-delay) 找到更多关于 Knative 同步函数缩放选项的详细信息。 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + scaleOptions: + knative: + autoscaling.knative.dev/initial-scale: "1" + autoscaling.knative.dev/scale-down-delay: "0" + autoscaling.knative.dev/window: "60s" + autoscaling.knative.dev/panic-window-percentage: "10.0" + autoscaling.knative.dev/metric: "concurrency" + autoscaling.knative.dev/target: "100" +``` + +### 触发器 + +触发器定义了如何激活异步函数的函数缩放。您可以使用所有 [KEDA 缩放器](https://keda.sh/docs/2.7/scalers/) 中定义的触发器作为 OpenFunction 的触发器规范。 + +> 同步函数的缩放是通过 HTTP 请求的各种选项激活的,这些选项已经在前面的 ScaleOption 部分中定义了。 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + scaleOptions: + keda: + triggers: + - type: kafka + metadata: + topic: logs + bootstrapServers: kafka-server-kafka-brokers.default.svc.cluster.local:9092 + consumerGroup: logs-handler + lagThreshold: "20" +``` diff --git a/content/zh/docs/concepts/function_signatures.md b/content/zh/docs/concepts/function_signatures.md new file mode 100644 index 00000000..c366de1c --- /dev/null +++ b/content/zh/docs/concepts/function_signatures.md @@ -0,0 +1,34 @@ +--- +title: "函数签名" +linkTitle: "函数签名" +weight: 3300 +description: +--- + +## 不同函数签名的比较 + +OpenFunction中有三种函数签名:`HTTP`,`CloudEvent`和`OpenFunction`。让我们使用Go函数为例,详细解释一下。 + +`HTTP`和`CloudEvent`签名可以用来创建同步函数,而`OpenFunction`签名可以用来创建同步和异步函数。 + +此外,`OpenFunction`签名可以利用各种Dapr构建块,包括Bindings,Pub/sub等访问各种BaaS服务,帮助创建更强大的函数。(Dapr状态管理,配置将很快得到支持) + +| | HTTP | CloudEvent | OpenFunction | +|-----------|----------------|----------------------|------------------------| +| 签名 | `func(http.ResponseWriter, *http.Request) error` | `func(context.Context, cloudevents.Event) error` | `func(ofctx.Context, []byte) (ofctx.Out, error)` | +| 同步函数 | 支持 | 支持 | 支持 | +| 异步函数 | 不支持 | 不支持 | 支持 | +| Dapr Binding | 不支持 | 不支持 | 支持 | +| Dapr Pub/sub | 不支持 | 不支持 | 支持 | + +## 示例 + +如您所见,`OpenFunction`签名是推荐的函数签名,我们正在努力在更多语言运行时支持此函数签名。 + +| | HTTP | CloudEvent | OpenFunction | +|-----------|----------------|----------------------|------------------------| +| Go | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/hello-world-go), [多函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/multiple-functions-go), [带路径参数的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/path-parameters-function-go), [日志处理](https://github.com/OpenFunction/samples/blob/main/functions/knative/logs-handler-function/LogsHandler.go) | [带路径参数的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/path-parameters-function-go) | [带路径参数的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/path-parameters-function-go), [带输出绑定的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/with-output-binding), [Kafka输入 & HTTP输出绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/logs-handler-function), [Cron输入 & Kafka输出绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/bindings/cron-input-kafka-output), [Cron输入绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/bindings/cron-input), [Kafka输入绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/bindings/kafka-input), [Kafka pubsub](https://github.com/OpenFunction/samples/tree/main/functions/async/pubsub) | +| Nodejs | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/hello-world-node) | | [带输出绑定的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/with-output-binding-node), [MQTT绑定 & pubsub](https://github.com/OpenFunction/samples/tree/main/functions/async/mqtt-io-node) | +| Python | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/hello-world-python) | | | +| Java | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/java/hello-world) | [CloudEvent](https://github.com/OpenFunction/samples/tree/main/functions/knative/java/cloudevent) | [带输出的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/java/with-output-binding), [Cron输入 & Kafka输出绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/java/cron-input-kafka-output), [Kafka pubsub](https://github.com/OpenFunction/samples/tree/main/functions/async/java/pubsub) | +| DotNet | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/hello-world-dotnet) | | | \ No newline at end of file diff --git a/content/zh/docs/concepts/function_trigger.md b/content/zh/docs/concepts/function_trigger.md new file mode 100644 index 00000000..934e5c52 --- /dev/null +++ b/content/zh/docs/concepts/function_trigger.md @@ -0,0 +1,83 @@ +--- +title: "函数触发器" +linkTitle: "函数触发器" +weight: 3200 +description: +--- +函数 `触发器` 用于定义如何触发函数。目前有两种触发器:`HTTP 触发器` 和 `Dapr 触发器`。默认的触发器是 `HTTP 触发器`。 + +## HTTP 触发器 + +`HTTP 触发器` 通过 HTTP 请求触发函数。你可以像这样为函数定义一个 `HTTP 触发器`: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + triggers: + http: + port: 8080 + route: + rules: + - matches: + - path: + type: PathPrefix + value: /echo +``` + +## Dapr 触发器 + +`Dapr 触发器` 通过 `Dapr bindings` 或 `Dapr pubsub` 的事件触发函数。你可以像这样定义一个带有 `Dapr 触发器` 的函数: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler + namespace: default +spec: + serving: + bindings: + kafka-receiver: + metadata: + - name: brokers + value: kafka-server-kafka-brokers:9092 + - name: authRequired + value: "false" + - name: publishTopic + value: logs + - name: topics + value: logs + - name: consumerGroup + value: logs-handler + type: bindings.kafka + version: v1 + triggers: + dapr: + - name: kafka-receiver + type: bindings.kafka +``` + +## 函数输入 + +`输入` 是函数可以从中获取额外输入数据的地方,目前支持 `Dapr 状态存储` 作为 `输入`。 + +你可以像这样定义函数输入: + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: logs-async-handler + namespace: default +spec: + serving: + triggers: + inputs: + - dapr: + name: mysql + type: state.mysql +``` \ No newline at end of file diff --git a/content/zh/docs/concepts/networking/_index.md b/content/zh/docs/concepts/networking/_index.md new file mode 100644 index 00000000..82a90572 --- /dev/null +++ b/content/zh/docs/concepts/networking/_index.md @@ -0,0 +1,6 @@ +--- +title: "网络" +linkTitle: "网络" +weight: 3400 +description: +--- diff --git a/content/zh/docs/concepts/networking/function-entrypoints.md b/content/zh/docs/concepts/networking/function-entrypoints.md new file mode 100644 index 00000000..9eaf61d8 --- /dev/null +++ b/content/zh/docs/concepts/networking/function-entrypoints.md @@ -0,0 +1,154 @@ +--- +title: "函数入口" +linkTitle: "函数入口" +weight: 3440 +description: +--- + +有几种方法可以访问同步函数。我们将在以下部分详细说明。 + +> 本文档假设你正在使用默认的 [OpenFunction 网关](../gateway/#the-default-openfunction-gateway) 并且你有一个名为 `function-sample` 的同步函数。 + +## 从集群内部访问函数 +### 通过内部地址访问函数 +OpenFunction 会为每个同步 `Function` 创建此服务:`{{.Name}}.{{.Namespace}}.svc.cluster.local`。此服务将用于提供函数的内部地址。 + +通过运行以下命令获取 `Function` 内部地址: +```shell +export FUNC_INTERNAL_ADDRESS=$(kubectl get function function-sample -o=jsonpath='{.status.addresses[?(@.type=="Internal")].value}') +``` + +这个地址提供了在集群内部访问函数的默认方法,适合用作 `EventSource` 的 `sink.url`。 + +在 pod 中使用 curl 访问 `Function`: +```shell= +kubectl run --rm ofn-test -i --tty --image=radial/busyboxplus:curl -- curl -sv $FUNC_INTERNAL_ADDRESS +``` + +## 从集群外部访问函数 +### 通过 Kubernetes 网关的 IP 地址访问函数 +获取 Kubernetes 网关的 ip 地址: +```shell +export IP=$(kubectl get node -l "! node.kubernetes.io/exclude-from-external-load-balancers" -o=jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}') +``` + +获取函数的 HOST 和 PATH: +```shell +export FUNC_HOST=$(kubectl get function function-sample -o=jsonpath='{.status.route.hosts[0]}') +export FUNC_PATH=$(kubectl get function function-sample -o=jsonpath='{.status.route.paths[0].value}') +``` + +直接使用 curl 访问 `Function`: +```shell +curl -sv -HHOST:$FUNC_HOST http://$IP$FUNC_PATH +``` + +### 通过外部地址访问函数 + +要通过外部地址访问同步函数,你需要先配置 DNS。Magic DNS 或真实 DNS 都可以: + +- Magic DNS + + 获取 Kubernetes 网关的 ip 地址: + ```shell + export IP=$(kubectl get node -l "! node.kubernetes.io/exclude-from-external-load-balancers" -o=jsonpath='{.items[0].status.addresses[?(@.type=="InternalIP")].address}') + ``` + 用 Magic DNS 替换 OpenFunction 网关中定义的域: + ```shell + export DOMAIN="$IP.sslip.io" + kubectl patch gateway.networking.openfunction.io/openfunction -n openfunction --type merge --patch '{"spec": {"domain": "'$DOMAIN'"}}' + ``` + 然后,你可以在 `Function` 的状态字段中看到 `Function` 外部地址: + ```shell + kubectl get function function-sample -oyaml + ``` + ```yaml + status: + addresses: + - type: External + value: http://function-sample.default.172.31.73.53.sslip.io/ + - type: Internal + value: http://function-sample.default.svc.cluster.local/ + build: + resourceHash: "14903236521345556383" + state: Skipped + route: + conditions: + - message: Valid HTTPRoute + reason: Valid + status: "True" + type: Accepted + hosts: + - function-sample.default.172.31.73.53.sslip.io + - function-sample.default.svc.cluster.local + paths: + - type: PathPrefix + value: / + serving: + lastSuccessfulResourceRef: serving-t56fq + resourceHash: "2638289828407595605" + resourceRef: serving-t56fq + service: serving-t56fq-ksvc-bv8ng + state: Running + ``` + +- Real DNS + + 如果你有一个外部 IP 地址,你可以配置一个通配符 A 记录作为你的域: + ``` + # 这里 example.com 是 OpenFunction 网关中定义的域 + *.example.com == A + ``` + 如果你有一个 CNAME,你可以配置一个 CNAME 记录作为你的域: + ``` + # 这里 example.com 是 OpenFunction 网关中定义的域 + *.example.com == CNAME + ``` + 用你上面配置的域替换 OpenFunction 网关中定义的域: + ```shell + export DOMAIN="example.com" + kubectl patch gateway.networking.openfunction.io/openfunction -n openfunction --type merge --patch '{"spec": {"domain": "'$DOMAIN'"}}' + ``` + 然后,你可以在 `Function` 的状态字段中看到 `Function` 外部地址: + ```shell + kubectl get function function-sample -oyaml + ``` + ```yaml + status: + addresses: + - type: External + value: http://function-sample.default.example.com/ + - type: Internal + value: http://function-sample.default.svc.cluster.local/ + build: + resourceHash: "14903236521345556383" + state: Skipped + route: + conditions: + - message: Valid HTTPRoute + reason: Valid + status: "True" + type: Accepted + hosts: + - function-sample.default.example.com + - function-sample.default.svc.cluster.local + paths: + - type: PathPrefix + value: / + serving: + lastSuccessfulResourceRef: serving-t56fq + resourceHash: "2638289828407595605" + resourceRef: serving-t56fq + service: serving-t56fq-ksvc-bv8ng + state: Running + ``` + +然后,你可以通过运行以下命令获取 `Function` 外部地址: +```shell +export FUNC_EXTERNAL_ADDRESS=$(kubectl get function function-sample -o=jsonpath='{.status.addresses[?(@.type=="External")].value}') +``` +现在,你可以直接使用 curl 访问 `Function`: + +```shell= +curl -sv $FUNC_EXTERNAL_ADDRESS +``` \ No newline at end of file diff --git a/content/zh/docs/concepts/networking/gateway.md b/content/zh/docs/concepts/networking/gateway.md new file mode 100644 index 00000000..e1c79a69 --- /dev/null +++ b/content/zh/docs/concepts/networking/gateway.md @@ -0,0 +1,110 @@ +--- +title: "网关" +linkTitle: "网关" +weight: 3420 +description: +--- + +## 深入理解 OpenFunction 网关 + +OpenFunction 网关由 [Kubernetes 网关](https://gateway-api.sigs.k8s.io/)支持,定义了用户如何访问同步函数。 + +每当创建一个 `OpenFunction 网关` 时,网关控制器将: + +- 如果 `gatewaySpec.listeners` 中没有,将添加一个名为 `ofn-http-internal` 的默认监听器。 + +- 根据 `domain` 或 `clusterDomain` 生成 `gatewaySpec.listeners.[*].hostname`。 + +- 将 `gatewaySpec.listenters` 注入到 `OpenFunction 网关` 的 `gatewayRef` 定义的现有 `Kubernetes 网关` 中。 + +- 根据 `OpenFunction 网关` 的 `gatewayDef` 中的 `gatewaySpec.listenters` 字段创建一个新的 `Kubernetes 网关`。 + +- 创建一个名为 `gateway.openfunction.svc.cluster.local` 的服务,该服务定义了同步函数的统一入口。 + +部署 `OpenFunction 网关` 后,你将能够在 `OpenFunction 网关` 状态中找到 `Kubernetes 网关` 和其 `listeners` 的状态: + +```yaml +status: + conditions: + - message: Gateway is scheduled + reason: Scheduled + status: "True" + type: Scheduled + - message: Valid Gateway + reason: Valid + status: "True" + type: Ready + listeners: + - attachedRoutes: 0 + conditions: + - message: Valid listener + reason: Ready + status: "True" + type: Ready + name: ofn-http-internal + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute + - attachedRoutes: 0 + conditions: + - message: Valid listener + reason: Ready + status: "True" + type: Ready + name: ofn-http-external + supportedKinds: + - group: gateway.networking.k8s.io + kind: HTTPRoute +``` + +## 默认的 OpenFunction 网关 + +`OpenFunction 网关` 使用 `Contour` 作为默认的 `Kubernetes 网关` 实现。 +安装 OpenFunction 后,将自动创建以下 `OpenFunction 网关`: + +```yaml +apiVersion: networking.openfunction.io/v1alpha1 +kind: Gateway +metadata: + name: openfunction + namespace: openfunction +spec: + domain: ofn.io + clusterDomain: cluster.local + hostTemplate: "{{.Name}}.{{.Namespace}}.{{.Domain}}" + pathTemplate: "{{.Namespace}}/{{.Name}}" + httpRouteLabelKey: "app.kubernetes.io/managed-by" + gatewayRef: + name: contour + namespace: projectcontour + gatewaySpec: + listeners: + - name: ofn-http-internal + hostname: "*.cluster.local" + protocol: HTTP + port: 80 + allowedRoutes: + namespaces: + from: All + - name: ofn-http-external + hostname: "*.ofn.io" + protocol: HTTP + port: 80 + allowedRoutes: + namespaces: + from: All +``` + +你可以像下面这样自定义默认的 `OpenFunction 网关`: +```shell +kubectl edit gateway openfunction -n openfunction +``` + +## 切换到不同的 Kubernetes 网关 + +你可以以更简单、厂商中立的方式切换到任何支持 [Kubernetes 网关 API](https://gateway-api.sigs.k8s.io/) 的 [网关实现](https://gateway-api.sigs.k8s.io/implementations/),如 Contour、Istio、Apache APISIX、Envoy Gateway(未来)等。 + +> [这里](../../../operations/networking/switch-gateway) 你可以找到更多详细信息。 + +## 多个 OpenFunction 网关 +对于 OpenFunction,多个 `Gateway` 没有意义,我们目前只支持一个 OpenFunction `Gateway`。 \ No newline at end of file diff --git a/content/zh/docs/concepts/networking/introduction.md b/content/zh/docs/concepts/networking/introduction.md new file mode 100644 index 00000000..4892ff2a --- /dev/null +++ b/content/zh/docs/concepts/networking/introduction.md @@ -0,0 +1,34 @@ +--- +title: "简介" +linkTitle: "简介" +weight: 3410 +description: +--- + +## 概述 + +从 v0.5.0 开始,OpenFunction 使用 Kubernetes Ingress 为同步函数提供统一的入口点,并且必须安装 nginx ingress 控制器。 + +随着 [Kubernetes Gateway API](https://gateway-api.sigs.k8s.io/) 的成熟,我们决定在 OpenFunction v0.7.0 中实现基于 [Kubernetes Gateway API](https://gateway-api.sigs.k8s.io/) 的 OpenFunction Gateway,以替代之前基于 ingress 的域方法。 + +>你可以在[这里](https://github.com/OpenFunction/OpenFunction/blob/main/docs/proposals/202207-openfunction-gateway.md)找到 OpenFunction Gateway 的提案 + +OpenFunction Gateway 提供了一个更强大、更灵活的函数网关,包括以下特性: + +- 使用户能够以更简单、厂商中立的方式切换到任何支持 [Kubernetes Gateway API](https://gateway-api.sigs.k8s.io/) 的 [网关实现](https://gateway-api.sigs.k8s.io/implementations/),如 Contour、Istio、Apache APISIX、Envoy Gateway(未来)等。 + +- 用户可以选择安装默认的网关实现(Contour),然后定义一个新的 `gateway.networking.k8s.io`,或者使用他们环境中的任何现有网关实现,然后引用现有的 `gateway.networking.k8s.io`。 + +- 允许用户自定义他们自己的函数访问模式,如 `hostTemplate: "{{.Name}}.{{.Namespace}}.{{.Domain}}"` 用于基于主机的访问。 + +- 允许用户自定义他们自己的函数访问模式,如 `pathTemplate: "{{.Namespace}}/{{.Name}}"` 用于基于路径的访问。 + +- 允许用户在函数定义中自定义每个函数的路由规则(基于主机、基于路径或两者都有),如果没有定义自定义的路由规则,将为每个函数提供默认的路由规则。 + +- 直接将流量发送到 Knative 服务修订版,而不再通过 Knative 自己的网关。从 OpenFunction 0.7.0 开始,你只需要 OpenFunction Gateway 就可以访问 OpenFunction 同步函数,如果你不需要直接访问 Knative 服务,你可以忽略 Knative 的域配置错误。 + +- 在函数修订版之间分割流量(未来) + +下图说明了客户端流量如何通过 OpenFunction Gateway,然后直接到达函数: + +
\ No newline at end of file diff --git a/content/zh/docs/concepts/networking/route.md b/content/zh/docs/concepts/networking/route.md new file mode 100644 index 00000000..ad1814af --- /dev/null +++ b/content/zh/docs/concepts/networking/route.md @@ -0,0 +1,180 @@ +--- +title: "路由" +linkTitle: "路由" +weight: 3430 +description: +--- + +## 什么是 `Route`? + +`Route` 是 `Function` 定义的一部分。`Route` 定义了来自 `Gateway` 监听器的流量如何路由到函数。 + +`Route` 在 `GatewayRef` 中指定了它将附加到的 `Gateway`,使其能够从 `Gateway` 接收流量。 + +一旦创建了同步 `Function`,函数控制器将: + +- 查找 `openfunction` 命名空间中名为 `openfunction` 的 `Gateway`,然后如果函数中没有定义 `route.gatewayRef`,则附加到此 `Gateway`。 +- 如果函数中没有定义 `route.hostnames`,则根据 `Gateway.spec.hostTemplate` 自动生成 `route.hostnames`。 +- 如果函数中没有定义 `route.rules`,则根据路径 `/` 自动生成 `route.rules`。 +- 根据 `Route` 创建一个 `HTTPRoute` 自定义资源。`BackendRefs` 将自动链接到相应的 Knative 服务修订版,并将 `HTTPRouteLabelKey` 标签添加到此 `HTTPRoute`。 +- 创建服务 `{{.Name}}.{{.Namespace}}.svc.cluster.local`,此服务定义了从集群内部访问函数的入口。 +- 如果 `route.gatewayRef` 引用的 `Gateway` 发生变化,将更新 `HTTPRoute`。 + +部署同步 `Function` 后,你将能够在 `Function` 的状态字段中找到 `Function` 地址和 `Route` 状态,例如: + +```yaml +status: + addresses: + - type: External + value: http://function-sample-serving-only.default.ofn.io/ + - type: Internal + value: http://function-sample-serving-only.default.svc.cluster.local/ + build: + resourceHash: "14903236521345556383" + state: Skipped + route: + conditions: + - message: Valid HTTPRoute + reason: Valid + status: "True" + type: Accepted + hosts: + - function-sample-serving-only.default.ofn.io + - function-sample-serving-only.default.svc.cluster.local + paths: + - type: PathPrefix + value: / + serving: + lastSuccessfulResourceRef: serving-znk54 + resourceHash: "10715302888241374768" + resourceRef: serving-znk54 + service: serving-znk54-ksvc-nbg6f + state: Running +``` + +{{% alert title="注意" color="success" %}} + +`Funtion.status` 中类型为 `Internal` 的地址提供了从集群内部访问函数的默认方法。 +这个内部地址不受 `route.gatewayRef` 引用的 `Gateway` 的影响,它适合用作 `EventSource` 的 `sink.url`。 + +`Funtion.status` 中类型为 `External` 的地址提供了从集群外部访问函数的方法(你可以选择配置 Magic DNS 或真实 DNS,请参考 [通过外部地址访问函数](../function-entrypoints/#通过外部地址访问函数) 获取更多详情)。 +这个外部地址是基于 `route.gatewayRef`、`router.hostnames` 和 `route.rules` 生成的。路由模式只对这个外部地址生效,下面的文档将解释它是如何工作的。 + +有关如何访问函数的更多信息,请参考 [函数入口点](../function-entrypoints/)。 + +{{% /alert %}} + +## 基于主机的路由 + +`基于主机` 是默认的路由模式。当 `route.hostnames` 未定义时, +将根据 `gateway.spec.hostTemplate` 自动生成 `route.hostnames`。 +如果 `route.rules` 未定义,将根据路径 `/` 自动生成 `route.rules`。 + +```shell +kubectl apply -f - < 如果你正在使用默认的 [OpenFunction Gateway](../gateway#默认的-openfunction-网关),函数的外部地址将如下: + +```shell +http://function-sample.default.ofn.io/ +``` + +## 基于路径的路由 + +如果你在函数中定义了 `route.hostnames`,将根据 `gateway.spec.pathTemplate` 自动生成 `route.rules`。 + +```shell +kubectl apply -f - < 如果你正在使用默认的 [OpenFunction Gateway](../gateway#默认的-openfunction-网关),函数的外部地址将如下: + +```shell +http://sample.default.ofn.io/default/function-sample/ +``` + +## 基于主机和路径的路由 + +你可以同时定义主机名和路径,以自定义流量应如何路由到你的函数。 + +{{% alert title="注意" color="success" %}} + +在这种模式下,你需要自己解决 HTTPRoutes 之间可能存在的冲突。 + +{{% /alert %}} +```shell +kubectl apply -f - < 如果你正在使用默认的 [OpenFunction Gateway](../gateway#默认的-openfunction-网关),函数的外部地址将如下: + +```shell +http://sample.default.ofn.io/v2/foo/ +``` diff --git a/content/zh/docs/concepts/serverless_apps.md b/content/zh/docs/concepts/serverless_apps.md new file mode 100644 index 00000000..f6400686 --- /dev/null +++ b/content/zh/docs/concepts/serverless_apps.md @@ -0,0 +1,124 @@ +--- +title: "无服务器应用" +linkTitle: "无服务器应用" +weight: 3330 +description: +--- +除了构建和运行无服务器函数外,你还可以使用 OpenFuntion 构建和运行无服务器应用。 + +OpenFunction 支持两种不同的方式将源代码构建成容器镜像: +- 使用 [Cloud Native Buildpacks](https://buildpacks.io/) 在没有 `Dockerfile` 的情况下构建源代码 +- 使用 [Buildah](https://buildah.io/) 或 [BuildKit](https://github.com/moby/buildkit) 在有 `Dockerfile` 的情况下构建源代码 + +> 要将镜像推送到容器镜像仓库,你需要创建一个包含镜像仓库凭据的 secret,并将 secret 添加到 `imageCredentials`。 +> 请参考 [先决条件](../../getting-started/Quickstarts/prerequisites) 部分获取更多信息。 + +## 使用 Dockerfile 构建和运行无服务器应用 + +如果你已经为你的应用创建了一个 `Dockerfile`,比如这个 [Go 应用](https://github.com/OpenFunction/samples/tree/main/apps/buildah/go),你可以像 [这样](https://github.com/OpenFunction/samples/blob/main/apps/buildah/go/sample-go-app.yaml) 以无服务器的方式构建和运行这个应用: + +1. 创建示例 Go 无服务器应用 + +```shell +cat < [这里](https://github.com/OpenFunction/samples/tree/main/apps/buildah/java)你可以找到一个 Java 无服务器应用(带有 Dockerfile)的示例。 + +## 不使用 Dockerfile 构建和运行无服务器应用 + +如果你有一个没有 Dockerfile 的应用,比如这个 [Java 应用](https://github.com/buildpacks/samples/tree/main/apps/java-maven),你也可以像这个 Java 应用 那样以无服务器的方式构建和运行你的应用: + +1. 创建示例 Java 无服务器应用 + +```shell +cat < - OpenFunction 概念之核心框架资源,函数负载器 Serving ---- - -**Serving** 的目标是以高度弹性的方式(动态伸缩:0 <-> N)为使用者运行应用负载。 - -当前,OpenFunction Serving 支持两种负载运行时:[Knative](#knative) 和 [OpenFuncAsync](#openfuncasync)。设置其中一种负载运行时之后,Serving 才能正常工作。 - -### Knative - -[Knative Serving](https://github.com/knative/serving) 建立在 Kubernetes 之上,支持部署和运行 Serverless 应用。Knative Serving 很容易上手,并可延伸支持复杂的应用场景。 - -### OpenFuncAsync - -OpenFuncAsync 是一个事件驱动的负载运行时。它基于 [KEDA](https://keda.sh/) 与 [Dapr](https://dapr.io/) 实现。OpenFuncAsync 负载的函数可以由各类事件、消息触发,如 MQ、cronjob、DB 事件等。在 Kubernetes 集群中,OpenFuncAsync 负载的函数可以通过无状态工作负载或任务的形式运行。 - -### 参考 - -Serving 是一种 [CustomResourceDefinitions(CRD)](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/)。你可以访问 [Serving CRD Spec]({{< ref "../reference/function-spec#servingimpl" >}}) 了解更多信息。 diff --git a/content/zh/docs/concepts/trigger.md b/content/zh/docs/concepts/trigger.md deleted file mode 100644 index 9909c741..00000000 --- a/content/zh/docs/concepts/trigger.md +++ /dev/null @@ -1,16 +0,0 @@ ---- -title: "Trigger" -linkTitle: "Trigger" -weight: 35 -description: > - OpenFunction 概念之事件框架资源,事件触发器 Trigger ---- - -**Trigger** 是对事件目的的抽象,即在收到一个消息时需要做什么。 - -**Trigger** 包含了使用者对事件目的的描述,它指导 Trigger 应该从哪些事件源获取事件,随后根据给定的条件决定是否触发目标函数。 - -### 参考 - -Trigger 是一种 [CustomResourceDefinitions(CRD)](https://kubernetes.io/docs/tasks/extend-kubernetes/custom-resources/custom-resource-definitions/)。你可以访问 [Trigger CRD Spec]({{< ref "../reference/trigger-spec" >}}) 了解更多信息。 - diff --git a/content/zh/docs/concepts/wasm_functions.md b/content/zh/docs/concepts/wasm_functions.md new file mode 100644 index 00000000..ae8490ad --- /dev/null +++ b/content/zh/docs/concepts/wasm_functions.md @@ -0,0 +1,98 @@ +--- +title: "Wasm 函数" +linkTitle: "Wasm 函数" +weight: 3310 +description: +--- + +`WasmEdge` 是一个轻量级、高性能、可扩展的 WebAssembly 运行时,用于云原生、边缘和去中心化应用。它支持无服务器应用、嵌入式函数、微服务、智能合约和物联网设备。 + +OpenFunction 现在支持使用 `WasmEdge` 作为工作负载运行时来构建和运行 wasm 函数。 + +> 你可以在[这里](https://github.com/OpenFunction/OpenFunction/blob/main/docs/proposals/20230223-wasmedge-integration.md)找到 WasmEdge 集成提案 + +## Wasm 容器镜像 + +包含 wasm 二进制文件的 wasm 镜像是一个没有操作系统层的特殊容器镜像。应该在这个 wasm 容器镜像中添加一个特殊的注解 `module.wasm.image/variant: compat-smart`,以便像 WasmEdge 这样的 wasm 运行时能够识别它。这在 OpenFunction 中是自动处理的,用户只需要将 `workloadRuntime` 指定为 `wasmedge`。 + +### Wasm 容器镜像的构建阶段 + +如果 `function.spec.workloadRuntime` 设置为 `wasmedge`,或者函数的注解包含 `module.wasm.image/variant: compat-smart`,`function.spec.build.shipwright.strategy` 将根据名为 `wasmedge` 的 `ClusterBuildStrategy` 自动生成,以便构建带有 `module.wasm.image/variant: compat-smart` 注解的 wasm 容器镜像。 + +### Wasm 容器镜像的服务阶段 + +当 `function.spec.workloadRuntime` 设置为 `wasmedge`,或者函数的注解包含 `module.wasm.image/variant: compat-smart` 时: +- 如果 `function.spec.serving.annotations` 不包含 `module.wasm.image/variant`,`module.wasm.image/variant: compat-smart` 将自动添加到 `function.spec.serving.annotations`。 +- 如果 `function.spec.serving.template.runtimeClassName` 没有设置,这个 `runtimeClassName` 将自动设置为默认的 `openfunction-crun` + +> 如果你的 kubernetes 集群在像 `Azure` 这样的公共云中,你可以手动设置 `spec.serving.template.runtimeClassName` 来覆盖默认的 `runtimeClassName`。 + +## 构建和运行 wasm 函数 + +> 要在 kubernetes 集群中设置 `WasmEdge` 工作负载运行时并将镜像推送到容器镜像仓库, +> 请参考[先决条件](../../getting-started/Quickstarts/prerequisites)部分以获取更多信息。 + +> 你可以在[这里](https://github.com/OpenFunction/samples/tree/main/functions/knative/wasmedge/http-server)找到关于这个示例函数的更多信息。 + +1. 创建一个 wasm 函数 + +```shell +cat <}}) 的提交并打开一个 PR +6. 等待 CI 过程完成并确保所有检查都是绿色的 +7. 您可以在几天内期待一次审查 + +### 使用工作进度中的 PR 获取早期反馈 + +在投入太多时间之前,一种进行沟通的好方法是创建一个 "工作进度中" 的 PR 并与您的审查者分享。做到这一点的标准方式是在您的 PR 的标题中添加 "[WIP]" 前缀并分配 **do-not-merge** 标签。这将让查看您的 PR 的人知道它还没有准备好。 + +## 开发者原创证书:签署您的工作 +### 每个提交都需要签署 + +开发者原创证书 (DCO) 是一种轻量级的方式,供贡献者证明他们编写或者以其他方式有权提交他们正在向项目贡献的代码。这里是 [DCO](https://developercertificate.org/) 的全文。 + +贡献者通过在提交消息中添加 `Signed-off-by` 行来签署他们遵守这些要求。 + +``` +这是我的提交消息 +Signed-off-by: 随机 J 开发者 +``` + +Git 有一个 `-s` 命令行选项,可以自动将此内容添加到您的提交消息中: +``` +git commit -s -m '这是我的提交消息' +``` + +每个拉取请求都会检查拉取请求中的提交是否包含有效的 Signed-off-by 行。 + +### 我没有签署我的提交,现在该怎么办?! + +别担心 - 您可以轻松地重播您的更改,签署它们并强制推送它们! + +``` +git checkout +git commit --amend --no-edit --signoff +git push --force-with-lease +``` + +## 开发指南 + +[这里](https://github.com/OpenFunction/OpenFunction/tree/main/docs/development) 您可以找到一个开发指南,它将指导您如何开始在您的本地环境中构建 OpenFunction。 + +## 行为准则 + +请参阅 [OpenFunction 社区行为准则](https://github.com/OpenFunction/OpenFunction/blob/main/code-of-conduct.md)。 diff --git a/content/zh/docs/contributing/roadmap.md b/content/zh/docs/contributing/roadmap.md new file mode 100644 index 00000000..af930808 --- /dev/null +++ b/content/zh/docs/contributing/roadmap.md @@ -0,0 +1,12 @@ +--- +title: "路线图" +linkTitle: "路线图" +weight: 7200 +description: +--- + +OpenFunction 鼓励社区帮助确定优先级。OpenFunction 的路线图的 [GitHub 项目](https://github.com/orgs/OpenFunction/projects/3/views/1?layout=board) 可供社区对提议的问题提供反馈并跟踪它们的开发。 + +请通过在 GitHub 问题上添加 👍 来投票,选择您最希望 OpenFunction 支持的功能。这将帮助 OpenFunction 的维护者更好地理解您的需求。 + +我们始终欢迎社区的贡献。如果路线图上有您感兴趣的功能,并且您想要对其进行贡献,请在 GitHub 问题上发表评论,并包含您的解决方案提议。 \ No newline at end of file diff --git a/content/zh/docs/development/_index.md b/content/zh/docs/development/_index.md deleted file mode 100644 index 76f96206..00000000 --- a/content/zh/docs/development/_index.md +++ /dev/null @@ -1,8 +0,0 @@ ---- -title: "开发 & 贡献指南" -linkTitle: "开发 & 贡献指南" -weight: 20 -description: > - 学习怎样开发 OpenFunction 及怎样贡献您的代码 ---- - diff --git a/content/zh/docs/development/development-workflow.md b/content/zh/docs/development/development-workflow.md deleted file mode 100644 index 96c3ddb0..00000000 --- a/content/zh/docs/development/development-workflow.md +++ /dev/null @@ -1,116 +0,0 @@ ---- -title: "开发流程" -linkTitle: "开发流程" -weight: 10 -description: > - 本文件将向您介绍项目开发的详细过程。 ---- - -## 步骤1. Fork - -1. 访问 https://github.com/OpenFunction/OpenFunction -2. 点击 “Fork” 按钮,在你的 GitHub 账户中创建一个 fork 项目。 - -## 步骤2. 克隆 fork 项目至本地 - -Per Go's [workspace instructions](https://golang.org/doc/code.html#Workspaces), place OpenFunction code on your `GOPATH` using the following cloning procedure. - -根据 Go 的 [workspace instructions](https://golang.org/doc/code.html#Workspaces),使用以下克隆工序将 OpenFunction 代码放在你的 `GOPATH` 上。 - -定义一个本地目录: - -``` -export working_dir=$GOPATH/src/openfunction.io -export user={your github profile name} -``` - -将代码克隆到本地: - -``` -mkdir -p $working_dir -cd $working_dir -git clone https://github.com/$user/OpenFunction.git -cd $working_dir/OpenFunction -git remote add upstream https://github.com/OpenFunction/OpenFunction.git - -# Never push to upstream master -git remote set-url --push upstream no_push - -# Confirm your remotes make sense: -git remote -v -``` - -## 步骤3. 保持与上游分支的同步 - -``` -git fetch upstream -git checkout main -git rebase upstream/main -``` - -## 步骤4. 增加新特性或补丁 - -从 master 中创建一个新分支: - -``` -git checkout -b myfeature -``` - -然后在 `myfeature` 分支上开发代码。参考 [effective_go](https://golang.org/doc/effective_go.html) 有助于你的编码。 - -### 测试与构建 - -目前,make 规则只包含简单的检查,如 vet、unit 测试,很快会加入 e2e 测试。 - -### 使用 KubeBuilder - -- 对于 Linux 操作系统,你可以下载并执行这个 [KubeBuilder脚本](https://raw.githubusercontent.com/kubesphere/kubesphere/master/hack/install_kubebuilder.sh)。 -- 对于 MacOS,你可以按照这个 [指南](https://book.kubebuilder.io/quick-start.html) 来安装 KubeBuilder。 - -### 运行与测试 - -``` -make all -# Run every unit test -make test -``` - -运行 `make help` 以获得关于 make 的额外信息。 - -## 步骤5. 开新分支开发 - -### 与上游分支同步 - -测试完成后,让你本地的代码与上游分支保持同步有助于避免冲突。 - -``` -# Rebase your master branch of your local repo. -git checkout main -git rebase upstream/main - -# Then make your development branch in sync with master branch -git checkout new_feature -git rebase -i main -``` - -### 提交本地变化 - -``` -git add -git commit -s -m "add your description" -``` - -## 步骤6. 推送至你的 fork 仓库 - -当准备好审查时(或者只是为了建立一个异地的工作备份),把你的本地分支推送到 GitHub 上的 fork 仓库。 - -``` -git push -f ${your_remote_name} myfeature -``` - -## 步骤7. 创建一个 PR - -- 访问你在 GitHub 上的 fork 仓库 https://github.com/$user/OpenFunction -- 点击你的 `myfeature` 分支旁的 ` Compare & Pull Request` 按钮 -- 请查看 [pull requests 流程](pull-requests.md),了解更多细节和建议 - diff --git a/content/zh/docs/development/pull-requests.md b/content/zh/docs/development/pull-requests.md deleted file mode 100644 index 05e6244b..00000000 --- a/content/zh/docs/development/pull-requests.md +++ /dev/null @@ -1,124 +0,0 @@ ---- -title: "Pull Request 流程" -linkTitle: "Pull Request 流程" -weight: 20 -description: > - 本文档将帮助你学习如何提交 pull requests。 ---- - -本文档演示了向 [OpenFunction 项目](https://github.com/OpenFunction/OpenFunction) 提交 PR 的过程和最佳实践。它可以为所有贡献者(尤其是新接触或不经常提交 PR 的开发者)提供有价值的参考。 - -- [在提交 PR 之前](#在提交-pr-之前) - - [运行本地验证](#运行本地验证) -- [PR 的提交流程](#pr-的提交流程) - - [如有需要,编写 Release notes ](#如有需要编写-release-notes) - - [测试与合并工作流](#测试与合并工作流) - - [标记未完成的 Pull Requests](#标记未完成的-pull-requests) - -## 在提交 PR 之前 - -本指南是为已经有 PR 要提交的贡献者准备的。如果你正在寻找关于如何搭建你的开发环境以及如何为 OpenFunction 贡献代码的信息,请参见 [开发指南](development-workflow.md) 。 - -**确保你的 PR 符合我们的最佳实践。这包括遵循项目惯例,提交小型 PR,以及全面地进行评论。请阅读本文件末尾关于[加快评审的最佳实践](#best-practices-for-faster-reviews)的更详细章节。** - -### 运行本地验证 - -你可以在提交 PR 之前运行这些本地验证,以预测持续集成的通过或失败。 - -## PR 的提交流程 - -合并一个 PR 需要在自动合并 PR 之前完成以下步骤。关于每个步骤的细节,请参见下面的[测试和合并工作流程](#the-testing-and-merge-workflow)部分。 - -- 生成 PR -- Release notes -- 包含以下一项: - - 在 release notes 中添加说明,或 - - 上传 release notes 的标签 -- 通过所有测试 -- 从 reviewer 处获得一个 `/lgtm` 标签 -- 从 owner 处获得一个 `approval` - -如果你的 PR 符合上述所有步骤,它将进入提交队列被合并。当它成为下一个被合并的队列时,测试将运行第二次。如果所有的测试都通过了,PR 将被自动合并。 - -### 如有需要,编写 Release notes - -任何带有用户可见变化的 PR 都需要 release notes,例如错误修复、功能添加和输出格式变化。 - -如果你不在 PR 模板中添加 release notes,那么在你创建 PR 后,“do-not-merge/release-note-label-needed” 的标签会自动添加到你的 PR 中。有几种方法可以更新它。 - -在 PR 描述中增加一个 release-note 部分。 - -对于有 release notes 的 PR: - - ```release-note - Your release note here - ``` - -对于需要用户在切换到新版本时采取额外操作的 PR,请在发布说明中加入 “action required” 的字符串(不区分大小写): - - ```release-note - action required: your release note here - ``` - -对于不需要在发布时提及的 PR,只需写上 “NONE”(不区分大小写): - - ```release-note - NONE - ``` - -`/release-note-none` 注释命令仍然可以用来替代在 release-note 块中写 “NONE”,如果它留空的话。 - -要了解如何格式化您的 release notes,请查看 [PR 模板](https://github.com/) 以了解一个简单的例子。PR 的标题和正文注释可以在发布前的任何时候进行修改,以使其对发布注释友好。 -// PR template TODO - -Release notes 适用于主分支上的 PR 。对于 cherry-pick PR,请参阅 [cherry-pick instructions](cherry-picks.md) 。这些规则的唯一例外是,当一个 PR 不是 cherry-pick,而是直接针对非主干分支时。 在这种情况下,非主分支 PR 需要一个 `release-note-*` 标签。 - -// cherry-pick TODO - -现在你的 release notes 已经成型了,让我们看看 PR 是如何被测试和合并的。 - -### 测试与合并工作流 - -OpenFunction 的合并工作流程使用注释来运行测试和标签来合并 PR。 - -注意:对于正在进行但尚未准备好接受审查的拉动请求,在 PR 标题前加上 “WIP” 或 “[WIP]”,并在 pull requests 描述中的检查清单中跟踪任何剩余的 TODO。 - -以下是 PR 从提交到合并的过程: - -1. 生成 pull request -2. `@o8x-merge-robot` 分配 reviewer //TODO - -如果你 **不是** 的 OpenFunction 组织的成员: - -1. Reviewer/OpenFunction 成员检查 PR 是否可以安全测试。如果是的话,他们会评论 `/ok-to-test`。 -2. Reviewer 建议编辑 -3. 提交编辑至你的 PR 分支 -4. 重复最先的两个步骤 -5. (可选)一些 reviewer 希望你在这一步合并(squash)提交的内容 -6. Owner 被安排处理这次合并,并将在 PR 上添加 `/approve` 标签 - -如果你是一个项目的成员,或者一个评论了 `/ok-to-test` 的成员,该 PR 将被认为是可信的。然后提交前的测试就会运行: - -1. 自动测试运行。参见 PR 上的当前测试列表 -2. 如果测试失败,通过向你的 PR 分支推送编辑来解决问题 -3. 如果失败是偶然的,任何受信任的 PR 上的人都可以评论 `/retest` 来重新运行失败的测试 - -一旦测试通过,所有的失败都被评论为偶然的,或者评审员添加了 `lgtm` 和 `approved` 标签,PR 就进入了最后的合并队列。合并队列是必须的,以确保在你的 PR 上最后一次运行测试后,其他 PR 没有引入不兼容的变化。 - -1. 该 PR 进入合并队列 -2. 合并队列触发了一个测试的重新运行,注释为 `/test all [submit-queue 正在验证这个 PR 是否可以安全合并]`。 - 2.1. 作者已经签署了 CLA(`cncf-cla: yes` 标签添加到 PR)。 - 2.2. 自上次应用 `lgtm` 标签以来,没有做出任何改变 -3. 如果测试失败,通过向你的 PR 分支推送编辑来解决问题 -4. 如果失败是偶然的,任何受信任的 PR 上的人都可以评论 `/retest` 来重新运行失败的测试 -5. 如果测试通过,合并队列将自动合并 PR - -这就是最后一步了。你的 PR 现在被合并了。 - -### 标记未完成的 Pull Requests - -如果你想在你的 pull requests 执行完成之前征求评论,你应该保留你的 pull requests,以确保合并队列不会试图合并它。有两种方法可以实现这一点。 - -1. 你可以添加 `/hold` 或 `/hold cancel` 的注释命令 -2. 你可以在你的 pull requests 标题中添加或删除 `WIP` 或 `[WIP]` 前缀 - -当你使用评论命令时,GitHub 机器人会添加和删除 `do-not-merge/hold` 标签,当你编辑标题时,会添加和删除 `do-not-merge/work in-progress` 标签。当这两个标签存在时,你的 pull requests 将不被考虑合并。 diff --git a/content/zh/docs/development/quickstarted.md b/content/zh/docs/development/quickstarted.md deleted file mode 100644 index 3a22ae24..00000000 --- a/content/zh/docs/development/quickstarted.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "快速上手" -linkTitle: "快速上手" -weight: 5 -description: > - 本文将指导你如何在你的本地环境中开始构建 OpenFunction。 ---- - -## 前提准备 - ---- - -如果你对开发控制器、管理器感兴趣,请参阅 [sample-controller](https://github.com/kubernetes/sample-controller) 和 [kubebuilder](https://github.com/kubernetes-sigs/kubebuilder)。 - -### Go - -OpenFunction 基于 [Kubernetes](https://github.com/kubernetes/kubernetes)。它们都是用 [Go](https://go.dev/) 编写的。如果你没有 Go 开发环境,请先 [设置 Go 开发环境](https://go.dev/doc/code)。 - -| Kubernetes | 要求的 Go 版本 | -| ---------- | -------------- | -| 1.18+ | go>=1.12 | - -> 提示: -> -> - 确保你的 GOPATH 和 PATH 已经按照 Go 环境说明进行了配置。 -> - 在使用 MacOS 进行开发时,建议安装 [macOS GNU tools](https://www.topbug.net/blog/2013/04/14/install-and-use-gnu-command-line-tools-in-mac-os-x)。 - -### Docker - -OpenFunction 组件通常在 Kubernetes 中以容器方式部署。如果你需要在 Kubernetes 集群中部署 OpenFunction 组件,你需要提前 [安装 Docker](https://docs.docker.com/install/)。 - -### 依赖管理 - -OpenFunction 使用 [Go Modules](https://github.com/golang/go/wiki/Modules) 管理依赖包。 - -## 制作镜像 & 运行 - ---- - -你可以通过修改 `cmd/Dockerfile` 来为你的本地环境制作 `openfunction` 镜像。 - -将镜像上传到你的个人镜像仓库后,在工作负载(Deployment)openfunction-controller-manager 中改变 `openfunction` 容器的镜像为你的个人镜像。 - -```shell -kubectl edit deployments.apps -n openfunction openfunction-controller-manager -``` - -保存后,Kubernetes 将自动应用新的镜像运行工作负载。 \ No newline at end of file diff --git a/content/zh/docs/getting-started/Quickstarts/_index.md b/content/zh/docs/getting-started/Quickstarts/_index.md new file mode 100644 index 00000000..981d60e3 --- /dev/null +++ b/content/zh/docs/getting-started/Quickstarts/_index.md @@ -0,0 +1,7 @@ +--- +title: "开始使用" +linkTitle: "开始使用" +weight: 2200 +description: +--- + diff --git a/content/zh/docs/getting-started/Quickstarts/async-functions.md b/content/zh/docs/getting-started/Quickstarts/async-functions.md new file mode 100644 index 00000000..ffd163a4 --- /dev/null +++ b/content/zh/docs/getting-started/Quickstarts/async-functions.md @@ -0,0 +1,20 @@ +--- +title: "创建异步函数" +linkTitle: "创建异步函数" +weight: 2230 +description: +--- + +> 在创建任何函数之前,请确保您已安装所有[先决条件](../prerequisites) + +异步函数是事件驱动的,它们的输入通常是来自非HTTP事件源的事件,如消息队列、cron触发器、MQTT代理等,通常客户端在通过传递事件触发异步函数后不会等待立即的响应。以下是不同语言的一些异步函数示例: + +| | 异步函数 | +|-----------|-----------------| +| Go | [Kafka输入和HTTP输出绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/logs-handler-function), [Cron输入和Kafka输出绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/bindings/cron-input-kafka-output), [Cron输入绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/bindings/cron-input), [Kafka输入绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/bindings/kafka-input), [Kafka pubsub](https://github.com/OpenFunction/samples/tree/main/functions/async/pubsub) | +| Nodejs | [MQTT绑定和pubsub](https://github.com/OpenFunction/samples/tree/main/functions/async/mqtt-io-node) | +| Python | | +| Java | [Cron输入和Kafka输出绑定](https://github.com/OpenFunction/samples/tree/main/functions/async/java/cron-input-kafka-output), [Kafka pubsub](https://github.com/OpenFunction/samples/tree/main/functions/async/java/pubsub) | +| DotNet | | + +> 您可以在[这里](../../../concepts/function_signatures/#samples)找到更多函数示例 diff --git a/content/zh/docs/getting-started/Quickstarts/prerequisites.md b/content/zh/docs/getting-started/Quickstarts/prerequisites.md new file mode 100644 index 00000000..eabcc265 --- /dev/null +++ b/content/zh/docs/getting-started/Quickstarts/prerequisites.md @@ -0,0 +1,239 @@ +--- +title: "先决条件" +linkTitle: "先决条件" +weight: 2210 +description: +--- + +## 镜像仓库凭证 + +在构建函数时,您需要将函数容器镜像推送到像[Docker Hub](https://hub.docker.com/)或[Quay.io](https://quay.io/)这样的容器镜像仓库。为此,您首先需要为您的容器镜像仓库生成一个密钥。 + +您可以通过填写`REGISTRY_SERVER`,`REGISTRY_USER`和`REGISTRY_PASSWORD`字段,然后运行以下命令来创建此密钥。 + +```bash +REGISTRY_SERVER=https://index.docker.io/v1/ +REGISTRY_USER= +REGISTRY_PASSWORD= +kubectl create secret docker-registry push-secret \ + --docker-server=$REGISTRY_SERVER \ + --docker-username=$REGISTRY_USER \ + --docker-password=$REGISTRY_PASSWORD +``` + +## 源代码库凭证 + +如果您的源代码位于私有git仓库中,您需要创建一个包含私有git仓库的用户名和密码的密钥: + +```shell +cat < + password: +EOF +``` + +然后,您可以在`Function` CR的spec.build.srcRepo.credentials中引用此密钥 + +```yaml +apiVersion: core.openfunction.io/v1beta1 +kind: Function +metadata: + name: function-sample +spec: + version: "v2.0.0" + image: "openfunctiondev/sample-go-func:v1" + imageCredentials: + name: push-secret + build: + builder: openfunction/builder-go:latest + env: + FUNC_NAME: "HelloWorld" + FUNC_CLEAR_SOURCE: "true" + srcRepo: + url: "https://github.com/OpenFunction/samples.git" + sourceSubPath: "functions/knative/hello-world-go" + revision: "main" + credentials: + name: git-repo-secret + serving: + template: + containers: + - name: function # DO NOT change this + imagePullPolicy: IfNotPresent + runtime: "knative" +``` + +## Kafka + +异步函数可以由消息队列中的事件触发,如Kafka,这里您可以找到设置Kafka集群的步骤,用于演示目的。 + +1. 在默认命名空间中安装[strimzi-kafka-operator](https://github.com/strimzi/strimzi-kafka-operator)。 + + ```shell + helm repo add strimzi https://strimzi.io/charts/ + helm install kafka-operator -n default strimzi/strimzi-kafka-operator + ``` + +2. 运行以下命令在默认命名空间中创建Kafka集群和Kafka Topic。此命令创建的Kafka和Zookeeper集群的存储类型为**ephemeral**,并使用emptyDir进行演示。 + + > 这里我们创建一个名为``的1副本Kafka服务器和一个名为``的1副本主题,带有10个分区 + + ```shell + cat < + namespace: default + spec: + kafka: + version: 3.3.1 + replicas: 1 + listeners: + - name: plain + port: 9092 + type: internal + tls: false + - name: tls + port: 9093 + type: internal + tls: true + config: + offsets.topic.replication.factor: 1 + transaction.state.log.replication.factor: 1 + transaction.state.log.min.isr: 1 + default.replication.factor: 1 + min.insync.replicas: 1 + inter.broker.protocol.version: "3.1" + storage: + type: ephemeral + zookeeper: + replicas: 1 + storage: + type: ephemeral + entityOperator: + topicOperator: {} + userOperator: {} + --- + apiVersion: kafka.strimzi.io/v1beta2 + kind: KafkaTopic + metadata: + name: + namespace: default + labels: + strimzi.io/cluster: + spec: + partitions: 10 + replicas: 1 + config: + cleanup.policy: delete + retention.ms: 7200000 + segment.bytes: 1073741824 + EOF + ``` + +3. 运行以下命令检查Pod状态,并等待Kafka和Zookeeper运行并启动。 + + ```shell + $ kubectl get po + NAME READY STATUS RESTARTS AGE + -entity-operator-568957ff84-nmtlw 3/3 Running 0 8m42s + -kafka-0 1/1 Running 0 9m13s + -zookeeper-0 1/1 Running 0 9m46s + strimzi-cluster-operator-687fdd6f77-cwmgm 1/1 Running 0 11m + ``` + + 运行以下命令查看Kafka集群的元数据。 + + ```shell + $ kafkacat -L -b -kafka-brokers:9092 + ``` + +## WasmEdge + +函数现在支持使用`WasmEdge`作为工作负载运行时,这里您可以找到在Kubernetes集群中设置`WasmEdge`工作负载运行时的步骤(以`containerd`为容器运行时)。 + +> 您应在集群的所有节点(或将承载wasm工作负载的节点的子集)上运行以下步骤。 + +### 步骤1:安装WasmEdge + +安装WasmEdge的最简单方法是运行以下命令。您的系统应已安装git和curl。 + ```shell + wget -qO- https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash -s -- -p /usr/local + ``` + +### 步骤2:安装容器运行时 + +#### crun + +crun项目已经内置了WasmEdge支持。现在,最简单的方法就是下载二进制文件并将其移动到`/usr/local/bin/` +```shell +wget https://github.com/OpenFunction/OpenFunction/releases/latest/download/crun-linux-amd64 +mv crun-linux-amd64 /usr/local/bin/crun +``` +如果上述方法对您不起作用,请参考[构建并安装带有WasmEdge支持的crun二进制文件。](https://wasmedge.org/book/en/use_cases/kubernetes/container/crun.html) + +### 步骤3:设置CRI运行时 + +#### 选项1:containerd + +> 您可以按照此[安装指南](https://github.com/containerd/containerd/blob/main/docs/getting-started.md#installing-containerd)来安装containerd,并按照此[设置指南](https://github.com/containerd/containerd/blob/main/docs/getting-started.md#setting-up-containerd-for-kubernetes)来为Kubernetes设置containerd。 + +首先,编辑配置`/etc/containerd/config.toml`,添加以下部分来设置crun运行时,确保BinaryName等于您的crun二进制路径 +``` +# Add crun runtime here +[plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun] + runtime_type = "io.containerd.runc.v2" + pod_annotations = ["*.wasm.*", "wasm.*", "module.wasm.image/*", "*.module.wasm.image", "module.wasm.image/variant.*"] + privileged_without_host_devices = false + [plugins."io.containerd.grpc.v1.cri".containerd.runtimes.crun.options] + BinaryName = "/usr/local/bin/crun" +``` + +接下来,重启containerd服务: + +```shell +sudo systemctl restart containerd +``` + +#### 选项2:CRI-O + +> 您可以按照此[安装指南](https://github.com/cri-o/cri-o/blob/main/install.md)来安装CRI-O,并按照此[设置指南](https://github.com/cri-o/cri-o/blob/main/tutorials/kubernetes.md#running-cri-o-on-kubernetes-cluster)来为Kubernetes设置CRI-O。 + +CRI-O默认使用runc运行时,我们需要配置它来使用crun。这是通过添加到两个配置文件来完成的。 + +首先,创建一个`/etc/crio/crio.conf`文件,并添加以下行作为其内容。它告诉CRI-O默认使用crun。 + +``` +[crio.runtime] +default_runtime = "crun" +``` + +crun运行时反过来在`/etc/crio/crio.conf.d/01-crio-runc.conf`文件中定义。 +``` +[crio.runtime.runtimes.runc] +runtime_path = "/usr/lib/cri-o-runc/sbin/runc" +runtime_type = "oci" +runtime_root = "/run/runc" +# The above is the original content + +# Add crun runtime here +[crio.runtime.runtimes.crun] +runtime_path = "/usr/local/bin/crun" +runtime_type = "oci" +runtime_root = "/run/crun" +``` + +接下来,重启CRI-O以应用配置更改。 + +```shell +systemctl restart crio +``` diff --git a/content/zh/docs/getting-started/Quickstarts/serverless-apps.md b/content/zh/docs/getting-started/Quickstarts/serverless-apps.md new file mode 100644 index 00000000..c8e45bc0 --- /dev/null +++ b/content/zh/docs/getting-started/Quickstarts/serverless-apps.md @@ -0,0 +1,19 @@ +--- +title: "创建无服务器应用" +linkTitle: "创建无服务器应用" +weight: 2240 +description: +--- + +> 在创建任何函数之前,请确保您已安装所有的[先决条件](../prerequisites) + +除了构建和运行无服务器函数,您还可以使用OpenFunction构建和运行无服务器应用。 + +这里有一些无服务器应用的示例: + +| | 无服务器应用 | +|-----------|-----------------| +| Go | [带有Dockerfile的Go应用](https://github.com/OpenFunction/samples/tree/main/apps/buildah/go) | +| Java | [带有Dockerfile的Java应用](https://github.com/OpenFunction/samples/tree/main/apps/buildah/java), [不带Dockerfile的Java应用](https://github.com/OpenFunction/samples/blob/main/apps/buildpacks/java/sample-java-app-buildpacks.yaml) & [源代码](https://github.com/buildpacks/samples/tree/main/apps/java-maven)| + +> 您可以在[这里](../../../concepts/serverless_apps/)找到关于这些无服务器应用的更多信息 \ No newline at end of file diff --git a/content/zh/docs/getting-started/Quickstarts/sync-functions.md b/content/zh/docs/getting-started/Quickstarts/sync-functions.md new file mode 100644 index 00000000..dcca0474 --- /dev/null +++ b/content/zh/docs/getting-started/Quickstarts/sync-functions.md @@ -0,0 +1,20 @@ +--- +title: "创建同步函数" +linkTitle: "创建同步函数" +weight: 2220 +description: +--- + +> 在创建任何函数之前,请确保您已安装所有的[先决条件](../prerequisites) + +同步函数是其输入为HTTP请求的有效载荷的函数,输出或响应在函数逻辑处理输入有效载荷后立即发送给等待的客户端。以下是不同语言的一些同步函数示例: + +| | 同步函数 | +|-----------|----------------| +| Go | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/hello-world-go), [多函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/multiple-functions-go), [带路径参数的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/path-parameters-function-go), [日志处理](https://github.com/OpenFunction/samples/blob/main/functions/knative/logs-handler-function/LogsHandler.go), [带输出绑定的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/with-output-binding) | +| Nodejs | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/hello-world-node), [带输出绑定的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/with-output-binding-node) | +| Python | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/hello-world-python) | +| Java | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/java/hello-world), [带输出的同步函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/java/with-output-binding) | +| DotNet | [Hello World](https://github.com/OpenFunction/samples/tree/main/functions/knative/hello-world-dotnet) | + +> 您可以在[这里](../../../concepts/function_signatures/#samples)找到更多函数示例 diff --git a/content/zh/docs/getting-started/Quickstarts/wasm_functions.md b/content/zh/docs/getting-started/Quickstarts/wasm_functions.md new file mode 100644 index 00000000..c0b25f1a --- /dev/null +++ b/content/zh/docs/getting-started/Quickstarts/wasm_functions.md @@ -0,0 +1,16 @@ +--- +title: "创建Wasm函数" +linkTitle: "创建Wasm函数" +weight: 2260 +description: +--- + +> 在创建任何函数之前,请确保您已安装所有的[先决条件](../prerequisites) + +这里有一些Wasm函数的示例: + +| 语言 | Wasm函数 | 运行时 | +|----------|------------------------------------------------------------------------------------------------------------------|----------| +| Rust | [wasmedge-http-server](https://github.com/OpenFunction/samples/tree/main/functions/knative/wasmedge/http-server) | wasmedge | + +> 您可以在[这里](../../../concepts/wasm_functions/)找到关于这些函数的更多信息 \ No newline at end of file diff --git a/content/zh/docs/getting-started/_index.md b/content/zh/docs/getting-started/_index.md index 8803137d..8d27abd9 100644 --- a/content/zh/docs/getting-started/_index.md +++ b/content/zh/docs/getting-started/_index.md @@ -1,97 +1,7 @@ --- -title: "入门" -linkTitle: "入门" -weight: 5 -description: > - 这里将指引您快速入门 OpenFunction,包括安装及一些案例的演示 +title: "快速入门" +linkTitle: "快速入门" +weight: 2000 +description: --- -## 概述 - -**OpenFunction** 是一个云原生、开源的 FaaS(函数即服务)框架,旨在让开发人员专注于他们的开发意图,而不必关心底层运行环境和基础设施。用户只需提交一段代码,就可以生成事件驱动的、动态伸缩的 Serverless 工作负载。 - -OpenFunction的特点: - -- 云原生,开源 -- 自动构建代码为 OCI 标准镜像 -- 自动部署具有动态伸缩能力的应用程序 -- 提供事件框架,使函数具备事件驱动能力 -- 提供函数版本控制和入口流量管理功能 - -OpenFunction有两个主要框架: - -- 由 CustomResourceDefinitions(CRD)[Function]({{}})、[Builder]({{}})、[Serving]({{}}) 提供支持的无服务计算(Serverless)框架 -- 由 CustomResourceDefinitions(CRD)[EventSource]({{}})、[EventBus (ClusterEventBus)]({{}})、[Trigger]({{}}) 提供支持的事件管理框架 - -## 兼容性 - -### Kubernetes 兼容性矩阵 - -我们对下列版本进行了测试验证,以确保他们可以按照所示的对应关系正常运行。但请注意,使用其他版本也可能正常运行! - -| OpenFunction | Kubernetes 1.19 | Kubernetes 1.20 | Kubernetes 1.21 | Kubernetes 1.22 | -| ------------------------------------------------------------ | --------------- | --------------- | --------------- | --------------- | -| [`release-0.3`](https://github.com/OpenFunction/OpenFunction/tree/v0.3.0) | √ | √ | √ | √ | -| [`release-0.4`](https://github.com/OpenFunction/OpenFunction/tree/v0.4.0) | × | √ | √ | √ | -| [`HEAD`](https://github.com/OpenFunction/OpenFunction/tree/main) | × | √ | √ | √ | - - -## 前提准备 - -当前版本的 OpenFunction 要求你有一个版本为 `等于或高于 1.18.6` 的 Kubernetes 集群。 - -此外,你需要为 OpenFunction 的 `Builder` 和 `Serving` 部署一些依赖项。 - -你可以使用以下命令来安装 OpenFunction 的 `Builder` 和 `Serving`: - -```shell -sh hack/deploy.sh --all -``` - -这个命令将安装 `Builder` 和 `Serving` 的所有依赖项到你的集群中。 - -你也可以用以下参数来定制安装的依赖软件。 - -| 参数 | 用途说明 | -| ---------------------------------- | ----------------------------------------------------------- | -| -\-all | 安装所有 `Builder` 和 `Serving` 的依赖软件 | -| -\-with-shipwright | 安装 ShipWright(Builder 的依赖软件) | -| -\-with-knative | 安装 Knative(Serving 的依赖软件) | -| -\-with-openFuncAsync | 安装 OpenFuncAsync(Serving 的依赖软件,包含 KEDA 与 Dapr) | -| -\-poor-network | 用于当你正使用无法有效访问 GitHub/Googleapis 的网络时 | - -## 安装 - -你可以使用以下命令安装 OpenFunction: - -- 安装最新稳定版本 - -```shell -kubectl create -f https://github.com/OpenFunction/OpenFunction/releases/download/v0.4.0/bundle.yaml -``` - -- 安装最新开发版本 - -```shell -kubectl create -f https://raw.githubusercontent.com/OpenFunction/OpenFunction/main/config/bundle.yaml -``` - -> 注意:当使用非默认的命名空间时,确保命名空间中的 ClusterRoleBinding 是匹配的。 - -### 案例:运行一个简单函数 - -如果你已经安装了 OpenFunction,推荐参考 [OpenFunction samples](https://github.com/OpenFunction/samples) 运行一个函数案例。 - -## 卸载 - -- 卸载最新的稳定版本 - -```shell -kubectl delete -f https://raw.githubusercontent.com/OpenFunction/OpenFunction/release-0.4/config/bundle.yaml -``` - -- 卸载最新的开发版本 - -```shell -kubectl delete -f https://raw.githubusercontent.com/OpenFunction/OpenFunction/main/config/bundle.yaml -``` diff --git a/content/zh/docs/getting-started/installation.md b/content/zh/docs/getting-started/installation.md new file mode 100644 index 00000000..f6bc9b19 --- /dev/null +++ b/content/zh/docs/getting-started/installation.md @@ -0,0 +1,165 @@ +--- +title: "安装" +linkTitle: "安装" +weight: 2100 +description: +--- + +本文档将介绍如何安装 OpenFunction。 + +## 先决条件 + +- 您需要拥有一个 Kubernetes 集群。 + +- 您需要确保您的 Kubernetes 版本满足以下兼容性矩阵中描述的要求。 + +| OpenFunction Version | Kubernetes 1.21 | Kubernetes 1.22 | Kubernetes 1.23 | Kubernetes 1.24 | Kubernetes 1.25 | Kubernetes 1.26+ | +|----------------------|-----------------|-----------------|-----------------|-----------------|-----------------|-----------------| +| HEAD | N/A | N/A | √ | √ | √ | √ | +| v1.2 | N/A | N/A | √ | √ | √ | √ | +| v1.1.x | √ | √ | √ | √ | √ | N/A | +| v1.0.x | √ | √ | √ | √ | √ | N/A | + +## 安装 OpenFunction + +现在您可以使用 helm charts 安装 OpenFunction 及其所有依赖项。 +> `ofn` CLI 安装方法已经弃用。 + +如果您想在离线环境中安装 OpenFunction,请参考 [在离线环境中安装 OpenFunction](https://openfunction.dev/docs/reference/faq/#q-how-to-install-openfunction-in-an-offline-environment) + +### 环境要求 +- Kubernetes version: `>=v1.21.0-0` +- Helm version: `>=v3.6.3` + +### 安装 OpenFunction helm charts 的步骤 + +1. 首先运行以下命令添加 OpenFunction chart 仓库: + ```shell + helm repo add openfunction https://openfunction.github.io/charts/ + helm repo update + ``` + +2. 然后您有几个选项来设置 OpenFunction,您可以选择: + + - 安装所有组件: + ```shell + kubectl create namespace openfunction + helm install openfunction openfunction/openfunction -n openfunction + ``` + + - 安装所有组件和 [Revision Controller](https://openfunction.dev/docs/concepts/cicd/): + ```shell + kubectl create namespace openfunction + helm install openfunction openfunction/openfunction -n openfunction --set revisionController.enable=true + ``` + + - 只安装 Serving(不包括 build): + ```shell + kubectl create namespace openfunction + helm install openfunction --set global.ShipwrightBuild.enabled=false --set global.TektonPipelines.enabled=false openfunction/openfunction -n openfunction + ``` + + - 只安装 Knative 同步运行时: + ```shell + kubectl create namespace openfunction + helm install openfunction --set global.Keda.enabled=false openfunction/openfunction -n openfunction + ``` + + - 只安装 OpenFunction 异步运行时: + ```shell + kubectl create namespace openfunction + helm install openfunction --set global.Contour.enabled=false --set global.KnativeServing.enabled=false openfunction/openfunction -n openfunction + ``` + + {{% alert title="Note" color="success" %}} + + 关于如何使用 Helm 安装 OpenFunction 的更多信息,请参见 [使用 Helm 安装 OpenFunction](https://github.com/OpenFunction/charts#install-the-chart). + + {{% /alert %}} + +3. Run the following command to verify OpenFunction is up and running: + ```shell + kubectl get po -n openfunction + ``` + +## 卸载 OpenFunction + +### Helm + +如果您使用 Helm 安装了 OpenFunction,请运行以下命令来卸载 OpenFunction 及其依赖项。 + +```shell +helm uninstall openfunction -n openfunction +``` +{{% alert title="Note" color="success" %}} + +关于如何使用 Helm 卸载 OpenFunction 的更多信息,请参见 [使用 Helm 卸载 OpenFunction](https://github.com/OpenFunction/charts#uninstall-the-chart). + +{{% /alert %}} + +## 升级 OpenFunction + +```shell +helm upgrade [RELEASE_NAME] openfunction/openfunction -n openfunction +``` + +使用 Helm v3,chart 创建的 CRD 默认不会更新,应手动更新。 另请参阅 [Helm 关于 CRD 的文档](https://helm.sh/docs/chart_best_practices/custom_resource_definitions)。 + +_参考 to [helm upgrade](https://helm.sh/docs/helm/helm_upgrade/) 以获取命令文档。_ + +### 将现有的发布升级到新版本 + +### 从 OpenFunction v0.6.0 升级到 OpenFunction v0.7.x + +从 v0.6.0 升级到 0.7.x 有一个破坏性的变化,需要额外的手动操作。 + +#### 卸载 Chart + +首先,您需要卸载旧的 `openfunction` release: +```shell +helm uninstall openfunction -n openfunction +``` + +确认组件命名空间已被删除,这需要一些时间: +```shell +kubectl get ns -o=jsonpath='{range .items[?(@.metadata.annotations.meta\.helm\.sh/release-name=="openfunction")]}{.metadata.name}: {.status.phase}{"\n"}{end}' +``` + +> 如果 knative-serving 命名空间长时间处于终止状态,尝试运行以下命令并删除 finalizers: +```shell +kubectl edit ingresses.networking.internal.knative.dev -n knative-serving +``` + +#### 升级 OpenFunction CRDs + +```shell +kubectl apply -f https://openfunction.sh1a.qingstor.com/crds/v0.7.0/openfunction.yaml +``` + +#### 升级依赖组件的 CRDs + +> 您只需要处理现有发布中包含的组件。 +- knative-serving CRDs + ```shell + kubectl apply -f https://openfunction.sh1a.qingstor.com/crds/v0.7.0/knative-serving.yaml + ``` +- shipwright-build CRDs + ```shell + kubectl apply -f https://openfunction.sh1a.qingstor.com/crds/v0.7.0/shipwright-build.yaml + ``` +- tekton-pipelines CRDs + ```shell + kubectl apply -f https://openfunction.sh1a.qingstor.com/crds/v0.7.0/tekton-pipelines.yaml + ``` + +#### 安装新 chart +```shell +helm repo update +helm install openfunction openfunction/openfunction -n openfunction +``` + +{{% alert title="Note" color="success" %}} + +有关如何使用 Helm 升级 OpenFunction 的更多信息,请参见 [使用 Helm 升级 OpenFunction](https://github.com/OpenFunction/charts#upgrading-chart). + +{{% /alert %}} \ No newline at end of file diff --git a/content/zh/docs/introduction.md b/content/zh/docs/introduction.md new file mode 100644 index 00000000..37cb9912 --- /dev/null +++ b/content/zh/docs/introduction.md @@ -0,0 +1,43 @@ +--- +title: "简介" +linkTitle: "简介" +weight: 1000 +description: +--- +## 概述 + +OpenFunction 是一个云原生的开源 FaaS(函数即服务)平台,旨在让您专注于业务逻辑,而不必维护底层的运行环境和基础设施。您只需要以函数的形式提交与业务相关的源代码,就可以生成事件驱动和动态伸缩的 Serverless 工作负载。 + +
+ + +## 架构和设计 + +
+ +## 核心特性 + +- 云无关、和云厂商的 BaaS 服务解耦 + +- 可插拔架构、支持多种函数运行时 + +- 支持同步和异步函数 + +- 独有的异步函数支持,直接从事件源消费事件 + +- 支持从函数源代码直接生成符合 OCI 标准的镜像 + +- 实现从 0 到 N 的弹性自动伸缩 + +- 基于事件源的特定指标实现领先的异步函数自动伸缩 + +- 引入 [Dapr](https://dapr.io/) 以简化同步和异步函数和 BaaS 服务的集成 + +- [K8s Gateway API](https://gateway-api.sigs.k8s.io/) 提供了领先的函数入口和流量管理能力 + +- 灵活易用的事件管理框架 + +## License + +OpenFunction 采用 Apache License 2.0 版本授权。更多信息,请参见 [LICENSE](https://github.com/OpenFunction/OpenFunction/blob/main/LICENSE). + diff --git a/content/zh/docs/operations/_index.md b/content/zh/docs/operations/_index.md new file mode 100644 index 00000000..c0739ae9 --- /dev/null +++ b/content/zh/docs/operations/_index.md @@ -0,0 +1,7 @@ +--- +title: "操作手册" +linkTitle: "操作手册" +weight: 4000 +description: +--- + diff --git a/content/zh/docs/operations/networking/_index.md b/content/zh/docs/operations/networking/_index.md new file mode 100644 index 00000000..7c5823e0 --- /dev/null +++ b/content/zh/docs/operations/networking/_index.md @@ -0,0 +1,7 @@ +--- +title: "网络" +linkTitle: "网络" +weight: 4100 +description: +--- + diff --git a/content/zh/docs/operations/networking/local-domain.md b/content/zh/docs/operations/networking/local-domain.md new file mode 100644 index 00000000..26d01ce4 --- /dev/null +++ b/content/zh/docs/operations/networking/local-domain.md @@ -0,0 +1,96 @@ +--- +title: "配置本地域名" +linkTitle: "配置本地域名" +weight: 4120 +description: +--- + +## 配置本地域名 +通过配置本地域名,您可以通过函数的外部地址从 Kubernetes 集群内部访问函数。 + +### 基于 `Gateway.spec.domain` 配置 `CoreDNS` +假设您有一个定义了此 `domain`:`*.ofn.io` 的 `Gateway`,您需要通过以下命令更新 `CoreDNS` 配置: +1. 编辑 `coredns` 配置映射: +```shell +kubectl -n kube-system edit cm coredns -o yaml +``` +2. 在 `.:53` 部分的配置文件中添加 `rewrite stop name regex .*\.ofn\.io gateway.openfunction.svc.cluster.local`,例如: +```yaml +apiVersion: v1 +data: + Corefile: | + .:53 { + errors + health { + lameduck 5s + } + ready + kubernetes cluster.local in-addr.arpa ip6.arpa { + pods insecure + fallthrough in-addr.arpa ip6.arpa + ttl 30 + } + rewrite stop name regex .*\.ofn\.io gateway.openfunction.svc.cluster.local + prometheus :9153 + forward . /etc/resolv.conf { + max_concurrent 1000 + } + cache 30 + loop + reload + loadbalance + } +... +``` + +### 基于 `Gateway.spec.domain` 配置 `nodelocaldns` +如果您也在使用 `nodelocaldns`,如 `Kubesphere`,您需要通过以下命令更新 `nodelocaldns` 配置: +1. 编辑 `nodelocaldns` 配置映射: +```shell +kubectl -n kube-system edit cm nodelocaldns -o yaml +``` +2. 在配置文件中添加 `ofn.io:53` 部分,例如: +```yaml +apiVersion: v1 +data: + Corefile: | + ofn.io:53 { + errors + cache { + success 9984 30 + denial 9984 5 + } + reload + loop + bind 169.254.25.10 + forward . 10.233.0.3 { + force_tcp + } + prometheus :9253 + } + cluster.local:53 { + errors + cache { + success 9984 30 + denial 9984 5 + } + reload + loop + bind 169.254.25.10 + forward . 10.233.0.3 { + force_tcp + } + prometheus :9253 + health 169.254.25.10:9254 + } + .:53 { + errors + cache 30 + reload + loop + bind 169.254.25.10 + forward . /etc/resolv.conf + prometheus :9253 + } +... +``` \ No newline at end of file diff --git a/content/zh/docs/operations/networking/switch-gateway.md b/content/zh/docs/operations/networking/switch-gateway.md new file mode 100644 index 00000000..c021b349 --- /dev/null +++ b/content/zh/docs/operations/networking/switch-gateway.md @@ -0,0 +1,90 @@ +--- +title: "切换到其他 Kubernetes Gateway 实现" +linkTitle: "切换到其他 Kubernetes Gateway 实现" +weight: 4110 +description: +--- + +您可以以更简单、厂商中立的方式切换到任何支持 [Kubernetes Gateway API](https://gateway-api.sigs.k8s.io/) 的 [网关实现](https://gateway-api.sigs.k8s.io/implementations/),如 Contour、Istio、Apache APISIX、Envoy Gateway(未来)等。 + +例如,您可以选择使用 Istio 作为底层的 `Kubernetes Gateway`,如下所示: + +1. 安装 OpenFunction,但不包括 `Contour`: + +```shell +helm install openfunction --set global.Contour.enabled=false openfunction/openfunction -n openfunction +``` + +2. 安装 `Istio`,然后启用其 Knative 集成: + +```shell +kubectl apply -l knative.dev/crd-install=true -f https://github.com/knative/net-istio/releases/download/knative-v1.3.0/istio.yaml +kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.3.0/istio.yaml +kubectl apply -f https://github.com/knative/net-istio/releases/download/knative-v1.3.0/net-istio.yaml +``` + +3. 创建一个名为 `istio` 的 `GatewayClass`: +```shell +kubectl apply -f - < 参阅 OpenFunction 中资源的详细使用说明 --- - -## v1alpha1 - -**core.openfunction.io/v1alpha1**,包含: - -- [functions.core.openfunction.io](function-spec) - -**events.openfunction.io/v1alpha1**,包含: - -- [eventsources.events.openfunction.io](eventsource-spec) -- [eventbus.events.openfunction.io](eventbus-spec) -- [clustereventbus.events.openfunction.io](eventbus-spec) -- [triggers.events.openfunction.io](trigger-spec) - diff --git a/content/zh/docs/reference/eventbus-spec/_index.md b/content/zh/docs/reference/eventbus-spec/_index.md deleted file mode 100644 index 88ccb3d6..00000000 --- a/content/zh/docs/reference/eventbus-spec/_index.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: "EventBus 参数说明" -linkTitle: "EventBus 参数说明" -weight: 15 -description: > - EventBus 及 ClusterEventBus CRD 参数规范说明 ---- - -## EventBus(ClusterEventBus) - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **apiVersion** *string* | events.openfunction.io/v1alpha1 | -| **kind** *string* | EventBus(ClusterEventBus) | -| **metadata** *[v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta)* | *(可选)* 参考 [v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta) 文档 | -| **spec** *[EventBusSpec](#eventsourcespec)* | 事件总线的规格,参考 [EventBusSpec](#eventsourcespec) | -| **status** *EventBusStatus* | 事件总线的状态 | - -### EventBusSpec - -*从属 [EventBus](#eventbus)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **topic** *string* | 事件总线的 topic 名称 | -| **natsStreaming** *[NatsStreamingSpec]({{}})* | (当前仅支持)nats streaming 事件总线的定义,参考 [NatsStreamingSpec]({{}}) | - -### GenericScaleOption - -*从属 scaleOption* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **pollingInterval** *int* | 检查每个伸缩触发器的时间间隔。默认是`30`秒 | -| **cooldownPeriod** *int* | 在将资源缩减到 0 之前,最后一个伸缩触发器报告激活后的等待时间。 默认为 `300` 秒 | -| **minReplicaCount** *int* | KEDA 将收缩资源的最小副本数。默认值是 `0` | -| **maxReplicaCount** *int* | 这个设置被传递给KEDA为特定资源创建的HPA定义,KEDA 扩展资源的最大副本数。 | -| **advanced** *[kedav1alpha1.AdvancedConfig](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#AdvancedConfig)* | 请查看 [KEDA 文档](https://keda.sh/docs/2.4/concepts/scaling-deployments/) | -| **metadata** *map[string]string* | KEDA 伸缩触发器的元数据 | -| **authRef** *[kedav1alpha1.ScaledObjectAuthRef](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaledObjectAuthRef)* | 你在 `TriggerAuthentication` 配置中定义的每个参数都不需要包含在你的 `ScaledObject` 定义的触发器的 `metadata` 中。要从 `ScaledObject` 中引用 `TriggerAuthentication`,你需要在触发器中添加 `authRef`,请参考 [KEDA 文档](https://keda.sh/docs/2.4/concepts/authentication/) | diff --git a/content/zh/docs/reference/eventbus-spec/natsstreaming-spec.md b/content/zh/docs/reference/eventbus-spec/natsstreaming-spec.md deleted file mode 100644 index c937df13..00000000 --- a/content/zh/docs/reference/eventbus-spec/natsstreaming-spec.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: "Nats Streaming 参数说明" -linkTitle: "Nats Streaming 参数说明" -weight: 15 -description: > - Nats Streaming 事件总线参数说明 ---- - -### NatsStreamingSpec - -*从属 [EventBusSpec]({{}})* - -> EventBus(ClusterEventBus) 会将配置提供给 EventSource 和 Trigger 引用,以便生成对应的 [Dapr Pub/Sub Components](https://docs.dapr.io/reference/components-reference/supported-pubsub/setup-nats-streaming/#component-format) 从事件总线处获取消息,原则上我们会尽量维持相关参数的一致性。你可以通过访问 [NATS Streaming pubsub spec](https://docs.dapr.io/reference/components-reference/supported-pubsub/setup-nats-streaming/#spec-metadata-fields) 获取更多信息。 - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **natsURL** *string* | NATS 服务器的地址,如:`nats://localhost:4222` | -| **natsStreamingClusterID** *string* | NATS 集群 ID,如:`stan` | -| **subscriptionType** *string* | 订阅器类型,可选:`topic`, `queue` | -| **ackWaitTime** *string* | *(可选)* 请参考 [Acknowledgements](https://docs.nats.io/developing-with-nats-streaming/acks#acknowledgements) 。如:`300ms` | -| **maxInFlight** *int64* | *(可选)* 请参考 [Max In Flight](https://docs.nats.io/developing-with-nats-streaming/acks#acknowledgements) 。如:`25` | -| **durableSubscriptionName** *string* | *(可选)* [持久化订阅器](https://docs.nats.io/developing-with-nats-streaming/durables) 的名称。如:`my-durable` | -| **deliverNew** *bool* | *(可选)* 订阅器选项(只能使用一个)。是否只发送新消息。可选:`true`,`false` | -| **startAtSequence** *int64* | *(可选)* 订阅器选项(只能使用一个)。设置起始序列位置和状态。如:`100000` | -| **startWithLastReceived** *bool* | *(可选)* 订阅器选项(只能使用一个)。是否将起始位置设置为最新消息处。可选:`true`,`false` | -| **deliverAll** *bool* | *(可选)* 订阅器选项(只能使用一个)。是否发送所有可用的信息。可选:`true`,`false` | -| **startAtTimeDelta** *string* | *(可选)* 订阅器选项(只能使用一个)。使用差值形式设置所需的开始时间位置和状态。如:`10m`,`23s` | -| **startAtTime** *string* | *(可选)* 订阅器选项(只能使用一个)。使用标值形式设置所需的开始时间位置和状态。如:`Feb 3, 2013 at 7:54pm (PST)` | -| **startAtTimeFormat** *string* | *(可选)* 必须与 startAtTime 一起使用。设置时间的格式。如:`Jan 2, 2006 at 3:04pm (MST)` | -| **scaleOption** [NatsStreamingScaleOption](#natsstreamingscaleoption) | *(可选)* Nats streaming 的自动伸缩选项 | - -### NatsStreamingScaleOption - -*从属 [NatsStreamingSpec](#natsstreamingspec)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ---------------------------------------------------- | -| *[GenericScaleOption]({{< ref "../eventbus-spec#genericscaleoption" >}})* | 通用的自动伸缩配置 | -| **natsServerMonitoringEndpoint** *string* | Nats streaming 的指标监控端点 | -| **queueGroup** *string* | Nats streaming 的 queue group 名称 | -| **durableName** *string* | Nats streaming 的 durable 名称 | -| **subject** *string* | 伸缩器监控的 subject 名称,如:`topicA`, `myTopic` | -| **lagThreshold** *string* | 伸缩器的触发阈值,此处为 Nats Streaming 的消息延迟量 | - diff --git a/content/zh/docs/reference/eventsource-spec/_index.md b/content/zh/docs/reference/eventsource-spec/_index.md deleted file mode 100644 index 0e4bd229..00000000 --- a/content/zh/docs/reference/eventsource-spec/_index.md +++ /dev/null @@ -1,65 +0,0 @@ ---- -title: "EventSource 参数说明" -linkTitle: "EventSource 参数说明" -weight: 10 -description: > - EventSource CRD 参数规范说明 ---- - -## EventSource - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **apiVersion** *string* | events.openfunction.io/v1alpha1 | -| **kind** *string* | EventSource | -| **metadata** *[v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta)* | *(可选)* 参考 [v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta) 文档 | -| **spec** *[EventSourceSpec](#eventsourcespec)* | 事件源的规格,参考 [EventSourceSpec](#eventsourcespec) | -| **status** *EventSourceStatus* | 事件源的状态 | - -### EventSourceSpec - -*从属 [EventSource](#eventsource)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **eventBus** *string* | *(可选)* 事件源关联的 EventBus 资源名称 | -| **redis** *map\[string][RedisSpec]({{}})* | *(可选)* redis 事件源的定义,参考 [RedisSpec]({{}}) | -| **kafka** *map\[string][KafkaSpec]({{}})* | *(可选)* kafka 事件源的定义,参考 [KafkaSpec]({{}}) | -| **cron** *map\[string][CronSpec]({{}})* | *(可选)* cron 事件源的定义,参考 [CronSpec]({{}}) | -| **sink** *[SinkSpec](#sinkspec)* | *(可选)* 事件源关联的 Sink(可寻址的访问资源,即同步请求)定义,参考 [SinkSpec](#sinkspec) | - -### SinkSpec - -*从属 [EventSourceSpec](#eventsourcespec)* - -| 字段 | 描述 | -| --------------------------------- | ---------------------------- | -| **ref** *[Reference](#reference)* | 参考 [Reference](#reference) | - -### Reference - -*从属 [SinkSpec](#sinkspec)* - -> 引用资源一般为 [Knative Service](https://knative.dev/docs/reference/api/serving-api/#serving.knative.dev/v1.Service) - -| 字段 | 描述 | -| ----------------------- | ------------------------------------------------------- | -| **kind** *string* | 引用资源的类型,默认为:`Service` | -| **namespace** *string* | 引用资源的命名空间,默认与 Trigger 的命名空间一致 | -| **name** *string* | 引用资源的名称,如:`function-ksvc` | -| **apiVersion** *string* | 引用资源的 apiVersion,默认为:`serving.knative.dev/v1` | - -### GenericScaleOption - -*从属 scaleOption* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **pollingInterval** *int* | 检查每个伸缩触发器的时间间隔。默认是`30`秒 | -| **cooldownPeriod** *int* | 在将资源缩减到 0 之前,最后一个伸缩触发器报告激活后的等待时间。 默认为 `300` 秒 | -| **minReplicaCount** *int* | KEDA 将收缩资源的最小副本数。默认值是 `0` | -| **maxReplicaCount** *int* | 这个设置被传递给KEDA为特定资源创建的HPA定义,KEDA 扩展资源的最大副本数。 | -| **advanced** *[kedav1alpha1.AdvancedConfig](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#AdvancedConfig)* | 请查看 [KEDA 文档](https://keda.sh/docs/2.4/concepts/scaling-deployments/) | -| **metadata** *map[string]string* | KEDA 伸缩触发器的元数据 | -| **authRef** *[kedav1alpha1.ScaledObjectAuthRef](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaledObjectAuthRef)* | 你在 `TriggerAuthentication` 配置中定义的每个参数都不需要包含在你的 `ScaledObject` 定义的触发器的 `metadata` 中。要从 `ScaledObject` 中引用 `TriggerAuthentication`,你需要在触发器中添加 `authRef`,请参考 [KEDA 文档](https://keda.sh/docs/2.4/concepts/authentication/) | - diff --git a/content/zh/docs/reference/eventsource-spec/cron-spec.md b/content/zh/docs/reference/eventsource-spec/cron-spec.md deleted file mode 100644 index 513cbb78..00000000 --- a/content/zh/docs/reference/eventsource-spec/cron-spec.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: "Cron 参数说明" -linkTitle: "Cron 参数说明" -weight: 25 -description: > - Cron 事件源参数说明 ---- - -### CronSpec - -*从属 [EventSourceSpec]({{}})* - -> EventSource 会根据 CronSpec 生成用于适配 Cron 事件源的 [Dapr Bindings Components](https://docs.dapr.io/reference/components-reference/supported-bindings/cron/#component-format) ,原则上我们会尽量维持相关参数的一致性。你可以通过访问 [Cron binding spec](https://docs.dapr.io/reference/components-reference/supported-bindings/cron/#spec-metadata-fields) 获取更多信息。 - -| 字段 | 描述 | -| --------------------- | ------------------------------------------------------------ | -| **schedule** *string* | 参考 [Schedule format](https://docs.dapr.io/reference/components-reference/supported-bindings/cron/#schedule-format) 了解合法的 schedule 格式。如:`@every 15m` | - diff --git a/content/zh/docs/reference/eventsource-spec/kafka-spec.md b/content/zh/docs/reference/eventsource-spec/kafka-spec.md deleted file mode 100644 index 779cd3d3..00000000 --- a/content/zh/docs/reference/eventsource-spec/kafka-spec.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: "Kafka 参数说明" -linkTitle: "Kafka 参数说明" -weight: 20 -description: > - Kafka 事件源参数说明 ---- - -### KafkaSpec - -*从属 [EventSourceSpec]({{}})* - -> EventSource 会根据 KafkaSpec 生成用于适配 Kafka 事件源的 [Dapr Bindings Components](https://docs.dapr.io/reference/components-reference/supported-bindings/kafka/#component-format) ,原则上我们会尽量维持相关参数的一致性。你可以通过访问 [Kafka binding spec](https://docs.dapr.io/reference/components-reference/supported-bindings/kafka/#spec-metadata-fields) 获取更多信息。 - -| 字段 | 描述 | -| ----------------------------------------------------- | ------------------------------------------------------------ | -| **brokers** *string* | 以逗号分隔的 Kafka 服务器地址的字符串。如:`localhost:9092` | -| **authRequired** *bool* | 是否启用 Kafka 服务器的 [SASL](https://en.wikipedia.org/wiki/Simple_Authentication_and_Security_Layer) 认证。可选:`true`, `false` | -| **topic** *string* | Kafka 事件源的 topic 名称,如:`topicA`,`myTopic` | -| **saslUsername** *string* | *(可选)* 用于认证的 SASL 用户名。只有在 authRequired 为 `true` 时才需要设置。如:`admin` | -| **saslPassword** *string* | *(可选)* 用于认证的 SASL 用户密码。只有在 authRequired 为 `true` 时才需要设置。如:`123456` | -| **maxMessageBytes** *int64* | *(可选)* 单个消息允许包含的最大字节数。默认为 `1024`。如:`2048` | -| **scaleOption** [KafkaScaleOption](#kafkascaleoption) | *(可选)* Kafka 的自动伸缩选项 | - -### KafkaScaleOption - -*从属 [KafkaSpec](#kafkaspec)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------ | -| *[GenericScaleOption]({{< ref "../eventsource-spec#genericscaleoption" >}})* | 通用的自动伸缩配置 | -| **consumerGroup** *string* | Kafka 的 consumer group 名称 | -| **topic** *string* | 伸缩器监控的 topic 名称,如:`topicA`, `myTopic` | -| **lagThreshold** *string* | 伸缩器的触发阈值,此处为 Kafka 的消息延迟量 | - diff --git a/content/zh/docs/reference/eventsource-spec/redis-spec.md b/content/zh/docs/reference/eventsource-spec/redis-spec.md deleted file mode 100644 index 147078e4..00000000 --- a/content/zh/docs/reference/eventsource-spec/redis-spec.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -title: "Redis 参数说明" -linkTitle: "Redis 参数说明" -weight: 15 -description: > - Redis 事件源参数说明 ---- - -### RedisSpec - -*从属 [EventSourceSpec]({{}})* - -> EventSource 会根据 RedisSpec 生成用于适配 Redis 事件源的 [Dapr Bindings Components](https://docs.dapr.io/reference/components-reference/supported-bindings/redis/#component-format) ,原则上我们会尽量维持相关参数的一致性。你可以通过访问 [Redis binding spec](https://docs.dapr.io/reference/components-reference/supported-bindings/redis/#spec-metadata-fields) 获取更多信息。 - -| 字段 | 描述 | -| ---------------------------------- | ------------------------------------------------------------ | -| **redisHost** *string* | Redis 服务器的地址,如:`localhost:6379` | -| **redisPassword** *string* | Redis 服务器的密码,如:`123456` | -| **enableTLS** *bool* | *(可选)* 是否启用 TLS 访问,默认为 `false` 。可选:`true`,`false` | -| **failover** *bool* | *(可选)* 是否启用 failover 特性。需要设置 sentinalMasterName 。默认为 `false` 。可选:`true`,`false` | -| **sentinelMasterName** *string* | *(可选)* sentinel master 的名称。参考 [Redis Sentinel Documentation](https://redis.io/topics/sentinel) 。 | -| **redeliverInterval** *string* | *(可选)* 重新发送的时间间隔。默认为 `60s`。`0` 表示禁用重新发送机制。如:`30s` | -| **processingTimeout** *string* | *(可选)* 消息处理超时时间。默认为 `15s`。`0` 表示禁用超时。如:`30s` | -| **redisType** *string* | *(可选)* Redis 的类型。可选:单节点模式的 `node` ,集群模式的 `cluster`。默认为 `node` | -| **redisDB** *int64* | *(可选)* 连接到 Redis 的数据库索引值。仅在 redisType 为 `node` 时生效。默认为 `0` 。 | -| **redisMaxRetries** *int64* | *(可选)* 最大重试次数。默认不重试。如:`5` | -| **redisMinRetryInterval** *string* | *(可选)* 重试的最小退避时间。默认值是 `8ms`。`-1` 表示禁用退避时间。如:`10ms` | -| **redisMaxRetryInterval** *string* | *(可选)* 重试的最大退避时间。默认值是 `512ms`。`-1` 表示禁用退避时间。如:`5s` | -| **dialTimeout** *string* | *(可选)* 建立新连接的超时时间。默认为 `5s`。 | -| **readTimeout** *string* | *(可选)* 读取超时时间。如果超时则会导致 Redis 命令失败而非以阻塞方式等待。默认为 `3s`,`-1` 表示没有超时。 | -| **writeTimeout** *string* | *(可选)* 写入超时时间。如果超时则会导致 Redis 命令失败而非以阻塞方式等待。默认与 readTimeout 一致。 | -| **poolSize** *int64* | *(可选)* 最大连接数量。默认每个物理 CPU 负载 10 个连接。如:`20` | -| **poolTimeout** *string* | *(可选)* 连接池的超时时间。默认是 readTimeout + 1 秒。如:`50s` | -| **maxConnAge** *string* | *(可选)* 连接老化时间。默认不关闭老化的连接。如:`30m` | -| **minIdleConns** *int64* | *(可选)* 维持的最小空闲连接数,以避免创建新连接带来的性能下降。默认为 `0`。如:`2` | -| **idleCheckFrequency** *string* | *(可选)* 空闲连接回收器的检查频率。默认为 `1m`。`-1` 表示禁用空闲连接回收器。如:`-1` | -| **idleTimeout** *string* | *(可选)* 关闭客户端闲置连接的超时时间。应该小于服务器的超时时间。默认为 `5m`。`-1` 表示禁用空闲超时检查。如:`10m` | diff --git a/content/zh/docs/reference/faq.md b/content/zh/docs/reference/faq.md new file mode 100644 index 00000000..c3b609bc --- /dev/null +++ b/content/zh/docs/reference/faq.md @@ -0,0 +1,568 @@ +--- +title: "常见问题解答" +linkTitle: "FAQ" +weight: 7100 +description: +--- + +本文档描述在使用OpenFunction时的常见问题解答。 + +## Q: 如何在OpenFunction中使用私有镜像仓库? + +A: OpenFunction在构建阶段使用Shipwright(利用Tekton与Cloud Native Buildpacks集成)将用户函数打包到应用镜像中。 + +用户通常选择以不安全的方式访问私有镜像仓库,这在Cloud Native Buildpacks中尚不受支持。 + +我们提供以下解决方法,暂时绕过这个限制: + +1. 使用IP地址而不是主机名作为私有镜像仓库的访问地址。 +2. 运行Knative-runtime函数时,应该[跳过标签解析](https://knative.dev/docs/serving/configuration/deployment/#skipping-tag-resolution)。 + +参考链接: + +[buildpacks/lifecycle#524](https://github.com/buildpacks/lifecycle/issues/524) + +[buildpacks/tekton-integration#31](https://github.com/buildpacks/tekton-integration/issues/31) + +## Q: 如何在不引入新的入口控制器的情况下访问Knative-runtime函数? + +A: OpenFunction提供了函数可访问性的统一入口点,它基于Ingress Nginx实现。然而,对于一些用户来说,这是不必要的,引入新的入口控制器可能会影响当前集群。 + +一般来说,可访问的地址用于同步(Knative-runtime)函数。以下是解决此问题的两种方法: + +- Magic DNS + + 您可以按照[此指南](https://knative.dev/docs/install/yaml-install/serving/install-serving-with-yaml/#configure-dns)配置DNS。 + +- CoreDNS + + 这类似于使用Magic DNS,不同之处在于DNS解析的配置放置在CoreDNS内部。假设用户已在`knative-serving`命名空间的`config-domain` ConfigMap下配置了一个名为"openfunction.dev"的域(如下所示): + + ```shell + $ kubectl -n knative-serving get cm config-domain -o yaml + + apiVersion: v1 + data: + openfunction.dev: "" + kind: ConfigMap + metadata: + annotations: + knative.dev/example-checksum: 81552d0b + labels: + app.kubernetes.io/part-of: knative-serving + app.kubernetes.io/version: 1.0.1 + serving.knative.dev/release: v1.0.1 + name: config-domain + namespace: knative-serving + ``` + +接下来,让我们为此域添加一个A记录。OpenFunction使用Kourier作为Knative Serving的默认网络层,该域名应该流向到Kourier。 + + ```shell + $ kubectl -n kourier-system get svc + + NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE + kourier LoadBalancer 10.233.7.202 80:31655/TCP,443:30980/TCP 36m + kourier-internal ClusterIP 10.233.47.71 80/TCP 36m + ``` + +然后,用户只需在CoreDNS中配置此通配符DNS解析,以解析集群中任何Knative服务的URL地址。 + +> 其中"10.233.47.71"是Service kourier-internal的地址。 + + ```shell + $ kubectl -n kube-system get cm coredns -o yaml + + apiVersion: v1 + data: + Corefile: | + .:53 { + errors + health + ready + template IN A openfunction.dev { + match .*\.openfunction\.dev + answer "{{ .Name }} 60 IN A 10.233.47.71" + fallthrough + } + kubernetes cluster.local in-addr.arpa ip6.arpa { + pods insecure + fallthrough in-addr.arpa ip6.arpa + } + hosts /etc/coredns/NodeHosts { + ttl 60 + reload 15s + fallthrough + } + prometheus :9153 + forward . /etc/resolv.conf + cache 30 + loop + reload + loadbalance + } + ... + ``` + +如果用户在集群外无法解析此函数的URL地址,请配置`hosts`文件如下: + +> 其中"serving-sr5v2-ksvc-sbtgr.default.openfunction.dev"是从命令"kubectl get ksvc"中获取的URL地址。 + + ```shell + 10.233.47.71 serving-sr5v2-ksvc-sbtgr.default.openfunction.dev + ``` + +配置完成后,可以使用以下命令获取函数的URL地址。然后,您可以使用`curl`或浏览器触发该函数。 + +```shell +$ kubectl get ksvc + +NAME URL +serving-sr5v + +2-ksvc-sbtgr http://serving-sr5v2-ksvc-sbtgr.default.openfunction.dev +``` + +## Q: 如何为函数启用和配置并发性? + +A: OpenFunction将函数类型分为"[同步运行时](../../concepts/function/#the-sync-runtime)"和"[异步运行时](../../concepts/function/#the-async-runtime)",基于正在处理的请求类型。这两种类型的函数由Knative Serving和Dapr + KEDA驱动。 + +因此,要启用和配置函数的并发性,您需要参考上述组件中的具体实现。 + +以下部分介绍了如何根据"[同步运行时](../../concepts/function/#the-sync-runtime)"和"[异步运行时](../../concepts/function/#the-async-runtime)"部分在OpenFunction中启用和配置函数的并发性。 + +### 同步运行时 + +您可以首先参考Knative Serving中的[此文档](https://knative.dev/docs/serving/autoscaling/concurrency/),了解如何启用和配置并发性功能。 + +#### 软限制 + +您可以参考此[文档](https://knative.dev/docs/serving/autoscaling/concurrency/#soft-limit)中的`Global(ConfigMap)`和`Global(Operator)`部分,配置全局并发性功能。 + +而对于`Per Revision`,您可以像这样进行配置[此处](../../concepts/function_scaling_trigger/)。 + +```yaml +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + scaleOptions: + knative: + autoscaling.knative.dev/target: "200" +``` + +#### 硬限制 + +OpenFunction目前不支持为`Per Revision`配置硬限制。您可以参考[此文档](https://knative.dev/docs/serving/autoscaling/concurrency/#hard-limit)中的`Global(ConfigMap)`和`Global(Operator)`部分,配置全局并发性功能。 + +#### 简而言之 + +简而言之,您可以为每个函数配置Knative Serving的与自动缩放相关的配置项,如下所示,只要它们可以作为***注释***传递,否则只能进行全局设置。 + +```yaml +# 在Knative Serving中的配置 +apiVersion: serving.knative.dev/v1 +kind: Service +metadata: + name: helloworld-go + namespace: default +spec: + template: + metadata: + annotations: + autoscaling.knative.dev/: "value" + +# 在OpenFunction中的配置(推荐) +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + scaleOptions: + knative: + : "value" + +# 替代方法 +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + annotations: + autoscaling.knative.dev/: "value" +``` + +### 异步运行时 + +您可以首先参考Dapr中的[此文档](https://docs.dapr.io/operations/configuration/control-concurrency/),了解如何启用和配置并发性功能。 + +与同步运行时的并发性配置相比,异步运行时的并发性配置更简单。 + +```yaml +# 在Dapr中的配置 +apiVersion: apps/v1 +kind: Deployment +metadata: + name: nodesubscriber + namespace: default +spec: + template: + metadata: + annotations: + dapr.io/app-max-concurrency: "value" + +# 在OpenFunction中的配置(推荐) +apiVersion: core.openfunction.io/v1beta2 +kind: Function +metadata: + name: function-sample +spec: + serving: + annotations: + dapr.io/app-max-concurrency: "value" +``` + +## Q: 如何为函数镜像构建过程创建源代码仓库凭据? + +A: 在使用`spec.build.srcRepo.credentials`时,您可能会遇到类似`Unsupported type of credentials provided, either SSH private key or username/password is supported (exit code 110)`的错误,这意味着您正在使用不正确的Secret资源作为源代码仓库凭据。 + +OpenFunction目前基于[ShipWright](https://shipwright.io/)实现函数镜像构建框架,因此我们需要参考此[文档](https://shipwright.io/docs/build/authentication/#authentication-for-git)来设置正确的源代码仓库凭据。 + +## Q: 如何在离线环境中安装OpenFunction? + +A: 您可以通过以下步骤在离线环境中安装和使用OpenFunction: + +### 拉取Helm Chart + +在可以访问GitHub的环境中拉取Helm Chart: + +```shell +helm repo add openfunction https://openfunction.github.io/charts/ +helm repo update +helm pull openfunction/openfunction +``` + +然后使用诸如scp之类的工具将Helm包复制到离线环境,例如: + +```shell +scp openfunction-v1.0.0-v0.5.0.tgz @:/home// +``` + +### 同步镜像 + +您需要将这些镜像同步到您的私有镜像仓库: + +``` +# dapr +docker.io/daprio/dashboard:0.10.0 +docker.io/daprio/dapr:1.8.3 + +# keda +openfunction/keda:2.8.1 +openfunction/keda-metrics-apiserver:2.8.1 + +# contour +docker.io/bitnami/contour:1.21.1-debian-11-r5 +docker.io/bitnami/envoy:1.22.2-debian-11-r6 +docker.io/bitnami/nginx:1.21.6-debian-11-r10 + +# tekton-pipelines +openfunction/tektoncd-pipeline-cmd-controller:v0.37.2 +openfunction/tektoncd-pipeline-cmd-kubeconfigwriter:v0.37.2 +openfunction/tektoncd-pipeline-cmd-git-init:v0.37.2 +openfunction/tektoncd-pipeline-cmd-entrypoint:v0.37.2 +openfunction/tektoncd-pipeline-cmd-nop:v0.37.2 +openfunction/tektoncd-pipeline-cmd-imagedigestexporter:v0.37.2 +openfunction/tektoncd-pipeline-cmd-pullrequest-init:v0.37.2 +openfunction/tektoncd-pipeline-cmd-pullrequest-init:v0.37.2 +openfunction/tektoncd-pipeline-cmd-workingdirinit:v0.37.2 +openfunction/cloudsdktool-cloud-sdk@sha256:27b2c22bf259d9bc1a291e99c63791ba0c27a04d2db0a43241ba0f1f20f4067f +openfunction/distroless-base@sha256:b16b57be9160a122ef048333c68ba205ae4fe1a7b7cc6a5b289956292ebf45cc +openfunction/tektoncd-pipeline-cmd-webhook:v0.37.2 + +# knative-serving +openfunction/knative.dev-serving-cmd-activator:v1.3.2 +openfunction/knative.dev-serving-cmd-autoscaler:v1.3.2 +openfunction/knative.dev-serving-cmd-queue:v1.3.2 +openfunction/knative.dev-serving-cmd-controller:v1.3.2 +openfunction/knative.dev-serving-cmd-domain-mapping:v1.3.2 +openfunction/knative.dev-serving-cmd-domain-mapping-webhook:v1.3.2 +openfunction/knative.dev-net-contour-cmd-controller:v1.3.0 +openfunction/knative.dev-serving-cmd-default-domain:v1.3.2 +openfunction/knative.dev-serving-cmd-webhook:v1.3.2 + +# shipwright-build +openfunction/shipwright-shipwright-build-controller:v0.10.0 +openfunction/shipwright-io-build-git:v0.10.0 +openfunction/shipwright-mutate-image:v0.10.0 +openfunction/shipwright-bundle:v0.10.0 +openfunction/shipwright-waiter:v0.10.0 +openfunction/buildah:v1.23.3 +openfunction/buildah:v1.28.0 + +# openfunction +openfunction/openfunction:v1.0.0 +openfunction/kube-rbac-proxy:v0.8.0 +openfunction/eventsource-handler:v4 +openfunction/trigger-handler:v4 +openfunction/dapr-proxy:v0.1.1 +openfunction/revision-controller:v1.0.0 +``` + +### 创建自定义值 + +在您的离线环境中创建 `custom-values.yaml` 文件: + +```shell +touch custom-values.yaml +``` + +编辑 `custom-values.yaml`,添加以下内容: + +```yaml +knative-serving: + activator: + activator: + image: + repository: <您的私有镜像仓库>/knative.dev-serving-cmd-activator + autoscaler: + autoscaler: + image: + repository: <您的私有镜像仓库>/knative.dev-serving-cmd-autoscaler + configDeployment: + queueSidecarImage: + repository: <您的私有镜像仓库>/knative.dev-serving-cmd-queue + controller: + controller: + image: + repository: <您的私有镜像仓库>/knative.dev-serving-cmd-controller + domainMapping: + domainMapping: + image: + repository: <您的私有镜像仓库>/knative.dev-serving-cmd-domain-mapping + domainmappingWebhook: + domainmappingWebhook: + image: + repository: <您的私有镜像仓库>/knative.dev-serving-cmd-domain-mapping-webhook + netContourController: + controller: + image: + repository: <您的私有镜像仓库>/knative.dev-net-contour-cmd-controller + defaultDomain: + job: + image: + repository: <您的私有镜像仓库>/knative.dev-serving-cmd-default-domain + webhook: + webhook: + image: + repository: <您的私有镜像仓库>/knative.dev-serving-cmd-webhook +shipwright-build: + shipwrightBuildController: + shipwrightBuild: + image: + repository: <您的私有镜像仓库>/shipwright-shipwright-build-controller + GIT_CONTAINER_IMAGE: + repository: <您的私有镜像仓库>/shipwright-io-build-git + MUTATE_IMAGE_CONTAINER_IMAGE: + repository: <您的私有镜像仓库>/shipwright-mutate-image + BUNDLE_CONTAINER_IMAGE: + repository: <您的私有镜像仓库>/shipwright-bundle + WAITER_CONTAINER_IMAGE: + repository: <您的私有镜像仓库>/shipwright-waiter +tekton-pipelines: + controller: + tektonPipelinesController: + image: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-controller + kubeconfigWriterImage: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-kubeconfigwriter + gitImage: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-git-init + entrypointImage: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-entrypoint + nopImage: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-nop + imagedigestExporterImage: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-imagedigestexporter + prImage: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-pullrequest-init + workingdirinitImage: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-workingdirinit + gsutilImage: + repository: <您的私有镜像仓库>/cloudsdktool-cloud-sdk + digest: sha256:27b2c22bf259d9bc1a291e99c63791ba0c27a04d2db0a43241ba0f1f20f4067f + shellImage: + repository: <您的私有镜像仓库>/distroless-base + digest: sha256:b16b57be9160a122ef048333c68ba205ae4fe1a7b7cc6a5b289956292ebf45cc + webhook: + webhook: + image: + repository: <您的私有镜像仓库>/tektoncd-pipeline-cmd-webhook +keda: + image: + keda: + repository: <您的私有镜像仓库>/keda + tag: 2.8.1 + metricsApiServer: + repository: <您的私有镜像仓库>/keda-metrics-apiserver + tag: 2.8.1 +dapr: + global: + registry: <您的私有镜像仓库>/daprio + tag: '1.8.3' +contour: + contour: + image: + registry: <您的私有镜像仓库> + repository: <您的私有镜像仓库>/contour + tag: 1.21.1-debian-11-r5 + envoy: + image: + registry: <您的私有镜像仓库> + repository: <您的私有镜像仓库>/envoy + tag: 1.22.2-debian-11-r6 + defaultBackend: + image: + registry: <您的私有镜像仓库> + repository: <您的私有镜像仓库>/nginx + tag: 1.21.6-debian-11-r10 +``` + +请将 `<您的私有镜像仓库>` 替换为您的私有镜像仓库的地址。 + +### 安装 OpenFunction + +在离线环境中运行以下命令尝试安装 OpenFunction: + +```shell +kubectl create namespace openfunction +helm install openfunction openfunction-v1.0.0-v0.5.0.tgz -n openfunction -f custom-values.yaml +``` + +{{% alert title="注意" color="success" %}} + +如果 `helm install` 命令卡住,可能是由于 job `contour-contour-cergen` 引起的。 + +运行以下命令确认 job 是否执行成功: + +```shell +kubectl get job contour-contour-cergen -n projectcontour +``` + +如果 job 存在且 job 状态为完成,运行以下命令完成安装: + +```shell +helm uninstall openfunction -n openfunction --no-hooks +helm install openfunction openfunction-v1.0.0-v0.5.0.tgz -n openfunction -f custom-values.yaml --no-hooks +``` + +{{% /alert %}} + +### 补丁 ClusterBuildStrategy + +如果您想在离线环境中构建 wasm 函数或使用 `buildah` 构建函数,运行以下命令补丁 `ClusterBuildStrategy`: + +```shell +kubectl patch clusterbuildstrategy buildah --type='json' -p='[{"op": "replace", "path": "/spec/buildSteps/0/image", "value":"openfunction/buildah:v1.28.0"}]' +kubectl patch clusterbuildstrategy wasmedge --type='json' -p='[{"op": "replace", "path": "/spec/buildSteps/0/image", "value":"openfunction/buildah:v1.28.0"}]' +``` + +## Q: 如何在离线环境中构建和运行函数 + +A: 以 [Java 函数](https://github.com/OpenFunction/samples/tree/main/functions/knative/java) 为例,说明如何在离线环境中构建和运行函数: + +- 将 `https://github.com/OpenFunction/samples.git` 同步到您的私有代码仓库 + +- 按照此 [prerequisites](https://openfunction.dev/docs/getting-started/quickstarts/prerequisites/) 文档创建 `push-secret` 和 `git-repo-secret` + +- 将公共 maven 仓库更改为私有 maven 仓库: + ```xml + + + 4.0.0 + + dev.openfunction.samples + samples + 1.0-SNAPSHOT + + + 11 + 11 + + + + + snapshots + Maven snapshots + + your private maven repository + + false + + + true + + + + + + + dev.openfunction.functions + functions-framework-api + 1.0.0-SNAPSHOT + + + + + ``` + > 确保将更改提交到代码仓库。 + +- 将 `openfunction/buildpacks-java18-run:v1` 同步到您的私有镜像仓库 + +- 根据您的环境修改 `functions/knative/java/hello-world/function-sample.yaml`: + ```yaml + apiVersion: core.openfunction.io/v1beta2 + kind: Function + metadata: + name: function-http-java + spec: + version: "v2.0.0" + image: "/sample-java-func:v1" + imageCredentials: + name: push-secret + build: + builder: /builder-java:v2-18 + params: + RUN_IMAGE: "/buildpacks-java18-run:v1" + env: + FUNC_NAME: "dev.openfunction.samples.HttpFunctionImpl" + FUNC_CLEAR_SOURCE: "true" + srcRepo: + url: "https:///OpenFunction/samples.git" + sourceSubPath: "functions/knative/java" + revision: "main" + credentials: + name: git-repo-secret + serving: + template: + containers: + - name: function # DO NOT change this + imagePullPolicy: IfNotPresent + triggers: + http: + port: 8080 + ``` + + > 如果您的私有镜像仓库是不安全的,请参考 [以不安全的方式使用私有镜像仓库](#q-如何在openfunction中使用私有镜像仓库) + +- 运行以下命令构建和运行函数: + + ```shell + kubectl apply -f functions/knative/java/hello-world/function-sample.yaml + ``` \ No newline at end of file diff --git a/content/zh/docs/reference/function-spec.md b/content/zh/docs/reference/function-spec.md deleted file mode 100644 index 46bd7909..00000000 --- a/content/zh/docs/reference/function-spec.md +++ /dev/null @@ -1,178 +0,0 @@ ---- -title: "Function 参数说明" -linkTitle: "Function 参数说明" -weight: 5 -description: > - Function CRD 参数规范说明 ---- - -## Function - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **apiVersion** *string* | core.openfunction.io/v1alpha1 | -| **kind** *string* | Function | -| **metadata** *[v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta)* | *(可选)* 参考 [v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta) 文档 | -| **spec** *[FunctionSpec](#functionspec)* | Function 的规格,参考 [FunctionSpec](#functionspec) | -| **status** *FunctionStatus* | Function 的状态,参考 FunctionStatus | - -### FunctionSpec - -*从属 [Function](#function)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **version** *string* | *(可选)* 函数版本,如:“v1.0.0” | -| **image** *string* | 函数构建后的镜像上传路径,如:“demorepo/demofunction:v1” | -| **imageCredentials** *[v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference)* | *(可选)* 访问镜像仓库的凭证,参考 [v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference) | -| **port** *int32* | *(可选)* 函数应用监听的端口,如:“8080” | -| **build** *[BuildImpl](#buildimpl)* | *(可选)* 函数的 Builder 规格,参考 [BuildImpl](#buildimpl) | -| **serving** *[ServingImpl](#servingimpl)* | *(可选)* 函数的 Serving 规格,参考 [ServingImpl](#servingimpl) | - -### BuildImpl - -*从属 [FunctionSpec](#functionspec)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **builder** *string* | 镜像构建器的名称 | -| **builderCredentials** *[v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference)* | *(可选)* 访问镜像仓库的凭证,参考 [v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference) | -| **shipwright** *[ShipwrightEngine](#shipwrightengine)* | *(可选)* Shipwright 引擎的规格,参考 [ShipwrightEngine](#shipwrightengine) | -| **params** *map[string]string* | *(可选)* 传递给 Shipwright 的参数 | -| **env** map[string]string | *(可选)* 传递给镜像构建器的参数 | -| **srcRepo** *[GitRepo](#gitrepo)* | 源代码仓库的配置,参考 [GitRepo](#gitrepo) | -| **dockerfile** *string* | *(可选)* Dockerfile 文件的路径,用于指导 Shipwright 使用 Dockerfile 构建镜像 | - -### ShipwrightEngine - -*从属 [BuildImpl](#buildimpl)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **strategy** *[Strategy](#strategy)* | *(可选)* 镜像构建策略的名称,参考 [Strategy](#strategy) | -| **timeout** *[v1.Duration](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration)* | *(可选)* 镜像构建超时时间,参考 [v1.Duration](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#Duration) | - -### Strategy - -*从属 [ShipwrightEngine](#shipwrightengine)* - -| 字段 | 描述 | -| --------------- | ------------------------------------------------------------ | -| **name** string | 镜像构建策略的名称 | -| **kind** string | *(可选)* 镜像构建策略的 Kind,默认为“BuildStrategy”,可选“ClusterBuildStrategy” | - -### GitRepo - -*从属 [BuildImpl](#buildimpl)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **url** *string* | 代码仓库地址 | -| **revision** *string* | *(可选)* 代码仓库中的可引用实例,如 commit id,branch name 等 | -| **sourceSubPath** *string* | *(可选)* 目标函数在代码仓库中的目录,如:“functions/function-a/” | -| **credentials** *[v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference)* | *(可选)* 代码仓库的访问凭证,参考 [v1.LocalObjectReference](https://pkg.go.dev/k8s.io/api/core/v1#LocalObjectReference) | - -### ServingImpl - -*从属 [FunctionSpec](#functionspec)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **runtime** *string* | 负载运行时的类型,可选:“**Knative**” 和 “**OpenFuncAsync**” | -| **params** map[string]string | *(可选)* 传递给应用负载的环境变量参数 | -| **openFuncAsync** *[OpenFuncAsyncRuntime](#openfuncasyncruntime)* | *(可选)* 当 runtime 为 OpenFuncAsync 时,用于定义 OpenFuncAsync 的配置,参考 [OpenFuncAsyncRuntime](#openfuncasyncruntime) | -| **template** *[v1.PodSpec](https://pkg.go.dev/k8s.io/api/core/v1#PodSpec)* | *(可选)* 应用负载中 Pod 的定义模板,参考 [v1.PodSpec](https://pkg.go.dev/k8s.io/api/core/v1#PodSpec) | - -### OpenFuncAsyncRuntime - -*从属 [ServingImpl](#servingimpl)* - -| 字段 | 描述 | -| ------------------------ | ----------------------------------------------------- | -| **dapr** *[Dapr](#dapr)* | *(可选)* Dapr components 的定义,参考 [Dapr](#dapr) | -| **keda** *[Keda](#keda)* | *(可选)* Keda 的定义,参考 [Keda](#keda) | - -### Dapr - -*从属 [OpenFuncAsyncRuntime](#openfuncasyncruntime)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **annotations** *map[string]string* | *(可选)* Dapr components 的注解,参考 [Dapr 相关文档](https://docs.dapr.io/reference/arguments-annotations-overview/) | -| **components** *\[][DaprComponent](#daprcomponent)* | *(可选)* Dapr Components Spec 数组,参考 [DaprComponent](#daprcomponent) | -| **subscriptions** *\[][DaprSubscription](#daprsubscription)* | *(可选)* Dapr Subscription Spec 数组,参考 [DaprSubscription](#daprsubscription) | -| **inputs** *\[][DaprIO](#daprio)* | *(可选)* 函数输入端的定义,参考 [DaprIO](#daprio) | -| **outputs** *\[][DaprIO](#daprio)* | *(可选)* 函数输出端的定义,参考 [DaprIO](#daprio) | - -### DaprComponent - -*从属 [Dapr](#dapr)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **name** *string* | Dapr component 的名称 | -| *[v1alpha1.ComponentSpec](https://pkg.go.dev/github.com/dapr/dapr/pkg/apis/components/v1alpha1#ComponentSpec)* | Dapr Components Spec 定义,参考 [Dapr 相关文档](https://docs.dapr.io/reference/components-reference/) | - -### DaprSubscription - -*从属 [Dapr](#dapr)* - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **name** *string* | Dapr components 的注解,参考 [Dapr 相关文档](https://docs.dapr.io/reference/arguments-annotations-overview/) | -| *[v1alpha1.SubscriptionSpec](https://pkg.go.dev/github.com/dapr/dapr/pkg/apis/subscriptions/v1alpha1#SubscriptionSpec)* | Dapr Subscription Spec 定义,参考 [Dapr 相关文档](https://docs.dapr.io/reference/components-reference/) | -| **scopes** *[]string* | | - -### DaprIO - -*从属 [Dapr](#dapr)* - -| 字段 | 描述 | -| ------------------------------ | ------------------------------------------------------------ | -| **name** *string* | 函数输入、输出端的名称,与 [DaprComponent](#daprcomponent) 的 name 一致即表示关联 | -| **type** *string* | Dapr component 的类型,可选:`bindings`、`pubsub`、`invoke` | -| **topic** *string* | *(可选)* 当 **type** 为 `pubsub` 时,需要设置 topic | -| **methodName** *string* | *(可选)* 当 **type** 为 `invoke` 时,需要设置 methodName,参考 [Dapr 相关文档](https://docs.dapr.io/reference/api/service_invocation_api/#url-parameters) | -| **params** *map[string]string* | *(可选)* 传递给 Dapr 的参数 | - -### Keda - -*从属 [OpenFuncAsyncRuntime](#openfuncasyncruntime)* - -| 字段 | 描述 | -| -------------------------------------------------------- | ------------------------------------------------------------ | -| **scaledObject** *[KedaScaledObject](#kedascaledobject)* | KEDA 可扩展对象(Deployments)定义,参考 [KedaScaledObject](#kedascaledobject) | -| **scaledJob** *[KedaScaledJob](#kedascaledjob)* | KEDA 可扩展任务定义,参考 [KedaScaledJob](#kedascaledjob) | - -### KedaScaledObject - -*从属 [Keda](#keda)* - -> 你可以参考 [Scaling Deployments, StatefulSets & Custom Resources](https://keda.sh/docs/2.4/concepts/scaling-deployments/) 获得更多信息 - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **workloadType** *string* | 以何种方式运行函数,可选:`Deployment`、 `StatefulSet`,默认为 `Deployment`. | -| **pollingInterval** *int32* | *(可选)* pollingInterval 的单位是秒。这是 KEDA 检查触发器的队列长度或流滞后的时间间隔。默认是 `30` 秒。 | -| **cooldownPeriod** *int32* | *(可选)* cooldownPeriod 也是以秒为单位,它是在最后一个触发器激活后等待的时间段,然后再缩减到 0。 默认是 `300` 秒。 | -| **minReplicaCount** *int32* | *(可选)* KEDA 在收缩资源的最小副本数。默认情况下为 `0`。 | -| **maxReplicaCount** *int32* | *(可选)* KEDA 会将该值传递给为资源创建的 HPA 定义。 | -| **advanced** *[kedav1alpha1.AdvancedConfig](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#AdvancedConfig)* | *(可选)* 此属性指定在删除 “ScaledObject” 后,目标资源(“Deployments”、“StatefulSet”...)是否应被缩减到原始副本数量。默认行为是保持复制数量与删除 “ScaledObject” 时的数量相同。参考 [kedav1alpha1.AdvancedConfig](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#AdvancedConfig) | -| **triggers** *\[][kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers)* | 触发工作负载动态伸缩的事件源,参考 [kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers) | - -### KedaScaledJob - -*从属 [Keda](#keda)* - -> 你可以参考 [Scaling Jobs](https://keda.sh/docs/2.4/concepts/scaling-jobs/) 获得更多信息 - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **restartPolicy** *[v1.RestartPolicy](https://pkg.go.dev/k8s.io/api/core/v1#RestartPolicy)* | 在 pod 内所有容器的重启策略。可选择 `OnFailure`、`Never`。默认为 `Never`。 | -| **pollingInterval** *int32* | *(可选)* pollingInterval 的单位是秒。这是 KEDA 检查触发器的队列长度或流滞后的时间间隔。默认是 `30` 秒。 | -| **successfulJobsHistoryLimit** *int32* | *(可选)* 应该保留多少个已完成的 Job。默认为 `100`。 | -| **failedJobsHistoryLimit** *int32* | *(可选)* 应该保留多少个失败的 Job。默认为 `100`。 | -| **maxReplicaCount** *int32* | *(可选)* 在一个轮询周期内可以创建的最大 pod 的数量。 | -| **scalingStrategy** *[kedav1alpha1.ScalingStrategy](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScalingStrategy)* | *(可选)* 选择一个缩放策略。可能的值是 `default`、`custom`、`accurate`。默认值是 `default`。参考 [kedav1alpha1.ScalingStrategy](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScalingStrategy) | -| **triggers** *\[][kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers)* | 触发工作负载动态伸缩的事件源,参考[kedav1alpha1.ScaleTriggers](https://pkg.go.dev/github.com/kedacore/keda/v2/api/v1alpha1#ScaleTriggers) | - diff --git a/content/zh/docs/reference/trigger-spec/_index.md b/content/zh/docs/reference/trigger-spec/_index.md deleted file mode 100644 index 9a97ac95..00000000 --- a/content/zh/docs/reference/trigger-spec/_index.md +++ /dev/null @@ -1,71 +0,0 @@ ---- -title: "Trigger 参数说明" -linkTitle: "Trigger 参数说明" -weight: 20 -description: > - Trigger CRD 参数规范说明 ---- - -## Trigger - -| 字段 | 描述 | -| ------------------------------------------------------------ | ------------------------------------------------------------ | -| **apiVersion** *string* | events.openfunction.io/v1alpha1 | -| **kind** *string* | Trigger | -| **metadata** *[v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta)* | *(可选)* 参考 [v1.ObjectMeta](https://pkg.go.dev/k8s.io/apimachinery/pkg/apis/meta/v1#ObjectMeta) 文档 | -| **spec** *[TriggerSpec](#triggerspec)* | 事件触发器的规格,参考 [TriggerSpec](#triggerspec) | -| **status** *TriggerStatus* | 触发器的状态 | - -### TriggerSpec - -*从属 [Trigger](#trigger)* - -| 字段 | 描述 | -| ---------------------------------------------- | ------------------------------------------------------------ | -| **eventBus** *string* | *(可选)* 事件触发器关联的 EventBus 资源名称 | -| **inputs** *map\[string][Input](#input)* | *(可选)* 输入触发器的事件,参考 map\[string][Input](#input) | -| **subscribers** *\[][Subscriber](#subscriber)* | *(可选)* 触发器的订阅者,参考 \[][Subscriber](#subscriber) | - -### Input - -*从属 [TriggerSpec](#triggerspec)* - -| 字段 | 描述 | -| ------------------------ | ------------------------------------------------------------ | -| **namespace** *string* | *(可选)* 事件源的的命名空间名称,默认与 Trigger 的命名空间一致。如:`default` | -| **eventSource** *string* | 事件源名称,如:`kafka-eventsource` | -| **event** *string* | 事件名称,如:`eventA` | - -### Subscriber - -*从属 [TriggerSpec](#triggerspec)* - -| 字段 | 描述 | -| ------------------------------------------ | ------------------------------------------------------------ | -| **condition** *string* | 触发器的触发条件,参考 [cel-spec](https://github.com/google/cel-spec/blob/master/doc/langdef.md) 获取更多写法规范。如:`eventA && eventB`,`eventA || eventB` | -| **sink** *[SinkSpec](#sinkspec)* | *(可选)* 触发的 Sink(可寻址的访问资源,即同步请求)定义,参考 [SinkSpec](#sinkspec) | -| **deadLetterSink** *[SinkSpec](#sinkspec)* | *(可选)* 触发的死信 Sink(可寻址的访问资源,即同步请求)定义,参考 [SinkSpec](#sinkspec) | -| **topic** *string* | *(可选)* 触发的发送给事件总线的 topic 名称,如:`topicTriggered` | -| **deadLetterTopic** *string* | *(可选)* 触发的发送给事件总线的死信 topic 名称,如:`topicDL` | - -### SinkSpec - -*从属 [Subscriber](#subscriber)* - -| 字段 | 描述 | -| --------------------------------- | ---------------------------- | -| **ref** *[Reference](#reference)* | 参考 [Reference](#reference) | - -### Reference - -*从属 [SinkSpec](#sinkspec)* - -> 引用资源一般为 [Knative Service](https://knative.dev/docs/reference/api/serving-api/#serving.knative.dev/v1.Service) - -| 字段 | 描述 | -| ----------------------- | ------------------------------------------------------- | -| **kind** *string* | 引用资源的类型,默认为:`Service` | -| **namespace** *string* | 引用资源的命名空间,默认与 Trigger 的命名空间一致 | -| **name** *string* | 引用资源的名称,如:`function-ksvc` | -| **apiVersion** *string* | 引用资源的 apiVersion,默认为:`serving.knative.dev/v1` | - diff --git a/content/zh/docs/roadmap/_index.md b/content/zh/docs/roadmap/_index.md deleted file mode 100644 index af4f654c..00000000 --- a/content/zh/docs/roadmap/_index.md +++ /dev/null @@ -1,44 +0,0 @@ ---- -title: "路线图" -linkTitle: "路线图" -weight: 80 -description: > - 了解 OpenFunction 的演进计划 ---- - -## v0.1.0,2021年5月 - -- [x] Create Function, Builder and Serving CRDs and corresponding controllers - -- [x] Support using existing function framework & buildpacks such as Google Cloud Function to build functions - -- [x] Support using Tekton and Cloud Native Buildpacks as Builder backend to build functions -- [x] Support Knative as Serving backend -- [x] Optimize and localize existing function framework & buildpacks - -## v0.2.0,2021年6月 - -- [x] Support OpenFunctionAsync serving runtime(backed by Dapr + KEDA + Deployment/Job) -- [x] Functions Frameworks async function support -- [x] Customized go function framework & builders for both Knative and OpenFunctionAsync serving runtime - -## v0.3.0,2021年7~8月 - -- [x] Add OpenFunction Events: OpenFunction's own event management framework -- [x] Support using [ShipWright](https://github.com/shipwright-io/build) as Builder backend to build functions or apps -- [x] Build and serving can be launched separately -- [x] Support running an application (container image) as a serverless workload directly - -## v0.4.0+,2021年Q4 - -- [ ] OpenFunction CLI -- [ ] Support more EventSources -- [ ] Use OpenFunction async functions to drive EventSource & EventTrigger workloads -- [ ] OpenFunction sync function -- [ ] Python functions frameworks & builder -- [ ] Nodejs functions frameworks & builder -- [ ] OpenFunction Console (WebUI) -- [ ] Support scheduling functions to Edge -- [ ] Use [ShipWright](https://github.com/shipwright-io/build) to build functions or apps with Dockerfile. -- [ ] Support Rust functions & WebAssembly runtime. - diff --git a/content/zh/openfunction-0.5-architecture.png b/content/zh/openfunction-0.5-architecture.png deleted file mode 100644 index c16fb481..00000000 Binary files a/content/zh/openfunction-0.5-architecture.png and /dev/null differ diff --git a/hugo.toml b/hugo.toml index dcf2b4ea..a434335f 100644 --- a/hugo.toml +++ b/hugo.toml @@ -108,9 +108,17 @@ version = "0.8" url_latest_version = "/docs" [[params.versions]] - version = "v1.0 (latest)" + version = "v1.2 (latest)" url = "/docs" +[[params.versions]] + version = "v1.1" + url = "https://v1-1.openfunction.dev/docs/" + +[[params.versions]] + version = "v1.0" + url = "https://v1-0.openfunction.dev/docs/" + [[params.versions]] version = "v0.8" url = "https://v0-8.openfunction.dev/docs/" diff --git a/layouts/partials/footer.html b/layouts/partials/footer.html index 349f8b7d..79a00434 100644 --- a/layouts/partials/footer.html +++ b/layouts/partials/footer.html @@ -34,7 +34,7 @@
- Copyright © 2023 The Linux Foundation ®. All rights reserved. + Copyright © 2025 The Linux Foundation ®. All rights reserved.
@@ -59,4 +59,4 @@ {{ end }} -{{ end }} \ No newline at end of file +{{ end }} diff --git a/layouts/partials/navbar.html b/layouts/partials/navbar.html index 6af36827..4b3b9870 100644 --- a/layouts/partials/navbar.html +++ b/layouts/partials/navbar.html @@ -6,11 +6,30 @@