diff --git a/README.md b/README.md index 10132a7..5e0eb1e 100644 --- a/README.md +++ b/README.md @@ -8,32 +8,32 @@ We currently support two kinds of runtime, Knative and OpenFuncAsync. ### Knative runtime -- "Hello world" in go - [v0.3.1](v0.3.1/functions/Knative/hello-world-go), [v0.4.0](v0.4.0/functions/Knative/hello-world-go), [v0.5.0](v0.5.0/functions/Knative/hello-world-go), [latest](latest/functions/Knative/hello-world-go) -- "Hello world" in java - [v0.3.1](v0.3.1/functions/Knative/hello-world-java), [v0.4.0](v0.4.0/functions/Knative/hello-world-java), [v0.5.0](v0.5.0/functions/Knative/hello-world-java), [latest](latest/functions/Knative/hello-world-java) -- "Hello world" in python - [v0.3.1](v0.3.1/functions/Knative/hello-world-python), [v0.4.0](v0.4.0/functions/Knative/hello-world-python), [v0.5.0](v0.5.0/functions/Knative/hello-world-python), [latest](latest/functions/Knative/hello-world-python) -- "Hello world" in node - [v0.3.1](v0.3.1/functions/Knative/hello-world-node), [v0.4.0](v0.4.0/functions/Knative/hello-world-node), [v0.5.0](v0.5.0/functions/Knative/hello-world-node), [latest](latest/functions/Knative/hello-world-node) -- "Hello world" in dotnet - [v0.3.1](v0.3.1/functions/Knative/hello-world-dotnet), [v0.4.0](v0.4.0/functions/Knative/hello-world-dotnet), [v0.5.0](v0.5.0/functions/Knative/hello-world-dotnet), [latest](latest/functions/Knative/hello-world-dotnet) -- Azure function sample - [v0.3.1](v0.3.1/functions/Knative/azure-func-go), [v0.4.0](v0.4.0/functions/Knative/azure-func-go), [v0.5.0](v0.5.0/functions/Knative/azure-func-go), [latest](latest/functions/Knative/azure-func-go) -- Logs handler function - [v0.3.1](v0.3.1/functions/Knative/logs-handler-function), [v0.4.0](v0.4.0/functions/Knative/logs-handler-function), [v0.5.0](v0.5.0/functions/Knative/logs-handler-function), [latest](latest/functions/Knative/logs-handler-function) +- ["Hello world" in go](functions/Knative/hello-world-go) +- ["Hello world" in java](functions/Knative/hello-world-java) +- ["Hello world" in python](functions/Knative/hello-world-python) +- ["Hello world" in node](functions/Knative/hello-world-node) +- ["Hello world" in dotnet](functions/Knative/hello-world-dotnet) +- [Azure function sample](functions/Knative/azure-func-go) +- [Logs handler function](functions/Knative/logs-handler-function) ### OpenFuncAsync runtime -- OpenFuncAsync bindings sample in go - [v0.3.1](v0.3.1/functions/OpenFuncAsync/bindings), [v0.4.0](v0.4.0/functions/OpenFuncAsync/bindings), [v0.5.0](v0.5.0/functions/OpenFuncAsync/bindings), [latest](latest/functions/OpenFuncAsync/bindings) -- OpenFuncAsync pubsub sample in go - [v0.3.1](v0.3.1/functions/OpenFuncAsync/pubsub), [v0.4.0](v0.4.0/functions/OpenFuncAsync/pubsub), [v0.5.0](v0.5.0/functions/OpenFuncAsync/pubsub), [latest](latest/functions/OpenFuncAsync/pubsub) -- Logs handler function - [v0.3.1](v0.3.1/functions/OpenFuncAsync/logs-handler-function), [v0.4.0](v0.4.0/functions/OpenFuncAsync/logs-handler-function), [v0.5.0](v0.5.0/functions/OpenFuncAsync/logs-handler-function), [latest](latest/functions/OpenFuncAsync/logs-handler-function) +- OpenFuncAsync bindings sample in [go](functions/OpenFuncAsync/bindings) +- OpenFuncAsync pubsub sample in [go](functions/OpenFuncAsync/pubsub) +- Logs handler function [go](functions/OpenFuncAsync/logs-handler-function) ## Application samples -- Java App - [v0.3.1](v0.3.1/apps/sample-apps-java-maven.yaml), [v0.4.0](v0.4.0/apps/sample-apps-java-maven.yaml), [v0.5.0](v0.5.0/apps/sample-apps-java-maven.yaml), [latest](latest/apps/sample-apps-java-maven.yaml) +- [Java App](apps/sample-apps-java-maven.yaml) ## Functions-framework samples The following are samples of OpenFunction functions-framework. -- Knative runtime demos in go - [v0.3.1](v0.3.1/functions-framework/golang/Knative), [v0.4.0](v0.4.0/functions-framework/golang/Knative), [v0.5.0](v0.5.0/functions-framework/golang/Knative), [latest](latest/functions-framework/golang/Knative) -- OpenFuncAsync runtime demos in go - [v0.3.1](v0.3.1/functions-framework/golang/OpenFuncAsync), [v0.4.0](v0.4.0/functions-framework/golang/OpenFuncAsync), [v0.5.0](v0.5.0/functions-framework/golang/OpenFuncAsync), [latest](latest/functions-framework/golang/OpenFuncAsync) -- Knative runtime demos in nodejs - [v0.3.1](v0.3.1/functions-framework/nodejs/Knative), [v0.4.0](v0.4.0/functions-framework/nodejs/Knative), [v0.5.0](v0.5.0/functions-framework/nodejs/Knative), [latest](latest/functions-framework/nodejs/Knative) -- OpenFuncAsync runtime demos in nodejs - [v0.3.1](v0.3.1/functions-framework/nodejs/OpenFuncAsync), [v0.4.0](v0.4.0/functions-framework/nodejs/OpenFuncAsync), [v0.5.0](v0.5.0/functions-framework/nodejs/OpenFuncAsync), [latest](latest/functions-framework/nodejs/OpenFuncAsync) +- Knative runtime demos in [go](functions-framework/golang/Knative) +- OpenFuncAsync runtime demos in [go](functions-framework/golang/OpenFuncAsync) +- Knative runtime demos in [nodejs](functions-framework/nodejs/Knative) +- OpenFuncAsync runtime demos in [nodejs](functions-framework/nodejs/OpenFuncAsync) ## Katacode scenarios diff --git a/v0.4.0/apps/sample-apps-java-maven.yaml b/apps/sample-apps-java-maven.yaml similarity index 86% rename from v0.4.0/apps/sample-apps-java-maven.yaml rename to apps/sample-apps-java-maven.yaml index b7ca44a..c991fa2 100644 --- a/v0.4.0/apps/sample-apps-java-maven.yaml +++ b/apps/sample-apps-java-maven.yaml @@ -4,7 +4,7 @@ metadata: name: sample-app-java-maven spec: version: "v1.0.0" - image: "openfunction/buildpacks-sample-apps-java-maven:v0.4.0" + image: "openfunction/buildpacks-sample-apps-java-maven:v0.4" imageCredentials: name: push-secret port: 8080 # default to 8080 diff --git a/latest/functions-framework/README.md b/functions-framework/README.md similarity index 100% rename from latest/functions-framework/README.md rename to functions-framework/README.md diff --git a/latest/functions-framework/golang/Knative/README.md b/functions-framework/golang/Knative/README.md similarity index 100% rename from latest/functions-framework/golang/Knative/README.md rename to functions-framework/golang/Knative/README.md diff --git a/latest/functions-framework/golang/Knative/simple-hello/README.md b/functions-framework/golang/Knative/simple-hello/README.md similarity index 100% rename from latest/functions-framework/golang/Knative/simple-hello/README.md rename to functions-framework/golang/Knative/simple-hello/README.md diff --git a/v0.4.0/functions-framework/golang/Knative/simple-hello/go.mod b/functions-framework/golang/Knative/simple-hello/go.mod similarity index 100% rename from v0.4.0/functions-framework/golang/Knative/simple-hello/go.mod rename to functions-framework/golang/Knative/simple-hello/go.mod diff --git a/latest/functions-framework/golang/Knative/simple-hello/main.go b/functions-framework/golang/Knative/simple-hello/main.go similarity index 100% rename from latest/functions-framework/golang/Knative/simple-hello/main.go rename to functions-framework/golang/Knative/simple-hello/main.go diff --git a/latest/functions-framework/golang/Knative/simple-hello/userfunction/hello.go b/functions-framework/golang/Knative/simple-hello/userfunction/hello.go similarity index 100% rename from latest/functions-framework/golang/Knative/simple-hello/userfunction/hello.go rename to functions-framework/golang/Knative/simple-hello/userfunction/hello.go diff --git a/latest/functions-framework/golang/OpenFuncAsync/README.md b/functions-framework/golang/OpenFuncAsync/README.md similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/README.md rename to functions-framework/golang/OpenFuncAsync/README.md diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/README.md b/functions-framework/golang/OpenFuncAsync/bindings/README.md similarity index 100% rename from v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/README.md rename to functions-framework/golang/OpenFuncAsync/bindings/README.md diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod b/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod similarity index 100% rename from v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod rename to functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod diff --git a/latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go b/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go rename to functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go diff --git a/latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go b/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go rename to functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go diff --git a/latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go b/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go rename to functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod b/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod similarity index 100% rename from v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod rename to functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod diff --git a/latest/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go b/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go rename to functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go diff --git a/latest/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go b/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go rename to functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go diff --git a/latest/functions-framework/golang/OpenFuncAsync/components/bindings.yaml b/functions-framework/golang/OpenFuncAsync/components/bindings.yaml similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/components/bindings.yaml rename to functions-framework/golang/OpenFuncAsync/components/bindings.yaml diff --git a/latest/functions-framework/golang/OpenFuncAsync/components/cron.yaml b/functions-framework/golang/OpenFuncAsync/components/cron.yaml similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/components/cron.yaml rename to functions-framework/golang/OpenFuncAsync/components/cron.yaml diff --git a/latest/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml b/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml rename to functions-framework/golang/OpenFuncAsync/components/pubsub.yaml diff --git a/latest/functions-framework/golang/OpenFuncAsync/components/statestore.yaml b/functions-framework/golang/OpenFuncAsync/components/statestore.yaml similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/components/statestore.yaml rename to functions-framework/golang/OpenFuncAsync/components/statestore.yaml diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/README.md b/functions-framework/golang/OpenFuncAsync/pubsub/README.md similarity index 100% rename from v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/README.md rename to functions-framework/golang/OpenFuncAsync/pubsub/README.md diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod b/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod similarity index 100% rename from v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod rename to functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod diff --git a/latest/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go b/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go rename to functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go diff --git a/latest/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go b/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go rename to functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod b/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod similarity index 100% rename from v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod rename to functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod diff --git a/latest/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go b/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go rename to functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go diff --git a/latest/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go b/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go similarity index 100% rename from latest/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go rename to functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go diff --git a/latest/functions-framework/nodejs/Knative/README.md b/functions-framework/nodejs/Knative/README.md similarity index 100% rename from latest/functions-framework/nodejs/Knative/README.md rename to functions-framework/nodejs/Knative/README.md diff --git a/latest/functions-framework/nodejs/Knative/cloudevent/README.md b/functions-framework/nodejs/Knative/cloudevent/README.md similarity index 100% rename from latest/functions-framework/nodejs/Knative/cloudevent/README.md rename to functions-framework/nodejs/Knative/cloudevent/README.md diff --git a/latest/functions-framework/nodejs/Knative/cloudevent/index.js b/functions-framework/nodejs/Knative/cloudevent/index.js similarity index 100% rename from latest/functions-framework/nodejs/Knative/cloudevent/index.js rename to functions-framework/nodejs/Knative/cloudevent/index.js diff --git a/latest/functions-framework/nodejs/Knative/cloudevent/package.json b/functions-framework/nodejs/Knative/cloudevent/package.json similarity index 100% rename from latest/functions-framework/nodejs/Knative/cloudevent/package.json rename to functions-framework/nodejs/Knative/cloudevent/package.json diff --git a/latest/functions-framework/nodejs/Knative/helloworld/README.md b/functions-framework/nodejs/Knative/helloworld/README.md similarity index 100% rename from latest/functions-framework/nodejs/Knative/helloworld/README.md rename to functions-framework/nodejs/Knative/helloworld/README.md diff --git a/latest/functions-framework/nodejs/Knative/helloworld/index.js b/functions-framework/nodejs/Knative/helloworld/index.js similarity index 100% rename from latest/functions-framework/nodejs/Knative/helloworld/index.js rename to functions-framework/nodejs/Knative/helloworld/index.js diff --git a/latest/functions-framework/nodejs/Knative/helloworld/package.json b/functions-framework/nodejs/Knative/helloworld/package.json similarity index 100% rename from latest/functions-framework/nodejs/Knative/helloworld/package.json rename to functions-framework/nodejs/Knative/helloworld/package.json diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/README.md b/functions-framework/nodejs/OpenFuncAsync/README.md similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/README.md rename to functions-framework/nodejs/OpenFuncAsync/README.md diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/bindings/README.md b/functions-framework/nodejs/OpenFuncAsync/bindings/README.md similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/bindings/README.md rename to functions-framework/nodejs/OpenFuncAsync/bindings/README.md diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml b/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml rename to functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/bindings/config.json b/functions-framework/nodejs/OpenFuncAsync/bindings/config.json similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/bindings/config.json rename to functions-framework/nodejs/OpenFuncAsync/bindings/config.json diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/bindings/index.js b/functions-framework/nodejs/OpenFuncAsync/bindings/index.js similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/bindings/index.js rename to functions-framework/nodejs/OpenFuncAsync/bindings/index.js diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/bindings/package.json b/functions-framework/nodejs/OpenFuncAsync/bindings/package.json similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/bindings/package.json rename to functions-framework/nodejs/OpenFuncAsync/bindings/package.json diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md b/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md rename to functions-framework/nodejs/OpenFuncAsync/helloworld/README.md diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js b/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js rename to functions-framework/nodejs/OpenFuncAsync/helloworld/index.js diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json b/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json rename to functions-framework/nodejs/OpenFuncAsync/helloworld/package.json diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md b/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md rename to functions-framework/nodejs/OpenFuncAsync/pubsub/README.md diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json b/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json rename to functions-framework/nodejs/OpenFuncAsync/pubsub/config.json diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js b/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js rename to functions-framework/nodejs/OpenFuncAsync/pubsub/index.js diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json b/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json rename to functions-framework/nodejs/OpenFuncAsync/pubsub/package.json diff --git a/latest/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml b/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml similarity index 100% rename from latest/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml rename to functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml diff --git a/latest/functions/Knative/azure-func-go/.funcignore b/functions/Knative/azure-func-go/.funcignore similarity index 100% rename from latest/functions/Knative/azure-func-go/.funcignore rename to functions/Knative/azure-func-go/.funcignore diff --git a/latest/functions/Knative/azure-func-go/HttpExample/function.json b/functions/Knative/azure-func-go/HttpExample/function.json similarity index 100% rename from latest/functions/Knative/azure-func-go/HttpExample/function.json rename to functions/Knative/azure-func-go/HttpExample/function.json diff --git a/latest/functions/Knative/azure-func-go/handler b/functions/Knative/azure-func-go/handler similarity index 100% rename from latest/functions/Knative/azure-func-go/handler rename to functions/Knative/azure-func-go/handler diff --git a/latest/functions/Knative/azure-func-go/handler.go b/functions/Knative/azure-func-go/handler.go similarity index 100% rename from latest/functions/Knative/azure-func-go/handler.go rename to functions/Knative/azure-func-go/handler.go diff --git a/latest/functions/Knative/azure-func-go/host.json b/functions/Knative/azure-func-go/host.json similarity index 100% rename from latest/functions/Knative/azure-func-go/host.json rename to functions/Knative/azure-func-go/host.json diff --git a/latest/functions/Knative/azure-func-go/proxies.json b/functions/Knative/azure-func-go/proxies.json similarity index 100% rename from latest/functions/Knative/azure-func-go/proxies.json rename to functions/Knative/azure-func-go/proxies.json diff --git a/latest/functions/Knative/hello-world-dotnet/Program.cs b/functions/Knative/hello-world-dotnet/Program.cs similarity index 100% rename from latest/functions/Knative/hello-world-dotnet/Program.cs rename to functions/Knative/hello-world-dotnet/Program.cs diff --git a/v0.4.0/functions/Knative/hello-world-dotnet/README.md b/functions/Knative/hello-world-dotnet/README.md similarity index 83% rename from v0.4.0/functions/Knative/hello-world-dotnet/README.md rename to functions/Knative/hello-world-dotnet/README.md index 4ebf466..552a81d 100644 --- a/v0.4.0/functions/Knative/hello-world-dotnet/README.md +++ b/functions/Knative/hello-world-dotnet/README.md @@ -14,7 +14,7 @@ metadata: name: dotnet-sample spec: version: "v1.0.0" - image: "/sample-dotnet-func:v0.4.0" + image: "/sample-dotnet-func:v0.4" imageCredentials: name: push-secret port: 8080 # default to 8080 @@ -24,8 +24,9 @@ spec: GOOGLE_FUNCTION_TARGET: "helloworld" GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/Knative/hello-world-dotnet" + sourceSubPath: "functions/Knative/hello-world-dotnet" serving: runtime: "Knative" # default to Knative ``` diff --git a/latest/functions/Knative/hello-world-dotnet/Startup.cs b/functions/Knative/hello-world-dotnet/Startup.cs similarity index 100% rename from latest/functions/Knative/hello-world-dotnet/Startup.cs rename to functions/Knative/hello-world-dotnet/Startup.cs diff --git a/latest/functions/Knative/hello-world-dotnet/helloworld.csproj b/functions/Knative/hello-world-dotnet/helloworld.csproj similarity index 100% rename from latest/functions/Knative/hello-world-dotnet/helloworld.csproj rename to functions/Knative/hello-world-dotnet/helloworld.csproj diff --git a/latest/functions/Knative/hello-world-go/README.md b/functions/Knative/hello-world-go/README.md similarity index 100% rename from latest/functions/Knative/hello-world-go/README.md rename to functions/Knative/hello-world-go/README.md diff --git a/v0.4.0/functions/Knative/hello-world-go/function-sample.yaml b/functions/Knative/hello-world-go/function-sample.yaml similarity index 80% rename from v0.4.0/functions/Knative/hello-world-go/function-sample.yaml rename to functions/Knative/hello-world-go/function-sample.yaml index c07a06e..5c4bcda 100644 --- a/v0.4.0/functions/Knative/hello-world-go/function-sample.yaml +++ b/functions/Knative/hello-world-go/function-sample.yaml @@ -4,7 +4,7 @@ metadata: name: function-sample spec: version: "v1.0.0" - image: "openfunctiondev/sample-go-func:v0.4.0" + image: "openfunctiondev/sample-go-func:v0.4" imageCredentials: name: push-secret port: 8080 # default to 8080 @@ -14,8 +14,9 @@ spec: FUNC_NAME: "HelloWorld" FUNC_TYPE: "http" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/Knative/hello-world-go" + sourceSubPath: "functions/Knative/hello-world-go" serving: runtime: Knative # default to Knative # template: diff --git a/latest/functions/Knative/hello-world-go/go.mod b/functions/Knative/hello-world-go/go.mod similarity index 100% rename from latest/functions/Knative/hello-world-go/go.mod rename to functions/Knative/hello-world-go/go.mod diff --git a/latest/functions/Knative/hello-world-go/hello.go b/functions/Knative/hello-world-go/hello.go similarity index 100% rename from latest/functions/Knative/hello-world-go/hello.go rename to functions/Knative/hello-world-go/hello.go diff --git a/v0.4.0/functions/Knative/hello-world-java/README.md b/functions/Knative/hello-world-java/README.md similarity index 84% rename from v0.4.0/functions/Knative/hello-world-java/README.md rename to functions/Knative/hello-world-java/README.md index f335b15..9b4558e 100644 --- a/v0.4.0/functions/Knative/hello-world-java/README.md +++ b/functions/Knative/hello-world-java/README.md @@ -14,7 +14,7 @@ metadata: name: java-sample spec: version: "v1.0.0" - image: "/sample-java-func:v0.4.0" + image: "/sample-java-func:v0.4" imageCredentials: name: push-secret port: 8080 # default to 8080 @@ -24,8 +24,9 @@ spec: GOOGLE_FUNCTION_TARGET: "com.openfunction.HelloWorld" GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/Knative/hello-world-java" + sourceSubPath: "functions/Knative/hello-world-java" serving: runtime: Knative # default to Knative ``` diff --git a/latest/functions/Knative/hello-world-java/pom.xml b/functions/Knative/hello-world-java/pom.xml similarity index 100% rename from latest/functions/Knative/hello-world-java/pom.xml rename to functions/Knative/hello-world-java/pom.xml diff --git a/latest/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java b/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java similarity index 100% rename from latest/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java rename to functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java diff --git a/v0.4.0/functions/Knative/hello-world-node/README.md b/functions/Knative/hello-world-node/README.md similarity index 83% rename from v0.4.0/functions/Knative/hello-world-node/README.md rename to functions/Knative/hello-world-node/README.md index aa032de..93f7908 100644 --- a/v0.4.0/functions/Knative/hello-world-node/README.md +++ b/functions/Knative/hello-world-node/README.md @@ -14,7 +14,7 @@ metadata: name: node-sample spec: version: "v1.0.0" - image: "/sample-node-func:v0.4.0" + image: "/sample-node-func:v0.4" imageCredentials: name: push-secret port: 8080 # default to 8080 @@ -24,8 +24,9 @@ spec: GOOGLE_FUNCTION_TARGET: "helloWorld" GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/Knative/hello-world-node" + sourceSubPath: "functions/Knative/hello-world-node" serving: runtime: "Knative" # default to Knative ``` diff --git a/latest/functions/Knative/hello-world-node/index.js b/functions/Knative/hello-world-node/index.js similarity index 100% rename from latest/functions/Knative/hello-world-node/index.js rename to functions/Knative/hello-world-node/index.js diff --git a/v0.4.0/functions/Knative/hello-world-python/README.md b/functions/Knative/hello-world-python/README.md similarity index 84% rename from v0.4.0/functions/Knative/hello-world-python/README.md rename to functions/Knative/hello-world-python/README.md index 9a1be5e..1057606 100644 --- a/v0.4.0/functions/Knative/hello-world-python/README.md +++ b/functions/Knative/hello-world-python/README.md @@ -14,7 +14,7 @@ metadata: name: python-sample spec: version: "v1.0.0" - image: "/sample-python-func:v0.4.0" + image: "/sample-python-func:v0.4" imageCredentials: name: push-secret port: 8080 # default to 8080 @@ -25,8 +25,9 @@ spec: GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" GOOGLE_FUNCTION_SOURCE: "main.py" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/Knative/hello-world-python" + sourceSubPath: "functions/Knative/hello-world-python" serving: runtime: Knative # default to Knative ``` diff --git a/latest/functions/Knative/hello-world-python/main.py b/functions/Knative/hello-world-python/main.py similarity index 100% rename from latest/functions/Knative/hello-world-python/main.py rename to functions/Knative/hello-world-python/main.py diff --git a/latest/functions/Knative/hello-world-python/requirements.txt b/functions/Knative/hello-world-python/requirements.txt similarity index 100% rename from latest/functions/Knative/hello-world-python/requirements.txt rename to functions/Knative/hello-world-python/requirements.txt diff --git a/latest/functions/Knative/logs-handler-function/LogsHandler.go b/functions/Knative/logs-handler-function/LogsHandler.go similarity index 100% rename from latest/functions/Knative/logs-handler-function/LogsHandler.go rename to functions/Knative/logs-handler-function/LogsHandler.go diff --git a/v0.4.0/functions/Knative/logs-handler-function/README.md b/functions/Knative/logs-handler-function/README.md similarity index 66% rename from v0.4.0/functions/Knative/logs-handler-function/README.md rename to functions/Knative/logs-handler-function/README.md index e8a8758..ff99cfe 100644 --- a/v0.4.0/functions/Knative/logs-handler-function/README.md +++ b/functions/Knative/logs-handler-function/README.md @@ -10,11 +10,11 @@ or ## Prerequisites -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. +Follow [this guide](../../../Prerequisites.md#openfunction) to install OpenFunction. -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. +Follow [this guide](../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. +Follow [this guide](../../../Prerequisites.md#registry-credential) to create a registry credential. ## Deployment diff --git a/latest/functions/Knative/logs-handler-function/go.mod b/functions/Knative/logs-handler-function/go.mod similarity index 100% rename from latest/functions/Knative/logs-handler-function/go.mod rename to functions/Knative/logs-handler-function/go.mod diff --git a/v0.4.0/functions/Knative/logs-handler-function/logs-handler-function.yaml b/functions/Knative/logs-handler-function/logs-handler-function.yaml similarity index 77% rename from v0.4.0/functions/Knative/logs-handler-function/logs-handler-function.yaml rename to functions/Knative/logs-handler-function/logs-handler-function.yaml index 207d4f8..d70ded6 100644 --- a/v0.4.0/functions/Knative/logs-handler-function/logs-handler-function.yaml +++ b/functions/Knative/logs-handler-function/logs-handler-function.yaml @@ -4,7 +4,7 @@ metadata: name: logs-sync-handler spec: version: "v1.0.0" - image: openfunctiondev/logs-sync-handler:v0.4.0 + image: openfunctiondev/logs-sync-handler:v0.4 imageCredentials: name: push-secret build: @@ -12,8 +12,9 @@ spec: env: FUNC_NAME: "LogsHandler" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/Knative/logs-handler-function/" + sourceSubPath: "functions/Knative/logs-handler-function/" serving: runtime: "Knative" # template: diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/README.md b/functions/OpenFuncAsync/bindings/README.md similarity index 90% rename from v0.4.0/functions/OpenFuncAsync/bindings/README.md rename to functions/OpenFuncAsync/bindings/README.md index 29bd8ac..1615fd5 100644 --- a/v0.4.0/functions/OpenFuncAsync/bindings/README.md +++ b/functions/OpenFuncAsync/bindings/README.md @@ -2,11 +2,11 @@ ## Prerequisites -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. +Follow [this guide](../../../Prerequisites.md#openfunction) to install OpenFunction. -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-bindings-server` and a Topic named `sample`. +Follow [this guide](../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-bindings-server` and a Topic named `sample`. -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. +Follow [this guide](../../../Prerequisites.md#registry-credential) to create a registry credential. ## Deployment diff --git a/latest/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go b/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go similarity index 100% rename from latest/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go rename to functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml b/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml similarity index 89% rename from v0.4.0/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml rename to functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml index 5547d08..a513055 100644 --- a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml +++ b/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml @@ -4,7 +4,7 @@ metadata: name: bindings-with-output spec: version: "v1.0.0" - image: openfunctiondev/bindings-with-output:v0.4.0 + image: openfunctiondev/bindings-with-output:v0.4 imageCredentials: name: push-secret build: @@ -12,8 +12,9 @@ spec: env: FUNC_NAME: "BindingsOutput" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/OpenFuncAsync/bindings/with-output/" + sourceSubPath: "functions/OpenFuncAsync/bindings/with-output/" serving: runtime: "OpenFuncAsync" openFuncAsync: diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/go.mod b/functions/OpenFuncAsync/bindings/with-output/go.mod similarity index 100% rename from v0.4.0/functions/OpenFuncAsync/bindings/with-output/go.mod rename to functions/OpenFuncAsync/bindings/with-output/go.mod diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/output/go.mod b/functions/OpenFuncAsync/bindings/with-output/output/go.mod similarity index 100% rename from v0.4.0/functions/OpenFuncAsync/bindings/with-output/output/go.mod rename to functions/OpenFuncAsync/bindings/with-output/output/go.mod diff --git a/latest/functions/OpenFuncAsync/bindings/with-output/output/goapp.go b/functions/OpenFuncAsync/bindings/with-output/output/goapp.go similarity index 100% rename from latest/functions/OpenFuncAsync/bindings/with-output/output/goapp.go rename to functions/OpenFuncAsync/bindings/with-output/output/goapp.go diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml b/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml similarity index 100% rename from v0.4.0/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml rename to functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml diff --git a/latest/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go b/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go similarity index 100% rename from latest/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go rename to functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml b/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml similarity index 82% rename from v0.4.0/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml rename to functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml index 9230cd7..0b3e1a0 100644 --- a/v0.4.0/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml +++ b/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml @@ -4,7 +4,7 @@ metadata: name: bindings-without-output spec: version: "v1.0.0" - image: openfunctiondev/bindings-without-output:v0.4.0 + image: openfunctiondev/bindings-without-output:v0.4 imageCredentials: name: push-secret build: @@ -12,8 +12,9 @@ spec: env: FUNC_NAME: "BindingsNoOutput" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/OpenFuncAsync/bindings/without-output/" + sourceSubPath: "functions/OpenFuncAsync/bindings/without-output/" serving: runtime: "OpenFuncAsync" openFuncAsync: diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/without-output/go.mod b/functions/OpenFuncAsync/bindings/without-output/go.mod similarity index 100% rename from v0.4.0/functions/OpenFuncAsync/bindings/without-output/go.mod rename to functions/OpenFuncAsync/bindings/without-output/go.mod diff --git a/latest/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go b/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go similarity index 100% rename from latest/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go rename to functions/OpenFuncAsync/logs-handler-function/LogsHandler.go diff --git a/v0.5.0/functions/OpenFuncAsync/logs-handler-function/README.md b/functions/OpenFuncAsync/logs-handler-function/README.md similarity index 66% rename from v0.5.0/functions/OpenFuncAsync/logs-handler-function/README.md rename to functions/OpenFuncAsync/logs-handler-function/README.md index a172fef..40a65a8 100644 --- a/v0.5.0/functions/OpenFuncAsync/logs-handler-function/README.md +++ b/functions/OpenFuncAsync/logs-handler-function/README.md @@ -10,11 +10,11 @@ or ## Prerequisites -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. +Follow [this guide](../../../Prerequisites.md#openfunction) to install OpenFunction. -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. +Follow [this guide](../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. +Follow [this guide](../../../Prerequisites.md#registry-credential) to create a registry credential. ## Deployment diff --git a/v0.4.0/functions/OpenFuncAsync/logs-handler-function/go.mod b/functions/OpenFuncAsync/logs-handler-function/go.mod similarity index 100% rename from v0.4.0/functions/OpenFuncAsync/logs-handler-function/go.mod rename to functions/OpenFuncAsync/logs-handler-function/go.mod diff --git a/v0.4.0/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml b/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml similarity index 90% rename from v0.4.0/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml rename to functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml index a746ff0..3141307 100644 --- a/v0.4.0/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml +++ b/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml @@ -4,7 +4,7 @@ metadata: name: logs-async-handler spec: version: "v1.0.0" - image: openfunctiondev/logs-async-handler:v0.4.0 + image: openfunctiondev/logs-async-handler:v0.4 imageCredentials: name: push-secret build: @@ -12,10 +12,11 @@ spec: env: FUNC_NAME: "LogsHandler" # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" + # FUNC_GOPROXY: "https://goproxy.cn" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/OpenFuncAsync/logs-handler-function/" + sourceSubPath: "functions/OpenFuncAsync/logs-handler-function/" serving: runtime: "OpenFuncAsync" openFuncAsync: diff --git a/v0.4.0/functions/OpenFuncAsync/pubsub/README.md b/functions/OpenFuncAsync/pubsub/README.md similarity index 78% rename from v0.4.0/functions/OpenFuncAsync/pubsub/README.md rename to functions/OpenFuncAsync/pubsub/README.md index 4066d0f..9b05aac 100644 --- a/v0.4.0/functions/OpenFuncAsync/pubsub/README.md +++ b/functions/OpenFuncAsync/pubsub/README.md @@ -2,11 +2,11 @@ ## Prerequisites -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. +Follow [this guide](../../../Prerequisites.md#openfunction) to install OpenFunction. -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-pubsub-server` and a Topic named `metric`. +Follow [this guide](../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-pubsub-server` and a Topic named `metric`. -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential.Kafka +Follow [this guide](../../../Prerequisites.md#registry-credential) to create a registry credential.Kafka ## Deployment diff --git a/v0.4.0/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml b/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml similarity index 87% rename from v0.4.0/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml rename to functions/OpenFuncAsync/pubsub/producer/function-producer.yaml index 87cbbc2..a1bce0d 100644 --- a/v0.4.0/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml +++ b/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml @@ -4,7 +4,7 @@ metadata: name: autoscaling-producer spec: version: "v1.0.0" - image: openfunctiondev/autoscaling-producer:v0.4.0 + image: openfunctiondev/autoscaling-producer:v0.4 imageCredentials: name: push-secret build: @@ -12,10 +12,11 @@ spec: env: FUNC_NAME: "Producer" # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" + # FUNC_GOPROXY: "https://goproxy.cn" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/OpenFuncAsync/pubsub/producer/" + sourceSubPath: "functions/OpenFuncAsync/pubsub/producer/" serving: runtime: "OpenFuncAsync" params: diff --git a/v0.4.0/functions/OpenFuncAsync/pubsub/producer/go.mod b/functions/OpenFuncAsync/pubsub/producer/go.mod similarity index 100% rename from v0.4.0/functions/OpenFuncAsync/pubsub/producer/go.mod rename to functions/OpenFuncAsync/pubsub/producer/go.mod diff --git a/latest/functions/OpenFuncAsync/pubsub/producer/producer.go b/functions/OpenFuncAsync/pubsub/producer/producer.go similarity index 100% rename from latest/functions/OpenFuncAsync/pubsub/producer/producer.go rename to functions/OpenFuncAsync/pubsub/producer/producer.go diff --git a/v0.4.0/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml b/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml similarity index 88% rename from v0.4.0/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml rename to functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml index d982890..e71d176 100644 --- a/v0.4.0/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml +++ b/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml @@ -4,7 +4,7 @@ metadata: name: autoscaling-subscriber spec: version: "v1.0.0" - image: openfunctiondev/autoscaling-subscriber:v0.4.0 + image: openfunctiondev/autoscaling-subscriber:v0.4 imageCredentials: name: push-secret build: @@ -12,10 +12,11 @@ spec: env: FUNC_NAME: "Subscriber" # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" + # FUNC_GOPROXY: "https://goproxy.cn" srcRepo: + revision: "release-0.4" url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.4.0/functions/OpenFuncAsync/pubsub/subscriber" + sourceSubPath: "functions/OpenFuncAsync/pubsub/subscriber" serving: runtime: "OpenFuncAsync" openFuncAsync: diff --git a/v0.4.0/functions/OpenFuncAsync/pubsub/subscriber/go.mod b/functions/OpenFuncAsync/pubsub/subscriber/go.mod similarity index 100% rename from v0.4.0/functions/OpenFuncAsync/pubsub/subscriber/go.mod rename to functions/OpenFuncAsync/pubsub/subscriber/go.mod diff --git a/latest/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go b/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go similarity index 100% rename from latest/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go rename to functions/OpenFuncAsync/pubsub/subscriber/subscriber.go diff --git a/latest/apps/buildah/function-buildah.yaml b/latest/apps/buildah/function-buildah.yaml deleted file mode 100644 index 8b63091..0000000 --- a/latest/apps/buildah/function-buildah.yaml +++ /dev/null @@ -1,26 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: function-buildah -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-buildah-go:latest" - imageCredentials: - name: push-secret - #port: 8080 # default to 8080 - build: - builder: openfunction/buildah:v1.23.1 - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/apps/with-dockerfile" - shipwright: - strategy: - name: buildah - kind: ClusterBuildStrategy - serving: - runtime: Knative - template: - containers: - - name: function - imagePullPolicy: Always - diff --git a/latest/apps/kaniko/function-kaniko.yaml b/latest/apps/kaniko/function-kaniko.yaml deleted file mode 100644 index 04d58b4..0000000 --- a/latest/apps/kaniko/function-kaniko.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: function-kaniko -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-kankio-go:latest" - imageCredentials: - name: push-secret - #port: 8080 # default to 8080 - build: - builder: openfunction/kaniko-executor:v1.7.0 - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/apps/with-dockerfile" - shipwright: - strategy: - name: kaniko - kind: ClusterBuildStrategy - serving: - runtime: Knative - template: - containers: - - name: function - imagePullPolicy: Always diff --git a/latest/apps/ko/function-ko.yaml b/latest/apps/ko/function-ko.yaml deleted file mode 100644 index 7d63864..0000000 --- a/latest/apps/ko/function-ko.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: function-ko -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-ko:latest" - imageCredentials: - name: push-secret - #port: 8080 # default to 8080 - build: - builder: golang:1.17 - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/apps/with-dockerfile" - shipwright: - strategy: - name: ko - kind: ClusterBuildStrategy - serving: - runtime: Knative - template: - containers: - - name: function - imagePullPolicy: Always diff --git a/latest/apps/sample-apps-java-maven.yaml b/latest/apps/sample-apps-java-maven.yaml deleted file mode 100644 index b7ee44d..0000000 --- a/latest/apps/sample-apps-java-maven.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: sample-app-java-maven -spec: - version: "v1.0.0" - image: "openfunction/buildpacks-sample-apps-java-maven:latest" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "cnbs/sample-builder:alpine" - srcRepo: - url: "https://github.com/buildpacks/samples.git" - sourceSubPath: "apps/java-maven" - serving: - runtime: "Knative" # default to Knative - template: - containers: - - name: function - imagePullPolicy: Always diff --git a/latest/apps/with-dockerfile/Dockerfile b/latest/apps/with-dockerfile/Dockerfile deleted file mode 100644 index 96857b6..0000000 --- a/latest/apps/with-dockerfile/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# From https://github.com/homeport/gonut/tree/master/assets/sample-apps/golang - -FROM golang:1.16 AS build - -COPY main.go . -ENV CGO_ENABLED=0 -RUN go build \ - -tags netgo \ - -ldflags "-s -w -extldflags '-static'" \ - -o /tmp/helloworld \ - main.go - -FROM scratch -COPY --from=build /tmp/helloworld ./helloworld -ENTRYPOINT [ "./helloworld" ] -EXPOSE 8080 diff --git a/latest/apps/with-dockerfile/go.mod b/latest/apps/with-dockerfile/go.mod deleted file mode 100644 index c0ecf8b..0000000 --- a/latest/apps/with-dockerfile/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module main - -go 1.17 diff --git a/latest/apps/with-dockerfile/main.go b/latest/apps/with-dockerfile/main.go deleted file mode 100644 index b5e659f..0000000 --- a/latest/apps/with-dockerfile/main.go +++ /dev/null @@ -1,26 +0,0 @@ -// From https://github.com/homeport/gonut/tree/master/assets/sample-apps/golang - -package main - -import ( - "fmt" - "net/http" - "os" - "runtime" - "strconv" -) - -func main() { - port := 8080 - if strValue, ok := os.LookupEnv("PORT"); ok { - if intValue, err := strconv.Atoi(strValue); err == nil { - port = intValue - } - } - - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello, World! I am using %s by the way.", runtime.Version()) - }) - - http.ListenAndServe(fmt.Sprintf(":%d", port), nil) -} diff --git a/latest/functions-framework/golang/Knative/simple-hello/go.mod b/latest/functions-framework/golang/Knative/simple-hello/go.mod deleted file mode 100644 index 351793f..0000000 --- a/latest/functions-framework/golang/Knative/simple-hello/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/latest/functions-framework/golang/OpenFuncAsync/bindings/README.md b/latest/functions-framework/golang/OpenFuncAsync/bindings/README.md deleted file mode 100644 index d42b729..0000000 --- a/latest/functions-framework/golang/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,175 +0,0 @@ -# Bindings - -- [Bindings without output](#bindings-without-output) -- [Bindings with output](#bindings-with-output) -- [Results](#results) - + [Without Output](#without-output) - + [With Output](#with-output) - -## Bindings without output - -This input source will be executed every 2s (Refer to [cron.yaml](../config/cron.yaml)). - -Prepare a context as follows, name it `function.json`. (You can refer to [OpenFunction Context Specs](https://github.com/OpenFunction/functions-framework/blob/main/docs/OpenFunction-context-specs.md) to learn more about the OpenFunction Context) - -```json -{ - "name": "bindings", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "50001", - "clientPort": "44544", - "inputs": { - "cron": { - "uri": "cron_input", - "type": "bindings", - "component": "cron_input" - } - }, - "outputs": {}, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"bindings","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"50001","clientPort":"44544","inputs":{"cron":{"uri":"cron_input","type":"bindings","component":"cron_input"}},"outputs":{},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd without-output/ -go mod tidy -dapr run --app-id bindings_grpc \ - --app-protocol grpc \ - --app-port 50001 \ - --dapr-grpc-port 44544 \ - --components-path ../../components \ - go run ./main.go -``` - -## Bindings with output - -We need to prepare an output target first. - -```shell -cd with-output/ -go mod tidy -dapr run --app-id output \ - --app-protocol http \ - --app-port 7489 \ - --dapr-http-port 7490 \ - go run ./output/main.go -``` - -This will generate two available targets, one for access through Dapr's proxy address and another for direct access through the app serving address. - -> Simple test with execution `curl -X POST -H "ContentType: application/json" -d '{"Hello": "World"}' ` -> -> `urlPath` refer to follows. - -``` -via Dapr: http://localhost:7490/v1.0/invoke/output_demo/method/echo -via App: http://localhost:7489/echo -``` - -In this example, the proxy address of Dapr will be used as the target of output. - ->Here we have defined only one output, which will be called `item` in the following -> ->`app-id` is "echo" derived from the key of `item` -> ->Dapr component params are in `item.params`. Refer to [Dapr components reference](https://docs.dapr.io/reference/components-reference/). - -```json -{ - "name": "bindings", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "50001", - "clientPort": "44544", - "inputs": { - "cron": { - "uri": "cron_input", - "type": "bindings", - "component": "cron_input" - } - }, - "outputs": { - "echo": { - "uri": "echo", - "operation": "create", - "component": "echo", - "metadata": { - "path": "echo", - "Content-Type": "application/json; charset=utf-8" - }, - "type": "bindings" - } - }, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"bindings","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"50001","clientPort":"44544","inputs":{"cron":{"uri":"cron_input","type":"bindings","component":"cron_input"}},"outputs":{"echo":{"uri":"echo","operation":"create","component":"echo","metadata":{"path":"echo","Content-Type":"application/json; charset=utf-8"},"type":"bindings"}},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd with-output/ -dapr run --app-id bindings_grpc \ - --app-protocol grpc \ - --app-port 50001 \ - --dapr-grpc-port 44544 \ - --components-path ../../components \ - go run ./main.go -``` - - -## Results - -### Without Output - -The logs of user function is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:43:58 binding - Data: Received -== APP == 2021/06/28 10:44:00 binding - Data: Received -``` - -
- -### With Output - -The logs of user function is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:39:43 binding - Data: Received -== APP == 2021/06/28 10:39:45 binding - Data: Received -``` - -
- -And the logs of output target app is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:39:45 Receive a message: -== APP == 2021/06/28 10:39:45 Hello -``` - -
diff --git a/latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod b/latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod deleted file mode 100644 index 351793f..0000000 --- a/latest/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/latest/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod b/latest/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod deleted file mode 100644 index 351793f..0000000 --- a/latest/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/latest/functions-framework/golang/OpenFuncAsync/pubsub/README.md b/latest/functions-framework/golang/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index 10115e9..0000000 --- a/latest/functions-framework/golang/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# Pubsub - -- [Subscriber](#subscriber) -- [Producer](#producer) -- [Results](#results) - -## Subscriber - -Prepare a context as follows, name it `function.json`. (You can refer to [OpenFunction Context Specs](https://github.com/OpenFunction/functions-framework/blob/main/docs/OpenFunction-context-specs.md) to learn more about the OpenFunction Context) - -```json -{ - "name": "subscriber", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "60011", - "clientPort": "44544", - "inputs": { - "sub": { - "uri": "my_topic", - "type": "pubsub", - "component": "msg" - } - }, - "outputs": {}, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"subscriber","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"60011","clientPort":"44544","inputs":{"sub":{"uri":"my_topic","type":"pubsub","component":"msg"}},"outputs":{},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd subscriber/ -go mod tidy -dapr run --app-id subscriber \ - --app-protocol grpc \ - --app-port 60011 \ - --dapr-grpc-port 44544 \ - --components-path ../../components \ - go run ./main.go -``` - -## Producer - -You also need a definition of producer. - -```json -{ - "name": "producer", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "60012", - "clientPort": "44545", - "inputs": {}, - "outputs": { - "pub": { - "uri": "my_topic", - "component": "msg", - "type": "pubsub" - } - }, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"producer","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"60012","clientPort":"44545","inputs":{},"outputs":{"pub":{"uri":"my_topic","component":"msg","type":"pubsub"}},"runtime":"OpenFuncAsync"}' -``` - -Start the service with another terminal to publish message. - -```shell -cd producer/ -go mod tidy -dapr run --app-id producer \ - --app-protocol grpc \ - --app-port 60012 \ - --dapr-grpc-port 44545 \ - --components-path ../../components \ - go run ./main.go -``` - -## Results - -
-View detailed producer logs. - -```shell -== APP == 0 published, 0/sec, 0 errors -== APP == 0 published, 0/sec, 0 errors -== APP == 0 published, 0/sec, 0 errors -== APP == 1 published, 0/sec, 0 errors -== APP == 4 published, 0/sec, 0 errors -== APP == 7 published, 0/sec, 0 errors -== APP == 10 published, 0/sec, 0 errors -== APP == 13 published, 1/sec, 0 errors -``` -
- -
-View detailed subscriber logs. - -```shell -== APP == 2021/06/28 10:04:18 event - Data: "{\"id\":\"p1-533d83d3-dd7c-4f1f-a822-f87b88f74d3e\",\"data\":\"QWdPTktLUjgxd1A1M096dVRDOHNWellyQjFoQ3FtM0FjeTY1Q2Q5S2NCVTRyMjhJbHlQcUVzdmxqWUJnZVB0YUlJRFRHWEFzWG5zZlQ3aGVRMUtrT21SalBHNzl4Rmx2bmNVSmNaOE11c3dmZ3plMk5ZRDF6Q0k5MmFFSVpuWUhmQ2J6aTlNSTQxajd1VURRNVJkMVNZYmhsUUs4UWRXN054Y3BDOXNHaDZTVEpZTzB5UFVJU2ZEQnZaZzJRYU5HaENDeFN6UzJPTVNYOU82QURxSnNndHB1dkIzcDVtRm1tT0haODJoMUM0UTl6blBjb3R0Qm8zbWRnQkhEbjE1Wg==\",\"sha\":\"f\\ufffd\\ufffd\\ufffdr\\ufffdE\\ufffdtu\\ufffd\\ufffd=n\\ufffd7\\u001d\\ufffd\\ufffdrB0^\\ufffd\\n1\\ufffd\\u0008\\ufffdWI\",\"time\":\"2021-06-28 10:04:13.867293349 +0800 CST m=+19.006097088\"}" -``` -
- diff --git a/latest/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod b/latest/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod deleted file mode 100644 index 450f392..0000000 --- a/latest/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 - github.com/google/uuid v1.1.2 -) \ No newline at end of file diff --git a/latest/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod b/latest/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod deleted file mode 100644 index 351793f..0000000 --- a/latest/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/latest/functions/Knative/hello-world-dotnet/README.md b/latest/functions/Knative/hello-world-dotnet/README.md deleted file mode 100644 index e39a49e..0000000 --- a/latest/functions/Knative/hello-world-dotnet/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Sample Function Dotnet - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```dotnet``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: dotnet-sample -spec: - version: "v1.0.0" - image: "/sample-dotnet-func:latest" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "helloworld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latestfunctions/Knative/hello-world-dotnet" - serving: - runtime: "Knative" # default to Knative - template: - containers: - - name: function - imagePullPolicy: Always -``` diff --git a/latest/functions/Knative/hello-world-go/function-sample.yaml b/latest/functions/Knative/hello-world-go/function-sample.yaml deleted file mode 100644 index 0669ffa..0000000 --- a/latest/functions/Knative/hello-world-go/function-sample.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: function-sample -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-go-func:latest" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: openfunction/builder:v1 - env: - FUNC_NAME: "HelloWorld" - FUNC_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/Knative/hello-world-go" - serving: - runtime: "Knative" # default to Knative - template: - containers: - - name: function - imagePullPolicy: Always - diff --git a/latest/functions/Knative/hello-world-java/README.md b/latest/functions/Knative/hello-world-java/README.md deleted file mode 100644 index e17563f..0000000 --- a/latest/functions/Knative/hello-world-java/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Sample Function Java - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```java``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: java-sample -spec: - version: "v1.0.0" - image: "/sample-java-func:latest" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "com.openfunction.HelloWorld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/Knative/hello-world-java" - serving: - runtime: Knative # default to Knative - template: - containers: - - name: function - imagePullPolicy: Always -``` diff --git a/latest/functions/Knative/hello-world-node/README.md b/latest/functions/Knative/hello-world-node/README.md deleted file mode 100644 index fb1893b..0000000 --- a/latest/functions/Knative/hello-world-node/README.md +++ /dev/null @@ -1,35 +0,0 @@ -# Sample Function Node - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```node``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: node-sample -spec: - version: "v1.0.0" - image: "/sample-node-func:latest" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "helloWorld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/Knative/hello-world-node" - serving: - runtime: "Knative" # default to Knative - template: - containers: - - name: function - imagePullPolicy: Always -``` \ No newline at end of file diff --git a/latest/functions/Knative/hello-world-python/README.md b/latest/functions/Knative/hello-world-python/README.md deleted file mode 100644 index 21bd02c..0000000 --- a/latest/functions/Knative/hello-world-python/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# Sample Function Python - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```python``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: python-sample -spec: - version: "v1.0.0" - image: "/sample-python-func:latest" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "hello_world" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - GOOGLE_FUNCTION_SOURCE: "main.py" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/Knative/hello-world-python" - serving: - runtime: Knative # default to Knative - template: - containers: - - name: function - imagePullPolicy: Always -``` - diff --git a/latest/functions/Knative/logs-handler-function/README.md b/latest/functions/Knative/logs-handler-function/README.md deleted file mode 100644 index 93ed6e0..0000000 --- a/latest/functions/Knative/logs-handler-function/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Function Logs Handler - -For a detailed description of this function example, you can refer to the following blogs: - -[OpenFunction 应用系列之一: 以 Serverless 的方式实现 Kubernetes 日志告警](https://kubesphere.io/zh/blogs/serverless-way-for-kubernetes-log-alert/) - -or - -[Serverless Use Case: Elastic Kubernetes Log Alerts with OpenFunction and Kafka](https://kubesphere.io/blogs/serverless-way-for-kubernetes-log-alert/) - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -Create logs handler function: - -```shell -kubectl apply -f logs-handler-function.yaml -``` - -The logs handler function is then driven by messages from the logs topic in Kafka. - diff --git a/latest/functions/Knative/logs-handler-function/logs-handler-function.yaml b/latest/functions/Knative/logs-handler-function/logs-handler-function.yaml deleted file mode 100644 index 98b1afe..0000000 --- a/latest/functions/Knative/logs-handler-function/logs-handler-function.yaml +++ /dev/null @@ -1,22 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: logs-sync-handler -spec: - version: "v1.0.0" - image: openfunctiondev/logs-sync-handler:latest - imageCredentials: - name: push-secret - build: - builder: openfunction/builder-go:v0.4.0-1.15 - env: - FUNC_NAME: "LogsHandler" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/Knative/logs-handler-function/" - serving: - runtime: "Knative" - template: - containers: - - name: function - imagePullPolicy: Always diff --git a/latest/functions/OpenFuncAsync/bindings/README.md b/latest/functions/OpenFuncAsync/bindings/README.md deleted file mode 100644 index 29bd8ac..0000000 --- a/latest/functions/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,116 +0,0 @@ -# Function Input/Output - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-bindings-server` and a Topic named `sample`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -### Input only sample - -We will use the sample in the `without-output` directory, which will be triggered by Dapr's `bindings.cron` component at a frequency of once every 2 seconds. - -Modify the `spec.image` field in `without-output/function-bindings.yaml` to your own container registry address: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-without-output -spec: - image: "/bindings-without-output:latest" -``` - -Use the following commands to create this Function: - -```shell -kubectl apply -f without-output/function-bindings.yaml -``` - -Afterwards, use the following command to observe the log of the function: - -```shell -kubectl logs -f \ - $(kubectl get po -l \ - openfunction.io/serving=$(kubectl get functions bindings-without-output -o jsonpath='{.status.serving.resourceRef}') \ - -o jsonpath='{.items[0].metadata.name}') \ - function -``` - -You will be able to see messages similar to the following: - -```shell -2021/07/02 09:02:02 binding - Data: Received -2021/07/02 09:02:04 binding - Data: Received -2021/07/02 09:02:06 binding - Data: Received -2021/07/02 09:02:08 binding - Data: Received -``` - -### Input and Output - -We will use the sample in the `with-output` directory, which will be triggered by Dapr's `bindings.cron` component at a frequency of once every 2 seconds. After being triggered, it will send a greeting to another service via Dapr's `bindings.kafka` component. - -Modify the `spec.image` field in `without-output/function-bindings.yaml` to your own container registry address: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-with-output -spec: - image: "/bindings-with-output:latest" -``` - -Use the following commands to create this Function: - -```shell -kubectl apply -f with-output/function-bindings.yaml -``` - -Afterwards, use the following command to observe the log of the function: - -```shell -kubectl logs -f \ - $(kubectl get po -l \ - openfunction.io/serving=$(kubectl get functions bindings-with-output -o jsonpath='{.status.serving.resourceRef}') \ - -o jsonpath='{.items[0].metadata.name}') \ - function -``` - -You will be able to see messages similar to the following: - -```shell -2021/07/02 09:02:02 binding - Data: Received -2021/07/02 09:02:04 binding - Data: Received -2021/07/02 09:02:06 binding - Data: Received -2021/07/02 09:02:08 binding - Data: Received -``` - -Now we need to start the output target function. - -```shell -kubectl apply -f with-output/output/output-target.yaml -``` - -Use the following command to observe the log of the function: - -```shell -kubectl logs -f \ - $(kubectl get po -l \ - openfunction.io/serving=$(kubectl get functions bindings-output-target -o jsonpath='{.status.serving.resourceRef}') \ - -o jsonpath='{.items[0].metadata.name}') \ - function -``` - -You will be able to see messages similar to the following: - -```shell -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -``` diff --git a/latest/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml b/latest/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml deleted file mode 100644 index 186a30b..0000000 --- a/latest/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml +++ /dev/null @@ -1,56 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-with-output -spec: - version: "v1.0.0" - image: openfunctiondev/bindings-with-output:latest - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.4.0-1.15" - env: - FUNC_NAME: "BindingsOutput" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/OpenFuncAsync/bindings/with-output/" - serving: - template: - containers: - - name: function - imagePullPolicy: Always - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: cron - component: cron - type: bindings - outputs: - - name: sample - component: sample-topic - type: bindings - operation: "create" - annotations: - "dapr.io/log-level": "debug" - components: - cron: - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" - sample-topic: - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-bindings-server-kafka-brokers:9092" - - name: topics - value: sample - - name: consumerGroup - value: group1 - - name: publishTopic - value: sample - - name: authRequired - value: "false" diff --git a/latest/functions/OpenFuncAsync/bindings/with-output/go.mod b/latest/functions/OpenFuncAsync/bindings/with-output/go.mod deleted file mode 100644 index f82353a..0000000 --- a/latest/functions/OpenFuncAsync/bindings/with-output/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/bindings - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.1.0 diff --git a/latest/functions/OpenFuncAsync/bindings/with-output/output/go.mod b/latest/functions/OpenFuncAsync/bindings/with-output/output/go.mod deleted file mode 100644 index 5ace5b1..0000000 --- a/latest/functions/OpenFuncAsync/bindings/with-output/output/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/main - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.1.0 diff --git a/latest/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml b/latest/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml deleted file mode 100644 index 4ec957a..0000000 --- a/latest/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml +++ /dev/null @@ -1,36 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-output-target -spec: - version: "v1.0.0" - image: openfunctiondev/bindings-output-target:latest - serving: - runtime: "OpenFuncAsync" - template: - containers: - - name: function - imagePullPolicy: Always - openFuncAsync: - dapr: - inputs: - - name: sample - component: sample-topic - type: bindings - annotations: - "dapr.io/log-level": "debug" - components: - sample-topic: - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-bindings-server-kafka-brokers:9092" - - name: topics - value: sample - - name: consumerGroup - value: group2 - - name: publishTopic - value: sample - - name: authRequired - value: "false" diff --git a/latest/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml b/latest/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml deleted file mode 100644 index a2308fb..0000000 --- a/latest/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml +++ /dev/null @@ -1,37 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-without-output -spec: - version: "v1.0.0" - image: openfunctiondev/bindings-without-output:latest - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.4.0-1.15" - env: - FUNC_NAME: "BindingsNoOutput" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/OpenFuncAsync/bindings/without-output/" - serving: - template: - containers: - - name: function - imagePullPolicy: Always - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: cron - component: cron - type: bindings - annotations: - "dapr.io/log-level": "debug" - components: - cron: - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" diff --git a/latest/functions/OpenFuncAsync/bindings/without-output/go.mod b/latest/functions/OpenFuncAsync/bindings/without-output/go.mod deleted file mode 100644 index f82353a..0000000 --- a/latest/functions/OpenFuncAsync/bindings/without-output/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/bindings - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.1.0 diff --git a/latest/functions/OpenFuncAsync/logs-handler-function/README.md b/latest/functions/OpenFuncAsync/logs-handler-function/README.md deleted file mode 100644 index a172fef..0000000 --- a/latest/functions/OpenFuncAsync/logs-handler-function/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Function Logs Handler - -For a detailed description of this function example, you can refer to the following blogs: - -[OpenFunction 应用系列之一: 以 Serverless 的方式实现 Kubernetes 日志告警](https://kubesphere.io/zh/blogs/serverless-way-for-kubernetes-log-alert/) - -or - -[Serverless Use Case: Elastic Kubernetes Log Alerts with OpenFunction and Kafka](https://kubesphere.io/blogs/serverless-way-for-kubernetes-log-alert/) - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -Create logs handler function: - -```shell -kubectl apply -f logs-handler-function.yaml -``` - -The logs handler function is then driven by messages from the logs topic in Kafka. \ No newline at end of file diff --git a/latest/functions/OpenFuncAsync/logs-handler-function/go.mod b/latest/functions/OpenFuncAsync/logs-handler-function/go.mod deleted file mode 100644 index 328b617..0000000 --- a/latest/functions/OpenFuncAsync/logs-handler-function/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module example.com/logshandler - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/prometheus/alertmanager v0.22.2 -) diff --git a/latest/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml b/latest/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml deleted file mode 100644 index 896a9e5..0000000 --- a/latest/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml +++ /dev/null @@ -1,71 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: logs-async-handler -spec: - version: "v1.0.0" - image: openfunctiondev/logs-async-handler:latest - imageCredentials: - name: push-secret - build: - builder: openfunction/builder-go:v0.4.0-1.15 - env: - FUNC_NAME: "LogsHandler" - # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/OpenFuncAsync/logs-handler-function/" - serving: - runtime: "OpenFuncAsync" - template: - containers: - - name: function - imagePullPolicy: Always - openFuncAsync: - dapr: - inputs: - - name: kafka - component: kafka-receiver - type: bindings - outputs: - - name: notify - type: bindings - component: notification-manager - operation: "post" - annotations: - dapr.io/log-level: "debug" - components: - kafka-receiver: - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-logs-receiver-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: publishTopic - value: "logs" - - name: topics - value: "logs" - - name: consumerGroup - value: "logs-handler" - notification-manager: - type: bindings.http - version: v1 - metadata: - - name: url - value: http://notification-manager-svc.kubesphere-monitoring-system.svc.cluster.local:19093/api/v2/alerts - keda: - scaledObject: - pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 - cooldownPeriod: 30 - triggers: - - type: kafka - metadata: - topic: logs - bootstrapServers: kafka-logs-receiver-kafka-brokers.default.svc.cluster.local:9092 - consumerGroup: logs-handler - lagThreshold: "10" diff --git a/latest/functions/OpenFuncAsync/pubsub/README.md b/latest/functions/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index 4066d0f..0000000 --- a/latest/functions/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Autoscaling service based on queue depth - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-pubsub-server` and a Topic named `metric`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential.Kafka - -## Deployment - -To configure the autoscaling demo we will deploy two functions: `subscriber` which will be used to process messages of the `metric` queue in Kafka, and the `producer`, which will be publishing messages. - -Modify the ``spec.image`` field in ``producer/function-producer.yaml`` and ``subscriber/function-subscribe.yaml`` to your own container registry address: - - ```yaml - apiVersion: core.openfunction.io/v1alpha2 - kind: Function - metadata: - name: autoscaling-producer - spec: - image: "/autoscaling-producer:latest" - ``` - - ```yaml - apiVersion: core.openfunction.io/v1alpha2 - kind: Function - metadata: - name: autoscaling-subscriber - spec: - image: "/autoscaling-subscriber:latest" - ``` - -Use the following commands to create these Functions: - -```shell -kubectl apply -f producer/function-producer.yaml -kubectl apply -f subscriber/function-subscriber.yaml -``` - -Back in the initial terminal now, some 20-30 seconds after the `producer` starts, you should see the number of `subscriber` pods being adjusted by Keda based on the number of the `metric` topic. - diff --git a/latest/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml b/latest/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml deleted file mode 100644 index d1a1c2b..0000000 --- a/latest/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml +++ /dev/null @@ -1,55 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: autoscaling-producer -spec: - version: "v1.0.0" - image: openfunctiondev/autoscaling-producer:latest - imageCredentials: - name: push-secret - build: - builder: openfunction/builder-go:v0.4.0-1.15 - env: - FUNC_NAME: "Producer" - # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/OpenFuncAsync/pubsub/producer/" - serving: - template: - containers: - - name: function - imagePullPolicy: Always - runtime: "OpenFuncAsync" - params: - OUTPUT_NAME: producer - TOPIC_NAME: metric - NUMBER_OF_PUBLISHERS: "2" - PUBLISHERS_FREQ: "100ms" - PUBLISHERS_DELAY: "10s" - LOG_FREQ: "3s" - PUBLISH_TO_CONSOLE: "false" - openFuncAsync: - dapr: - outputs: - - name: producer - component: autoscaling-producer - type: pubsub - topic: metric - annotations: - "dapr.io/log-level": "debug" - components: - autoscaling-producer: - type: pubsub.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-pubsub-server-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: allowedTopics - value: "metric" - - name: consumerID - value: "autoscaling-producer" - diff --git a/latest/functions/OpenFuncAsync/pubsub/producer/go.mod b/latest/functions/OpenFuncAsync/pubsub/producer/go.mod deleted file mode 100644 index d83c736..0000000 --- a/latest/functions/OpenFuncAsync/pubsub/producer/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module example.com/producer - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/google/uuid v1.1.2 -) diff --git a/latest/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml b/latest/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml deleted file mode 100644 index 91d7b88..0000000 --- a/latest/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml +++ /dev/null @@ -1,60 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: autoscaling-subscriber -spec: - version: "v1.0.0" - image: openfunctiondev/autoscaling-subscriber:latest - imageCredentials: - name: push-secret - build: - builder: openfunction/builder-go:v0.4.0-1.15 - env: - FUNC_NAME: "Subscriber" - # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/functions/OpenFuncAsync/pubsub/subscriber" - serving: - runtime: "OpenFuncAsync" - template: - containers: - - name: function - imagePullPolicy: Always - openFuncAsync: - dapr: - inputs: - - name: subscriber - component: autoscaling-subscriber - type: pubsub - topic: metric - annotations: - dapr.io/log-level: "debug" - components: - autoscaling-subscriber: - type: pubsub.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-pubsub-server-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: allowedTopics - value: "metric" - - name: consumerID - value: "autoscaling-subscriber" - keda: - scaledObject: - pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 - cooldownPeriod: 30 - triggers: - - type: kafka - metadata: - topic: metric - bootstrapServers: kafka-pubsub-server-kafka-brokers.default.svc.cluster.local:9092 - consumerGroup: autoscaling-subscriber - lagThreshold: "10" - diff --git a/latest/functions/OpenFuncAsync/pubsub/subscriber/go.mod b/latest/functions/OpenFuncAsync/pubsub/subscriber/go.mod deleted file mode 100644 index dba3bf7..0000000 --- a/latest/functions/OpenFuncAsync/pubsub/subscriber/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/subscriber - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.1.0 diff --git a/v0.3.1/apps/sample-apps-java-maven.yaml b/v0.3.1/apps/sample-apps-java-maven.yaml deleted file mode 100644 index a9c8f38..0000000 --- a/v0.3.1/apps/sample-apps-java-maven.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: sample-app-java-maven -spec: - version: "v1.0.0" - image: "openfunction/buildpacks-sample-apps-java-maven:v0.3.1" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "cnbs/sample-builder:alpine" - srcRepo: - url: "https://github.com/buildpacks/samples.git" - sourceSubPath: "apps/java-maven" - serving: - runtime: "Knative" # default to Knative diff --git a/v0.3.1/functions-framework/README.md b/v0.3.1/functions-framework/README.md deleted file mode 100644 index e9930b7..0000000 --- a/v0.3.1/functions-framework/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Functions framework demos - -This directory holds the validation demos for the [functions-framework](https://github.com/OpenFunction/functions-framework). - -Current supported list: - -- [functions-framework-go](https://github.com/OpenFunction/functions-framework-go); -- [functions-framework-nodejs](https://github.com/OpenFunction/functions-framework-nodejs). - -Depending on the type of runtime, the demos are divided into `Knative` and `OpenFuncAsync`, please check them separately: - -* Golang - * [Knative runtime demos](golang/Knative) - * [OpenFuncAsync runtime demos](golang/OpenFuncAsync) -* Nodejs - * [Knative runtime demos](nodejs/Knative) - * [OpenFuncAsync runtime demos](nodejs/OpenFuncAsync) - diff --git a/v0.3.1/functions-framework/golang/Knative/README.md b/v0.3.1/functions-framework/golang/Knative/README.md deleted file mode 100644 index 9375746..0000000 --- a/v0.3.1/functions-framework/golang/Knative/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Knative Runtime examples - -In order to follow these examples, you need to install [Knative](https://knative.dev/docs/install/) and [Go 1.15+](https://golang.org/doc/install). - -## OpenFunction Context Function - -- HTTP request - - [example](simple-hello) - diff --git a/v0.3.1/functions-framework/golang/Knative/simple-hello/README.md b/v0.3.1/functions-framework/golang/Knative/simple-hello/README.md deleted file mode 100644 index e67278c..0000000 --- a/v0.3.1/functions-framework/golang/Knative/simple-hello/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# HTTP request - -Start the service. - -```go -go mod tidy -go run main.go -``` - -> The service uses port `8080` by default, if you want to customize the port, you can set it using the environment variable `PORT`. -> -> ```shell -> PORT=8081 go run main.go -> ``` - -You can see the following. - -```shell -2021/06/29 10:10:48 Knative Function serving http: listening on port 8080 -``` - -Now you can access the service via `curl` command.If everything works, you can see the following. - -```shell -~# curl http://localhost:8080 -Hello, World! -``` - diff --git a/v0.3.1/functions-framework/golang/Knative/simple-hello/go.mod b/v0.3.1/functions-framework/golang/Knative/simple-hello/go.mod deleted file mode 100644 index 1014eb3..0000000 --- a/v0.3.1/functions-framework/golang/Knative/simple-hello/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/v0.3.1/functions-framework/golang/Knative/simple-hello/main.go b/v0.3.1/functions-framework/golang/Knative/simple-hello/main.go deleted file mode 100644 index 02775e1..0000000 --- a/v0.3.1/functions-framework/golang/Knative/simple-hello/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) int); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.HelloWorld); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.3.1/functions-framework/golang/Knative/simple-hello/userfunction/hello.go b/v0.3.1/functions-framework/golang/Knative/simple-hello/userfunction/hello.go deleted file mode 100644 index a66ded7..0000000 --- a/v0.3.1/functions-framework/golang/Knative/simple-hello/userfunction/hello.go +++ /dev/null @@ -1,11 +0,0 @@ -package userfunction - -import ( - "fmt" - "net/http" -) - -// HelloWorld writes "Hello, World!" to the HTTP response. -func HelloWorld(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "Hello, World!\n") -} \ No newline at end of file diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/README.md b/v0.3.1/functions-framework/golang/OpenFuncAsync/README.md deleted file mode 100644 index 89709c5..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# OpenFuncAsync Runtime examples - -In order to follow these examples, you need to install [Dapr](https://docs.dapr.io/getting-started/install-dapr-selfhost/) and [Go 1.15+](https://golang.org/doc/install). - -## OpenFunction Context Function - -- Bindings - - [example](bindings) - -- Pubsub - - [example](pubsub) \ No newline at end of file diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/README.md b/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/README.md deleted file mode 100644 index 16ec422..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,169 +0,0 @@ -# Bindings - -- [Bindings without output](#bindings-without-output) -- [Bindings with output](#bindings-with-output) -- [Results](#results) - + [Without Output](#without-output) - + [With Output](#with-output) - -## Bindings without output - -This input source will be executed every 2s (Refer to [cron.yaml](../config/cron.yaml)). - -Prepare a context as follows, name it `function.json`. (You can refer to [OpenFunction Context Specs](https://github.com/OpenFunction/functions-framework/blob/main/docs/OpenFunction-context-specs.md) to learn more about the OpenFunction Context) - -```json -{ - "name": "bindings", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "50001", - "input": { - "name": "cron_input", - "uri": "cron_input", - "params": { - "type": "bindings" - } - }, - "outputs": {}, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"bindings_grpc","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"50001","input":{"name":"cron_input","uri":"cron_input","params":{"type":"bindings"}},"outputs":{},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd without-output/ -go mod tidy -dapr run --app-id bindings_grpc \ - --app-protocol grpc \ - --app-port 50001 \ - --components-path ../../components \ - go run ./main.go -``` - -## Bindings with output - -We need to prepare an output target first. - -```shell -cd with-output/ -go mod tidy -dapr run --app-id output \ - --app-protocol http \ - --app-port 7489 \ - --dapr-http-port 7490 \ - go run ./output/main.go -``` - -This will generate two available targets, one for access through Dapr's proxy address and another for direct access through the app serving address. - -> Simple test with execution `curl -X POST -H "ContentType: application/json" -d '{"Hello": "World"}' ` -> -> `urlPath` refer to follows. - -``` -via Dapr: http://localhost:7490/v1.0/invoke/output_demo/method/echo -via App: http://localhost:7489/echo -``` - -In this example, the proxy address of Dapr will be used as the target of output. - ->Here we have defined only one output, which will be called `item` in the following -> ->`app-id` is "echo" derived from the key of `item` -> ->Dapr component params are in `item.params`. Refer to [Dapr components reference](https://docs.dapr.io/reference/components-reference/). - -```json -{ - "name": "bindings", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "50001", - "input": { - "name": "cron_input", - "uri": "cron_input", - "params": { - "type": "bindings" - } - }, - "outputs": { - "echo": { - "params": { - "uri": "echo", - "operation": "create", - "metadata": "{\"path\": \"/echo\", \"Content-Type\": \"application/json; charset=utf-8\"}", - "type": "bindings" - } - } - }, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"bindings","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"50001","input":{"name":"cron_input","uri":"cron_input","params":{"type":"bindings"}},"outputs":{"echo":{"params":{"uri":"echo","operation":"create","metadata":"{\"path\": \"/echo\", \"Content-Type\": \"application/json; charset=utf-8\"}","type":"bindings"}}},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd with-output/ -dapr run --app-id bindings_grpc \ - --app-protocol grpc \ - --app-port 50001 \ - --components-path ../../components \ - go run ./main.go -``` - - -## Results - -### Without Output - -The logs of user function is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:43:58 binding - Data: Received -== APP == 2021/06/28 10:44:00 binding - Data: Received -``` - -
- -### With Output - -The logs of user function is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:39:43 binding - Data: Received -== APP == 2021/06/28 10:39:45 binding - Data: Received -``` - -
- -And the logs of output target app is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:39:45 Receive a message: -== APP == 2021/06/28 10:39:45 Hello -``` - -
diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod b/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod deleted file mode 100644 index 1014eb3..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go deleted file mode 100644 index 3e31462..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) int); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.BindingsOutput); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go deleted file mode 100644 index d2fc094..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "io" - "log" - "net/http" -) - -func echo(w http.ResponseWriter, req *http.Request) { - content, err := io.ReadAll(req.Body) - if err != nil { - w.WriteHeader(500) - return - } - log.Println("Receive a message:") - log.Println(string(content)) -} - -func main() { - - http.HandleFunc("/echo", echo) - - err := http.ListenAndServe(":7489", nil) - if err != nil { - return - } -} diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go deleted file mode 100644 index ccd76a0..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go +++ /dev/null @@ -1,24 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsOutput(ctx *ofctx.OpenFunctionContext, in []byte) int { - var greeting []byte - if in != nil { - log.Printf("binding - Data: %s", in) - greeting = in - } else { - log.Print("binding - Data: Received") - greeting = []byte("Hello") - } - - err := ctx.SendTo(greeting, "echo") - if err != nil { - log.Printf("Error: %v\n", err) - return 500 - } - return 200 -} diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod b/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod deleted file mode 100644 index 1014eb3..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go deleted file mode 100644 index 7fa2b37..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) int); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.BindingsNoOutput); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go deleted file mode 100644 index 9370f8d..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go +++ /dev/null @@ -1,15 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsNoOutput(ctx *ofctx.OpenFunctionContext, in []byte) int { - if in != nil { - log.Printf("binding - Data: %s", in) - } else { - log.Print("binding - Data: Received") - } - return 200 -} diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/components/bindings.yaml b/v0.3.1/functions-framework/golang/OpenFuncAsync/components/bindings.yaml deleted file mode 100644 index f120b3d..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/components/bindings.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: echo -spec: - type: bindings.http - version: v1 - metadata: - - name: url - value: http://localhost:7489 diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/components/cron.yaml b/v0.3.1/functions-framework/golang/OpenFuncAsync/components/cron.yaml deleted file mode 100644 index bd9b4be..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/components/cron.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: cron_input -spec: - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml b/v0.3.1/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml deleted file mode 100644 index 94f938a..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: msg -spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: localhost:6379 - - name: redisPassword - value: "" diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/components/statestore.yaml b/v0.3.1/functions-framework/golang/OpenFuncAsync/components/statestore.yaml deleted file mode 100644 index 18cba84..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/components/statestore.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: statestore -spec: - type: state.redis - version: v1 - metadata: - - name: redisHost - value: localhost:6379 - - name: redisPassword - value: "" - - name: actorStateStore - value: "true" diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/README.md b/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index 4016688..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# Pubsub - -- [Subscriber](#subscriber) -- [Producer](#producer) -- [Results](#results) - -## Subscriber - -Prepare a context as follows, name it `function.json`. (You can refer to [OpenFunction Context Specs](https://github.com/OpenFunction/functions-framework/blob/main/docs/OpenFunction-context-specs.md) to learn more about the OpenFunction Context) - -```json -{ - "name": "subscriber", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "60011", - "input": { - "name": "msg", - "uri": "my_topic", - "params": { - "type": "pubsub" - } - }, - "outputs": {}, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"subscriber","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"60011","input":{"name":"msg","uri":"my_topic","params":{"type":"pubsub"}},"outputs":{},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd subscriber/ -go mod tidy -dapr run --app-id subscriber \ - --app-protocol grpc \ - --app-port 60011 \ - --components-path ../../components \ - go run ./main.go -``` - -## Producer - -You also need a definition of producer. - -```json -{ - "name": "producer", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "60012", - "input": {}, - "outputs": { - "msg": { - "uri": "my_topic", - "params": { - "type": "pubsub" - } - } - }, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"producer","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"60012","input":{},"outputs":{"msg":{"uri":"my_topic","params":{"type":"pubsub"}}},"runtime":"OpenFuncAsync"}' -``` - -Start the service with another terminal to publish message. - -```shell -cd producer/ -go mod tidy -dapr run --app-id producer \ - --app-protocol grpc \ - --app-port 60012 \ - --components-path ../../components \ - go run ./main.go -``` - -## Results - -
-View detailed producer logs. - -```shell -== APP == 0 published, 0/sec, 0 errors -== APP == 0 published, 0/sec, 0 errors -== APP == 0 published, 0/sec, 0 errors -== APP == 1 published, 0/sec, 0 errors -== APP == 4 published, 0/sec, 0 errors -== APP == 7 published, 0/sec, 0 errors -== APP == 10 published, 0/sec, 0 errors -== APP == 13 published, 1/sec, 0 errors -``` -
- -
-View detailed subscriber logs. - -```shell -== APP == 2021/06/28 10:04:18 event - Data: "{\"id\":\"p1-533d83d3-dd7c-4f1f-a822-f87b88f74d3e\",\"data\":\"QWdPTktLUjgxd1A1M096dVRDOHNWellyQjFoQ3FtM0FjeTY1Q2Q5S2NCVTRyMjhJbHlQcUVzdmxqWUJnZVB0YUlJRFRHWEFzWG5zZlQ3aGVRMUtrT21SalBHNzl4Rmx2bmNVSmNaOE11c3dmZ3plMk5ZRDF6Q0k5MmFFSVpuWUhmQ2J6aTlNSTQxajd1VURRNVJkMVNZYmhsUUs4UWRXN054Y3BDOXNHaDZTVEpZTzB5UFVJU2ZEQnZaZzJRYU5HaENDeFN6UzJPTVNYOU82QURxSnNndHB1dkIzcDVtRm1tT0haODJoMUM0UTl6blBjb3R0Qm8zbWRnQkhEbjE1Wg==\",\"sha\":\"f\\ufffd\\ufffd\\ufffdr\\ufffdE\\ufffdtu\\ufffd\\ufffd=n\\ufffd7\\u001d\\ufffd\\ufffdrB0^\\ufffd\\n1\\ufffd\\u0008\\ufffdWI\",\"time\":\"2021-06-28 10:04:13.867293349 +0800 CST m=+19.006097088\"}" -``` -
- diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod b/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod deleted file mode 100644 index 769d059..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 - github.com/cloudevents/sdk-go/v2 v2.4.1 - github.com/google/uuid v1.1.2 -) \ No newline at end of file diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go deleted file mode 100644 index fa65929..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) int); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.Producer); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go deleted file mode 100644 index 33e1c99..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go +++ /dev/null @@ -1,189 +0,0 @@ -// An example, referenced from https://github.com/mchmarny/dapr-demos/tree/master/autoscaling-on-queue - -package userfunction - -import ( - "crypto/sha256" - "encoding/json" - "fmt" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "github.com/google/uuid" - "log" - "math/rand" - "os" - "os/signal" - "strconv" - "strings" - "sync" - "syscall" - "time" -) - -const ( - chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" -) - -var ( - logger = log.New(os.Stdout, "", 0) - pubSubName = getEnvVar("PUBSUB_NAME", "autoscaling-pubsub") - numOfPublishers = getEnvIntOrFail("NUMBER_OF_PUBLISHERS", "1") - publishFrequency = getEnvDurationOrFail("PUBLISHERS_FREQ", "1s") - publishDelay = getEnvDurationOrFail("PUBLISHERS_DELAY", "10s") - logFrequency = getEnvDurationOrFail("LOG_FREQ", "3s") - publishToConsole = getEnvBoolOrFail("PUBLISH_TO_CONSOLE", "false") -) - -func Producer(ctx *ofctx.OpenFunctionContext, in []byte) int { - if numOfPublishers < 1 { - numOfPublishers = 1 - } - logger.Printf("subscription name: %s", pubSubName) - logger.Printf("number of publishers: %d", numOfPublishers) - logger.Printf("publish frequency: %v", publishFrequency) - logger.Printf("log frequency: %v", logFrequency) - logger.Printf("publish delay: %v", publishDelay) - - // handle signals - stop := make(chan os.Signal) - signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) - - resultCh := make(chan bool, 100) - stopCh := make(chan struct{}) - - go func() { - <-stop - close(stopCh) - }() - - // print results - go monitor(resultCh, stopCh) - - // start producing - for i := 1; i <= numOfPublishers; i++ { - go publish(ctx, i, resultCh, stopCh) - } - - return 200 -} - -func monitor(resultCh <-chan bool, stopCh <-chan struct{}) { - var mux sync.Mutex - var successCounter int64 = 0 - var errorCounter int64 = 0 - startTime := time.Now() - tickerCh := time.NewTicker(logFrequency).C - for { - select { - case r := <-resultCh: - mux.Lock() - if r { - successCounter++ - } else { - errorCounter++ - } - mux.Unlock() - case <-tickerCh: - var avg float64 = 0 - if successCounter > 0 { - avg = float64(successCounter) / time.Since(startTime).Seconds() - } - logger.Printf("%10d published, %3.0f/sec, %3d errors", successCounter, avg, errorCounter) - case <-stopCh: - os.Exit(0) - } - } -} - -func publish(ctx *ofctx.OpenFunctionContext, index int, resultCh chan<- bool, stopCh <-chan struct{}) { - delayCh := time.NewTicker(publishDelay).C - <-delayCh - - tickerCh := time.NewTicker(publishFrequency).C - for { - select { - case <-stopCh: - return - case <-tickerCh: - d := getEventData(index) - if publishToConsole { - logger.Printf("%s", d) - resultCh <- true - continue - } - if err := ctx.SendTo(d, pubSubName); err != nil { - logger.Printf("send error, %v", err) - resultCh <- false - } else { - resultCh <- true - } - } - } -} - -func getEventData(index int) []byte { - r := requestContent{ - ID: fmt.Sprintf("p%d-%s", index, uuid.New().String()), - Data: []byte(getData(256)), - Time: time.Now().String(), - } - - // hash the entire message - inSha := sha256.Sum256(r.Data) - r.Sha = string(inSha[:]) - - b, err := json.Marshal(r) - if err != nil { - logger.Fatalf("error generating request: %v", err) - } - return b -} - -func getData(length int) string { - seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) - b := make([]byte, length) - for i := range b { - b[i] = chars[seededRand.Intn(len(chars))] - } - return string(b) -} - -type requestContent struct { - ID string `json:"id"` - Data []byte `json:"data"` - Sha string `json:"sha"` - Time string `json:"time"` -} - -func getEnvVar(key, fallbackValue string) string { - if val, ok := os.LookupEnv(key); ok { - return strings.TrimSpace(val) - } - return fallbackValue -} - -func getEnvIntOrFail(key, fallbackValue string) int { - s := getEnvVar(key, fallbackValue) - v, err := strconv.Atoi(s) - if err != nil { - logger.Fatalf("invalid number variable: %s - %v", s, err) - } - return v -} - -func getEnvDurationOrFail(key, fallbackValue string) time.Duration { - s := getEnvVar(key, fallbackValue) - v, err := time.ParseDuration(s) - if err != nil { - logger.Fatalf("invalid duration variable: %s - %v", s, err) - } - return v -} - -func getEnvBoolOrFail(key, fallbackValue string) bool { - s := getEnvVar(key, fallbackValue) - v, err := strconv.ParseBool(s) - if err != nil { - logger.Fatalf("invalid bool variable: %s - %v", s, err) - } - return v -} diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod b/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod deleted file mode 100644 index 1014eb3..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go deleted file mode 100644 index 5492c49..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) int); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.Subscriber); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go b/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go deleted file mode 100644 index 79051b2..0000000 --- a/v0.3.1/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go +++ /dev/null @@ -1,11 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func Subscriber(ctx *ofctx.OpenFunctionContext, in []byte) int { - log.Printf("event - Data: %s", in) - return 200 -} diff --git a/v0.3.1/functions-framework/nodejs/Knative/README.md b/v0.3.1/functions-framework/nodejs/Knative/README.md deleted file mode 100644 index cb3c00c..0000000 --- a/v0.3.1/functions-framework/nodejs/Knative/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Knative Runtime examples - -- [HTTP request](helloworld) - -- [Cloudevent](cloudevent) - diff --git a/v0.3.1/functions-framework/nodejs/Knative/cloudevent/README.md b/v0.3.1/functions-framework/nodejs/Knative/cloudevent/README.md deleted file mode 100644 index 5cd75e8..0000000 --- a/v0.3.1/functions-framework/nodejs/Knative/cloudevent/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# Cloudevent - -The functions framework can unmarshall incoming [CloudEvents](http://cloudevents.io/) payloads to a `cloudevent` object. Note that your function must use the `cloudevent-style` function signature. - -```js -exports.helloCloudEvents = (cloudevent) => { - return cloudevent -} -``` - -Your `package.json` - -```json - "scripts": { - "start": "functions-framework --target=helloCloudEvents --source=cloudevent" - } -``` - -**A binary one** - -See [payload content](https://github.com/OpenFunction/functions-framework-nodejs/blob/main/mock/payload/binary.json) - -```bash -$ curl -X POST \ - -d'@../mock/payload/binary.json' \ - -H'Content-Type:application/json' \ - -H'ce-specversion:1.0' \ - -H'ce-type:com.github.pull.create' \ - -H'ce-source:https://github.com/cloudevents/spec/pull/123' \ - -H'ce-id:45c83279-c8a1-4db6-a703-b3768db93887' \ - -H'ce-time:2019-11-06T11:17:00Z' \ - -H'ce-myextension:extension value' \ - http://localhost:8080/ -# The response is -{ - "datacontenttype": "application/json", - "data": { - "runtime": "cloudevent" - }, - "specversion": "1.0", - "type": "com.github.pull.create", - "source": "https://github.com/cloudevents/spec/pull/123", - "id": "45c83279-c8a1-4db6-a703-b3768db93887", - "time": "2019-11-06T11:17:00Z", - "myextension": "extension value" -} -``` - -**A structed one** - -See [payload content](https://github.com/OpenFunction/functions-framework-nodejs/blob/main/mock/payload/structured.json) - -```bash -$ curl -X POST \ - -d'@../mock/payload/structured.json' \ - -H'Content-Type:application/cloudevents+json' \ - http://localhost:8080/ -# The response is -{ - "specversion": "1.0", - "type": "com.github.pull.create", - "source": "https://github.com/cloudevents/spec/pull/123", - "id": "b25e2717-a470-45a0-8231-985a99aa9416", - "time": "2019-11-06T11:08:00Z", - "datacontenttype": "application/json", - "data": { - "framework": "openfunction" - } -} -``` - diff --git a/v0.3.1/functions-framework/nodejs/Knative/cloudevent/index.js b/v0.3.1/functions-framework/nodejs/Knative/cloudevent/index.js deleted file mode 100644 index 3a7dceb..0000000 --- a/v0.3.1/functions-framework/nodejs/Knative/cloudevent/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloCloudEvents = (cloudevent) => { - return cloudevent -} \ No newline at end of file diff --git a/v0.3.1/functions-framework/nodejs/Knative/cloudevent/package.json b/v0.3.1/functions-framework/nodejs/Knative/cloudevent/package.json deleted file mode 100644 index 705e839..0000000 --- a/v0.3.1/functions-framework/nodejs/Knative/cloudevent/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "cloudevent", - "version": "1.0.0", - "description": "The functions framework can unmarshall incoming [CloudEvents](http://cloudevents.io/) payloads to a `cloudevent` object. Note that your function must use the `cloudevent-style` function signature.", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloCloudEvents --source=cloudevent" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.3.1/functions-framework/nodejs/Knative/helloworld/README.md b/v0.3.1/functions-framework/nodejs/Knative/helloworld/README.md deleted file mode 100644 index 5857bad..0000000 --- a/v0.3.1/functions-framework/nodejs/Knative/helloworld/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Hello World Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = (req, res) => { - res.send('Hello, World'); - }; - ``` - -3. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -4. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --source http" - } - ``` - -5. Use `npm start` to start the built-in local development server: - - ```bash - $ npm start - ... - The functionModulePath is: /.../.../index.js - Openfunction functions framework listening at http://localhost:8080 - ``` - -6. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl localhost:8080 - # Output: Hello, World - ``` diff --git a/v0.3.1/functions-framework/nodejs/Knative/helloworld/index.js b/v0.3.1/functions-framework/nodejs/Knative/helloworld/index.js deleted file mode 100644 index 64f3c6f..0000000 --- a/v0.3.1/functions-framework/nodejs/Knative/helloworld/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloWorld = (req, res) => { - res.send('Hello, World'); -}; \ No newline at end of file diff --git a/v0.3.1/functions-framework/nodejs/Knative/helloworld/package.json b/v0.3.1/functions-framework/nodejs/Knative/helloworld/package.json deleted file mode 100644 index c338493..0000000 --- a/v0.3.1/functions-framework/nodejs/Knative/helloworld/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "helloworld", - "version": "1.0.0", - "description": "1. Create a `package.json` file using `npm init`:", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --source http" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/README.md b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/README.md deleted file mode 100644 index 7de4247..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# OpenFuncAsync Runtime examples - -- [HTTP Request](helloworld) - -- [Bindings](bindings) - -- [Pubsub](pubsub) diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/README.md b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/README.md deleted file mode 100644 index 1894e4f..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# BIndings Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data - } - ``` - -3. Add your `config.json` - - ```json - { - "input": { - "name": "sample-topic", - "uri": "test", - "params": { - "type": "bindings" - } - }, - "outputs": { - "sample-topic": { - "uri": "test", - "params": { - "type": "bindings", - "operation": "create" - } - } - } - } - ``` - -4. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -5. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --port 4000" - } - ``` - -6. Note that if we want to test it locally, we need a Dapr config file: - - ```yaml - apiVersion: dapr.io/v1alpha1 - kind: Component - metadata: - name: sample-topic - spec: - type: bindings.kafka - version: v1 - metadata: - # Kafka broker connection setting - - name: brokers - value: localhost:9092 - # consumer configuration: topic and consumer group - - name: topics - value: sample - - name: consumerGroup - value: group1 - # publisher configuration: topic - - name: publishTopic - value: sample - - name: authRequired - value: "false" - ``` - -7. Use `dapr` to run `npm start` and start the built-in local development server: - - ```bash - $ dapr run --app-id hello-world --app-port 4000 --dapr-http-port 3500 --components-path ./bindings.yaml npm start - ``` - -8. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl -X POST \ - -d'{"data": "hello"}' \ - -H'Content-Type:application/json' \ - http://localhost:4000/test - ``` - -9. And the output will be like: - - ```shell - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:31 +0000] "POST /test HTTP/1.1" 200 - "-" "curl/7.58.0" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:36 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:41 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:46 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - ``` - - - diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml deleted file mode 100644 index 3aa06a7..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: sample-topic -spec: - type: bindings.kafka - version: v1 - metadata: - # Kafka broker connection setting - - name: brokers - value: localhost:9092 - # consumer configuration: topic and consumer group - - name: topics - value: sample - - name: consumerGroup - value: group1 - # publisher configuration: topic - - name: publishTopic - value: sample - - name: authRequired - value: "false" \ No newline at end of file diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/config.json b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/config.json deleted file mode 100644 index ebe6373..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/config.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "input": { - "name": "sample-topic", - "uri": "test", - "params": { - "type": "bindings" - } - }, - "outputs": { - "sample-topic": { - "uri": "test", - "params": { - "type": "bindings", - "operation": "create" - } - } - } -} \ No newline at end of file diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/index.js b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/index.js deleted file mode 100644 index 8bda8c1..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/index.js +++ /dev/null @@ -1,6 +0,0 @@ -exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data -} \ No newline at end of file diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/package.json b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/package.json deleted file mode 100644 index f9e6340..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/bindings/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "bindings", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --port 4000" - }, - "author": "", - "license": "ISC" -} diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md deleted file mode 100644 index 8f57ff1..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# Hello World Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - /** - * Send {"data": "Hello, World"} - * @param data - data is the request body contents, which should be a json object - */ - exports.helloWorld = (data) => { - return 'Hello, World'; - }; - ``` - -3. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -4. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld" - } - ``` - -5. Use `npm start` to start the built-in local development server: - - ```bash - $ npm start - ... - The functionModulePath is: /.../.../index.js - Openfunction functions framework listening at http://localhost:8080 - ``` - -6. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl localhost:8080 - # Output: Hello, World - ``` diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js deleted file mode 100644 index 7d7ab84..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Send {"data": "Hello, World"} - * @param data - data is the request body contents, which should be a json object - */ - exports.helloWorld = (data) => { - return 'Hello, World'; -}; \ No newline at end of file diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json deleted file mode 100644 index d3cb74c..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "helloworld", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index ac0cc4d..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# Pub/Sub Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data - } - ``` - -3. Add your `config.json` - - ```json - { - "input": { - "name": "pubsub", - "uri": "test", - "params": { - "type": "pubsub" - } - }, - "outputs": { - "pubsub": { - "uri": "test", - "params": { - "type": "pubsub" - } - } - } - } - ``` - -4. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -5. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --port 4000" - } - ``` - -6. Note that if we want to test it locally, we need a Dapr config file: - - ```yaml - apiVersion: dapr.io/v1alpha1 - kind: Component - metadata: - name: pubsub # midlleware component name - spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: ${YOUR_REDIS_ADDRESS} - - name: redisPassword - value: "" - ``` - -7. Use `dapr` to run `npm start` and start the built-in local development server: - - ```bash - $ dapr run --app-id hello-world --app-port 4000 --dapr-http-port 3500 --components-path ./pubsub.yaml npm start - ``` - -8. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl -X POST \ - -d'@../mock/payload/structured.json' \ - -H'Content-Type:application/cloudevents+json' \ - http://localhost:4000/test - ``` - -9. The `structured.json` is like below: (note that in dapr, pubsub mode respects the cloud event style) - - ```json - { - "specversion":"1.0", - "type":"com.github.pull.create", - "source":"https://github.com/cloudevents/spec/pull/123", - "id":"b25e2717-a470-45a0-8231-985a99aa9416", - "time":"2019-11-06T11:08:00Z", - "datacontenttype":"application/json", - "data":{ - "framework":"openfunction" - } - } - ``` - -10. And the output will be like: - - ```shell - == APP == { framework: 'openfunction' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:31 +0000] "POST /test HTTP/1.1" 200 - "-" "curl/7.58.0" - == APP == { data: { framework: 'openfunction' } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:36 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: { data: { framework: 'openfunction' } } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:41 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: { data: { data: [Object] } } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:46 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - ``` - - - diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json deleted file mode 100644 index 64336f8..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "input": { - "name": "pubsub", - "uri": "test", - "params": { - "type": "pubsub" - } - }, - "outputs": { - "pubsub": { - "uri": "test", - "params": { - "type": "pubsub" - } - } - } -} \ No newline at end of file diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js deleted file mode 100644 index 8bda8c1..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js +++ /dev/null @@ -1,6 +0,0 @@ -exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data -} \ No newline at end of file diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json deleted file mode 100644 index 4637e47..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "pubsub", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --port 4000" - }, - "author": "", - "license": "ISC" -} diff --git a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml b/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml deleted file mode 100644 index f0ad8a3..0000000 --- a/v0.3.1/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: pubsub # midlleware component name -spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: ${YOUR_REDIS_ADDRESS} - - name: redisPassword - value: "" \ No newline at end of file diff --git a/v0.3.1/functions/Knative/azure-func-go/.funcignore b/v0.3.1/functions/Knative/azure-func-go/.funcignore deleted file mode 100644 index 414df2f..0000000 --- a/v0.3.1/functions/Knative/azure-func-go/.funcignore +++ /dev/null @@ -1,4 +0,0 @@ -.git* -.vscode -local.settings.json -test \ No newline at end of file diff --git a/v0.3.1/functions/Knative/azure-func-go/HttpExample/function.json b/v0.3.1/functions/Knative/azure-func-go/HttpExample/function.json deleted file mode 100644 index 7eb1f8f..0000000 --- a/v0.3.1/functions/Knative/azure-func-go/HttpExample/function.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post" - ] - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] -} diff --git a/v0.3.1/functions/Knative/azure-func-go/handler b/v0.3.1/functions/Knative/azure-func-go/handler deleted file mode 100755 index 78a20b4..0000000 Binary files a/v0.3.1/functions/Knative/azure-func-go/handler and /dev/null differ diff --git a/v0.3.1/functions/Knative/azure-func-go/handler.go b/v0.3.1/functions/Knative/azure-func-go/handler.go deleted file mode 100644 index 6637d44..0000000 --- a/v0.3.1/functions/Knative/azure-func-go/handler.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - "os" -) - -func helloHandler(w http.ResponseWriter, r *http.Request) { - message := "This HTTP triggered function executed successfully. Pass a name in the query string for a personalized response.\n" - name := r.URL.Query().Get("name") - if name != "" { - message = fmt.Sprintf("Hello, %s. This HTTP triggered function executed successfully.\n", name) - } - fmt.Fprint(w, message) -} - -func main() { - listenAddr := ":8080" - if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok { - listenAddr = ":" + val - } - http.HandleFunc("/api/HttpExample", helloHandler) - log.Printf("About to listen on %s. Go to https://127.0.0.1%s/", listenAddr, listenAddr) - log.Fatal(http.ListenAndServe(listenAddr, nil)) -} \ No newline at end of file diff --git a/v0.3.1/functions/Knative/azure-func-go/host.json b/v0.3.1/functions/Knative/azure-func-go/host.json deleted file mode 100644 index 20a2cdc..0000000 --- a/v0.3.1/functions/Knative/azure-func-go/host.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } - }, - "extensionBundle": { - "id": "Microsoft.Azure.Functions.ExtensionBundle", - "version": "[1.*, 2.0.0)" - }, - "customHandler": { - "description": { - "defaultExecutablePath": "handler", - "workingDirectory": "", - "arguments": [] - }, - "enableForwardingHttpRequest": true - } -} diff --git a/v0.3.1/functions/Knative/azure-func-go/proxies.json b/v0.3.1/functions/Knative/azure-func-go/proxies.json deleted file mode 100644 index b385252..0000000 --- a/v0.3.1/functions/Knative/azure-func-go/proxies.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/proxies", - "proxies": {} -} diff --git a/v0.3.1/functions/Knative/hello-world-dotnet/Program.cs b/v0.3.1/functions/Knative/hello-world-dotnet/Program.cs deleted file mode 100644 index 00618b6..0000000 --- a/v0.3.1/functions/Knative/hello-world-dotnet/Program.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -using System; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; - -namespace helloworld -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) - { - string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; - string url = String.Concat("http://0.0.0.0:", port); - - return Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup().UseUrls(url); - }); - } - } -} diff --git a/v0.3.1/functions/Knative/hello-world-dotnet/README.md b/v0.3.1/functions/Knative/hello-world-dotnet/README.md deleted file mode 100644 index 0cd1821..0000000 --- a/v0.3.1/functions/Knative/hello-world-dotnet/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Sample Function Dotnet - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```dotnet``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: dotnet-sample -spec: - version: "v1.0.0" - image: "/sample-dotnet-func:v0.3.1" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "helloworld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/Knative/hello-world-dotnet" - serving: - runtime: "Knative" # default to Knative -``` diff --git a/v0.3.1/functions/Knative/hello-world-dotnet/Startup.cs b/v0.3.1/functions/Knative/hello-world-dotnet/Startup.cs deleted file mode 100644 index d81a8cb..0000000 --- a/v0.3.1/functions/Knative/hello-world-dotnet/Startup.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace helloworld -{ - public class Startup - { - public void ConfigureServices(IServiceCollection services) - { - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - app.UseRouting(); - - app.UseEndpoints(endpoints => - { - endpoints.MapGet("/", async context => - { - await context.Response.WriteAsync("hello, world"); - }); - }); - } - } -} diff --git a/v0.3.1/functions/Knative/hello-world-dotnet/helloworld.csproj b/v0.3.1/functions/Knative/hello-world-dotnet/helloworld.csproj deleted file mode 100644 index f9f2057..0000000 --- a/v0.3.1/functions/Knative/hello-world-dotnet/helloworld.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - netcoreapp3.1 - helloworld - - - diff --git a/v0.3.1/functions/Knative/hello-world-go/README.md b/v0.3.1/functions/Knative/hello-world-go/README.md deleted file mode 100644 index 93e067b..0000000 --- a/v0.3.1/functions/Knative/hello-world-go/README.md +++ /dev/null @@ -1,100 +0,0 @@ -# Sample Function Go - -## Prerequisites - -### OpenFunction - -You can refer to the [Installation Guide](https://github.com/OpenFunction/OpenFunction#install-openfunction) to setup OpenFunction. - -## Deployment - -1. Creating a secret - -Generate a secret to access your container registry, such as one on [Docker Hub](https://hub.docker.com/) or [Quay.io](https://quay.io/). -You can create this secret by editing the ``REGISTRY_SERVER``, ``REGISTRY_USER`` and ``REGISTRY_PASSWORD`` fields in following command, and then run it. - - ```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 - ``` - -2. Creating functions - - For sample function below, modify the ``spec.image`` field in ``function-sample.yaml`` to your own container registry address: - - ```yaml - apiVersion: core.openfunction.io/v1alpha1 - kind: Function - metadata: - name: function-sample - spec: - image: "/sample-go-func:v0.3.1" - ``` - - Use the following command to create this Function: - - ```shell - kubectl apply -f function-sample.yaml - ``` - -3. Result observation - - You can observe the process of a function with the following command: - - ```shell - kubectl get functions.core.openfunction.io - - NAME AGE - function-sample 5s - ``` - - You can also observe the process of a builder in the [Tekton Dashboard](https://tekton.dev/docs/dashboard/). - - Finally, you can observe the final state of the function workload in the Serving: - - ```shell - kubectl get servings.core.openfunction.io - - NAME AGE - function-sample-serving 15s - ``` - - You can now find out the service entry of the function with the following command: - - ```shell - kubectl get ksvc - - NAME URL LATESTCREATED LATESTREADY READY REASON - function-sample-serving-ksvc http://function-sample-serving-ksvc.default..sslip.io function-sample-serving-ksvc-00001 function-sample-serving-ksvc-00001 True - ``` - - Or get the service address directly with the following command: - - > where` `indicates the external address of your gateway service. - > - > You can do a simple configuration to use the node ip as the `` as follows (Assuming you are using Kourier as network layer of Knative). Where `1.2.3.4` can be replaced by your node ip. - > - > ```shell - > kubectl patch svc -n kourier-system kourier \ - > -p '{"spec": {"type": "LoadBalancer", "externalIPs": ["1.2.3.4"]}}' - > - > kubectl patch configmap/config-domain -n knative-serving \ - > --type merge --patch '{"data":{"1.2.3.4.sslip.io":""}}' - > ``` - - ```shell - kubectl get ksvc function-sample-serving-ksvc -o jsonpath={.status.url} - - http://function-sample-serving-ksvc.default..sslip.io - ``` - - Access the above service address via commands such as ``curl``: - - ```shell - curl http://function-sample-serving-ksvc.default..sslip.io - - Hello, World! - ``` \ No newline at end of file diff --git a/v0.3.1/functions/Knative/hello-world-go/function-sample.yaml b/v0.3.1/functions/Knative/hello-world-go/function-sample.yaml deleted file mode 100644 index ea24055..0000000 --- a/v0.3.1/functions/Knative/hello-world-go/function-sample.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: function-sample -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-go-func:v0.3.1" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: openfunction/builder:v1 - env: - FUNC_NAME: "HelloWorld" - FUNC_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/Knative/hello-world-go" - serving: - runtime: Knative # default to Knative -# template: -# containers: -# - name: function -# # Set imagePullPolicy if needed -# imagePullPolicy: Always diff --git a/v0.3.1/functions/Knative/hello-world-go/go.mod b/v0.3.1/functions/Knative/hello-world-go/go.mod deleted file mode 100644 index adf50d7..0000000 --- a/v0.3.1/functions/Knative/hello-world-go/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module example.com/hello - -go 1.15 diff --git a/v0.3.1/functions/Knative/hello-world-go/hello.go b/v0.3.1/functions/Knative/hello-world-go/hello.go deleted file mode 100644 index 6db3585..0000000 --- a/v0.3.1/functions/Knative/hello-world-go/hello.go +++ /dev/null @@ -1,11 +0,0 @@ -package hello - -import ( - "fmt" - "net/http" -) - -// HelloWorld writes "Hello, World!" to the HTTP response. -func HelloWorld(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "Hello, World!\n") -} diff --git a/v0.3.1/functions/Knative/hello-world-java/README.md b/v0.3.1/functions/Knative/hello-world-java/README.md deleted file mode 100644 index 3824775..0000000 --- a/v0.3.1/functions/Knative/hello-world-java/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Sample Function Java - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```java``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: java-sample -spec: - version: "v1.0.0" - image: "/sample-java-func:v0.3.1" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "com.openfunction.HelloWorld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/Knative/hello-world-java" - serving: - runtime: Knative # default to Knative -``` diff --git a/v0.3.1/functions/Knative/hello-world-java/pom.xml b/v0.3.1/functions/Knative/hello-world-java/pom.xml deleted file mode 100644 index bc93ba7..0000000 --- a/v0.3.1/functions/Knative/hello-world-java/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - 4.0.0 - - com.openfunction - java-sample - 1.0.0-SNAPSHOT - - 11 - 11 - - - - - - com.google.cloud.functions - functions-framework-api - 1.0.4 - provided - - - - - - - - com.google.cloud.functions - function-maven-plugin - 0.9.7 - - com.openfunction.HelloWorld - - - - - diff --git a/v0.3.1/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java b/v0.3.1/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java deleted file mode 100644 index 02b2c43..0000000 --- a/v0.3.1/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.openfunction; - -import com.google.cloud.functions.HttpFunction; -import com.google.cloud.functions.HttpRequest; -import com.google.cloud.functions.HttpResponse; -import java.io.BufferedWriter; -import java.io.IOException; - -public class HelloWorld implements HttpFunction { - // Simple function to return "Hello World" - @Override - public void service(HttpRequest request, HttpResponse response) - throws IOException { - BufferedWriter writer = response.getWriter(); - writer.write("Hello World!"); - } -} diff --git a/v0.3.1/functions/Knative/hello-world-node/README.md b/v0.3.1/functions/Knative/hello-world-node/README.md deleted file mode 100644 index e68c1a1..0000000 --- a/v0.3.1/functions/Knative/hello-world-node/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Sample Function Node - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```node``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: node-sample -spec: - version: "v1.0.0" - image: "/sample-node-func:v0.3.1" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "helloWorld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/Knative/hello-world-node" - serving: - runtime: "Knative" # default to Knative -``` diff --git a/v0.3.1/functions/Knative/hello-world-node/index.js b/v0.3.1/functions/Knative/hello-world-node/index.js deleted file mode 100644 index 26ef1ae..0000000 --- a/v0.3.1/functions/Knative/hello-world-node/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloWorld = (req, res) => { - res.send('hello, world'); -}; diff --git a/v0.3.1/functions/Knative/hello-world-python/README.md b/v0.3.1/functions/Knative/hello-world-python/README.md deleted file mode 100644 index 9aeb82e..0000000 --- a/v0.3.1/functions/Knative/hello-world-python/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Sample Function Python - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```python``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: python-sample -spec: - version: "v1.0.0" - image: "/sample-python-func:v0.3.1" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "hello_world" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - GOOGLE_FUNCTION_SOURCE: "main.py" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/Knative/hello-world-python" - serving: - runtime: Knative # default to Knative -``` diff --git a/v0.3.1/functions/Knative/hello-world-python/main.py b/v0.3.1/functions/Knative/hello-world-python/main.py deleted file mode 100644 index 249f1b8..0000000 --- a/v0.3.1/functions/Knative/hello-world-python/main.py +++ /dev/null @@ -1,2 +0,0 @@ -def hello_world(request): - return "hello, world" diff --git a/v0.3.1/functions/Knative/hello-world-python/requirements.txt b/v0.3.1/functions/Knative/hello-world-python/requirements.txt deleted file mode 100644 index bc9616b..0000000 --- a/v0.3.1/functions/Knative/hello-world-python/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -functions-framework==1.4.3 \ No newline at end of file diff --git a/v0.3.1/functions/Knative/logs-handler-function/LogsHandler.go b/v0.3.1/functions/Knative/logs-handler-function/LogsHandler.go deleted file mode 100644 index ebbf8c0..0000000 --- a/v0.3.1/functions/Knative/logs-handler-function/LogsHandler.go +++ /dev/null @@ -1,96 +0,0 @@ -package logshandler - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net/http" - "regexp" - "time" - - alert "github.com/prometheus/alertmanager/template" -) - -const ( - HTTPCodeNotFound = "404" - Namespace = "demo-project" - PodName = "wordpress-v1-[A-Za-z0-9]{5,15}-[A-Za-z0-9]{3,10}" - AlertName = "404 Request" - Severity = "warning" - NotificationManagerAddress = "http://notification-manager-svc.kubesphere-monitoring-system.svc.cluster.local:19093/api/v2/alerts" -) - -func LogsHandler(w http.ResponseWriter, r *http.Request) { - reqBody, err := ioutil.ReadAll(r.Body) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Get request body failed") - return - } - content := string(reqBody) - matchHTTPCode, _ := regexp.MatchString(fmt.Sprintf(" %s ", HTTPCodeNotFound), content) - matchNamespace, _ := regexp.MatchString(fmt.Sprintf("namespace_name\":\"%s", Namespace), content) - matchPodName := regexp.MustCompile(fmt.Sprintf(`(%s)`, PodName)).FindStringSubmatch(content) - - if matchHTTPCode && matchNamespace && matchPodName != nil { - log.Printf("Match log - Content: %s", content) - - match := regexp.MustCompile(`([A-Z]+) (/\S*) HTTP`).FindStringSubmatch(content) - if match == nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Cannot retrieve information") - return - } - path := match[len(match)-1] - method := match[len(match)-2] - podName := matchPodName[len(matchPodName)-1] - - notify := &alert.Data{ - Receiver: "notification_manager", - Status: "firing", - Alerts: alert.Alerts{}, - GroupLabels: alert.KV{"alertname": AlertName, "namespace": Namespace}, - CommonLabels: alert.KV{"alertname": AlertName, "namespace": Namespace, "severity": Severity}, - CommonAnnotations: alert.KV{}, - ExternalURL: "", - } - alt := alert.Alert{ - Status: "firing", - Labels: alert.KV{ - "alertname": AlertName, - "namespace": Namespace, - "severity": Severity, - "pod": podName, - "path": path, - "method": method, - }, - Annotations: alert.KV{}, - StartsAt: time.Now(), - EndsAt: time.Time{}, - GeneratorURL: "", - Fingerprint: "", - } - notify.Alerts = append(notify.Alerts, alt) - notifyBytes, _ := json.Marshal(notify) - - req, err := http.NewRequest("POST", NotificationManagerAddress, bytes.NewReader(notifyBytes)) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Failed to create request") - return - } - req.Header.Set("Content-Type", "application/json") - client := &http.Client{} - _, err = client.Do(req) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Failed to send request to notification manager") - return - } - - log.Printf("Send log to notification manager") - } - return -} diff --git a/v0.3.1/functions/Knative/logs-handler-function/README.md b/v0.3.1/functions/Knative/logs-handler-function/README.md deleted file mode 100644 index dcbb643..0000000 --- a/v0.3.1/functions/Knative/logs-handler-function/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Function Logs Handler - -For a detailed description of this function example, you can refer to the following blogs: - -[OpenFunction 应用系列之一: 以 Serverless 的方式实现 Kubernetes 日志告警](https://kubesphere.io/zh/blogs/serverless-way-for-kubernetes-log-alert/) - -or - -[Serverless Use Case: Elastic Kubernetes Log Alerts with OpenFunction and Kafka](https://mp.weixin.qq.com/s/EZWYqtXJ7Cj-Yd7Fro6uyA) - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -Create logs handler function: - -```shell -kubectl apply -f logs-handler-function.yaml -``` - -The logs handler function is then driven by messages from the logs topic in Kafka. - diff --git a/v0.3.1/functions/Knative/logs-handler-function/go.mod b/v0.3.1/functions/Knative/logs-handler-function/go.mod deleted file mode 100644 index dbf3c35..0000000 --- a/v0.3.1/functions/Knative/logs-handler-function/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -module example.com/logshandler - -go 1.15 - -require ( - github.com/prometheus/alertmanager v0.22.2 -) diff --git a/v0.3.1/functions/Knative/logs-handler-function/logs-handler-function.yaml b/v0.3.1/functions/Knative/logs-handler-function/logs-handler-function.yaml deleted file mode 100644 index 72a3130..0000000 --- a/v0.3.1/functions/Knative/logs-handler-function/logs-handler-function.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: logs-sync-handler -spec: - version: "v1.0.0" - image: openfunctiondev/logs-sync-handler:v0.3.1 - imageCredentials: - name: push-secret - build: - builder: openfunction/builder-go:v0.2.2-1.15 - env: - FUNC_NAME: "LogsHandler" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/Knative/logs-handler-function/" - serving: - runtime: "Knative" -# template: -# containers: -# - name: function -# # Set imagePullPolicy if needed -# imagePullPolicy: Always diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/README.md b/v0.3.1/functions/OpenFuncAsync/bindings/README.md deleted file mode 100644 index c831e90..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,107 +0,0 @@ -# Function Input/Output - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-bindings-server` and a Topic named `sample`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -### Input only sample - -We will use the sample in the `without-output` directory, which will be triggered by Dapr's `bindings.cron` component at a frequency of once every 2 seconds. - -Modify the `spec.image` field in `without-output/function-bindings.yaml` to your own container registry address: - -```yaml -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: bindings-without-output -spec: - image: "/bindings-without-output:v0.3.1" -``` - -Use the following commands to create this Function: - -```shell -kubectl apply -f without-output/function-bindings.yaml -``` - -Afterwards, use the following command to observe the log of the function: - -```shell -kubectl logs -f \ - $(kubectl get po -l \ - openfunction.io/serving=$(kubectl get functions bindings-without-output -o jsonpath='{.status.serving.resourceRef}') \ - -o jsonpath='{.items[0].metadata.name}') \ - function -``` - -You will be able to see messages similar to the following: - -```shell -2021/07/02 09:02:02 binding - Data: Received -2021/07/02 09:02:04 binding - Data: Received -2021/07/02 09:02:06 binding - Data: Received -2021/07/02 09:02:08 binding - Data: Received -``` - -### Input and Output - -We will use the sample in the `with-output` directory, which will be triggered by Dapr's `bindings.cron` component at a frequency of once every 2 seconds. After being triggered, it will send a greeting to another service via Dapr's `bindings.kafka` component. - -Modify the `spec.image` field in `without-output/function-bindings.yaml` to your own container registry address: - -```yaml -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: bindings-with-output -spec: - image: "/bindings-with-output:v0.3.1" -``` - -Use the following commands to create this Function: - -```shell -kubectl apply -f with-output/function-bindings.yaml -``` - -Afterwards, use the following command to observe the log of the function: - -```shell -kubectl logs -f \ - $(kubectl get po -l \ - openfunction.io/serving=$(kubectl get functions bindings-with-output -o jsonpath='{.status.serving.resourceRef}') \ - -o jsonpath='{.items[0].metadata.name}') \ - function -``` - -You will be able to see messages similar to the following: - -```shell -2021/07/02 09:02:02 binding - Data: Received -2021/07/02 09:02:04 binding - Data: Received -2021/07/02 09:02:06 binding - Data: Received -2021/07/02 09:02:08 binding - Data: Received -``` - -Now we need to start the output target service. (Use `kubectl delete -f with-output/output/goapp.yaml` for cleaning.) - -```shell -kubectl apply -f with-output/output/goapp.yaml -``` - -Use command `kubectl logs -f $(kubectl get po -l app=bindingsgoapp -o jsonpath='{.items[0].metadata.name}') go` to observe the logs of output target service: - -```shell -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -``` - diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go b/v0.3.1/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go deleted file mode 100644 index 58b35d8..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go +++ /dev/null @@ -1,25 +0,0 @@ -package bindings - -import ( - "encoding/json" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsOutput(ctx *ofctx.OpenFunctionContext, in []byte) int { - var greeting []byte - if in != nil { - log.Printf("binding - Data: %s", in) - greeting = in - } else { - log.Print("binding - Data: Received") - greeting, _ = json.Marshal(map[string]string{"message": "Hello"}) - } - - err := ctx.SendTo(greeting, "sample-topic") - if err != nil { - log.Printf("Error: %v\n", err) - return 500 - } - return 200 -} diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml b/v0.3.1/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml deleted file mode 100644 index 2d52645..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml +++ /dev/null @@ -1,56 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: bindings-with-output -spec: - version: "v1.0.0" - image: openfunctiondev/bindings-with-output:v0.3.1 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.2.2-1.15" - env: - FUNC_NAME: "BindingsOutput" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/OpenFuncAsync/bindings/with-output/" - serving: - template: - containers: - - name: function - imagePullPolicy: Always - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: cron - type: bindings - outputs: - - name: sample-topic - type: bindings - params: - operation: "create" - type: "bindings" - annotations: - "dapr.io/log-level": "debug" - components: - - name: cron - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" - - name: sample-topic - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-bindings-server-kafka-brokers:9092" - - name: topics - value: sample - - name: consumerGroup - value: group1 - - name: publishTopic - value: sample - - name: authRequired - value: "false" diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/go.mod b/v0.3.1/functions/OpenFuncAsync/bindings/with-output/go.mod deleted file mode 100644 index e3c2148..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/bindings - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/Dockerfile b/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/Dockerfile deleted file mode 100644 index e7288cf..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM golang:1.15 as builder - -WORKDIR /app - -COPY go.mod go.mod - -RUN go mod download - -COPY goapp.go main.go - -# Build -RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o main main.go - -# Use distroless as minimal base image to package the openfunction binary -# Refer to https://github.com/GoogleContainerTools/distroless for more details -FROM openfunction/distroless-static:nonroot -WORKDIR / -COPY --from=builder /app/main . -USER nonroot:nonroot - -ENTRYPOINT ["/main"] diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/go.mod b/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/go.mod deleted file mode 100644 index b7131f8..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module example.com/main - -go 1.15 \ No newline at end of file diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/goapp.go b/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/goapp.go deleted file mode 100644 index 2a26151..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/goapp.go +++ /dev/null @@ -1,31 +0,0 @@ -package main - -import ( - "encoding/json" - "fmt" - "net/http" -) - -func main() { - http.HandleFunc("/sample-topic", func(rw http.ResponseWriter, req *http.Request) { - var msg Message - - err := json.NewDecoder(req.Body).Decode(&msg) - if err != nil { - fmt.Println("error reading message from Kafka binding", err) - rw.WriteHeader(500) - return - } - fmt.Printf("message from Kafka '%s'\n", msg) - rw.WriteHeader(200) - }) - err := http.ListenAndServe(":3000", nil) - if err != nil { - fmt.Println(err) - return - } -} - -type Message struct { - Msg string `json:"message"` -} diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/goapp.yaml b/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/goapp.yaml deleted file mode 100644 index 384b2a5..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/with-output/output/goapp.yaml +++ /dev/null @@ -1,26 +0,0 @@ -apiVersion: apps/v1 -kind: Deployment -metadata: - name: bindings-goapp - labels: - app: bindingsgoapp -spec: - replicas: 1 - selector: - matchLabels: - app: bindingsgoapp - template: - metadata: - labels: - app: bindingsgoapp - annotations: - dapr.io/enabled: "true" - dapr.io/app-id: "bindings-goapp" - dapr.io/app-port: "3000" - spec: - containers: - - name: go - image: openfunctiondev/bindings-output-goapp:latest - ports: - - containerPort: 3000 - imagePullPolicy: Always \ No newline at end of file diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go b/v0.3.1/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go deleted file mode 100644 index 77eb2eb..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go +++ /dev/null @@ -1,15 +0,0 @@ -package bindings - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsNoOutput(ctx *ofctx.OpenFunctionContext, in []byte) int { - if in != nil { - log.Printf("binding - Data: %s", in) - } else { - log.Print("binding - Data: Received") - } - return 200 -} diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml b/v0.3.1/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml deleted file mode 100644 index 3c98a9c..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml +++ /dev/null @@ -1,36 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: bindings-without-output -spec: - version: "v1.0.0" - image: openfunctiondev/bindings-without-output:v0.3.1 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.2.2-1.15" - env: - FUNC_NAME: "BindingsNoOutput" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/OpenFuncAsync/bindings/without-output/" - serving: - template: - containers: - - name: function - imagePullPolicy: Always - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: cron - type: bindings - annotations: - "dapr.io/log-level": "debug" - components: - - name: cron - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" diff --git a/v0.3.1/functions/OpenFuncAsync/bindings/without-output/go.mod b/v0.3.1/functions/OpenFuncAsync/bindings/without-output/go.mod deleted file mode 100644 index e3c2148..0000000 --- a/v0.3.1/functions/OpenFuncAsync/bindings/without-output/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/bindings - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 diff --git a/v0.3.1/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go b/v0.3.1/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go deleted file mode 100644 index e86bcea..0000000 --- a/v0.3.1/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go +++ /dev/null @@ -1,73 +0,0 @@ -package logs_handler_function - -import ( - "encoding/json" - "fmt" - "log" - "regexp" - "time" - - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - alert "github.com/prometheus/alertmanager/template" -) - -const ( - HTTPCodeNotFound = "404" - Namespace = "demo-project" - PodName = "wordpress-v1-[A-Za-z0-9]{5,15}-[A-Za-z0-9]{3,10}" - AlertName = "404 Request" - Severity = "warning" -) - -func LogsHandler(ctx *ofctx.OpenFunctionContext, in []byte) int { - content := string(in) - matchHTTPCode, _ := regexp.MatchString(fmt.Sprintf(" %s ", HTTPCodeNotFound), content) - matchNamespace, _ := regexp.MatchString(fmt.Sprintf("namespace_name\":\"%s", Namespace), content) - matchPodName := regexp.MustCompile(fmt.Sprintf(`(%s)`, PodName)).FindStringSubmatch(content) - - if matchHTTPCode && matchNamespace && matchPodName != nil { - log.Printf("Match log - Content: %s", content) - - match := regexp.MustCompile(`([A-Z]+) (/\S*) HTTP`).FindStringSubmatch(content) - if match == nil { - return 500 - } - path := match[len(match)-1] - method := match[len(match)-2] - podName := matchPodName[len(matchPodName)-1] - - notify := &alert.Data{ - Receiver: "notification_manager", - Status: "firing", - Alerts: alert.Alerts{}, - GroupLabels: alert.KV{"alertname": AlertName, "namespace": Namespace}, - CommonLabels: alert.KV{"alertname": AlertName, "namespace": Namespace, "severity": Severity}, - CommonAnnotations: alert.KV{}, - ExternalURL: "", - } - alt := alert.Alert{ - Status: "firing", - Labels: alert.KV{ - "alertname": AlertName, - "namespace": Namespace, - "severity": Severity, - "pod": podName, - "path": path, - "method": method, - }, - Annotations: alert.KV{}, - StartsAt: time.Now(), - EndsAt: time.Time{}, - GeneratorURL: "", - Fingerprint: "", - } - notify.Alerts = append(notify.Alerts, alt) - notifyBytes, _ := json.Marshal(notify) - - if err := ctx.SendTo(notifyBytes, "notification-manager"); err != nil { - panic(err) - } - log.Printf("Send log to notification manager.") - } - return 200 -} \ No newline at end of file diff --git a/v0.3.1/functions/OpenFuncAsync/logs-handler-function/README.md b/v0.3.1/functions/OpenFuncAsync/logs-handler-function/README.md deleted file mode 100644 index 85c9bc6..0000000 --- a/v0.3.1/functions/OpenFuncAsync/logs-handler-function/README.md +++ /dev/null @@ -1,29 +0,0 @@ -# Function Logs Handler - -For a detailed description of this function example, you can refer to the following blogs: - -[OpenFunction 应用系列之一: 以 Serverless 的方式实现 Kubernetes 日志告警](https://kubesphere.io/zh/blogs/serverless-way-for-kubernetes-log-alert/) - -or - -[Serverless Use Case: Elastic Kubernetes Log Alerts with OpenFunction and Kafka](https://kubesphere.io/blogs/serverless-way-for-kubernetes-log-alert/) - -## - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -Create logs handler function: - -```shell -kubectl apply -f logs-handler-function.yaml -``` - -The logs handler function is then driven by messages from the logs topic in Kafka. \ No newline at end of file diff --git a/v0.3.1/functions/OpenFuncAsync/logs-handler-function/go.mod b/v0.3.1/functions/OpenFuncAsync/logs-handler-function/go.mod deleted file mode 100644 index ee735ae..0000000 --- a/v0.3.1/functions/OpenFuncAsync/logs-handler-function/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module example.com/logshandler - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 - github.com/prometheus/alertmanager v0.22.2 -) \ No newline at end of file diff --git a/v0.3.1/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml b/v0.3.1/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml deleted file mode 100644 index 76aa58d..0000000 --- a/v0.3.1/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml +++ /dev/null @@ -1,70 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: logs-async-handler -spec: - version: "v1.0.0" - image: openfunctiondev/logs-async-handler:v0.3.1 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.2.2-1.15" - env: - FUNC_NAME: "LogsHandler" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/OpenFuncAsync/logs-handler-function/" - serving: - runtime: "OpenFuncAsync" -# template: -# containers: -# - name: function -# # Set imagePullPolicy if needed -# imagePullPolicy: Always - openFuncAsync: - dapr: - inputs: - - name: kafka-receiver - type: bindings - outputs: - - name: notification-manager - type: bindings - params: - operation: "post" - type: "bindings" - annotations: - dapr.io/log-level: "debug" - components: - - name: kafka-receiver - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-logs-receiver-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: publishTopic - value: "logs" - - name: topics - value: "logs" - - name: consumerGroup - value: "logs-handler" - - name: notification-m1anager - type: bindings.http - version: v1 - metadata: - - name: url - value: http://notification-manager-svc.kubesphere-monitoring-system.svc.cluster.local:19093/api/v2/alerts - keda: - scaledObject: - pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 - cooldownPeriod: 30 - triggers: - - type: kafka - metadata: - topic: logs - bootstrapServers: kafka-logs-receiver-kafka-brokers.default.svc.cluster.local:9092 - consumerGroup: logs-handler - lagThreshold: "10" diff --git a/v0.3.1/functions/OpenFuncAsync/pubsub/README.md b/v0.3.1/functions/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index ee57e5a..0000000 --- a/v0.3.1/functions/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Autoscaling service based on queue depth - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-pubsub-server` and a Topic named `metric`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential.Kafka - -## Deployment - -To configure the autoscaling demo we will deploy two functions: `subscriber` which will be used to process messages of the `metric` queue in Kafka, and the `producer`, which will be publishing messages. - -Modify the ``spec.image`` field in ``producer/function-producer.yaml`` and ``subscriber/function-subscribe.yaml`` to your own container registry address: - - ```yaml - apiVersion: core.openfunction.io/v1alpha1 - kind: Function - metadata: - name: autoscaling-producer - spec: - image: "/autoscaling-producer:v0.3.1" - ``` - - ```yaml - apiVersion: core.openfunction.io/v1alpha1 - kind: Function - metadata: - name: autoscaling-subscriber - spec: - image: "/autoscaling-subscriber:v0.3.1" - ``` - -Use the following commands to create these Functions: - -```shell -kubectl apply -f producer/function-producer.yaml -kubectl apply -f subscriber/function-subscriber.yaml -``` - -Back in the initial terminal now, some 20-30 seconds after the `producer` starts, you should see the number of `subscriber` pods being adjusted by Keda based on the number of the `metric` topic. - diff --git a/v0.3.1/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml b/v0.3.1/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml deleted file mode 100644 index 93a9c42..0000000 --- a/v0.3.1/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml +++ /dev/null @@ -1,52 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: autoscaling-producer -spec: - version: "v1.0.0" - image: openfunctiondev/autoscaling-producer:v0.3.1 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.2.2-1.15" - env: - FUNC_NAME: "Producer" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/OpenFuncAsync/pubsub/producer/" - serving: - template: - containers: - - name: function - imagePullPolicy: Always - runtime: "OpenFuncAsync" - params: - PUBSUB_NAME: autoscaling-producer - TOPIC_NAME: metric - NUMBER_OF_PUBLISHERS: "2" - PUBLISHERS_FREQ: "100ms" - PUBLISHERS_DELAY: "10s" - LOG_FREQ: "3s" - PUBLISH_TO_CONSOLE: "false" - openFuncAsync: - dapr: - outputs: - - name: autoscaling-producer - type: pubsub - topic: metric - annotations: - "dapr.io/log-level": "debug" - components: - - name: autoscaling-producer - type: pubsub.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-pubsub-server-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: allowedTopics - value: "metric" - - name: consumerID - value: "autoscaling-producer" - diff --git a/v0.3.1/functions/OpenFuncAsync/pubsub/producer/go.mod b/v0.3.1/functions/OpenFuncAsync/pubsub/producer/go.mod deleted file mode 100644 index eeb2010..0000000 --- a/v0.3.1/functions/OpenFuncAsync/pubsub/producer/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module example.com/producer - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 - github.com/google/uuid v1.1.2 -) diff --git a/v0.3.1/functions/OpenFuncAsync/pubsub/producer/producer.go b/v0.3.1/functions/OpenFuncAsync/pubsub/producer/producer.go deleted file mode 100644 index 104deec..0000000 --- a/v0.3.1/functions/OpenFuncAsync/pubsub/producer/producer.go +++ /dev/null @@ -1,189 +0,0 @@ -// An example, referenced from https://github.com/mchmarny/dapr-demos/tree/master/autoscaling-on-queue - -package producer - -import ( - "crypto/sha256" - "encoding/json" - "fmt" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "github.com/google/uuid" - "log" - "math/rand" - "os" - "os/signal" - "strconv" - "strings" - "sync" - "syscall" - "time" -) - -const ( - chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" -) - -var ( - logger = log.New(os.Stdout, "", 0) - pubSubName = getEnvVar("PUBSUB_NAME", "autoscaling-pubsub") - numOfPublishers = getEnvIntOrFail("NUMBER_OF_PUBLISHERS", "1") - publishFrequency = getEnvDurationOrFail("PUBLISHERS_FREQ", "1s") - publishDelay = getEnvDurationOrFail("PUBLISHERS_DELAY", "10s") - logFrequency = getEnvDurationOrFail("LOG_FREQ", "3s") - publishToConsole = getEnvBoolOrFail("PUBLISH_TO_CONSOLE", "false") -) - -func Producer(ctx *ofctx.OpenFunctionContext, in []byte) int { - if numOfPublishers < 1 { - numOfPublishers = 1 - } - logger.Printf("subscription name: %s", pubSubName) - logger.Printf("number of publishers: %d", numOfPublishers) - logger.Printf("publish frequency: %v", publishFrequency) - logger.Printf("log frequency: %v", logFrequency) - logger.Printf("publish delay: %v", publishDelay) - - // handle signals - stop := make(chan os.Signal) - signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) - - resultCh := make(chan bool, 100) - stopCh := make(chan struct{}) - - go func() { - <-stop - close(stopCh) - }() - - // print results - go monitor(resultCh, stopCh) - - // start producing - for i := 1; i <= numOfPublishers; i++ { - go publish(ctx, i, resultCh, stopCh) - } - - return 200 -} - -func monitor(resultCh <-chan bool, stopCh <-chan struct{}) { - var mux sync.Mutex - var successCounter int64 = 0 - var errorCounter int64 = 0 - startTime := time.Now() - tickerCh := time.NewTicker(logFrequency).C - for { - select { - case r := <-resultCh: - mux.Lock() - if r { - successCounter++ - } else { - errorCounter++ - } - mux.Unlock() - case <-tickerCh: - var avg float64 = 0 - if successCounter > 0 { - avg = float64(successCounter) / time.Since(startTime).Seconds() - } - logger.Printf("%10d published, %3.0f/sec, %3d errors", successCounter, avg, errorCounter) - case <-stopCh: - os.Exit(0) - } - } -} - -func publish(ctx *ofctx.OpenFunctionContext, index int, resultCh chan<- bool, stopCh <-chan struct{}) { - delayCh := time.NewTicker(publishDelay).C - <-delayCh - - tickerCh := time.NewTicker(publishFrequency).C - for { - select { - case <-stopCh: - return - case <-tickerCh: - d := getEventData(index) - if publishToConsole { - logger.Printf("%s", d) - resultCh <- true - continue - } - if err := ctx.SendTo(d, pubSubName); err != nil { - logger.Printf("send error, %v", err) - resultCh <- false - } else { - resultCh <- true - } - } - } -} - -func getEventData(index int) []byte { - r := requestContent{ - ID: fmt.Sprintf("p%d-%s", index, uuid.New().String()), - Data: []byte(getData(256)), - Time: time.Now().String(), - } - - // hash the entire message - inSha := sha256.Sum256(r.Data) - r.Sha = string(inSha[:]) - - b, err := json.Marshal(r) - if err != nil { - logger.Fatalf("error generating request: %v", err) - } - return b -} - -func getData(length int) string { - seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) - b := make([]byte, length) - for i := range b { - b[i] = chars[seededRand.Intn(len(chars))] - } - return string(b) -} - -type requestContent struct { - ID string `json:"id"` - Data []byte `json:"data"` - Sha string `json:"sha"` - Time string `json:"time"` -} - -func getEnvVar(key, fallbackValue string) string { - if val, ok := os.LookupEnv(key); ok { - return strings.TrimSpace(val) - } - return fallbackValue -} - -func getEnvIntOrFail(key, fallbackValue string) int { - s := getEnvVar(key, fallbackValue) - v, err := strconv.Atoi(s) - if err != nil { - logger.Fatalf("invalid number variable: %s - %v", s, err) - } - return v -} - -func getEnvDurationOrFail(key, fallbackValue string) time.Duration { - s := getEnvVar(key, fallbackValue) - v, err := time.ParseDuration(s) - if err != nil { - logger.Fatalf("invalid duration variable: %s - %v", s, err) - } - return v -} - -func getEnvBoolOrFail(key, fallbackValue string) bool { - s := getEnvVar(key, fallbackValue) - v, err := strconv.ParseBool(s) - if err != nil { - logger.Fatalf("invalid bool variable: %s - %v", s, err) - } - return v -} diff --git a/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml b/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml deleted file mode 100644 index feefc59..0000000 --- a/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml +++ /dev/null @@ -1,53 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha1 -kind: Function -metadata: - name: autoscaling-subscriber -spec: - version: "v1.0.0" - image: openfunctiondev/autoscaling-subscriber:v0.3.1 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.2.2-1.15" - env: - FUNC_NAME: "Subscriber" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.3.1/functions/OpenFuncAsync/pubsub/subscriber" - serving: - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: autoscaling-subscriber - type: pubsub - topic: metric - annotations: - dapr.io/log-level: "debug" - components: - autoscaling-subscriber: - type: pubsub.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-pubsub-server-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: allowedTopics - value: "metric" - - name: consumerID - value: "autoscaling-subscriber" - keda: - scaledObject: - pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 - cooldownPeriod: 30 - triggers: - - type: kafka - metadata: - topic: metric - bootstrapServers: kafka-cp-kafka.kafka.svc.cluster.local:9092 - consumerGroup: autoscaling-subscriber - lagThreshold: "10" - diff --git a/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/go.mod b/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/go.mod deleted file mode 100644 index 38fc439..0000000 --- a/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/subscriber - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.0.0-20210628081257-4137e46a99a6 diff --git a/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go b/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go deleted file mode 100644 index 24930d0..0000000 --- a/v0.3.1/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go +++ /dev/null @@ -1,11 +0,0 @@ -package subscriber - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func Subscriber(ctx *ofctx.OpenFunctionContext, in []byte) int { - log.Printf("event - Data: %s", in) - return 200 -} diff --git a/v0.4.0/functions-framework/README.md b/v0.4.0/functions-framework/README.md deleted file mode 100644 index e9930b7..0000000 --- a/v0.4.0/functions-framework/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Functions framework demos - -This directory holds the validation demos for the [functions-framework](https://github.com/OpenFunction/functions-framework). - -Current supported list: - -- [functions-framework-go](https://github.com/OpenFunction/functions-framework-go); -- [functions-framework-nodejs](https://github.com/OpenFunction/functions-framework-nodejs). - -Depending on the type of runtime, the demos are divided into `Knative` and `OpenFuncAsync`, please check them separately: - -* Golang - * [Knative runtime demos](golang/Knative) - * [OpenFuncAsync runtime demos](golang/OpenFuncAsync) -* Nodejs - * [Knative runtime demos](nodejs/Knative) - * [OpenFuncAsync runtime demos](nodejs/OpenFuncAsync) - diff --git a/v0.4.0/functions-framework/golang/Knative/README.md b/v0.4.0/functions-framework/golang/Knative/README.md deleted file mode 100644 index 9375746..0000000 --- a/v0.4.0/functions-framework/golang/Knative/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Knative Runtime examples - -In order to follow these examples, you need to install [Knative](https://knative.dev/docs/install/) and [Go 1.15+](https://golang.org/doc/install). - -## OpenFunction Context Function - -- HTTP request - - [example](simple-hello) - diff --git a/v0.4.0/functions-framework/golang/Knative/simple-hello/README.md b/v0.4.0/functions-framework/golang/Knative/simple-hello/README.md deleted file mode 100644 index e67278c..0000000 --- a/v0.4.0/functions-framework/golang/Knative/simple-hello/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# HTTP request - -Start the service. - -```go -go mod tidy -go run main.go -``` - -> The service uses port `8080` by default, if you want to customize the port, you can set it using the environment variable `PORT`. -> -> ```shell -> PORT=8081 go run main.go -> ``` - -You can see the following. - -```shell -2021/06/29 10:10:48 Knative Function serving http: listening on port 8080 -``` - -Now you can access the service via `curl` command.If everything works, you can see the following. - -```shell -~# curl http://localhost:8080 -Hello, World! -``` - diff --git a/v0.4.0/functions-framework/golang/Knative/simple-hello/main.go b/v0.4.0/functions-framework/golang/Knative/simple-hello/main.go deleted file mode 100644 index 80767a1..0000000 --- a/v0.4.0/functions-framework/golang/Knative/simple-hello/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.HelloWorld); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.4.0/functions-framework/golang/Knative/simple-hello/userfunction/hello.go b/v0.4.0/functions-framework/golang/Knative/simple-hello/userfunction/hello.go deleted file mode 100644 index a66ded7..0000000 --- a/v0.4.0/functions-framework/golang/Knative/simple-hello/userfunction/hello.go +++ /dev/null @@ -1,11 +0,0 @@ -package userfunction - -import ( - "fmt" - "net/http" -) - -// HelloWorld writes "Hello, World!" to the HTTP response. -func HelloWorld(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "Hello, World!\n") -} \ No newline at end of file diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/README.md b/v0.4.0/functions-framework/golang/OpenFuncAsync/README.md deleted file mode 100644 index 08d4091..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# OpenFuncAsync Runtime examples - -In order to follow these examples, you need to install [Dapr](https://docs.dapr.io/getting-started/install-dapr-selfhost/) and [Go 1.15+](https://golang.org/doc/install). - -## OpenFunction Context Function - -- Bindings - - [example](bindings) - -- Pubsub - - [example](pubsub) - - diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go deleted file mode 100644 index 20b3c0f..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.BindingsOutput); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go deleted file mode 100644 index d2fc094..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "io" - "log" - "net/http" -) - -func echo(w http.ResponseWriter, req *http.Request) { - content, err := io.ReadAll(req.Body) - if err != nil { - w.WriteHeader(500) - return - } - log.Println("Receive a message:") - log.Println(string(content)) -} - -func main() { - - http.HandleFunc("/echo", echo) - - err := http.ListenAndServe(":7489", nil) - if err != nil { - return - } -} diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go deleted file mode 100644 index ba85476..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go +++ /dev/null @@ -1,24 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsOutput(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - var greeting []byte - if in != nil { - log.Printf("binding - Data: %s", in) - greeting = in - } else { - log.Print("binding - Data: Received") - greeting = []byte("Hello") - } - - err := ctx.SendTo(greeting, "echo") - if err != nil { - log.Printf("Error: %v\n", err) - return ctx.ReturnWithInternalError() - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go deleted file mode 100644 index 5e1486a..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.BindingsNoOutput); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go deleted file mode 100644 index 1e37b47..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go +++ /dev/null @@ -1,15 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsNoOutput(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - if in != nil { - log.Printf("binding - Data: %s", in) - } else { - log.Print("binding - Data: Received") - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/components/bindings.yaml b/v0.4.0/functions-framework/golang/OpenFuncAsync/components/bindings.yaml deleted file mode 100644 index f120b3d..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/components/bindings.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: echo -spec: - type: bindings.http - version: v1 - metadata: - - name: url - value: http://localhost:7489 diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/components/cron.yaml b/v0.4.0/functions-framework/golang/OpenFuncAsync/components/cron.yaml deleted file mode 100644 index bd9b4be..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/components/cron.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: cron_input -spec: - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml b/v0.4.0/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml deleted file mode 100644 index 94f938a..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: msg -spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: localhost:6379 - - name: redisPassword - value: "" diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/components/statestore.yaml b/v0.4.0/functions-framework/golang/OpenFuncAsync/components/statestore.yaml deleted file mode 100644 index 18cba84..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/components/statestore.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: statestore -spec: - type: state.redis - version: v1 - metadata: - - name: redisHost - value: localhost:6379 - - name: redisPassword - value: "" - - name: actorStateStore - value: "true" diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go deleted file mode 100644 index 13dee20..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.Producer); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go deleted file mode 100644 index 9eacf41..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go +++ /dev/null @@ -1,189 +0,0 @@ -// An example, referenced from https://github.com/mchmarny/dapr-demos/tree/master/autoscaling-on-queue - -package userfunction - -import ( - "crypto/sha256" - "encoding/json" - "fmt" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "github.com/google/uuid" - "log" - "math/rand" - "os" - "os/signal" - "strconv" - "strings" - "sync" - "syscall" - "time" -) - -const ( - chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" -) - -var ( - logger = log.New(os.Stdout, "", 0) - outputName = getEnvVar("OUTPUT_NAME", "pub") - numOfPublishers = getEnvIntOrFail("NUMBER_OF_PUBLISHERS", "1") - publishFrequency = getEnvDurationOrFail("PUBLISHERS_FREQ", "1s") - publishDelay = getEnvDurationOrFail("PUBLISHERS_DELAY", "10s") - logFrequency = getEnvDurationOrFail("LOG_FREQ", "3s") - publishToConsole = getEnvBoolOrFail("PUBLISH_TO_CONSOLE", "false") -) - -func Producer(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - if numOfPublishers < 1 { - numOfPublishers = 1 - } - logger.Printf("subscription name: %s", outputName) - logger.Printf("number of publishers: %d", numOfPublishers) - logger.Printf("publish frequency: %v", publishFrequency) - logger.Printf("log frequency: %v", logFrequency) - logger.Printf("publish delay: %v", publishDelay) - - // handle signals - stop := make(chan os.Signal) - signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) - - resultCh := make(chan bool, 100) - stopCh := make(chan struct{}) - - go func() { - <-stop - close(stopCh) - }() - - // print results - go monitor(resultCh, stopCh) - - // start producing - for i := 1; i <= numOfPublishers; i++ { - go publish(ctx, i, resultCh, stopCh) - } - - return ctx.ReturnWithSuccess() -} - -func monitor(resultCh <-chan bool, stopCh <-chan struct{}) { - var mux sync.Mutex - var successCounter int64 = 0 - var errorCounter int64 = 0 - startTime := time.Now() - tickerCh := time.NewTicker(logFrequency).C - for { - select { - case r := <-resultCh: - mux.Lock() - if r { - successCounter++ - } else { - errorCounter++ - } - mux.Unlock() - case <-tickerCh: - var avg float64 = 0 - if successCounter > 0 { - avg = float64(successCounter) / time.Since(startTime).Seconds() - } - logger.Printf("%10d published, %3.0f/sec, %3d errors", successCounter, avg, errorCounter) - case <-stopCh: - os.Exit(0) - } - } -} - -func publish(ctx *ofctx.OpenFunctionContext, index int, resultCh chan<- bool, stopCh <-chan struct{}) { - delayCh := time.NewTicker(publishDelay).C - <-delayCh - - tickerCh := time.NewTicker(publishFrequency).C - for { - select { - case <-stopCh: - return - case <-tickerCh: - d := getEventData(index) - if publishToConsole { - logger.Printf("%s", d) - resultCh <- true - continue - } - if _, err := ctx.Send(outputName, d); err != nil { - logger.Printf("send error, %v", err) - resultCh <- false - } else { - resultCh <- true - } - } - } -} - -func getEventData(index int) []byte { - r := requestContent{ - ID: fmt.Sprintf("p%d-%s", index, uuid.New().String()), - Data: []byte(getData(256)), - Time: time.Now().String(), - } - - // hash the entire message - inSha := sha256.Sum256(r.Data) - r.Sha = string(inSha[:]) - - b, err := json.Marshal(r) - if err != nil { - logger.Fatalf("error generating request: %v", err) - } - return b -} - -func getData(length int) string { - seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) - b := make([]byte, length) - for i := range b { - b[i] = chars[seededRand.Intn(len(chars))] - } - return string(b) -} - -type requestContent struct { - ID string `json:"id"` - Data []byte `json:"data"` - Sha string `json:"sha"` - Time string `json:"time"` -} - -func getEnvVar(key, fallbackValue string) string { - if val, ok := os.LookupEnv(key); ok { - return strings.TrimSpace(val) - } - return fallbackValue -} - -func getEnvIntOrFail(key, fallbackValue string) int { - s := getEnvVar(key, fallbackValue) - v, err := strconv.Atoi(s) - if err != nil { - logger.Fatalf("invalid number variable: %s - %v", s, err) - } - return v -} - -func getEnvDurationOrFail(key, fallbackValue string) time.Duration { - s := getEnvVar(key, fallbackValue) - v, err := time.ParseDuration(s) - if err != nil { - logger.Fatalf("invalid duration variable: %s - %v", s, err) - } - return v -} - -func getEnvBoolOrFail(key, fallbackValue string) bool { - s := getEnvVar(key, fallbackValue) - v, err := strconv.ParseBool(s) - if err != nil { - logger.Fatalf("invalid bool variable: %s - %v", s, err) - } - return v -} diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go deleted file mode 100644 index 84b944f..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.Subscriber); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go b/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go deleted file mode 100644 index a2b2133..0000000 --- a/v0.4.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go +++ /dev/null @@ -1,11 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func Subscriber(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - log.Printf("event - Data: %s", in) - return ctx.ReturnWithSuccess() -} diff --git a/v0.4.0/functions-framework/nodejs/Knative/README.md b/v0.4.0/functions-framework/nodejs/Knative/README.md deleted file mode 100644 index cb3c00c..0000000 --- a/v0.4.0/functions-framework/nodejs/Knative/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Knative Runtime examples - -- [HTTP request](helloworld) - -- [Cloudevent](cloudevent) - diff --git a/v0.4.0/functions-framework/nodejs/Knative/cloudevent/README.md b/v0.4.0/functions-framework/nodejs/Knative/cloudevent/README.md deleted file mode 100644 index 5cd75e8..0000000 --- a/v0.4.0/functions-framework/nodejs/Knative/cloudevent/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# Cloudevent - -The functions framework can unmarshall incoming [CloudEvents](http://cloudevents.io/) payloads to a `cloudevent` object. Note that your function must use the `cloudevent-style` function signature. - -```js -exports.helloCloudEvents = (cloudevent) => { - return cloudevent -} -``` - -Your `package.json` - -```json - "scripts": { - "start": "functions-framework --target=helloCloudEvents --source=cloudevent" - } -``` - -**A binary one** - -See [payload content](https://github.com/OpenFunction/functions-framework-nodejs/blob/main/mock/payload/binary.json) - -```bash -$ curl -X POST \ - -d'@../mock/payload/binary.json' \ - -H'Content-Type:application/json' \ - -H'ce-specversion:1.0' \ - -H'ce-type:com.github.pull.create' \ - -H'ce-source:https://github.com/cloudevents/spec/pull/123' \ - -H'ce-id:45c83279-c8a1-4db6-a703-b3768db93887' \ - -H'ce-time:2019-11-06T11:17:00Z' \ - -H'ce-myextension:extension value' \ - http://localhost:8080/ -# The response is -{ - "datacontenttype": "application/json", - "data": { - "runtime": "cloudevent" - }, - "specversion": "1.0", - "type": "com.github.pull.create", - "source": "https://github.com/cloudevents/spec/pull/123", - "id": "45c83279-c8a1-4db6-a703-b3768db93887", - "time": "2019-11-06T11:17:00Z", - "myextension": "extension value" -} -``` - -**A structed one** - -See [payload content](https://github.com/OpenFunction/functions-framework-nodejs/blob/main/mock/payload/structured.json) - -```bash -$ curl -X POST \ - -d'@../mock/payload/structured.json' \ - -H'Content-Type:application/cloudevents+json' \ - http://localhost:8080/ -# The response is -{ - "specversion": "1.0", - "type": "com.github.pull.create", - "source": "https://github.com/cloudevents/spec/pull/123", - "id": "b25e2717-a470-45a0-8231-985a99aa9416", - "time": "2019-11-06T11:08:00Z", - "datacontenttype": "application/json", - "data": { - "framework": "openfunction" - } -} -``` - diff --git a/v0.4.0/functions-framework/nodejs/Knative/cloudevent/index.js b/v0.4.0/functions-framework/nodejs/Knative/cloudevent/index.js deleted file mode 100644 index 3a7dceb..0000000 --- a/v0.4.0/functions-framework/nodejs/Knative/cloudevent/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloCloudEvents = (cloudevent) => { - return cloudevent -} \ No newline at end of file diff --git a/v0.4.0/functions-framework/nodejs/Knative/cloudevent/package.json b/v0.4.0/functions-framework/nodejs/Knative/cloudevent/package.json deleted file mode 100644 index 705e839..0000000 --- a/v0.4.0/functions-framework/nodejs/Knative/cloudevent/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "cloudevent", - "version": "1.0.0", - "description": "The functions framework can unmarshall incoming [CloudEvents](http://cloudevents.io/) payloads to a `cloudevent` object. Note that your function must use the `cloudevent-style` function signature.", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloCloudEvents --source=cloudevent" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.4.0/functions-framework/nodejs/Knative/helloworld/README.md b/v0.4.0/functions-framework/nodejs/Knative/helloworld/README.md deleted file mode 100644 index 5857bad..0000000 --- a/v0.4.0/functions-framework/nodejs/Knative/helloworld/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Hello World Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = (req, res) => { - res.send('Hello, World'); - }; - ``` - -3. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -4. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --source http" - } - ``` - -5. Use `npm start` to start the built-in local development server: - - ```bash - $ npm start - ... - The functionModulePath is: /.../.../index.js - Openfunction functions framework listening at http://localhost:8080 - ``` - -6. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl localhost:8080 - # Output: Hello, World - ``` diff --git a/v0.4.0/functions-framework/nodejs/Knative/helloworld/index.js b/v0.4.0/functions-framework/nodejs/Knative/helloworld/index.js deleted file mode 100644 index 64f3c6f..0000000 --- a/v0.4.0/functions-framework/nodejs/Knative/helloworld/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloWorld = (req, res) => { - res.send('Hello, World'); -}; \ No newline at end of file diff --git a/v0.4.0/functions-framework/nodejs/Knative/helloworld/package.json b/v0.4.0/functions-framework/nodejs/Knative/helloworld/package.json deleted file mode 100644 index c338493..0000000 --- a/v0.4.0/functions-framework/nodejs/Knative/helloworld/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "helloworld", - "version": "1.0.0", - "description": "1. Create a `package.json` file using `npm init`:", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --source http" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/README.md b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/README.md deleted file mode 100644 index 7de4247..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# OpenFuncAsync Runtime examples - -- [HTTP Request](helloworld) - -- [Bindings](bindings) - -- [Pubsub](pubsub) diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/README.md b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/README.md deleted file mode 100644 index 1894e4f..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# BIndings Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data - } - ``` - -3. Add your `config.json` - - ```json - { - "input": { - "name": "sample-topic", - "uri": "test", - "params": { - "type": "bindings" - } - }, - "outputs": { - "sample-topic": { - "uri": "test", - "params": { - "type": "bindings", - "operation": "create" - } - } - } - } - ``` - -4. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -5. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --port 4000" - } - ``` - -6. Note that if we want to test it locally, we need a Dapr config file: - - ```yaml - apiVersion: dapr.io/v1alpha1 - kind: Component - metadata: - name: sample-topic - spec: - type: bindings.kafka - version: v1 - metadata: - # Kafka broker connection setting - - name: brokers - value: localhost:9092 - # consumer configuration: topic and consumer group - - name: topics - value: sample - - name: consumerGroup - value: group1 - # publisher configuration: topic - - name: publishTopic - value: sample - - name: authRequired - value: "false" - ``` - -7. Use `dapr` to run `npm start` and start the built-in local development server: - - ```bash - $ dapr run --app-id hello-world --app-port 4000 --dapr-http-port 3500 --components-path ./bindings.yaml npm start - ``` - -8. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl -X POST \ - -d'{"data": "hello"}' \ - -H'Content-Type:application/json' \ - http://localhost:4000/test - ``` - -9. And the output will be like: - - ```shell - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:31 +0000] "POST /test HTTP/1.1" 200 - "-" "curl/7.58.0" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:36 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:41 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:46 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - ``` - - - diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml deleted file mode 100644 index 3aa06a7..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: sample-topic -spec: - type: bindings.kafka - version: v1 - metadata: - # Kafka broker connection setting - - name: brokers - value: localhost:9092 - # consumer configuration: topic and consumer group - - name: topics - value: sample - - name: consumerGroup - value: group1 - # publisher configuration: topic - - name: publishTopic - value: sample - - name: authRequired - value: "false" \ No newline at end of file diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/config.json b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/config.json deleted file mode 100644 index ebe6373..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/config.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "input": { - "name": "sample-topic", - "uri": "test", - "params": { - "type": "bindings" - } - }, - "outputs": { - "sample-topic": { - "uri": "test", - "params": { - "type": "bindings", - "operation": "create" - } - } - } -} \ No newline at end of file diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/index.js b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/index.js deleted file mode 100644 index 8bda8c1..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/index.js +++ /dev/null @@ -1,6 +0,0 @@ -exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data -} \ No newline at end of file diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/package.json b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/package.json deleted file mode 100644 index f9e6340..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/bindings/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "bindings", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --port 4000" - }, - "author": "", - "license": "ISC" -} diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md deleted file mode 100644 index 8f57ff1..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# Hello World Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - /** - * Send {"data": "Hello, World"} - * @param data - data is the request body contents, which should be a json object - */ - exports.helloWorld = (data) => { - return 'Hello, World'; - }; - ``` - -3. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -4. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld" - } - ``` - -5. Use `npm start` to start the built-in local development server: - - ```bash - $ npm start - ... - The functionModulePath is: /.../.../index.js - Openfunction functions framework listening at http://localhost:8080 - ``` - -6. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl localhost:8080 - # Output: Hello, World - ``` diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js deleted file mode 100644 index 7d7ab84..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Send {"data": "Hello, World"} - * @param data - data is the request body contents, which should be a json object - */ - exports.helloWorld = (data) => { - return 'Hello, World'; -}; \ No newline at end of file diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json deleted file mode 100644 index d3cb74c..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "helloworld", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index ac0cc4d..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# Pub/Sub Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data - } - ``` - -3. Add your `config.json` - - ```json - { - "input": { - "name": "pubsub", - "uri": "test", - "params": { - "type": "pubsub" - } - }, - "outputs": { - "pubsub": { - "uri": "test", - "params": { - "type": "pubsub" - } - } - } - } - ``` - -4. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -5. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --port 4000" - } - ``` - -6. Note that if we want to test it locally, we need a Dapr config file: - - ```yaml - apiVersion: dapr.io/v1alpha1 - kind: Component - metadata: - name: pubsub # midlleware component name - spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: ${YOUR_REDIS_ADDRESS} - - name: redisPassword - value: "" - ``` - -7. Use `dapr` to run `npm start` and start the built-in local development server: - - ```bash - $ dapr run --app-id hello-world --app-port 4000 --dapr-http-port 3500 --components-path ./pubsub.yaml npm start - ``` - -8. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl -X POST \ - -d'@../mock/payload/structured.json' \ - -H'Content-Type:application/cloudevents+json' \ - http://localhost:4000/test - ``` - -9. The `structured.json` is like below: (note that in dapr, pubsub mode respects the cloud event style) - - ```json - { - "specversion":"1.0", - "type":"com.github.pull.create", - "source":"https://github.com/cloudevents/spec/pull/123", - "id":"b25e2717-a470-45a0-8231-985a99aa9416", - "time":"2019-11-06T11:08:00Z", - "datacontenttype":"application/json", - "data":{ - "framework":"openfunction" - } - } - ``` - -10. And the output will be like: - - ```shell - == APP == { framework: 'openfunction' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:31 +0000] "POST /test HTTP/1.1" 200 - "-" "curl/7.58.0" - == APP == { data: { framework: 'openfunction' } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:36 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: { data: { framework: 'openfunction' } } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:41 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: { data: { data: [Object] } } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:46 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - ``` - - - diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json deleted file mode 100644 index 64336f8..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "input": { - "name": "pubsub", - "uri": "test", - "params": { - "type": "pubsub" - } - }, - "outputs": { - "pubsub": { - "uri": "test", - "params": { - "type": "pubsub" - } - } - } -} \ No newline at end of file diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js deleted file mode 100644 index 8bda8c1..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js +++ /dev/null @@ -1,6 +0,0 @@ -exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data -} \ No newline at end of file diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json deleted file mode 100644 index 4637e47..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "pubsub", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --port 4000" - }, - "author": "", - "license": "ISC" -} diff --git a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml b/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml deleted file mode 100644 index f0ad8a3..0000000 --- a/v0.4.0/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: pubsub # midlleware component name -spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: ${YOUR_REDIS_ADDRESS} - - name: redisPassword - value: "" \ No newline at end of file diff --git a/v0.4.0/functions/Knative/azure-func-go/.funcignore b/v0.4.0/functions/Knative/azure-func-go/.funcignore deleted file mode 100644 index 414df2f..0000000 --- a/v0.4.0/functions/Knative/azure-func-go/.funcignore +++ /dev/null @@ -1,4 +0,0 @@ -.git* -.vscode -local.settings.json -test \ No newline at end of file diff --git a/v0.4.0/functions/Knative/azure-func-go/HttpExample/function.json b/v0.4.0/functions/Knative/azure-func-go/HttpExample/function.json deleted file mode 100644 index 7eb1f8f..0000000 --- a/v0.4.0/functions/Knative/azure-func-go/HttpExample/function.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post" - ] - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] -} diff --git a/v0.4.0/functions/Knative/azure-func-go/handler b/v0.4.0/functions/Knative/azure-func-go/handler deleted file mode 100755 index 78a20b4..0000000 Binary files a/v0.4.0/functions/Knative/azure-func-go/handler and /dev/null differ diff --git a/v0.4.0/functions/Knative/azure-func-go/handler.go b/v0.4.0/functions/Knative/azure-func-go/handler.go deleted file mode 100644 index 6637d44..0000000 --- a/v0.4.0/functions/Knative/azure-func-go/handler.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - "os" -) - -func helloHandler(w http.ResponseWriter, r *http.Request) { - message := "This HTTP triggered function executed successfully. Pass a name in the query string for a personalized response.\n" - name := r.URL.Query().Get("name") - if name != "" { - message = fmt.Sprintf("Hello, %s. This HTTP triggered function executed successfully.\n", name) - } - fmt.Fprint(w, message) -} - -func main() { - listenAddr := ":8080" - if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok { - listenAddr = ":" + val - } - http.HandleFunc("/api/HttpExample", helloHandler) - log.Printf("About to listen on %s. Go to https://127.0.0.1%s/", listenAddr, listenAddr) - log.Fatal(http.ListenAndServe(listenAddr, nil)) -} \ No newline at end of file diff --git a/v0.4.0/functions/Knative/azure-func-go/host.json b/v0.4.0/functions/Knative/azure-func-go/host.json deleted file mode 100644 index 20a2cdc..0000000 --- a/v0.4.0/functions/Knative/azure-func-go/host.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } - }, - "extensionBundle": { - "id": "Microsoft.Azure.Functions.ExtensionBundle", - "version": "[1.*, 2.0.0)" - }, - "customHandler": { - "description": { - "defaultExecutablePath": "handler", - "workingDirectory": "", - "arguments": [] - }, - "enableForwardingHttpRequest": true - } -} diff --git a/v0.4.0/functions/Knative/azure-func-go/proxies.json b/v0.4.0/functions/Knative/azure-func-go/proxies.json deleted file mode 100644 index b385252..0000000 --- a/v0.4.0/functions/Knative/azure-func-go/proxies.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/proxies", - "proxies": {} -} diff --git a/v0.4.0/functions/Knative/hello-world-dotnet/Program.cs b/v0.4.0/functions/Knative/hello-world-dotnet/Program.cs deleted file mode 100644 index 00618b6..0000000 --- a/v0.4.0/functions/Knative/hello-world-dotnet/Program.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -using System; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; - -namespace helloworld -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) - { - string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; - string url = String.Concat("http://0.0.0.0:", port); - - return Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup().UseUrls(url); - }); - } - } -} diff --git a/v0.4.0/functions/Knative/hello-world-dotnet/Startup.cs b/v0.4.0/functions/Knative/hello-world-dotnet/Startup.cs deleted file mode 100644 index d81a8cb..0000000 --- a/v0.4.0/functions/Knative/hello-world-dotnet/Startup.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace helloworld -{ - public class Startup - { - public void ConfigureServices(IServiceCollection services) - { - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - app.UseRouting(); - - app.UseEndpoints(endpoints => - { - endpoints.MapGet("/", async context => - { - await context.Response.WriteAsync("hello, world"); - }); - }); - } - } -} diff --git a/v0.4.0/functions/Knative/hello-world-dotnet/helloworld.csproj b/v0.4.0/functions/Knative/hello-world-dotnet/helloworld.csproj deleted file mode 100644 index f9f2057..0000000 --- a/v0.4.0/functions/Knative/hello-world-dotnet/helloworld.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - netcoreapp3.1 - helloworld - - - diff --git a/v0.4.0/functions/Knative/hello-world-go/README.md b/v0.4.0/functions/Knative/hello-world-go/README.md deleted file mode 100644 index 5d4b6d7..0000000 --- a/v0.4.0/functions/Knative/hello-world-go/README.md +++ /dev/null @@ -1,100 +0,0 @@ -# Sample Function Go - -## Prerequisites - -### OpenFunction - -You can refer to the [Installation Guide](https://github.com/OpenFunction/OpenFunction#install-openfunction) to setup OpenFunction. - -## Deployment - -1. Creating a secret - -Generate a secret to access your container registry, such as one on [Docker Hub](https://hub.docker.com/) or [Quay.io](https://quay.io/). -You can create this secret by editing the ``REGISTRY_SERVER``, ``REGISTRY_USER`` and ``REGISTRY_PASSWORD`` fields in following command, and then run it. - - ```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 - ``` - -2. Creating functions - - For sample function below, modify the ``spec.image`` field in ``function-sample.yaml`` to your own container registry address: - - ```yaml - apiVersion: core.openfunction.io/v1alpha2 - kind: Function - metadata: - name: function-sample - spec: - image: "/sample-go-func:latest" - ``` - - Use the following command to create this Function: - - ```shell - kubectl apply -f function-sample.yaml - ``` - -3. Result observation - - You can observe the process of a function with the following command: - - ```shell - kubectl get functions.core.openfunction.io - - NAME AGE - function-sample 5s - ``` - - You can also observe the process of a builder in the [Tekton Dashboard](https://tekton.dev/docs/dashboard/). - - Finally, you can observe the final state of the function workload in the Serving: - - ```shell - kubectl get servings.core.openfunction.io - - NAME AGE - function-sample-serving 15s - ``` - - You can now find out the service entry of the function with the following command: - - ```shell - kubectl get ksvc - - NAME URL LATESTCREATED LATESTREADY READY REASON - function-sample-serving-ksvc http://function-sample-serving-ksvc.default..sslip.io function-sample-serving-ksvc-00001 function-sample-serving-ksvc-00001 True - ``` - - Or get the service address directly with the following command: - - > where` `indicates the external address of your gateway service. - > - > You can do a simple configuration to use the node ip as the `` as follows (Assuming you are using Kourier as network layer of Knative). Where `1.2.3.4` can be replaced by your node ip. - > - > ```shell - > kubectl patch svc -n kourier-system kourier \ - > -p '{"spec": {"type": "LoadBalancer", "externalIPs": ["1.2.3.4"]}}' - > - > kubectl patch configmap/config-domain -n knative-serving \ - > --type merge --patch '{"data":{"1.2.3.4.sslip.io":""}}' - > ``` - - ```shell - kubectl get ksvc function-sample-serving-ksvc -o jsonpath={.status.url} - - http://function-sample-serving-ksvc.default..sslip.io - ``` - - Access the above service address via commands such as ``curl``: - - ```shell - curl http://function-sample-serving-ksvc.default..sslip.io - - Hello, World! - ``` \ No newline at end of file diff --git a/v0.4.0/functions/Knative/hello-world-go/go.mod b/v0.4.0/functions/Knative/hello-world-go/go.mod deleted file mode 100644 index adf50d7..0000000 --- a/v0.4.0/functions/Knative/hello-world-go/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module example.com/hello - -go 1.15 diff --git a/v0.4.0/functions/Knative/hello-world-go/hello.go b/v0.4.0/functions/Knative/hello-world-go/hello.go deleted file mode 100644 index 6db3585..0000000 --- a/v0.4.0/functions/Knative/hello-world-go/hello.go +++ /dev/null @@ -1,11 +0,0 @@ -package hello - -import ( - "fmt" - "net/http" -) - -// HelloWorld writes "Hello, World!" to the HTTP response. -func HelloWorld(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "Hello, World!\n") -} diff --git a/v0.4.0/functions/Knative/hello-world-java/pom.xml b/v0.4.0/functions/Knative/hello-world-java/pom.xml deleted file mode 100644 index bc93ba7..0000000 --- a/v0.4.0/functions/Knative/hello-world-java/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - 4.0.0 - - com.openfunction - java-sample - 1.0.0-SNAPSHOT - - 11 - 11 - - - - - - com.google.cloud.functions - functions-framework-api - 1.0.4 - provided - - - - - - - - com.google.cloud.functions - function-maven-plugin - 0.9.7 - - com.openfunction.HelloWorld - - - - - diff --git a/v0.4.0/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java b/v0.4.0/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java deleted file mode 100644 index 02b2c43..0000000 --- a/v0.4.0/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.openfunction; - -import com.google.cloud.functions.HttpFunction; -import com.google.cloud.functions.HttpRequest; -import com.google.cloud.functions.HttpResponse; -import java.io.BufferedWriter; -import java.io.IOException; - -public class HelloWorld implements HttpFunction { - // Simple function to return "Hello World" - @Override - public void service(HttpRequest request, HttpResponse response) - throws IOException { - BufferedWriter writer = response.getWriter(); - writer.write("Hello World!"); - } -} diff --git a/v0.4.0/functions/Knative/hello-world-node/index.js b/v0.4.0/functions/Knative/hello-world-node/index.js deleted file mode 100644 index 26ef1ae..0000000 --- a/v0.4.0/functions/Knative/hello-world-node/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloWorld = (req, res) => { - res.send('hello, world'); -}; diff --git a/v0.4.0/functions/Knative/hello-world-python/main.py b/v0.4.0/functions/Knative/hello-world-python/main.py deleted file mode 100644 index 249f1b8..0000000 --- a/v0.4.0/functions/Knative/hello-world-python/main.py +++ /dev/null @@ -1,2 +0,0 @@ -def hello_world(request): - return "hello, world" diff --git a/v0.4.0/functions/Knative/hello-world-python/requirements.txt b/v0.4.0/functions/Knative/hello-world-python/requirements.txt deleted file mode 100644 index bc9616b..0000000 --- a/v0.4.0/functions/Knative/hello-world-python/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -functions-framework==1.4.3 \ No newline at end of file diff --git a/v0.4.0/functions/Knative/logs-handler-function/LogsHandler.go b/v0.4.0/functions/Knative/logs-handler-function/LogsHandler.go deleted file mode 100644 index ebbf8c0..0000000 --- a/v0.4.0/functions/Knative/logs-handler-function/LogsHandler.go +++ /dev/null @@ -1,96 +0,0 @@ -package logshandler - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net/http" - "regexp" - "time" - - alert "github.com/prometheus/alertmanager/template" -) - -const ( - HTTPCodeNotFound = "404" - Namespace = "demo-project" - PodName = "wordpress-v1-[A-Za-z0-9]{5,15}-[A-Za-z0-9]{3,10}" - AlertName = "404 Request" - Severity = "warning" - NotificationManagerAddress = "http://notification-manager-svc.kubesphere-monitoring-system.svc.cluster.local:19093/api/v2/alerts" -) - -func LogsHandler(w http.ResponseWriter, r *http.Request) { - reqBody, err := ioutil.ReadAll(r.Body) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Get request body failed") - return - } - content := string(reqBody) - matchHTTPCode, _ := regexp.MatchString(fmt.Sprintf(" %s ", HTTPCodeNotFound), content) - matchNamespace, _ := regexp.MatchString(fmt.Sprintf("namespace_name\":\"%s", Namespace), content) - matchPodName := regexp.MustCompile(fmt.Sprintf(`(%s)`, PodName)).FindStringSubmatch(content) - - if matchHTTPCode && matchNamespace && matchPodName != nil { - log.Printf("Match log - Content: %s", content) - - match := regexp.MustCompile(`([A-Z]+) (/\S*) HTTP`).FindStringSubmatch(content) - if match == nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Cannot retrieve information") - return - } - path := match[len(match)-1] - method := match[len(match)-2] - podName := matchPodName[len(matchPodName)-1] - - notify := &alert.Data{ - Receiver: "notification_manager", - Status: "firing", - Alerts: alert.Alerts{}, - GroupLabels: alert.KV{"alertname": AlertName, "namespace": Namespace}, - CommonLabels: alert.KV{"alertname": AlertName, "namespace": Namespace, "severity": Severity}, - CommonAnnotations: alert.KV{}, - ExternalURL: "", - } - alt := alert.Alert{ - Status: "firing", - Labels: alert.KV{ - "alertname": AlertName, - "namespace": Namespace, - "severity": Severity, - "pod": podName, - "path": path, - "method": method, - }, - Annotations: alert.KV{}, - StartsAt: time.Now(), - EndsAt: time.Time{}, - GeneratorURL: "", - Fingerprint: "", - } - notify.Alerts = append(notify.Alerts, alt) - notifyBytes, _ := json.Marshal(notify) - - req, err := http.NewRequest("POST", NotificationManagerAddress, bytes.NewReader(notifyBytes)) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Failed to create request") - return - } - req.Header.Set("Content-Type", "application/json") - client := &http.Client{} - _, err = client.Do(req) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Failed to send request to notification manager") - return - } - - log.Printf("Send log to notification manager") - } - return -} diff --git a/v0.4.0/functions/Knative/logs-handler-function/go.mod b/v0.4.0/functions/Knative/logs-handler-function/go.mod deleted file mode 100644 index dbf3c35..0000000 --- a/v0.4.0/functions/Knative/logs-handler-function/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -module example.com/logshandler - -go 1.15 - -require ( - github.com/prometheus/alertmanager v0.22.2 -) diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go b/v0.4.0/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go deleted file mode 100644 index 1d885fa..0000000 --- a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go +++ /dev/null @@ -1,25 +0,0 @@ -package bindings - -import ( - "encoding/json" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsOutput(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - var greeting []byte - if in != nil { - log.Printf("binding - Data: %s", in) - greeting = in - } else { - log.Print("binding - Data: Received") - greeting, _ = json.Marshal(map[string]string{"message": "Hello"}) - } - - _, err := ctx.Send("sample", greeting) - if err != nil { - log.Printf("Error: %v\n", err) - return ctx.ReturnWithInternalError() - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/output/goapp.go b/v0.4.0/functions/OpenFuncAsync/bindings/with-output/output/goapp.go deleted file mode 100644 index e4d44fc..0000000 --- a/v0.4.0/functions/OpenFuncAsync/bindings/with-output/output/goapp.go +++ /dev/null @@ -1,22 +0,0 @@ -package bindings - -import ( - "encoding/json" - "fmt" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" -) - -func OutputTarget(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - var msg Message - err := json.Unmarshal(in, &msg) - if err != nil { - fmt.Println("error reading message from Kafka binding", err) - return ctx.ReturnWithInternalError() - } - fmt.Printf("message from Kafka '%s'\n", msg) - return ctx.ReturnWithSuccess() -} - -type Message struct { - Msg string `json:"message"` -} diff --git a/v0.4.0/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go b/v0.4.0/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go deleted file mode 100644 index 3ae795f..0000000 --- a/v0.4.0/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go +++ /dev/null @@ -1,15 +0,0 @@ -package bindings - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsNoOutput(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - if in != nil { - log.Printf("binding - Data: %s", in) - } else { - log.Print("binding - Data: Received") - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.4.0/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go b/v0.4.0/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go deleted file mode 100644 index 967ae51..0000000 --- a/v0.4.0/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go +++ /dev/null @@ -1,73 +0,0 @@ -package logs_handler_function - -import ( - "encoding/json" - "fmt" - "log" - "regexp" - "time" - - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - alert "github.com/prometheus/alertmanager/template" -) - -const ( - HTTPCodeNotFound = "404" - Namespace = "demo-project" - PodName = "wordpress-v1-[A-Za-z0-9]{5,15}-[A-Za-z0-9]{3,10}" - AlertName = "404 Request" - Severity = "warning" -) - -func LogsHandler(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - content := string(in) - matchHTTPCode, _ := regexp.MatchString(fmt.Sprintf(" %s ", HTTPCodeNotFound), content) - matchNamespace, _ := regexp.MatchString(fmt.Sprintf("namespace_name\":\"%s", Namespace), content) - matchPodName := regexp.MustCompile(fmt.Sprintf(`(%s)`, PodName)).FindStringSubmatch(content) - - if matchHTTPCode && matchNamespace && matchPodName != nil { - log.Printf("Match log - Content: %s", content) - - match := regexp.MustCompile(`([A-Z]+) (/\S*) HTTP`).FindStringSubmatch(content) - if match == nil { - return ctx.ReturnWithInternalError() - } - path := match[len(match)-1] - method := match[len(match)-2] - podName := matchPodName[len(matchPodName)-1] - - notify := &alert.Data{ - Receiver: "notification_manager", - Status: "firing", - Alerts: alert.Alerts{}, - GroupLabels: alert.KV{"alertname": AlertName, "namespace": Namespace}, - CommonLabels: alert.KV{"alertname": AlertName, "namespace": Namespace, "severity": Severity}, - CommonAnnotations: alert.KV{}, - ExternalURL: "", - } - alt := alert.Alert{ - Status: "firing", - Labels: alert.KV{ - "alertname": AlertName, - "namespace": Namespace, - "severity": Severity, - "pod": podName, - "path": path, - "method": method, - }, - Annotations: alert.KV{}, - StartsAt: time.Now(), - EndsAt: time.Time{}, - GeneratorURL: "", - Fingerprint: "", - } - notify.Alerts = append(notify.Alerts, alt) - notifyBytes, _ := json.Marshal(notify) - - if _, err := ctx.Send("notify", notifyBytes); err != nil { - panic(err) - } - log.Printf("Send log to notification manager.") - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.4.0/functions/OpenFuncAsync/logs-handler-function/README.md b/v0.4.0/functions/OpenFuncAsync/logs-handler-function/README.md deleted file mode 100644 index a172fef..0000000 --- a/v0.4.0/functions/OpenFuncAsync/logs-handler-function/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# Function Logs Handler - -For a detailed description of this function example, you can refer to the following blogs: - -[OpenFunction 应用系列之一: 以 Serverless 的方式实现 Kubernetes 日志告警](https://kubesphere.io/zh/blogs/serverless-way-for-kubernetes-log-alert/) - -or - -[Serverless Use Case: Elastic Kubernetes Log Alerts with OpenFunction and Kafka](https://kubesphere.io/blogs/serverless-way-for-kubernetes-log-alert/) - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -Create logs handler function: - -```shell -kubectl apply -f logs-handler-function.yaml -``` - -The logs handler function is then driven by messages from the logs topic in Kafka. \ No newline at end of file diff --git a/v0.4.0/functions/OpenFuncAsync/pubsub/producer/producer.go b/v0.4.0/functions/OpenFuncAsync/pubsub/producer/producer.go deleted file mode 100644 index 515c829..0000000 --- a/v0.4.0/functions/OpenFuncAsync/pubsub/producer/producer.go +++ /dev/null @@ -1,189 +0,0 @@ -// An example, referenced from https://github.com/mchmarny/dapr-demos/tree/master/autoscaling-on-queue - -package producer - -import ( - "crypto/sha256" - "encoding/json" - "fmt" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "github.com/google/uuid" - "log" - "math/rand" - "os" - "os/signal" - "strconv" - "strings" - "sync" - "syscall" - "time" -) - -const ( - chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" -) - -var ( - logger = log.New(os.Stdout, "", 0) - outputName = getEnvVar("OUTPUT_NAME", "autoscaling") - numOfPublishers = getEnvIntOrFail("NUMBER_OF_PUBLISHERS", "1") - publishFrequency = getEnvDurationOrFail("PUBLISHERS_FREQ", "1s") - publishDelay = getEnvDurationOrFail("PUBLISHERS_DELAY", "10s") - logFrequency = getEnvDurationOrFail("LOG_FREQ", "3s") - publishToConsole = getEnvBoolOrFail("PUBLISH_TO_CONSOLE", "false") -) - -func Producer(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - if numOfPublishers < 1 { - numOfPublishers = 1 - } - logger.Printf("subscription name: %s", outputName) - logger.Printf("number of publishers: %d", numOfPublishers) - logger.Printf("publish frequency: %v", publishFrequency) - logger.Printf("log frequency: %v", logFrequency) - logger.Printf("publish delay: %v", publishDelay) - - // handle signals - stop := make(chan os.Signal) - signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) - - resultCh := make(chan bool, 100) - stopCh := make(chan struct{}) - - go func() { - <-stop - close(stopCh) - }() - - // print results - go monitor(resultCh, stopCh) - - // start producing - for i := 1; i <= numOfPublishers; i++ { - go publish(ctx, i, resultCh, stopCh) - } - - return ctx.ReturnWithSuccess() -} - -func monitor(resultCh <-chan bool, stopCh <-chan struct{}) { - var mux sync.Mutex - var successCounter int64 = 0 - var errorCounter int64 = 0 - startTime := time.Now() - tickerCh := time.NewTicker(logFrequency).C - for { - select { - case r := <-resultCh: - mux.Lock() - if r { - successCounter++ - } else { - errorCounter++ - } - mux.Unlock() - case <-tickerCh: - var avg float64 = 0 - if successCounter > 0 { - avg = float64(successCounter) / time.Since(startTime).Seconds() - } - logger.Printf("%10d published, %3.0f/sec, %3d errors", successCounter, avg, errorCounter) - case <-stopCh: - os.Exit(0) - } - } -} - -func publish(ctx *ofctx.OpenFunctionContext, index int, resultCh chan<- bool, stopCh <-chan struct{}) { - delayCh := time.NewTicker(publishDelay).C - <-delayCh - - tickerCh := time.NewTicker(publishFrequency).C - for { - select { - case <-stopCh: - return - case <-tickerCh: - d := getEventData(index) - if publishToConsole { - logger.Printf("%s", d) - resultCh <- true - continue - } - if _, err := ctx.Send(outputName, d); err != nil { - logger.Printf("send error, %v", err) - resultCh <- false - } else { - resultCh <- true - } - } - } -} - -func getEventData(index int) []byte { - r := requestContent{ - ID: fmt.Sprintf("p%d-%s", index, uuid.New().String()), - Data: []byte(getData(256)), - Time: time.Now().String(), - } - - // hash the entire message - inSha := sha256.Sum256(r.Data) - r.Sha = string(inSha[:]) - - b, err := json.Marshal(r) - if err != nil { - logger.Fatalf("error generating request: %v", err) - } - return b -} - -func getData(length int) string { - seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) - b := make([]byte, length) - for i := range b { - b[i] = chars[seededRand.Intn(len(chars))] - } - return string(b) -} - -type requestContent struct { - ID string `json:"id"` - Data []byte `json:"data"` - Sha string `json:"sha"` - Time string `json:"time"` -} - -func getEnvVar(key, fallbackValue string) string { - if val, ok := os.LookupEnv(key); ok { - return strings.TrimSpace(val) - } - return fallbackValue -} - -func getEnvIntOrFail(key, fallbackValue string) int { - s := getEnvVar(key, fallbackValue) - v, err := strconv.Atoi(s) - if err != nil { - logger.Fatalf("invalid number variable: %s - %v", s, err) - } - return v -} - -func getEnvDurationOrFail(key, fallbackValue string) time.Duration { - s := getEnvVar(key, fallbackValue) - v, err := time.ParseDuration(s) - if err != nil { - logger.Fatalf("invalid duration variable: %s - %v", s, err) - } - return v -} - -func getEnvBoolOrFail(key, fallbackValue string) bool { - s := getEnvVar(key, fallbackValue) - v, err := strconv.ParseBool(s) - if err != nil { - logger.Fatalf("invalid bool variable: %s - %v", s, err) - } - return v -} diff --git a/v0.4.0/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go b/v0.4.0/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go deleted file mode 100644 index b609fc4..0000000 --- a/v0.4.0/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go +++ /dev/null @@ -1,11 +0,0 @@ -package subscriber - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func Subscriber(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - log.Printf("event - Data: %s", in) - return ctx.ReturnWithSuccess() -} diff --git a/v0.5.0/apps/buildah/function-buildah.yaml b/v0.5.0/apps/buildah/function-buildah.yaml deleted file mode 100644 index dffa49f..0000000 --- a/v0.5.0/apps/buildah/function-buildah.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: function-buildah -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-buildah-go:v0.5.0" - imageCredentials: - name: push-secret - #port: 8080 # default to 8080 - build: - builder: openfunction/buildah:v1.23.1 - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/apps/with-dockerfile" - shipwright: - strategy: - name: buildah - kind: ClusterBuildStrategy - serving: - runtime: Knative diff --git a/v0.5.0/apps/kaniko/function-kaniko.yaml b/v0.5.0/apps/kaniko/function-kaniko.yaml deleted file mode 100644 index eff9d9e..0000000 --- a/v0.5.0/apps/kaniko/function-kaniko.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: function-kaniko -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-kankio-go:v0.5.0" - imageCredentials: - name: push-secret - #port: 8080 # default to 8080 - build: - builder: openfunction/kaniko-executor:v1.7.0 - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/apps/with-dockerfile" - shipwright: - strategy: - name: kaniko - kind: ClusterBuildStrategy - serving: - runtime: Knative diff --git a/v0.5.0/apps/ko/function-ko.yaml b/v0.5.0/apps/ko/function-ko.yaml deleted file mode 100644 index dbe1630..0000000 --- a/v0.5.0/apps/ko/function-ko.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: function-ko -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-ko:v0.5.0" - imageCredentials: - name: push-secret - #port: 8080 # default to 8080 - build: - builder: golang:1.17 - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "latest/apps/with-dockerfile" - shipwright: - strategy: - name: ko - kind: ClusterBuildStrategy - serving: - runtime: Knative diff --git a/v0.5.0/apps/sample-apps-java-maven.yaml b/v0.5.0/apps/sample-apps-java-maven.yaml deleted file mode 100644 index 2361f6b..0000000 --- a/v0.5.0/apps/sample-apps-java-maven.yaml +++ /dev/null @@ -1,17 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: sample-app-java-maven -spec: - version: "v1.0.0" - image: "openfunction/buildpacks-sample-apps-java-maven:v0.5.0" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "cnbs/sample-builder:alpine" - srcRepo: - url: "https://github.com/buildpacks/samples.git" - sourceSubPath: "apps/java-maven" - serving: - runtime: "Knative" # default to Knative diff --git a/v0.5.0/apps/with-dockerfile/Dockerfile b/v0.5.0/apps/with-dockerfile/Dockerfile deleted file mode 100644 index 96857b6..0000000 --- a/v0.5.0/apps/with-dockerfile/Dockerfile +++ /dev/null @@ -1,16 +0,0 @@ -# From https://github.com/homeport/gonut/tree/master/assets/sample-apps/golang - -FROM golang:1.16 AS build - -COPY main.go . -ENV CGO_ENABLED=0 -RUN go build \ - -tags netgo \ - -ldflags "-s -w -extldflags '-static'" \ - -o /tmp/helloworld \ - main.go - -FROM scratch -COPY --from=build /tmp/helloworld ./helloworld -ENTRYPOINT [ "./helloworld" ] -EXPOSE 8080 diff --git a/v0.5.0/apps/with-dockerfile/go.mod b/v0.5.0/apps/with-dockerfile/go.mod deleted file mode 100644 index c0ecf8b..0000000 --- a/v0.5.0/apps/with-dockerfile/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module main - -go 1.17 diff --git a/v0.5.0/apps/with-dockerfile/main.go b/v0.5.0/apps/with-dockerfile/main.go deleted file mode 100644 index b5e659f..0000000 --- a/v0.5.0/apps/with-dockerfile/main.go +++ /dev/null @@ -1,26 +0,0 @@ -// From https://github.com/homeport/gonut/tree/master/assets/sample-apps/golang - -package main - -import ( - "fmt" - "net/http" - "os" - "runtime" - "strconv" -) - -func main() { - port := 8080 - if strValue, ok := os.LookupEnv("PORT"); ok { - if intValue, err := strconv.Atoi(strValue); err == nil { - port = intValue - } - } - - http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { - fmt.Fprintf(w, "Hello, World! I am using %s by the way.", runtime.Version()) - }) - - http.ListenAndServe(fmt.Sprintf(":%d", port), nil) -} diff --git a/v0.5.0/functions-framework/README.md b/v0.5.0/functions-framework/README.md deleted file mode 100644 index e9930b7..0000000 --- a/v0.5.0/functions-framework/README.md +++ /dev/null @@ -1,18 +0,0 @@ -# Functions framework demos - -This directory holds the validation demos for the [functions-framework](https://github.com/OpenFunction/functions-framework). - -Current supported list: - -- [functions-framework-go](https://github.com/OpenFunction/functions-framework-go); -- [functions-framework-nodejs](https://github.com/OpenFunction/functions-framework-nodejs). - -Depending on the type of runtime, the demos are divided into `Knative` and `OpenFuncAsync`, please check them separately: - -* Golang - * [Knative runtime demos](golang/Knative) - * [OpenFuncAsync runtime demos](golang/OpenFuncAsync) -* Nodejs - * [Knative runtime demos](nodejs/Knative) - * [OpenFuncAsync runtime demos](nodejs/OpenFuncAsync) - diff --git a/v0.5.0/functions-framework/golang/Knative/README.md b/v0.5.0/functions-framework/golang/Knative/README.md deleted file mode 100644 index 9375746..0000000 --- a/v0.5.0/functions-framework/golang/Knative/README.md +++ /dev/null @@ -1,9 +0,0 @@ -# Knative Runtime examples - -In order to follow these examples, you need to install [Knative](https://knative.dev/docs/install/) and [Go 1.15+](https://golang.org/doc/install). - -## OpenFunction Context Function - -- HTTP request - - [example](simple-hello) - diff --git a/v0.5.0/functions-framework/golang/Knative/simple-hello/README.md b/v0.5.0/functions-framework/golang/Knative/simple-hello/README.md deleted file mode 100644 index e67278c..0000000 --- a/v0.5.0/functions-framework/golang/Knative/simple-hello/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# HTTP request - -Start the service. - -```go -go mod tidy -go run main.go -``` - -> The service uses port `8080` by default, if you want to customize the port, you can set it using the environment variable `PORT`. -> -> ```shell -> PORT=8081 go run main.go -> ``` - -You can see the following. - -```shell -2021/06/29 10:10:48 Knative Function serving http: listening on port 8080 -``` - -Now you can access the service via `curl` command.If everything works, you can see the following. - -```shell -~# curl http://localhost:8080 -Hello, World! -``` - diff --git a/v0.5.0/functions-framework/golang/Knative/simple-hello/go.mod b/v0.5.0/functions-framework/golang/Knative/simple-hello/go.mod deleted file mode 100644 index 351793f..0000000 --- a/v0.5.0/functions-framework/golang/Knative/simple-hello/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/v0.5.0/functions-framework/golang/Knative/simple-hello/main.go b/v0.5.0/functions-framework/golang/Knative/simple-hello/main.go deleted file mode 100644 index 80767a1..0000000 --- a/v0.5.0/functions-framework/golang/Knative/simple-hello/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.HelloWorld); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.5.0/functions-framework/golang/Knative/simple-hello/userfunction/hello.go b/v0.5.0/functions-framework/golang/Knative/simple-hello/userfunction/hello.go deleted file mode 100644 index a66ded7..0000000 --- a/v0.5.0/functions-framework/golang/Knative/simple-hello/userfunction/hello.go +++ /dev/null @@ -1,11 +0,0 @@ -package userfunction - -import ( - "fmt" - "net/http" -) - -// HelloWorld writes "Hello, World!" to the HTTP response. -func HelloWorld(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "Hello, World!\n") -} \ No newline at end of file diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/README.md b/v0.5.0/functions-framework/golang/OpenFuncAsync/README.md deleted file mode 100644 index 08d4091..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/README.md +++ /dev/null @@ -1,13 +0,0 @@ -# OpenFuncAsync Runtime examples - -In order to follow these examples, you need to install [Dapr](https://docs.dapr.io/getting-started/install-dapr-selfhost/) and [Go 1.15+](https://golang.org/doc/install). - -## OpenFunction Context Function - -- Bindings - - [example](bindings) - -- Pubsub - - [example](pubsub) - - diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/README.md b/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/README.md deleted file mode 100644 index d42b729..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,175 +0,0 @@ -# Bindings - -- [Bindings without output](#bindings-without-output) -- [Bindings with output](#bindings-with-output) -- [Results](#results) - + [Without Output](#without-output) - + [With Output](#with-output) - -## Bindings without output - -This input source will be executed every 2s (Refer to [cron.yaml](../config/cron.yaml)). - -Prepare a context as follows, name it `function.json`. (You can refer to [OpenFunction Context Specs](https://github.com/OpenFunction/functions-framework/blob/main/docs/OpenFunction-context-specs.md) to learn more about the OpenFunction Context) - -```json -{ - "name": "bindings", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "50001", - "clientPort": "44544", - "inputs": { - "cron": { - "uri": "cron_input", - "type": "bindings", - "component": "cron_input" - } - }, - "outputs": {}, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"bindings","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"50001","clientPort":"44544","inputs":{"cron":{"uri":"cron_input","type":"bindings","component":"cron_input"}},"outputs":{},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd without-output/ -go mod tidy -dapr run --app-id bindings_grpc \ - --app-protocol grpc \ - --app-port 50001 \ - --dapr-grpc-port 44544 \ - --components-path ../../components \ - go run ./main.go -``` - -## Bindings with output - -We need to prepare an output target first. - -```shell -cd with-output/ -go mod tidy -dapr run --app-id output \ - --app-protocol http \ - --app-port 7489 \ - --dapr-http-port 7490 \ - go run ./output/main.go -``` - -This will generate two available targets, one for access through Dapr's proxy address and another for direct access through the app serving address. - -> Simple test with execution `curl -X POST -H "ContentType: application/json" -d '{"Hello": "World"}' ` -> -> `urlPath` refer to follows. - -``` -via Dapr: http://localhost:7490/v1.0/invoke/output_demo/method/echo -via App: http://localhost:7489/echo -``` - -In this example, the proxy address of Dapr will be used as the target of output. - ->Here we have defined only one output, which will be called `item` in the following -> ->`app-id` is "echo" derived from the key of `item` -> ->Dapr component params are in `item.params`. Refer to [Dapr components reference](https://docs.dapr.io/reference/components-reference/). - -```json -{ - "name": "bindings", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "50001", - "clientPort": "44544", - "inputs": { - "cron": { - "uri": "cron_input", - "type": "bindings", - "component": "cron_input" - } - }, - "outputs": { - "echo": { - "uri": "echo", - "operation": "create", - "component": "echo", - "metadata": { - "path": "echo", - "Content-Type": "application/json; charset=utf-8" - }, - "type": "bindings" - } - }, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"bindings","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"50001","clientPort":"44544","inputs":{"cron":{"uri":"cron_input","type":"bindings","component":"cron_input"}},"outputs":{"echo":{"uri":"echo","operation":"create","component":"echo","metadata":{"path":"echo","Content-Type":"application/json; charset=utf-8"},"type":"bindings"}},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd with-output/ -dapr run --app-id bindings_grpc \ - --app-protocol grpc \ - --app-port 50001 \ - --dapr-grpc-port 44544 \ - --components-path ../../components \ - go run ./main.go -``` - - -## Results - -### Without Output - -The logs of user function is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:43:58 binding - Data: Received -== APP == 2021/06/28 10:44:00 binding - Data: Received -``` - -
- -### With Output - -The logs of user function is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:39:43 binding - Data: Received -== APP == 2021/06/28 10:39:45 binding - Data: Received -``` - -
- -And the logs of output target app is ... - -
-View detailed logs. - -```shell -== APP == 2021/06/28 10:39:45 Receive a message: -== APP == 2021/06/28 10:39:45 Hello -``` - -
diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod b/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod deleted file mode 100644 index 351793f..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go deleted file mode 100644 index 20b3c0f..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.BindingsOutput); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go deleted file mode 100644 index d2fc094..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/output/main.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "io" - "log" - "net/http" -) - -func echo(w http.ResponseWriter, req *http.Request) { - content, err := io.ReadAll(req.Body) - if err != nil { - w.WriteHeader(500) - return - } - log.Println("Receive a message:") - log.Println(string(content)) -} - -func main() { - - http.HandleFunc("/echo", echo) - - err := http.ListenAndServe(":7489", nil) - if err != nil { - return - } -} diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go deleted file mode 100644 index ba85476..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/with-output/userfunction/bindings_with_output.go +++ /dev/null @@ -1,24 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsOutput(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - var greeting []byte - if in != nil { - log.Printf("binding - Data: %s", in) - greeting = in - } else { - log.Print("binding - Data: Received") - greeting = []byte("Hello") - } - - err := ctx.SendTo(greeting, "echo") - if err != nil { - log.Printf("Error: %v\n", err) - return ctx.ReturnWithInternalError() - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod b/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod deleted file mode 100644 index 351793f..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go deleted file mode 100644 index 5e1486a..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.BindingsNoOutput); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go deleted file mode 100644 index 1e37b47..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/bindings/without-output/userfunction/bindings_without_output.go +++ /dev/null @@ -1,15 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsNoOutput(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - if in != nil { - log.Printf("binding - Data: %s", in) - } else { - log.Print("binding - Data: Received") - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/components/bindings.yaml b/v0.5.0/functions-framework/golang/OpenFuncAsync/components/bindings.yaml deleted file mode 100644 index f120b3d..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/components/bindings.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: echo -spec: - type: bindings.http - version: v1 - metadata: - - name: url - value: http://localhost:7489 diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/components/cron.yaml b/v0.5.0/functions-framework/golang/OpenFuncAsync/components/cron.yaml deleted file mode 100644 index bd9b4be..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/components/cron.yaml +++ /dev/null @@ -1,10 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: cron_input -spec: - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml b/v0.5.0/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml deleted file mode 100644 index 94f938a..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/components/pubsub.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: msg -spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: localhost:6379 - - name: redisPassword - value: "" diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/components/statestore.yaml b/v0.5.0/functions-framework/golang/OpenFuncAsync/components/statestore.yaml deleted file mode 100644 index 18cba84..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/components/statestore.yaml +++ /dev/null @@ -1,14 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: statestore -spec: - type: state.redis - version: v1 - metadata: - - name: redisHost - value: localhost:6379 - - name: redisPassword - value: "" - - name: actorStateStore - value: "true" diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/README.md b/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index 10115e9..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,115 +0,0 @@ -# Pubsub - -- [Subscriber](#subscriber) -- [Producer](#producer) -- [Results](#results) - -## Subscriber - -Prepare a context as follows, name it `function.json`. (You can refer to [OpenFunction Context Specs](https://github.com/OpenFunction/functions-framework/blob/main/docs/OpenFunction-context-specs.md) to learn more about the OpenFunction Context) - -```json -{ - "name": "subscriber", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "60011", - "clientPort": "44544", - "inputs": { - "sub": { - "uri": "my_topic", - "type": "pubsub", - "component": "msg" - } - }, - "outputs": {}, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"subscriber","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"60011","clientPort":"44544","inputs":{"sub":{"uri":"my_topic","type":"pubsub","component":"msg"}},"outputs":{},"runtime":"OpenFuncAsync"}' -``` - -Start the service and watch the logs. - -```shell -cd subscriber/ -go mod tidy -dapr run --app-id subscriber \ - --app-protocol grpc \ - --app-port 60011 \ - --dapr-grpc-port 44544 \ - --components-path ../../components \ - go run ./main.go -``` - -## Producer - -You also need a definition of producer. - -```json -{ - "name": "producer", - "version": "v1", - "requestID": "a0f2ad8d-5062-4812-91e9-95416489fb01", - "port": "60012", - "clientPort": "44545", - "inputs": {}, - "outputs": { - "pub": { - "uri": "my_topic", - "component": "msg", - "type": "pubsub" - } - }, - "runtime": "OpenFuncAsync" -} -``` - -Create an environment variable `FUNC_CONTEXT` and assign the above context to it. - -```shell -export FUNC_CONTEXT='{"name":"producer","version":"v1","requestID":"a0f2ad8d-5062-4812-91e9-95416489fb01","port":"60012","clientPort":"44545","inputs":{},"outputs":{"pub":{"uri":"my_topic","component":"msg","type":"pubsub"}},"runtime":"OpenFuncAsync"}' -``` - -Start the service with another terminal to publish message. - -```shell -cd producer/ -go mod tidy -dapr run --app-id producer \ - --app-protocol grpc \ - --app-port 60012 \ - --dapr-grpc-port 44545 \ - --components-path ../../components \ - go run ./main.go -``` - -## Results - -
-View detailed producer logs. - -```shell -== APP == 0 published, 0/sec, 0 errors -== APP == 0 published, 0/sec, 0 errors -== APP == 0 published, 0/sec, 0 errors -== APP == 1 published, 0/sec, 0 errors -== APP == 4 published, 0/sec, 0 errors -== APP == 7 published, 0/sec, 0 errors -== APP == 10 published, 0/sec, 0 errors -== APP == 13 published, 1/sec, 0 errors -``` -
- -
-View detailed subscriber logs. - -```shell -== APP == 2021/06/28 10:04:18 event - Data: "{\"id\":\"p1-533d83d3-dd7c-4f1f-a822-f87b88f74d3e\",\"data\":\"QWdPTktLUjgxd1A1M096dVRDOHNWellyQjFoQ3FtM0FjeTY1Q2Q5S2NCVTRyMjhJbHlQcUVzdmxqWUJnZVB0YUlJRFRHWEFzWG5zZlQ3aGVRMUtrT21SalBHNzl4Rmx2bmNVSmNaOE11c3dmZ3plMk5ZRDF6Q0k5MmFFSVpuWUhmQ2J6aTlNSTQxajd1VURRNVJkMVNZYmhsUUs4UWRXN054Y3BDOXNHaDZTVEpZTzB5UFVJU2ZEQnZaZzJRYU5HaENDeFN6UzJPTVNYOU82QURxSnNndHB1dkIzcDVtRm1tT0haODJoMUM0UTl6blBjb3R0Qm8zbWRnQkhEbjE1Wg==\",\"sha\":\"f\\ufffd\\ufffd\\ufffdr\\ufffdE\\ufffdtu\\ufffd\\ufffd=n\\ufffd7\\u001d\\ufffd\\ufffdrB0^\\ufffd\\n1\\ufffd\\u0008\\ufffdWI\",\"time\":\"2021-06-28 10:04:13.867293349 +0800 CST m=+19.006097088\"}" -``` -
- diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod b/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod deleted file mode 100644 index 450f392..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/go.mod +++ /dev/null @@ -1,9 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 - github.com/google/uuid v1.1.2 -) \ No newline at end of file diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go deleted file mode 100644 index 13dee20..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.Producer); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go deleted file mode 100644 index 9eacf41..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/producer/userfunction/producer.go +++ /dev/null @@ -1,189 +0,0 @@ -// An example, referenced from https://github.com/mchmarny/dapr-demos/tree/master/autoscaling-on-queue - -package userfunction - -import ( - "crypto/sha256" - "encoding/json" - "fmt" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "github.com/google/uuid" - "log" - "math/rand" - "os" - "os/signal" - "strconv" - "strings" - "sync" - "syscall" - "time" -) - -const ( - chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" -) - -var ( - logger = log.New(os.Stdout, "", 0) - outputName = getEnvVar("OUTPUT_NAME", "pub") - numOfPublishers = getEnvIntOrFail("NUMBER_OF_PUBLISHERS", "1") - publishFrequency = getEnvDurationOrFail("PUBLISHERS_FREQ", "1s") - publishDelay = getEnvDurationOrFail("PUBLISHERS_DELAY", "10s") - logFrequency = getEnvDurationOrFail("LOG_FREQ", "3s") - publishToConsole = getEnvBoolOrFail("PUBLISH_TO_CONSOLE", "false") -) - -func Producer(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - if numOfPublishers < 1 { - numOfPublishers = 1 - } - logger.Printf("subscription name: %s", outputName) - logger.Printf("number of publishers: %d", numOfPublishers) - logger.Printf("publish frequency: %v", publishFrequency) - logger.Printf("log frequency: %v", logFrequency) - logger.Printf("publish delay: %v", publishDelay) - - // handle signals - stop := make(chan os.Signal) - signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) - - resultCh := make(chan bool, 100) - stopCh := make(chan struct{}) - - go func() { - <-stop - close(stopCh) - }() - - // print results - go monitor(resultCh, stopCh) - - // start producing - for i := 1; i <= numOfPublishers; i++ { - go publish(ctx, i, resultCh, stopCh) - } - - return ctx.ReturnWithSuccess() -} - -func monitor(resultCh <-chan bool, stopCh <-chan struct{}) { - var mux sync.Mutex - var successCounter int64 = 0 - var errorCounter int64 = 0 - startTime := time.Now() - tickerCh := time.NewTicker(logFrequency).C - for { - select { - case r := <-resultCh: - mux.Lock() - if r { - successCounter++ - } else { - errorCounter++ - } - mux.Unlock() - case <-tickerCh: - var avg float64 = 0 - if successCounter > 0 { - avg = float64(successCounter) / time.Since(startTime).Seconds() - } - logger.Printf("%10d published, %3.0f/sec, %3d errors", successCounter, avg, errorCounter) - case <-stopCh: - os.Exit(0) - } - } -} - -func publish(ctx *ofctx.OpenFunctionContext, index int, resultCh chan<- bool, stopCh <-chan struct{}) { - delayCh := time.NewTicker(publishDelay).C - <-delayCh - - tickerCh := time.NewTicker(publishFrequency).C - for { - select { - case <-stopCh: - return - case <-tickerCh: - d := getEventData(index) - if publishToConsole { - logger.Printf("%s", d) - resultCh <- true - continue - } - if _, err := ctx.Send(outputName, d); err != nil { - logger.Printf("send error, %v", err) - resultCh <- false - } else { - resultCh <- true - } - } - } -} - -func getEventData(index int) []byte { - r := requestContent{ - ID: fmt.Sprintf("p%d-%s", index, uuid.New().String()), - Data: []byte(getData(256)), - Time: time.Now().String(), - } - - // hash the entire message - inSha := sha256.Sum256(r.Data) - r.Sha = string(inSha[:]) - - b, err := json.Marshal(r) - if err != nil { - logger.Fatalf("error generating request: %v", err) - } - return b -} - -func getData(length int) string { - seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) - b := make([]byte, length) - for i := range b { - b[i] = chars[seededRand.Intn(len(chars))] - } - return string(b) -} - -type requestContent struct { - ID string `json:"id"` - Data []byte `json:"data"` - Sha string `json:"sha"` - Time string `json:"time"` -} - -func getEnvVar(key, fallbackValue string) string { - if val, ok := os.LookupEnv(key); ok { - return strings.TrimSpace(val) - } - return fallbackValue -} - -func getEnvIntOrFail(key, fallbackValue string) int { - s := getEnvVar(key, fallbackValue) - v, err := strconv.Atoi(s) - if err != nil { - logger.Fatalf("invalid number variable: %s - %v", s, err) - } - return v -} - -func getEnvDurationOrFail(key, fallbackValue string) time.Duration { - s := getEnvVar(key, fallbackValue) - v, err := time.ParseDuration(s) - if err != nil { - logger.Fatalf("invalid duration variable: %s - %v", s, err) - } - return v -} - -func getEnvBoolOrFail(key, fallbackValue string) bool { - s := getEnvVar(key, fallbackValue) - v, err := strconv.ParseBool(s) - if err != nil { - logger.Fatalf("invalid bool variable: %s - %v", s, err) - } - return v -} diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod b/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod deleted file mode 100644 index 351793f..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module main.go - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/cloudevents/sdk-go/v2 v2.4.1 -) \ No newline at end of file diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go deleted file mode 100644 index 84b944f..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/main.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "context" - "errors" - "fmt" - "github.com/OpenFunction/functions-framework-go/functionframeworks" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - cloudevents "github.com/cloudevents/sdk-go/v2" - "log" - "main.go/userfunction" - "net/http" -) - -func register(fn interface{}) error { - ctx := context.Background() - if fnHTTP, ok := fn.(func(http.ResponseWriter, *http.Request)); ok { - if err := functionframeworks.RegisterHTTPFunction(ctx, fnHTTP); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnCloudEvent, ok := fn.(func(context.Context, cloudevents.Event) error); ok { - if err := functionframeworks.RegisterCloudEventFunction(ctx, fnCloudEvent); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else if fnOpenFunction, ok := fn.(func(*ofctx.OpenFunctionContext, []byte) ofctx.RetValue); ok { - if err := functionframeworks.RegisterOpenFunction(ctx, fnOpenFunction); err != nil { - return fmt.Errorf("Function failed to register: %v\n", err) - } - } else { - err := errors.New("unrecognized function") - return fmt.Errorf("Function failed to register: %v\n", err) - } - return nil -} - -func main() { - if err := register(userfunction.Subscriber); err != nil { - log.Fatalf("Failed to register: %v\n", err) - } - - if err := functionframeworks.Start(); err != nil { - log.Fatalf("Failed to start: %v\n", err) - } -} diff --git a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go b/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go deleted file mode 100644 index a2b2133..0000000 --- a/v0.5.0/functions-framework/golang/OpenFuncAsync/pubsub/subscriber/userfunction/subscriber.go +++ /dev/null @@ -1,11 +0,0 @@ -package userfunction - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func Subscriber(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - log.Printf("event - Data: %s", in) - return ctx.ReturnWithSuccess() -} diff --git a/v0.5.0/functions-framework/nodejs/Knative/README.md b/v0.5.0/functions-framework/nodejs/Knative/README.md deleted file mode 100644 index cb3c00c..0000000 --- a/v0.5.0/functions-framework/nodejs/Knative/README.md +++ /dev/null @@ -1,6 +0,0 @@ -# Knative Runtime examples - -- [HTTP request](helloworld) - -- [Cloudevent](cloudevent) - diff --git a/v0.5.0/functions-framework/nodejs/Knative/cloudevent/README.md b/v0.5.0/functions-framework/nodejs/Knative/cloudevent/README.md deleted file mode 100644 index 5cd75e8..0000000 --- a/v0.5.0/functions-framework/nodejs/Knative/cloudevent/README.md +++ /dev/null @@ -1,71 +0,0 @@ -# Cloudevent - -The functions framework can unmarshall incoming [CloudEvents](http://cloudevents.io/) payloads to a `cloudevent` object. Note that your function must use the `cloudevent-style` function signature. - -```js -exports.helloCloudEvents = (cloudevent) => { - return cloudevent -} -``` - -Your `package.json` - -```json - "scripts": { - "start": "functions-framework --target=helloCloudEvents --source=cloudevent" - } -``` - -**A binary one** - -See [payload content](https://github.com/OpenFunction/functions-framework-nodejs/blob/main/mock/payload/binary.json) - -```bash -$ curl -X POST \ - -d'@../mock/payload/binary.json' \ - -H'Content-Type:application/json' \ - -H'ce-specversion:1.0' \ - -H'ce-type:com.github.pull.create' \ - -H'ce-source:https://github.com/cloudevents/spec/pull/123' \ - -H'ce-id:45c83279-c8a1-4db6-a703-b3768db93887' \ - -H'ce-time:2019-11-06T11:17:00Z' \ - -H'ce-myextension:extension value' \ - http://localhost:8080/ -# The response is -{ - "datacontenttype": "application/json", - "data": { - "runtime": "cloudevent" - }, - "specversion": "1.0", - "type": "com.github.pull.create", - "source": "https://github.com/cloudevents/spec/pull/123", - "id": "45c83279-c8a1-4db6-a703-b3768db93887", - "time": "2019-11-06T11:17:00Z", - "myextension": "extension value" -} -``` - -**A structed one** - -See [payload content](https://github.com/OpenFunction/functions-framework-nodejs/blob/main/mock/payload/structured.json) - -```bash -$ curl -X POST \ - -d'@../mock/payload/structured.json' \ - -H'Content-Type:application/cloudevents+json' \ - http://localhost:8080/ -# The response is -{ - "specversion": "1.0", - "type": "com.github.pull.create", - "source": "https://github.com/cloudevents/spec/pull/123", - "id": "b25e2717-a470-45a0-8231-985a99aa9416", - "time": "2019-11-06T11:08:00Z", - "datacontenttype": "application/json", - "data": { - "framework": "openfunction" - } -} -``` - diff --git a/v0.5.0/functions-framework/nodejs/Knative/cloudevent/index.js b/v0.5.0/functions-framework/nodejs/Knative/cloudevent/index.js deleted file mode 100644 index 3a7dceb..0000000 --- a/v0.5.0/functions-framework/nodejs/Knative/cloudevent/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloCloudEvents = (cloudevent) => { - return cloudevent -} \ No newline at end of file diff --git a/v0.5.0/functions-framework/nodejs/Knative/cloudevent/package.json b/v0.5.0/functions-framework/nodejs/Knative/cloudevent/package.json deleted file mode 100644 index 705e839..0000000 --- a/v0.5.0/functions-framework/nodejs/Knative/cloudevent/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "cloudevent", - "version": "1.0.0", - "description": "The functions framework can unmarshall incoming [CloudEvents](http://cloudevents.io/) payloads to a `cloudevent` object. Note that your function must use the `cloudevent-style` function signature.", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloCloudEvents --source=cloudevent" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.5.0/functions-framework/nodejs/Knative/helloworld/README.md b/v0.5.0/functions-framework/nodejs/Knative/helloworld/README.md deleted file mode 100644 index 5857bad..0000000 --- a/v0.5.0/functions-framework/nodejs/Knative/helloworld/README.md +++ /dev/null @@ -1,45 +0,0 @@ -# Hello World Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = (req, res) => { - res.send('Hello, World'); - }; - ``` - -3. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -4. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --source http" - } - ``` - -5. Use `npm start` to start the built-in local development server: - - ```bash - $ npm start - ... - The functionModulePath is: /.../.../index.js - Openfunction functions framework listening at http://localhost:8080 - ``` - -6. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl localhost:8080 - # Output: Hello, World - ``` diff --git a/v0.5.0/functions-framework/nodejs/Knative/helloworld/index.js b/v0.5.0/functions-framework/nodejs/Knative/helloworld/index.js deleted file mode 100644 index 64f3c6f..0000000 --- a/v0.5.0/functions-framework/nodejs/Knative/helloworld/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloWorld = (req, res) => { - res.send('Hello, World'); -}; \ No newline at end of file diff --git a/v0.5.0/functions-framework/nodejs/Knative/helloworld/package.json b/v0.5.0/functions-framework/nodejs/Knative/helloworld/package.json deleted file mode 100644 index c338493..0000000 --- a/v0.5.0/functions-framework/nodejs/Knative/helloworld/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "helloworld", - "version": "1.0.0", - "description": "1. Create a `package.json` file using `npm init`:", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --source http" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/README.md b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/README.md deleted file mode 100644 index 7de4247..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/README.md +++ /dev/null @@ -1,7 +0,0 @@ -# OpenFuncAsync Runtime examples - -- [HTTP Request](helloworld) - -- [Bindings](bindings) - -- [Pubsub](pubsub) diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/README.md b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/README.md deleted file mode 100644 index 1894e4f..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,112 +0,0 @@ -# BIndings Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data - } - ``` - -3. Add your `config.json` - - ```json - { - "input": { - "name": "sample-topic", - "uri": "test", - "params": { - "type": "bindings" - } - }, - "outputs": { - "sample-topic": { - "uri": "test", - "params": { - "type": "bindings", - "operation": "create" - } - } - } - } - ``` - -4. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -5. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --port 4000" - } - ``` - -6. Note that if we want to test it locally, we need a Dapr config file: - - ```yaml - apiVersion: dapr.io/v1alpha1 - kind: Component - metadata: - name: sample-topic - spec: - type: bindings.kafka - version: v1 - metadata: - # Kafka broker connection setting - - name: brokers - value: localhost:9092 - # consumer configuration: topic and consumer group - - name: topics - value: sample - - name: consumerGroup - value: group1 - # publisher configuration: topic - - name: publishTopic - value: sample - - name: authRequired - value: "false" - ``` - -7. Use `dapr` to run `npm start` and start the built-in local development server: - - ```bash - $ dapr run --app-id hello-world --app-port 4000 --dapr-http-port 3500 --components-path ./bindings.yaml npm start - ``` - -8. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl -X POST \ - -d'{"data": "hello"}' \ - -H'Content-Type:application/json' \ - http://localhost:4000/test - ``` - -9. And the output will be like: - - ```shell - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:31 +0000] "POST /test HTTP/1.1" 200 - "-" "curl/7.58.0" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:36 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:41 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: 'hello' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:46 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - ``` - - - diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml deleted file mode 100644 index 3aa06a7..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/bindings.yaml +++ /dev/null @@ -1,21 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: sample-topic -spec: - type: bindings.kafka - version: v1 - metadata: - # Kafka broker connection setting - - name: brokers - value: localhost:9092 - # consumer configuration: topic and consumer group - - name: topics - value: sample - - name: consumerGroup - value: group1 - # publisher configuration: topic - - name: publishTopic - value: sample - - name: authRequired - value: "false" \ No newline at end of file diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/config.json b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/config.json deleted file mode 100644 index ebe6373..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/config.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "input": { - "name": "sample-topic", - "uri": "test", - "params": { - "type": "bindings" - } - }, - "outputs": { - "sample-topic": { - "uri": "test", - "params": { - "type": "bindings", - "operation": "create" - } - } - } -} \ No newline at end of file diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/index.js b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/index.js deleted file mode 100644 index 8bda8c1..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/index.js +++ /dev/null @@ -1,6 +0,0 @@ -exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data -} \ No newline at end of file diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/package.json b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/package.json deleted file mode 100644 index f9e6340..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/bindings/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "bindings", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --port 4000" - }, - "author": "", - "license": "ISC" -} diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md deleted file mode 100644 index 8f57ff1..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/README.md +++ /dev/null @@ -1,49 +0,0 @@ -# Hello World Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - /** - * Send {"data": "Hello, World"} - * @param data - data is the request body contents, which should be a json object - */ - exports.helloWorld = (data) => { - return 'Hello, World'; - }; - ``` - -3. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -4. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld" - } - ``` - -5. Use `npm start` to start the built-in local development server: - - ```bash - $ npm start - ... - The functionModulePath is: /.../.../index.js - Openfunction functions framework listening at http://localhost:8080 - ``` - -6. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl localhost:8080 - # Output: Hello, World - ``` diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js deleted file mode 100644 index 7d7ab84..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/index.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * Send {"data": "Hello, World"} - * @param data - data is the request body contents, which should be a json object - */ - exports.helloWorld = (data) => { - return 'Hello, World'; -}; \ No newline at end of file diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json deleted file mode 100644 index d3cb74c..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/helloworld/package.json +++ /dev/null @@ -1,15 +0,0 @@ -{ - "name": "helloworld", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld" - }, - "author": "", - "license": "ISC", - "dependencies": { - "@openfunction/functions-framework": "^0.3.0" - } -} diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index ac0cc4d..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,118 +0,0 @@ -# Pub/Sub Example - -1. Create a `package.json` file using `npm init`: - - ```bash - $ npm init - ``` - -2. Create an `index.js` file with the following contents: - - ```js - exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data - } - ``` - -3. Add your `config.json` - - ```json - { - "input": { - "name": "pubsub", - "uri": "test", - "params": { - "type": "pubsub" - } - }, - "outputs": { - "pubsub": { - "uri": "test", - "params": { - "type": "pubsub" - } - } - } - } - ``` - -4. Now install the Functions Framework: - - ```bash - $ npm install @openfunction/functions-framework - ``` - -5. Add a `start` script to `package.json`, with configuration passed via command-line arguments: - - ```json - "scripts": { - "start": "functions-framework --target=helloWorld --port 4000" - } - ``` - -6. Note that if we want to test it locally, we need a Dapr config file: - - ```yaml - apiVersion: dapr.io/v1alpha1 - kind: Component - metadata: - name: pubsub # midlleware component name - spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: ${YOUR_REDIS_ADDRESS} - - name: redisPassword - value: "" - ``` - -7. Use `dapr` to run `npm start` and start the built-in local development server: - - ```bash - $ dapr run --app-id hello-world --app-port 4000 --dapr-http-port 3500 --components-path ./pubsub.yaml npm start - ``` - -8. Send requests to this function using `curl` from another terminal window: - - ```bash - $ curl -X POST \ - -d'@../mock/payload/structured.json' \ - -H'Content-Type:application/cloudevents+json' \ - http://localhost:4000/test - ``` - -9. The `structured.json` is like below: (note that in dapr, pubsub mode respects the cloud event style) - - ```json - { - "specversion":"1.0", - "type":"com.github.pull.create", - "source":"https://github.com/cloudevents/spec/pull/123", - "id":"b25e2717-a470-45a0-8231-985a99aa9416", - "time":"2019-11-06T11:08:00Z", - "datacontenttype":"application/json", - "data":{ - "framework":"openfunction" - } - } - ``` - -10. And the output will be like: - - ```shell - == APP == { framework: 'openfunction' } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:31 +0000] "POST /test HTTP/1.1" 200 - "-" "curl/7.58.0" - == APP == { data: { framework: 'openfunction' } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:36 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: { data: { framework: 'openfunction' } } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:41 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - == APP == { data: { data: { data: [Object] } } } - == APP == ::ffff:127.0.0.1 - - [07/Aug/2021:09:09:46 +0000] "POST /test HTTP/1.1" 200 - "-" "fasthttp" - ``` - - - diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json deleted file mode 100644 index 64336f8..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/config.json +++ /dev/null @@ -1,17 +0,0 @@ -{ - "input": { - "name": "pubsub", - "uri": "test", - "params": { - "type": "pubsub" - } - }, - "outputs": { - "pubsub": { - "uri": "test", - "params": { - "type": "pubsub" - } - } - } -} \ No newline at end of file diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js deleted file mode 100644 index 8bda8c1..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/index.js +++ /dev/null @@ -1,6 +0,0 @@ -exports.helloWorld = async (data) => { - console.log(data) - const delay = ms => new Promise(resolve => setTimeout(resolve, ms)) - await delay(5000) - return data -} \ No newline at end of file diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json deleted file mode 100644 index 4637e47..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/package.json +++ /dev/null @@ -1,12 +0,0 @@ -{ - "name": "pubsub", - "version": "1.0.0", - "description": "", - "main": "index.js", - "scripts": { - "test": "echo \"Error: no test specified\" && exit 1", - "start": "functions-framework --target=helloWorld --port 4000" - }, - "author": "", - "license": "ISC" -} diff --git a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml b/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml deleted file mode 100644 index f0ad8a3..0000000 --- a/v0.5.0/functions-framework/nodejs/OpenFuncAsync/pubsub/pubsub.yaml +++ /dev/null @@ -1,12 +0,0 @@ -apiVersion: dapr.io/v1alpha1 -kind: Component -metadata: - name: pubsub # midlleware component name -spec: - type: pubsub.redis - version: v1 - metadata: - - name: redisHost - value: ${YOUR_REDIS_ADDRESS} - - name: redisPassword - value: "" \ No newline at end of file diff --git a/v0.5.0/functions/Knative/azure-func-go/.funcignore b/v0.5.0/functions/Knative/azure-func-go/.funcignore deleted file mode 100644 index 414df2f..0000000 --- a/v0.5.0/functions/Knative/azure-func-go/.funcignore +++ /dev/null @@ -1,4 +0,0 @@ -.git* -.vscode -local.settings.json -test \ No newline at end of file diff --git a/v0.5.0/functions/Knative/azure-func-go/HttpExample/function.json b/v0.5.0/functions/Knative/azure-func-go/HttpExample/function.json deleted file mode 100644 index 7eb1f8f..0000000 --- a/v0.5.0/functions/Knative/azure-func-go/HttpExample/function.json +++ /dev/null @@ -1,19 +0,0 @@ -{ - "bindings": [ - { - "authLevel": "anonymous", - "type": "httpTrigger", - "direction": "in", - "name": "req", - "methods": [ - "get", - "post" - ] - }, - { - "type": "http", - "direction": "out", - "name": "res" - } - ] -} diff --git a/v0.5.0/functions/Knative/azure-func-go/handler b/v0.5.0/functions/Knative/azure-func-go/handler deleted file mode 100755 index 78a20b4..0000000 Binary files a/v0.5.0/functions/Knative/azure-func-go/handler and /dev/null differ diff --git a/v0.5.0/functions/Knative/azure-func-go/handler.go b/v0.5.0/functions/Knative/azure-func-go/handler.go deleted file mode 100644 index 6637d44..0000000 --- a/v0.5.0/functions/Knative/azure-func-go/handler.go +++ /dev/null @@ -1,27 +0,0 @@ -package main - -import ( - "fmt" - "log" - "net/http" - "os" -) - -func helloHandler(w http.ResponseWriter, r *http.Request) { - message := "This HTTP triggered function executed successfully. Pass a name in the query string for a personalized response.\n" - name := r.URL.Query().Get("name") - if name != "" { - message = fmt.Sprintf("Hello, %s. This HTTP triggered function executed successfully.\n", name) - } - fmt.Fprint(w, message) -} - -func main() { - listenAddr := ":8080" - if val, ok := os.LookupEnv("FUNCTIONS_CUSTOMHANDLER_PORT"); ok { - listenAddr = ":" + val - } - http.HandleFunc("/api/HttpExample", helloHandler) - log.Printf("About to listen on %s. Go to https://127.0.0.1%s/", listenAddr, listenAddr) - log.Fatal(http.ListenAndServe(listenAddr, nil)) -} \ No newline at end of file diff --git a/v0.5.0/functions/Knative/azure-func-go/host.json b/v0.5.0/functions/Knative/azure-func-go/host.json deleted file mode 100644 index 20a2cdc..0000000 --- a/v0.5.0/functions/Knative/azure-func-go/host.json +++ /dev/null @@ -1,23 +0,0 @@ -{ - "version": "2.0", - "logging": { - "applicationInsights": { - "samplingSettings": { - "isEnabled": true, - "excludedTypes": "Request" - } - } - }, - "extensionBundle": { - "id": "Microsoft.Azure.Functions.ExtensionBundle", - "version": "[1.*, 2.0.0)" - }, - "customHandler": { - "description": { - "defaultExecutablePath": "handler", - "workingDirectory": "", - "arguments": [] - }, - "enableForwardingHttpRequest": true - } -} diff --git a/v0.5.0/functions/Knative/azure-func-go/proxies.json b/v0.5.0/functions/Knative/azure-func-go/proxies.json deleted file mode 100644 index b385252..0000000 --- a/v0.5.0/functions/Knative/azure-func-go/proxies.json +++ /dev/null @@ -1,4 +0,0 @@ -{ - "$schema": "http://json.schemastore.org/proxies", - "proxies": {} -} diff --git a/v0.5.0/functions/Knative/hello-world-dotnet/Program.cs b/v0.5.0/functions/Knative/hello-world-dotnet/Program.cs deleted file mode 100644 index 00618b6..0000000 --- a/v0.5.0/functions/Knative/hello-world-dotnet/Program.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -using System; -using Microsoft.AspNetCore.Hosting; -using Microsoft.Extensions.Hosting; - -namespace helloworld -{ - public class Program - { - public static void Main(string[] args) - { - CreateHostBuilder(args).Build().Run(); - } - - public static IHostBuilder CreateHostBuilder(string[] args) - { - string port = Environment.GetEnvironmentVariable("PORT") ?? "8080"; - string url = String.Concat("http://0.0.0.0:", port); - - return Host.CreateDefaultBuilder(args) - .ConfigureWebHostDefaults(webBuilder => - { - webBuilder.UseStartup().UseUrls(url); - }); - } - } -} diff --git a/v0.5.0/functions/Knative/hello-world-dotnet/README.md b/v0.5.0/functions/Knative/hello-world-dotnet/README.md deleted file mode 100644 index c79f762..0000000 --- a/v0.5.0/functions/Knative/hello-world-dotnet/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Sample Function Dotnet - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```dotnet``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: dotnet-sample -spec: - version: "v1.0.0" - image: "/sample-dotnet-func:v0.5.0" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "helloworld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/Knative/hello-world-dotnet" - serving: - runtime: "Knative" # default to Knative -``` diff --git a/v0.5.0/functions/Knative/hello-world-dotnet/Startup.cs b/v0.5.0/functions/Knative/hello-world-dotnet/Startup.cs deleted file mode 100644 index d81a8cb..0000000 --- a/v0.5.0/functions/Knative/hello-world-dotnet/Startup.cs +++ /dev/null @@ -1,42 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -using System; -using Microsoft.AspNetCore.Builder; -using Microsoft.AspNetCore.Hosting; -using Microsoft.AspNetCore.Http; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Hosting; - -namespace helloworld -{ - public class Startup - { - public void ConfigureServices(IServiceCollection services) - { - } - - public void Configure(IApplicationBuilder app, IWebHostEnvironment env) - { - app.UseRouting(); - - app.UseEndpoints(endpoints => - { - endpoints.MapGet("/", async context => - { - await context.Response.WriteAsync("hello, world"); - }); - }); - } - } -} diff --git a/v0.5.0/functions/Knative/hello-world-dotnet/helloworld.csproj b/v0.5.0/functions/Knative/hello-world-dotnet/helloworld.csproj deleted file mode 100644 index f9f2057..0000000 --- a/v0.5.0/functions/Knative/hello-world-dotnet/helloworld.csproj +++ /dev/null @@ -1,8 +0,0 @@ - - - - netcoreapp3.1 - helloworld - - - diff --git a/v0.5.0/functions/Knative/hello-world-go/README.md b/v0.5.0/functions/Knative/hello-world-go/README.md deleted file mode 100644 index 5d4b6d7..0000000 --- a/v0.5.0/functions/Knative/hello-world-go/README.md +++ /dev/null @@ -1,100 +0,0 @@ -# Sample Function Go - -## Prerequisites - -### OpenFunction - -You can refer to the [Installation Guide](https://github.com/OpenFunction/OpenFunction#install-openfunction) to setup OpenFunction. - -## Deployment - -1. Creating a secret - -Generate a secret to access your container registry, such as one on [Docker Hub](https://hub.docker.com/) or [Quay.io](https://quay.io/). -You can create this secret by editing the ``REGISTRY_SERVER``, ``REGISTRY_USER`` and ``REGISTRY_PASSWORD`` fields in following command, and then run it. - - ```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 - ``` - -2. Creating functions - - For sample function below, modify the ``spec.image`` field in ``function-sample.yaml`` to your own container registry address: - - ```yaml - apiVersion: core.openfunction.io/v1alpha2 - kind: Function - metadata: - name: function-sample - spec: - image: "/sample-go-func:latest" - ``` - - Use the following command to create this Function: - - ```shell - kubectl apply -f function-sample.yaml - ``` - -3. Result observation - - You can observe the process of a function with the following command: - - ```shell - kubectl get functions.core.openfunction.io - - NAME AGE - function-sample 5s - ``` - - You can also observe the process of a builder in the [Tekton Dashboard](https://tekton.dev/docs/dashboard/). - - Finally, you can observe the final state of the function workload in the Serving: - - ```shell - kubectl get servings.core.openfunction.io - - NAME AGE - function-sample-serving 15s - ``` - - You can now find out the service entry of the function with the following command: - - ```shell - kubectl get ksvc - - NAME URL LATESTCREATED LATESTREADY READY REASON - function-sample-serving-ksvc http://function-sample-serving-ksvc.default..sslip.io function-sample-serving-ksvc-00001 function-sample-serving-ksvc-00001 True - ``` - - Or get the service address directly with the following command: - - > where` `indicates the external address of your gateway service. - > - > You can do a simple configuration to use the node ip as the `` as follows (Assuming you are using Kourier as network layer of Knative). Where `1.2.3.4` can be replaced by your node ip. - > - > ```shell - > kubectl patch svc -n kourier-system kourier \ - > -p '{"spec": {"type": "LoadBalancer", "externalIPs": ["1.2.3.4"]}}' - > - > kubectl patch configmap/config-domain -n knative-serving \ - > --type merge --patch '{"data":{"1.2.3.4.sslip.io":""}}' - > ``` - - ```shell - kubectl get ksvc function-sample-serving-ksvc -o jsonpath={.status.url} - - http://function-sample-serving-ksvc.default..sslip.io - ``` - - Access the above service address via commands such as ``curl``: - - ```shell - curl http://function-sample-serving-ksvc.default..sslip.io - - Hello, World! - ``` \ No newline at end of file diff --git a/v0.5.0/functions/Knative/hello-world-go/function-sample.yaml b/v0.5.0/functions/Knative/hello-world-go/function-sample.yaml deleted file mode 100644 index ec2c8b3..0000000 --- a/v0.5.0/functions/Knative/hello-world-go/function-sample.yaml +++ /dev/null @@ -1,25 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: function-sample -spec: - version: "v1.0.0" - image: "openfunctiondev/sample-go-func:v0.5.0" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: openfunction/builder:v1 - env: - FUNC_NAME: "HelloWorld" - FUNC_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/Knative/hello-world-go" - serving: - runtime: Knative # default to Knative -# template: -# containers: -# - name: function -# # Set imagePullPolicy if needed -# imagePullPolicy: Always diff --git a/v0.5.0/functions/Knative/hello-world-go/go.mod b/v0.5.0/functions/Knative/hello-world-go/go.mod deleted file mode 100644 index adf50d7..0000000 --- a/v0.5.0/functions/Knative/hello-world-go/go.mod +++ /dev/null @@ -1,3 +0,0 @@ -module example.com/hello - -go 1.15 diff --git a/v0.5.0/functions/Knative/hello-world-go/hello.go b/v0.5.0/functions/Knative/hello-world-go/hello.go deleted file mode 100644 index 6db3585..0000000 --- a/v0.5.0/functions/Knative/hello-world-go/hello.go +++ /dev/null @@ -1,11 +0,0 @@ -package hello - -import ( - "fmt" - "net/http" -) - -// HelloWorld writes "Hello, World!" to the HTTP response. -func HelloWorld(w http.ResponseWriter, r *http.Request) { - fmt.Fprint(w, "Hello, World!\n") -} diff --git a/v0.5.0/functions/Knative/hello-world-java/README.md b/v0.5.0/functions/Knative/hello-world-java/README.md deleted file mode 100644 index ff3d582..0000000 --- a/v0.5.0/functions/Knative/hello-world-java/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Sample Function Java - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```java``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: java-sample -spec: - version: "v1.0.0" - image: "/sample-java-func:v0.5.0" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "com.openfunction.HelloWorld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/Knative/hello-world-java" - serving: - runtime: Knative # default to Knative -``` diff --git a/v0.5.0/functions/Knative/hello-world-java/pom.xml b/v0.5.0/functions/Knative/hello-world-java/pom.xml deleted file mode 100644 index bc93ba7..0000000 --- a/v0.5.0/functions/Knative/hello-world-java/pom.xml +++ /dev/null @@ -1,45 +0,0 @@ - - 4.0.0 - - com.openfunction - java-sample - 1.0.0-SNAPSHOT - - 11 - 11 - - - - - - com.google.cloud.functions - functions-framework-api - 1.0.4 - provided - - - - - - - - com.google.cloud.functions - function-maven-plugin - 0.9.7 - - com.openfunction.HelloWorld - - - - - diff --git a/v0.5.0/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java b/v0.5.0/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java deleted file mode 100644 index 02b2c43..0000000 --- a/v0.5.0/functions/Knative/hello-world-java/src/main/java/com/openfunction/HelloWorld.java +++ /dev/null @@ -1,30 +0,0 @@ -// Copyright 2019 Google LLC -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// -// https://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -package com.openfunction; - -import com.google.cloud.functions.HttpFunction; -import com.google.cloud.functions.HttpRequest; -import com.google.cloud.functions.HttpResponse; -import java.io.BufferedWriter; -import java.io.IOException; - -public class HelloWorld implements HttpFunction { - // Simple function to return "Hello World" - @Override - public void service(HttpRequest request, HttpResponse response) - throws IOException { - BufferedWriter writer = response.getWriter(); - writer.write("Hello World!"); - } -} diff --git a/v0.5.0/functions/Knative/hello-world-node/README.md b/v0.5.0/functions/Knative/hello-world-node/README.md deleted file mode 100644 index 515a6e7..0000000 --- a/v0.5.0/functions/Knative/hello-world-node/README.md +++ /dev/null @@ -1,31 +0,0 @@ -# Sample Function Node - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```node``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: node-sample -spec: - version: "v1.0.0" - image: "/sample-node-func:v0.5.0" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "helloWorld" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/Knative/hello-world-node" - serving: - runtime: "Knative" # default to Knative -``` \ No newline at end of file diff --git a/v0.5.0/functions/Knative/hello-world-node/index.js b/v0.5.0/functions/Knative/hello-world-node/index.js deleted file mode 100644 index 26ef1ae..0000000 --- a/v0.5.0/functions/Knative/hello-world-node/index.js +++ /dev/null @@ -1,3 +0,0 @@ -exports.helloWorld = (req, res) => { - res.send('hello, world'); -}; diff --git a/v0.5.0/functions/Knative/hello-world-python/README.md b/v0.5.0/functions/Knative/hello-world-python/README.md deleted file mode 100644 index 6478b02..0000000 --- a/v0.5.0/functions/Knative/hello-world-python/README.md +++ /dev/null @@ -1,33 +0,0 @@ -# Sample Function Python - -## Run on OpenFunction - -1. [Install OpenFunction](https://github.com/OpenFunction/OpenFunction#install-openfunction) -2. [Refer to the go function sample](../hello-world-go/README.md) - -Definition of a ```Function``` for ```python``` is shown below: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: python-sample -spec: - version: "v1.0.0" - image: "/sample-python-func:v0.5.0" - imageCredentials: - name: push-secret - port: 8080 # default to 8080 - build: - builder: "openfunction/gcp-builder:v1" - env: - GOOGLE_FUNCTION_TARGET: "hello_world" - GOOGLE_FUNCTION_SIGNATURE_TYPE: "http" - GOOGLE_FUNCTION_SOURCE: "main.py" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/Knative/hello-world-python" - serving: - runtime: Knative # default to Knative -``` - diff --git a/v0.5.0/functions/Knative/hello-world-python/main.py b/v0.5.0/functions/Knative/hello-world-python/main.py deleted file mode 100644 index 249f1b8..0000000 --- a/v0.5.0/functions/Knative/hello-world-python/main.py +++ /dev/null @@ -1,2 +0,0 @@ -def hello_world(request): - return "hello, world" diff --git a/v0.5.0/functions/Knative/hello-world-python/requirements.txt b/v0.5.0/functions/Knative/hello-world-python/requirements.txt deleted file mode 100644 index bc9616b..0000000 --- a/v0.5.0/functions/Knative/hello-world-python/requirements.txt +++ /dev/null @@ -1 +0,0 @@ -functions-framework==1.4.3 \ No newline at end of file diff --git a/v0.5.0/functions/Knative/logs-handler-function/LogsHandler.go b/v0.5.0/functions/Knative/logs-handler-function/LogsHandler.go deleted file mode 100644 index ebbf8c0..0000000 --- a/v0.5.0/functions/Knative/logs-handler-function/LogsHandler.go +++ /dev/null @@ -1,96 +0,0 @@ -package logshandler - -import ( - "bytes" - "encoding/json" - "fmt" - "io/ioutil" - "log" - "net/http" - "regexp" - "time" - - alert "github.com/prometheus/alertmanager/template" -) - -const ( - HTTPCodeNotFound = "404" - Namespace = "demo-project" - PodName = "wordpress-v1-[A-Za-z0-9]{5,15}-[A-Za-z0-9]{3,10}" - AlertName = "404 Request" - Severity = "warning" - NotificationManagerAddress = "http://notification-manager-svc.kubesphere-monitoring-system.svc.cluster.local:19093/api/v2/alerts" -) - -func LogsHandler(w http.ResponseWriter, r *http.Request) { - reqBody, err := ioutil.ReadAll(r.Body) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Get request body failed") - return - } - content := string(reqBody) - matchHTTPCode, _ := regexp.MatchString(fmt.Sprintf(" %s ", HTTPCodeNotFound), content) - matchNamespace, _ := regexp.MatchString(fmt.Sprintf("namespace_name\":\"%s", Namespace), content) - matchPodName := regexp.MustCompile(fmt.Sprintf(`(%s)`, PodName)).FindStringSubmatch(content) - - if matchHTTPCode && matchNamespace && matchPodName != nil { - log.Printf("Match log - Content: %s", content) - - match := regexp.MustCompile(`([A-Z]+) (/\S*) HTTP`).FindStringSubmatch(content) - if match == nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Cannot retrieve information") - return - } - path := match[len(match)-1] - method := match[len(match)-2] - podName := matchPodName[len(matchPodName)-1] - - notify := &alert.Data{ - Receiver: "notification_manager", - Status: "firing", - Alerts: alert.Alerts{}, - GroupLabels: alert.KV{"alertname": AlertName, "namespace": Namespace}, - CommonLabels: alert.KV{"alertname": AlertName, "namespace": Namespace, "severity": Severity}, - CommonAnnotations: alert.KV{}, - ExternalURL: "", - } - alt := alert.Alert{ - Status: "firing", - Labels: alert.KV{ - "alertname": AlertName, - "namespace": Namespace, - "severity": Severity, - "pod": podName, - "path": path, - "method": method, - }, - Annotations: alert.KV{}, - StartsAt: time.Now(), - EndsAt: time.Time{}, - GeneratorURL: "", - Fingerprint: "", - } - notify.Alerts = append(notify.Alerts, alt) - notifyBytes, _ := json.Marshal(notify) - - req, err := http.NewRequest("POST", NotificationManagerAddress, bytes.NewReader(notifyBytes)) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Failed to create request") - return - } - req.Header.Set("Content-Type", "application/json") - client := &http.Client{} - _, err = client.Do(req) - if err != nil { - w.WriteHeader(500) - fmt.Fprintln(w, "Failed to send request to notification manager") - return - } - - log.Printf("Send log to notification manager") - } - return -} diff --git a/v0.5.0/functions/Knative/logs-handler-function/README.md b/v0.5.0/functions/Knative/logs-handler-function/README.md deleted file mode 100644 index 93ed6e0..0000000 --- a/v0.5.0/functions/Knative/logs-handler-function/README.md +++ /dev/null @@ -1,28 +0,0 @@ -# Function Logs Handler - -For a detailed description of this function example, you can refer to the following blogs: - -[OpenFunction 应用系列之一: 以 Serverless 的方式实现 Kubernetes 日志告警](https://kubesphere.io/zh/blogs/serverless-way-for-kubernetes-log-alert/) - -or - -[Serverless Use Case: Elastic Kubernetes Log Alerts with OpenFunction and Kafka](https://kubesphere.io/blogs/serverless-way-for-kubernetes-log-alert/) - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-logs-receiver` and a Topic named `logs`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -Create logs handler function: - -```shell -kubectl apply -f logs-handler-function.yaml -``` - -The logs handler function is then driven by messages from the logs topic in Kafka. - diff --git a/v0.5.0/functions/Knative/logs-handler-function/go.mod b/v0.5.0/functions/Knative/logs-handler-function/go.mod deleted file mode 100644 index dbf3c35..0000000 --- a/v0.5.0/functions/Knative/logs-handler-function/go.mod +++ /dev/null @@ -1,7 +0,0 @@ -module example.com/logshandler - -go 1.15 - -require ( - github.com/prometheus/alertmanager v0.22.2 -) diff --git a/v0.5.0/functions/Knative/logs-handler-function/logs-handler-function.yaml b/v0.5.0/functions/Knative/logs-handler-function/logs-handler-function.yaml deleted file mode 100644 index fa6e260..0000000 --- a/v0.5.0/functions/Knative/logs-handler-function/logs-handler-function.yaml +++ /dev/null @@ -1,23 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: logs-sync-handler -spec: - version: "v1.0.0" - image: openfunctiondev/logs-sync-handler:v0.5.0 - imageCredentials: - name: push-secret - build: - builder: openfunction/builder-go:v0.4.0-1.15 - env: - FUNC_NAME: "LogsHandler" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/Knative/logs-handler-function/" - serving: - runtime: "Knative" -# template: -# containers: -# - name: function -# # Set imagePullPolicy if needed -# imagePullPolicy: Always \ No newline at end of file diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/README.md b/v0.5.0/functions/OpenFuncAsync/bindings/README.md deleted file mode 100644 index 29bd8ac..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/README.md +++ /dev/null @@ -1,116 +0,0 @@ -# Function Input/Output - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-bindings-server` and a Topic named `sample`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. - -## Deployment - -### Input only sample - -We will use the sample in the `without-output` directory, which will be triggered by Dapr's `bindings.cron` component at a frequency of once every 2 seconds. - -Modify the `spec.image` field in `without-output/function-bindings.yaml` to your own container registry address: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-without-output -spec: - image: "/bindings-without-output:latest" -``` - -Use the following commands to create this Function: - -```shell -kubectl apply -f without-output/function-bindings.yaml -``` - -Afterwards, use the following command to observe the log of the function: - -```shell -kubectl logs -f \ - $(kubectl get po -l \ - openfunction.io/serving=$(kubectl get functions bindings-without-output -o jsonpath='{.status.serving.resourceRef}') \ - -o jsonpath='{.items[0].metadata.name}') \ - function -``` - -You will be able to see messages similar to the following: - -```shell -2021/07/02 09:02:02 binding - Data: Received -2021/07/02 09:02:04 binding - Data: Received -2021/07/02 09:02:06 binding - Data: Received -2021/07/02 09:02:08 binding - Data: Received -``` - -### Input and Output - -We will use the sample in the `with-output` directory, which will be triggered by Dapr's `bindings.cron` component at a frequency of once every 2 seconds. After being triggered, it will send a greeting to another service via Dapr's `bindings.kafka` component. - -Modify the `spec.image` field in `without-output/function-bindings.yaml` to your own container registry address: - -```yaml -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-with-output -spec: - image: "/bindings-with-output:latest" -``` - -Use the following commands to create this Function: - -```shell -kubectl apply -f with-output/function-bindings.yaml -``` - -Afterwards, use the following command to observe the log of the function: - -```shell -kubectl logs -f \ - $(kubectl get po -l \ - openfunction.io/serving=$(kubectl get functions bindings-with-output -o jsonpath='{.status.serving.resourceRef}') \ - -o jsonpath='{.items[0].metadata.name}') \ - function -``` - -You will be able to see messages similar to the following: - -```shell -2021/07/02 09:02:02 binding - Data: Received -2021/07/02 09:02:04 binding - Data: Received -2021/07/02 09:02:06 binding - Data: Received -2021/07/02 09:02:08 binding - Data: Received -``` - -Now we need to start the output target function. - -```shell -kubectl apply -f with-output/output/output-target.yaml -``` - -Use the following command to observe the log of the function: - -```shell -kubectl logs -f \ - $(kubectl get po -l \ - openfunction.io/serving=$(kubectl get functions bindings-output-target -o jsonpath='{.status.serving.resourceRef}') \ - -o jsonpath='{.items[0].metadata.name}') \ - function -``` - -You will be able to see messages similar to the following: - -```shell -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -data from Event Hubs '{Hello}' -``` diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go b/v0.5.0/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go deleted file mode 100644 index 1d885fa..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/bindings_with_output.go +++ /dev/null @@ -1,25 +0,0 @@ -package bindings - -import ( - "encoding/json" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsOutput(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - var greeting []byte - if in != nil { - log.Printf("binding - Data: %s", in) - greeting = in - } else { - log.Print("binding - Data: Received") - greeting, _ = json.Marshal(map[string]string{"message": "Hello"}) - } - - _, err := ctx.Send("sample", greeting) - if err != nil { - log.Printf("Error: %v\n", err) - return ctx.ReturnWithInternalError() - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml b/v0.5.0/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml deleted file mode 100644 index 111a1cd..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/function-bindings.yaml +++ /dev/null @@ -1,52 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-with-output -spec: - version: "v1.0.0" - image: openfunctiondev/bindings-with-output:v0.5.0 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.4.0-1.15" - env: - FUNC_NAME: "BindingsOutput" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/OpenFuncAsync/bindings/with-output/" - serving: - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: cron - component: cron - type: bindings - outputs: - - name: sample - component: sample-topic - type: bindings - operation: "create" - annotations: - "dapr.io/log-level": "debug" - components: - cron: - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" - sample-topic: - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-bindings-server-kafka-brokers:9092" - - name: topics - value: sample - - name: consumerGroup - value: group1 - - name: publishTopic - value: sample - - name: authRequired - value: "false" diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/go.mod b/v0.5.0/functions/OpenFuncAsync/bindings/with-output/go.mod deleted file mode 100644 index f82353a..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/bindings - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.1.0 diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/go.mod b/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/go.mod deleted file mode 100644 index 5ace5b1..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/main - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.1.0 diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/goapp.go b/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/goapp.go deleted file mode 100644 index e4d44fc..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/goapp.go +++ /dev/null @@ -1,22 +0,0 @@ -package bindings - -import ( - "encoding/json" - "fmt" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" -) - -func OutputTarget(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - var msg Message - err := json.Unmarshal(in, &msg) - if err != nil { - fmt.Println("error reading message from Kafka binding", err) - return ctx.ReturnWithInternalError() - } - fmt.Printf("message from Kafka '%s'\n", msg) - return ctx.ReturnWithSuccess() -} - -type Message struct { - Msg string `json:"message"` -} diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml b/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml deleted file mode 100644 index e8ed3d8..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/with-output/output/output-target.yaml +++ /dev/null @@ -1,32 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-output-target -spec: - version: "v1.0.0" - image: openfunctiondev/bindings-output-target:v0.5.0 - serving: - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: sample - component: sample-topic - type: bindings - annotations: - "dapr.io/log-level": "debug" - components: - sample-topic: - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-bindings-server-kafka-brokers:9092" - - name: topics - value: sample - - name: consumerGroup - value: group2 - - name: publishTopic - value: sample - - name: authRequired - value: "false" diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go b/v0.5.0/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go deleted file mode 100644 index 3ae795f..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/without-output/bindings_without_output.go +++ /dev/null @@ -1,15 +0,0 @@ -package bindings - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func BindingsNoOutput(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - if in != nil { - log.Printf("binding - Data: %s", in) - } else { - log.Print("binding - Data: Received") - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml b/v0.5.0/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml deleted file mode 100644 index 65d281e..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/without-output/function-bindings.yaml +++ /dev/null @@ -1,34 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: bindings-without-output -spec: - version: "v1.0.0" - image: openfunctiondev/bindings-without-output:v0.5.0 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.4.0-1.15" - env: - FUNC_NAME: "BindingsNoOutput" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/OpenFuncAsync/bindings/without-output/" - serving: - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: cron - component: cron - type: bindings - annotations: - "dapr.io/log-level": "debug" - components: - cron: - type: bindings.cron - version: v1 - metadata: - - name: schedule - value: "@every 2s" - diff --git a/v0.5.0/functions/OpenFuncAsync/bindings/without-output/go.mod b/v0.5.0/functions/OpenFuncAsync/bindings/without-output/go.mod deleted file mode 100644 index 7d592b0..0000000 --- a/v0.5.0/functions/OpenFuncAsync/bindings/without-output/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/bindings - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.1.0 \ No newline at end of file diff --git a/v0.5.0/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go b/v0.5.0/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go deleted file mode 100644 index 967ae51..0000000 --- a/v0.5.0/functions/OpenFuncAsync/logs-handler-function/LogsHandler.go +++ /dev/null @@ -1,73 +0,0 @@ -package logs_handler_function - -import ( - "encoding/json" - "fmt" - "log" - "regexp" - "time" - - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - alert "github.com/prometheus/alertmanager/template" -) - -const ( - HTTPCodeNotFound = "404" - Namespace = "demo-project" - PodName = "wordpress-v1-[A-Za-z0-9]{5,15}-[A-Za-z0-9]{3,10}" - AlertName = "404 Request" - Severity = "warning" -) - -func LogsHandler(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - content := string(in) - matchHTTPCode, _ := regexp.MatchString(fmt.Sprintf(" %s ", HTTPCodeNotFound), content) - matchNamespace, _ := regexp.MatchString(fmt.Sprintf("namespace_name\":\"%s", Namespace), content) - matchPodName := regexp.MustCompile(fmt.Sprintf(`(%s)`, PodName)).FindStringSubmatch(content) - - if matchHTTPCode && matchNamespace && matchPodName != nil { - log.Printf("Match log - Content: %s", content) - - match := regexp.MustCompile(`([A-Z]+) (/\S*) HTTP`).FindStringSubmatch(content) - if match == nil { - return ctx.ReturnWithInternalError() - } - path := match[len(match)-1] - method := match[len(match)-2] - podName := matchPodName[len(matchPodName)-1] - - notify := &alert.Data{ - Receiver: "notification_manager", - Status: "firing", - Alerts: alert.Alerts{}, - GroupLabels: alert.KV{"alertname": AlertName, "namespace": Namespace}, - CommonLabels: alert.KV{"alertname": AlertName, "namespace": Namespace, "severity": Severity}, - CommonAnnotations: alert.KV{}, - ExternalURL: "", - } - alt := alert.Alert{ - Status: "firing", - Labels: alert.KV{ - "alertname": AlertName, - "namespace": Namespace, - "severity": Severity, - "pod": podName, - "path": path, - "method": method, - }, - Annotations: alert.KV{}, - StartsAt: time.Now(), - EndsAt: time.Time{}, - GeneratorURL: "", - Fingerprint: "", - } - notify.Alerts = append(notify.Alerts, alt) - notifyBytes, _ := json.Marshal(notify) - - if _, err := ctx.Send("notify", notifyBytes); err != nil { - panic(err) - } - log.Printf("Send log to notification manager.") - } - return ctx.ReturnWithSuccess() -} diff --git a/v0.5.0/functions/OpenFuncAsync/logs-handler-function/go.mod b/v0.5.0/functions/OpenFuncAsync/logs-handler-function/go.mod deleted file mode 100644 index 328b617..0000000 --- a/v0.5.0/functions/OpenFuncAsync/logs-handler-function/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module example.com/logshandler - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/prometheus/alertmanager v0.22.2 -) diff --git a/v0.5.0/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml b/v0.5.0/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml deleted file mode 100644 index 9903d1c..0000000 --- a/v0.5.0/functions/OpenFuncAsync/logs-handler-function/logs-handler-function.yaml +++ /dev/null @@ -1,67 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: logs-async-handler -spec: - version: "v1.0.0" - image: openfunctiondev/logs-async-handler:v0.5.0 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.4.0-1.15" - env: - FUNC_NAME: "LogsHandler" - # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/OpenFuncAsync/logs-handler-function/" - serving: - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: kafka - component: kafka-receiver - type: bindings - outputs: - - name: notify - type: bindings - component: notification-manager - operation: "post" - annotations: - dapr.io/log-level: "debug" - components: - kafka-receiver: - type: bindings.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-logs-receiver-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: publishTopic - value: "logs" - - name: topics - value: "logs" - - name: consumerGroup - value: "logs-handler" - notification-manager: - type: bindings.http - version: v1 - metadata: - - name: url - value: http://notification-manager-svc.kubesphere-monitoring-system.svc.cluster.local:19093/api/v2/alerts - keda: - scaledObject: - pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 - cooldownPeriod: 30 - triggers: - - type: kafka - metadata: - topic: logs - bootstrapServers: kafka-logs-receiver-kafka-brokers.default.svc.cluster.local:9092 - consumerGroup: logs-handler - lagThreshold: "10" diff --git a/v0.5.0/functions/OpenFuncAsync/pubsub/README.md b/v0.5.0/functions/OpenFuncAsync/pubsub/README.md deleted file mode 100644 index 4066d0f..0000000 --- a/v0.5.0/functions/OpenFuncAsync/pubsub/README.md +++ /dev/null @@ -1,43 +0,0 @@ -# Autoscaling service based on queue depth - -## Prerequisites - -Follow [this guide](../../../../Prerequisites.md#openfunction) to install OpenFunction. - -Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-pubsub-server` and a Topic named `metric`. - -Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential.Kafka - -## Deployment - -To configure the autoscaling demo we will deploy two functions: `subscriber` which will be used to process messages of the `metric` queue in Kafka, and the `producer`, which will be publishing messages. - -Modify the ``spec.image`` field in ``producer/function-producer.yaml`` and ``subscriber/function-subscribe.yaml`` to your own container registry address: - - ```yaml - apiVersion: core.openfunction.io/v1alpha2 - kind: Function - metadata: - name: autoscaling-producer - spec: - image: "/autoscaling-producer:latest" - ``` - - ```yaml - apiVersion: core.openfunction.io/v1alpha2 - kind: Function - metadata: - name: autoscaling-subscriber - spec: - image: "/autoscaling-subscriber:latest" - ``` - -Use the following commands to create these Functions: - -```shell -kubectl apply -f producer/function-producer.yaml -kubectl apply -f subscriber/function-subscriber.yaml -``` - -Back in the initial terminal now, some 20-30 seconds after the `producer` starts, you should see the number of `subscriber` pods being adjusted by Keda based on the number of the `metric` topic. - diff --git a/v0.5.0/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml b/v0.5.0/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml deleted file mode 100644 index 0bf527a..0000000 --- a/v0.5.0/functions/OpenFuncAsync/pubsub/producer/function-producer.yaml +++ /dev/null @@ -1,51 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: autoscaling-producer -spec: - version: "v1.0.0" - image: openfunctiondev/autoscaling-producer:v0.5.0 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.4.0-1.15" - env: - FUNC_NAME: "Producer" - # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/OpenFuncAsync/pubsub/producer/" - serving: - runtime: "OpenFuncAsync" - params: - OUTPUT_NAME: producer - TOPIC_NAME: metric - NUMBER_OF_PUBLISHERS: "2" - PUBLISHERS_FREQ: "100ms" - PUBLISHERS_DELAY: "10s" - LOG_FREQ: "3s" - PUBLISH_TO_CONSOLE: "false" - openFuncAsync: - dapr: - outputs: - - name: producer - component: autoscaling-producer - type: pubsub - topic: metric - annotations: - "dapr.io/log-level": "debug" - components: - autoscaling-producer: - type: pubsub.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-pubsub-server-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: allowedTopics - value: "metric" - - name: consumerID - value: "autoscaling-producer" - diff --git a/v0.5.0/functions/OpenFuncAsync/pubsub/producer/go.mod b/v0.5.0/functions/OpenFuncAsync/pubsub/producer/go.mod deleted file mode 100644 index d83c736..0000000 --- a/v0.5.0/functions/OpenFuncAsync/pubsub/producer/go.mod +++ /dev/null @@ -1,8 +0,0 @@ -module example.com/producer - -go 1.15 - -require ( - github.com/OpenFunction/functions-framework-go v0.1.0 - github.com/google/uuid v1.1.2 -) diff --git a/v0.5.0/functions/OpenFuncAsync/pubsub/producer/producer.go b/v0.5.0/functions/OpenFuncAsync/pubsub/producer/producer.go deleted file mode 100644 index 515c829..0000000 --- a/v0.5.0/functions/OpenFuncAsync/pubsub/producer/producer.go +++ /dev/null @@ -1,189 +0,0 @@ -// An example, referenced from https://github.com/mchmarny/dapr-demos/tree/master/autoscaling-on-queue - -package producer - -import ( - "crypto/sha256" - "encoding/json" - "fmt" - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "github.com/google/uuid" - "log" - "math/rand" - "os" - "os/signal" - "strconv" - "strings" - "sync" - "syscall" - "time" -) - -const ( - chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" -) - -var ( - logger = log.New(os.Stdout, "", 0) - outputName = getEnvVar("OUTPUT_NAME", "autoscaling") - numOfPublishers = getEnvIntOrFail("NUMBER_OF_PUBLISHERS", "1") - publishFrequency = getEnvDurationOrFail("PUBLISHERS_FREQ", "1s") - publishDelay = getEnvDurationOrFail("PUBLISHERS_DELAY", "10s") - logFrequency = getEnvDurationOrFail("LOG_FREQ", "3s") - publishToConsole = getEnvBoolOrFail("PUBLISH_TO_CONSOLE", "false") -) - -func Producer(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - if numOfPublishers < 1 { - numOfPublishers = 1 - } - logger.Printf("subscription name: %s", outputName) - logger.Printf("number of publishers: %d", numOfPublishers) - logger.Printf("publish frequency: %v", publishFrequency) - logger.Printf("log frequency: %v", logFrequency) - logger.Printf("publish delay: %v", publishDelay) - - // handle signals - stop := make(chan os.Signal) - signal.Notify(stop, syscall.SIGTERM, syscall.SIGINT) - - resultCh := make(chan bool, 100) - stopCh := make(chan struct{}) - - go func() { - <-stop - close(stopCh) - }() - - // print results - go monitor(resultCh, stopCh) - - // start producing - for i := 1; i <= numOfPublishers; i++ { - go publish(ctx, i, resultCh, stopCh) - } - - return ctx.ReturnWithSuccess() -} - -func monitor(resultCh <-chan bool, stopCh <-chan struct{}) { - var mux sync.Mutex - var successCounter int64 = 0 - var errorCounter int64 = 0 - startTime := time.Now() - tickerCh := time.NewTicker(logFrequency).C - for { - select { - case r := <-resultCh: - mux.Lock() - if r { - successCounter++ - } else { - errorCounter++ - } - mux.Unlock() - case <-tickerCh: - var avg float64 = 0 - if successCounter > 0 { - avg = float64(successCounter) / time.Since(startTime).Seconds() - } - logger.Printf("%10d published, %3.0f/sec, %3d errors", successCounter, avg, errorCounter) - case <-stopCh: - os.Exit(0) - } - } -} - -func publish(ctx *ofctx.OpenFunctionContext, index int, resultCh chan<- bool, stopCh <-chan struct{}) { - delayCh := time.NewTicker(publishDelay).C - <-delayCh - - tickerCh := time.NewTicker(publishFrequency).C - for { - select { - case <-stopCh: - return - case <-tickerCh: - d := getEventData(index) - if publishToConsole { - logger.Printf("%s", d) - resultCh <- true - continue - } - if _, err := ctx.Send(outputName, d); err != nil { - logger.Printf("send error, %v", err) - resultCh <- false - } else { - resultCh <- true - } - } - } -} - -func getEventData(index int) []byte { - r := requestContent{ - ID: fmt.Sprintf("p%d-%s", index, uuid.New().String()), - Data: []byte(getData(256)), - Time: time.Now().String(), - } - - // hash the entire message - inSha := sha256.Sum256(r.Data) - r.Sha = string(inSha[:]) - - b, err := json.Marshal(r) - if err != nil { - logger.Fatalf("error generating request: %v", err) - } - return b -} - -func getData(length int) string { - seededRand := rand.New(rand.NewSource(time.Now().UnixNano())) - b := make([]byte, length) - for i := range b { - b[i] = chars[seededRand.Intn(len(chars))] - } - return string(b) -} - -type requestContent struct { - ID string `json:"id"` - Data []byte `json:"data"` - Sha string `json:"sha"` - Time string `json:"time"` -} - -func getEnvVar(key, fallbackValue string) string { - if val, ok := os.LookupEnv(key); ok { - return strings.TrimSpace(val) - } - return fallbackValue -} - -func getEnvIntOrFail(key, fallbackValue string) int { - s := getEnvVar(key, fallbackValue) - v, err := strconv.Atoi(s) - if err != nil { - logger.Fatalf("invalid number variable: %s - %v", s, err) - } - return v -} - -func getEnvDurationOrFail(key, fallbackValue string) time.Duration { - s := getEnvVar(key, fallbackValue) - v, err := time.ParseDuration(s) - if err != nil { - logger.Fatalf("invalid duration variable: %s - %v", s, err) - } - return v -} - -func getEnvBoolOrFail(key, fallbackValue string) bool { - s := getEnvVar(key, fallbackValue) - v, err := strconv.ParseBool(s) - if err != nil { - logger.Fatalf("invalid bool variable: %s - %v", s, err) - } - return v -} diff --git a/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml b/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml deleted file mode 100644 index 4997088..0000000 --- a/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/function-subscriber.yaml +++ /dev/null @@ -1,56 +0,0 @@ -apiVersion: core.openfunction.io/v1alpha2 -kind: Function -metadata: - name: autoscaling-subscriber -spec: - version: "v1.0.0" - image: openfunctiondev/autoscaling-subscriber:v0.5.0 - imageCredentials: - name: push-secret - build: - builder: "openfunction/builder-go:v0.4.0-1.15" - env: - FUNC_NAME: "Subscriber" - # Use FUNC_GOPROXY to set the goproxy - #FUNC_GOPROXY: "https://goproxy.cn" - srcRepo: - url: "https://github.com/OpenFunction/samples.git" - sourceSubPath: "v0.5.0/functions/OpenFuncAsync/pubsub/subscriber" - serving: - runtime: "OpenFuncAsync" - openFuncAsync: - dapr: - inputs: - - name: subscriber - component: autoscaling-subscriber - type: pubsub - topic: metric - annotations: - dapr.io/log-level: "debug" - components: - autoscaling-subscriber: - type: pubsub.kafka - version: v1 - metadata: - - name: brokers - value: "kafka-pubsub-server-kafka-brokers:9092" - - name: authRequired - value: "false" - - name: allowedTopics - value: "metric" - - name: consumerID - value: "autoscaling-subscriber" - keda: - scaledObject: - pollingInterval: 15 - minReplicaCount: 0 - maxReplicaCount: 10 - cooldownPeriod: 30 - triggers: - - type: kafka - metadata: - topic: metric - bootstrapServers: kafka-pubsub-server-kafka-brokers.default.svc.cluster.local:9092 - consumerGroup: autoscaling-subscriber - lagThreshold: "10" - diff --git a/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/go.mod b/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/go.mod deleted file mode 100644 index dba3bf7..0000000 --- a/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/go.mod +++ /dev/null @@ -1,5 +0,0 @@ -module example.com/subscriber - -go 1.15 - -require github.com/OpenFunction/functions-framework-go v0.1.0 diff --git a/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go b/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go deleted file mode 100644 index b609fc4..0000000 --- a/v0.5.0/functions/OpenFuncAsync/pubsub/subscriber/subscriber.go +++ /dev/null @@ -1,11 +0,0 @@ -package subscriber - -import ( - ofctx "github.com/OpenFunction/functions-framework-go/openfunction-context" - "log" -) - -func Subscriber(ctx *ofctx.OpenFunctionContext, in []byte) ofctx.RetValue { - log.Printf("event - Data: %s", in) - return ctx.ReturnWithSuccess() -}