Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add openfunction plugin #7634

Merged
merged 79 commits into from
Sep 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
79 commits
Select commit Hold shift + click to select a range
05dc0a6
feat: add openfunction plugin
Jul 24, 2022
fc8a099
feat: add openfunction plugin
Aug 4, 2022
2b46f00
fix: change test uri
Aug 8, 2022
0c3887a
CI: prepare openfunction env
Aug 8, 2022
3d549ec
docs: add openfunction plugins
Aug 8, 2022
e13f870
fix: increase the timeout time
Aug 9, 2022
f59a15f
fix: correct htpasswd command
Aug 9, 2022
69ee651
ci: fix openfunction ci params
Aug 9, 2022
283c5e8
ci: fix openfunction ci params
Aug 9, 2022
467d6d0
docs: fix name
jackkkkklee Aug 10, 2022
e88936c
docs: fix verification command
jackkkkklee Aug 10, 2022
757f520
Merge branch 'apache:master' into master
jackkkkklee Aug 10, 2022
98b9ba1
fix: fix Code Lint
Aug 10, 2022
23521f1
fix: fix Lint
Aug 10, 2022
822b589
ci: avoid function building and run function in docker
Aug 11, 2022
c31b6c8
test: update openfunction test case
Aug 11, 2022
4f0c086
docs: add openfunction index
Aug 11, 2022
a779ca1
feat: reuse serverless.generic-upstream
Aug 11, 2022
5096a41
docs: fix lint
jackkkkklee Aug 12, 2022
9b5dc62
docs: fix lint
jackkkkklee Aug 12, 2022
2d02b02
docs: update timeout
Aug 12, 2022
f9efd9d
test: add check user-specific auth header
Aug 12, 2022
0dfc092
Merge branch 'master' of https://github.com/jackkkkklee/apisix
Aug 12, 2022
59d5236
docs: update attributes description
Aug 14, 2022
25c7910
docs: fix lint
Aug 15, 2022
9e33f23
Merge branch 'apache:master' into master
jackkkkklee Aug 15, 2022
4b4844c
Merge branch 'master' of https://github.com/jackkkkklee/apisix
Aug 15, 2022
1af451d
fix: set headers in lower-case
Aug 15, 2022
79c0b3c
ci: add building image locally
Aug 15, 2022
90d5555
docs: fix plugin description
Aug 15, 2022
f7a689c
fix: set auth header once users specify it
Aug 17, 2022
b6f6ab9
docs: fix lint
jackkkkklee Aug 17, 2022
a2b1ab5
docs: fix lint
jackkkkklee Aug 17, 2022
42f214d
docs: fix lint
jackkkkklee Aug 17, 2022
2deca1c
docs: add prerequisites section
Aug 17, 2022
2039b79
docs: fix lint
Aug 17, 2022
274f11b
docs: add sub headers
Aug 18, 2022
461ad96
docs: fix lint
jackkkkklee Aug 19, 2022
026a96a
docs: fix lint
jackkkkklee Aug 19, 2022
ed816ea
docs: fix lint
jackkkkklee Aug 19, 2022
eeee130
feat: add path forwarding test cases and docs
Aug 19, 2022
c95f3c1
docs: fix lint
Aug 19, 2022
de829b4
docs: fix lint
jackkkkklee Aug 20, 2022
ba3f404
docs: fix lint
jackkkkklee Aug 20, 2022
2ab75ca
test: add function-example and change directory structure
Aug 21, 2022
6eb79f9
ci: build function by inner repository
Aug 21, 2022
a703e08
fix: change directory name
Aug 21, 2022
09b73ff
fix: add licenses
Aug 21, 2022
0cd9975
fix: update licenses
Aug 22, 2022
898bb5d
feat: run OpenFunction function images in docker-compse
Aug 22, 2022
1857410
ci: build Openfunction functions image before running
Aug 22, 2022
72ee91a
fix: move build-function-image.sh to ./t/plugin/openfunction/
Aug 22, 2022
d47e753
ci: add building OpenFunction function images by build-pack
Aug 22, 2022
0723388
ci: add building OpenFunction function images by build-pack
Aug 22, 2022
7c5d140
fix: add openfunction in license
Aug 22, 2022
a940223
ci: modify directory of function-example
Aug 22, 2022
7411491
ci: modify directory of function-example
Aug 22, 2022
bf72abf
docs:optimize docs
jackkkkklee Aug 23, 2022
b294d83
docs: fix grammar problems
Aug 23, 2022
41d2362
docs: fix lint
jackkkkklee Aug 24, 2022
ada1d15
docs: fix lint
Aug 24, 2022
85a9c94
docs: modify expression
jackkkkklee Aug 25, 2022
55ac693
docs: modify expression
jackkkkklee Aug 25, 2022
a667c6e
docs: modify expression
jackkkkklee Aug 25, 2022
c6a56d4
docs: modify expression
jackkkkklee Aug 25, 2022
f8f07ab
docs: modify expression
jackkkkklee Aug 25, 2022
35e32ef
docs: modify expression
jackkkkklee Aug 25, 2022
5e6647a
docs: modify expression
jackkkkklee Aug 25, 2022
04edf39
docs: modify expression
jackkkkklee Aug 25, 2022
0643864
docs: modify expression
jackkkkklee Aug 25, 2022
ba5e58d
docs: modify expression
jackkkkklee Aug 25, 2022
107d685
docs: modify expression
jackkkkklee Aug 25, 2022
0d3545c
docs: fix lint
Aug 25, 2022
eed4f5a
docs: fix lint
Aug 25, 2022
b89805a
docs: update latest admin port
jackkkkklee Aug 31, 2022
558948a
ci: discard change
Aug 31, 2022
3ee2c41
docs: update admin api port
Aug 31, 2022
698f371
ci: solve conflict
Aug 31, 2022
bf5d4c9
Merge branch 'master' of https://github.com/apache/apisix
Aug 31, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ jobs:
- name: Start CI env (PLUGIN_TEST)
if: steps.test_env.outputs.type == 'plugin'
run: |
sh ci/pod/openfunction/build-function-image.sh
make ci-env-up project_compose_ci=ci/pod/docker-compose.${{ steps.test_env.outputs.type }}.yml
sudo ./ci/init-${{ steps.test_env.outputs.type }}-test-service.sh

Expand Down
1 change: 1 addition & 0 deletions .github/workflows/centos7-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ jobs:
- name: Start CI env (PLUGIN_TEST)
if: steps.test_env.outputs.type == 'plugin'
run: |
sh ci/pod/openfunction/build-function-image.sh
make ci-env-up project_compose_ci=ci/pod/docker-compose.${{ steps.test_env.outputs.type }}.yml
./ci/init-${{ steps.test_env.outputs.type }}-test-service.sh

Expand Down
1 change: 1 addition & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,4 @@ The following components are provided under the Apache License. See project link
The text of each license is the standard Apache 2.0 license.

ewma.lua file from kubernetes/ingress-nginx: https://github.com/kubernetes/ingress-nginx Apache 2.0
hello.go file from OpenFunction/samples: https://github.com/OpenFunction/samples Apache 2.0
35 changes: 35 additions & 0 deletions apisix/plugins/openfunction.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
--
-- Licensed to the Apache Software Foundation (ASF) under one or more
-- contributor license agreements. See the NOTICE file distributed with
-- this work for additional information regarding copyright ownership.
-- The ASF licenses this file to You 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
--
-- http://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.
--
local ngx_encode_base64 = ngx.encode_base64
local plugin_name, plugin_version, priority = "openfunction", 0.1, -1902

local openfunction_authz_schema = {
service_token = {type = "string"}
}

local function request_processor(conf, ctx, params)
local headers = params.headers or {}
-- setting authorization headers if authorization.service_token exists
if conf.authorization and conf.authorization.service_token then
headers["authorization"] = "Basic " .. ngx_encode_base64(conf.authorization.service_token)
end

params.headers = headers
end

return require("apisix.plugins.serverless.generic-upstream")(plugin_name,
plugin_version, priority, request_processor, openfunction_authz_schema)
29 changes: 29 additions & 0 deletions ci/pod/docker-compose.plugin.yml
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,35 @@ services:
xpack.security.enabled: 'true'


# The function services of OpenFunction
test-header:
image: test-header-image:latest
restart: unless-stopped
ports:
- "30583:8080"
environment:
CONTEXT_MODE: "self-host"
FUNC_CONTEXT: "{\"name\":\"HelloWorld\",\"version\":\"v1.0.0\",\"port\":\"8080\",\"runtime\":\"Knative\"}"

test-uri:
image: test-uri-image:latest
restart: unless-stopped
ports:
- "30584:8080"
environment:
CONTEXT_MODE: "self-host"
FUNC_CONTEXT: "{\"name\":\"HelloWorld\",\"version\":\"v1.0.0\",\"port\":\"8080\",\"runtime\":\"Knative\"}"

test-body:
image: test-body-image:latest
restart: unless-stopped
ports:
- "30585:8080"
environment:
CONTEXT_MODE: "self-host"
FUNC_CONTEXT: "{\"name\":\"HelloWorld\",\"version\":\"v1.0.0\",\"port\":\"8080\",\"runtime\":\"Knative\"}"


networks:
apisix_net:
kafka_net:
Expand Down
25 changes: 25 additions & 0 deletions ci/pod/openfunction/build-function-image.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
#
# Licensed to the Apache Software Foundation (ASF) under one or more
# contributor license agreements. See the NOTICE file distributed with
# this work for additional information regarding copyright ownership.
# The ASF licenses this file to You 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
#
# http://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.
#

wget https://github.com/buildpacks/pack/releases/download/v0.27.0/pack-v0.27.0-linux.tgz
tar -zxvf pack-v0.27.0-linux.tgz

# please update function-example/*/hello.go if you want to update function
./pack build test-uri-image --path ./ci/pod/openfunction/function-example/test-uri --builder openfunction/builder-go:v2.4.0-1.17 --env FUNC_NAME="HelloWorld" --env FUNC_CLEAR_SOURCE=true --env FUNC_GOPROXY="https://goproxy.cn"
./pack build test-body-image --path ./ci/pod/openfunction/function-example/test-body --builder openfunction/builder-go:v2.4.0-1.17 --env FUNC_NAME="HelloWorld" --env FUNC_CLEAR_SOURCE=true --env FUNC_GOPROXY="https://goproxy.cn"
./pack build test-header-image --path ./ci/pod/openfunction/function-example/test-header --builder openfunction/builder-go:v2.4.0-1.17 --env FUNC_NAME="HelloWorld" --env FUNC_CLEAR_SOURCE=true --env FUNC_GOPROXY="https://goproxy.cn"
5 changes: 5 additions & 0 deletions ci/pod/openfunction/function-example/test-body/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module example.com/hello

go 1.16

require github.com/OpenFunction/functions-framework-go v0.3.0
36 changes: 36 additions & 0 deletions ci/pod/openfunction/function-example/test-body/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright 2022 The OpenFunction Authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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 hello

import (
"fmt"
"net/http"
"io/ioutil"
"github.com/OpenFunction/functions-framework-go/functions"
)

func init() {
functions.HTTP("HelloWorld", HelloWorld)
}

func HelloWorld(w http.ResponseWriter, r *http.Request) {
body,_ := ioutil.ReadAll(r.Body)
fmt.Fprintf(w, "Hello, %s!\n", string(body))
}
3 changes: 3 additions & 0 deletions ci/pod/openfunction/function-example/test-header/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module example.com/hello

go 1.16
30 changes: 30 additions & 0 deletions ci/pod/openfunction/function-example/test-header/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2022 The OpenFunction Authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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 hello

import (
"fmt"
"net/http"
)

func HelloWorld(w http.ResponseWriter, r *http.Request) {
header := r.Header
fmt.Fprintf(w, "%s", header["Authorization"])
}
5 changes: 5 additions & 0 deletions ci/pod/openfunction/function-example/test-uri/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module example.com/hello

go 1.17

require github.com/OpenFunction/functions-framework-go v0.4.0
38 changes: 38 additions & 0 deletions ci/pod/openfunction/function-example/test-uri/hello.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright 2022 The OpenFunction Authors.
*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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
*
* http://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 hello

import (
"fmt"
ofctx "github.com/OpenFunction/functions-framework-go/context"
"net/http"

"github.com/OpenFunction/functions-framework-go/functions"
)

func init() {
functions.HTTP("HelloWorld", HelloWorld,
functions.WithFunctionPath("/{greeting}"))
}

func HelloWorld(w http.ResponseWriter, r *http.Request) {
vars := ofctx.VarsFromCtx(r.Context())
fmt.Fprintf(w, "Hello, %s!\n", vars["greeting"])
}
1 change: 1 addition & 0 deletions conf/config-default.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -471,6 +471,7 @@ plugins: # plugin list (sorted by priority)
- aws-lambda # priority: -1899
- azure-functions # priority: -1900
- openwhisk # priority: -1901
- openfunction # priority: -1902
- serverless-post-function # priority: -2000
- ext-plugin-post-req # priority: -3000
- ext-plugin-post-resp # priority: -4000
Expand Down
3 changes: 2 additions & 1 deletion docs/en/latest/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,8 @@
"plugins/azure-functions",
"plugins/openwhisk",
"plugins/aws-lambda",
"plugins/workflow"
"plugins/workflow",
"plugins/openfunction"
]
},
{
Expand Down
Loading