Skip to content

Commit c513e41

Browse files
authored
Merge pull request #1 from wrongerror/main
implement dapr proxy
2 parents 0b12620 + 3cbd781 commit c513e41

35 files changed

+4954
-0
lines changed

.github/workflows/e2e-test.sh

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#! /bin/bash
2+
3+
# Copyright 2022 The OpenFunction Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
function verify_bindings_http() {
18+
kubectl apply -f test/http/bindings/manifests.yaml
19+
20+
data_expected="hello: world"
21+
plugin_expected="sum: 2"
22+
while /bin/true; do
23+
data_result=$(kubectl logs --tail=2 -l app="bindings-target" -c target | grep Data | awk '{ print $8 }' | yq -P '.' -)
24+
plugin_result=$(kubectl logs --tail=2 -l app="bindings-target" -c target | grep plugin | awk '{ print $8 }' | yq -P '.' -)
25+
if [ "${data_result}" != "${data_expected}" ] || [ "${plugin_result}" != "${plugin_expected}" ]; then
26+
sleep 1
27+
continue
28+
else
29+
echo "bindings http tested successfully!"
30+
kubectl delete -f test/http/bindings/manifests.yaml
31+
break
32+
fi
33+
done
34+
}
35+
36+
function verify_pubsub_http() {
37+
kubectl apply -f test/http/pubsub/manifests.yaml
38+
39+
data_expected="hello: world"
40+
plugin_expected="sum: 2"
41+
while /bin/true; do
42+
data_result=$(kubectl logs --tail=2 -l app="pubsub-subscriber" -c sub | grep Data | awk '{ print $8 }' | yq -P '.' -)
43+
plugin_result=$(kubectl logs --tail=2 -l app="pubsub-subscriber" -c sub | grep plugin | awk '{ print $8 }' | yq -P '.' -)
44+
if [ "${data_result}" != "${data_expected}" ] || [ "${plugin_result}" != "${plugin_expected}" ]; then
45+
sleep 1
46+
continue
47+
else
48+
echo "bindings http tested successfully!"
49+
kubectl delete -f test/http/pubsub/manifests.yaml
50+
break
51+
fi
52+
done
53+
}
54+
55+
function verify_bindings_grpc() {
56+
kubectl apply -f test/grpc/bindings/manifests.yaml
57+
58+
data_expected="hello: world"
59+
plugin_expected="sum: 2"
60+
while /bin/true; do
61+
data_result=$(kubectl logs --tail=2 -l app="bindings-target" -c target | grep Data | awk '{ print $8 }' | yq -P '.' -)
62+
plugin_result=$(kubectl logs --tail=2 -l app="bindings-target" -c target | grep plugin | awk '{ print $8 }' | yq -P '.' -)
63+
if [ "${data_result}" != "${data_expected}" ] || [ "${plugin_result}" != "${plugin_expected}" ]; then
64+
sleep 1
65+
continue
66+
else
67+
echo "bindings http tested successfully!"
68+
kubectl delete -f test/grpc/bindings/manifests.yaml
69+
break
70+
fi
71+
done
72+
}
73+
74+
function verify_pubsub_grpc() {
75+
kubectl apply -f test/grpc/pubsub/manifests.yaml
76+
77+
data_expected="hello: world"
78+
plugin_expected="sum: 2"
79+
while /bin/true; do
80+
data_result=$(kubectl logs --tail=2 -l app="pubsub-subscriber" -c sub | grep Data | awk '{ print $8 }' | yq -P '.' -)
81+
plugin_result=$(kubectl logs --tail=2 -l app="pubsub-subscriber" -c sub | grep plugin | awk '{ print $8 }' | yq -P '.' -)
82+
if [ "${data_result}" != "${data_expected}" ] || [ "${plugin_result}" != "${plugin_expected}" ]; then
83+
sleep 1
84+
continue
85+
else
86+
echo "bindings http tested successfully!"
87+
kubectl delete -f test/grpc/pubsub/manifests.yaml
88+
break
89+
fi
90+
done
91+
}
92+
93+
case $1 in
94+
95+
bindings_http)
96+
verify_bindings_http
97+
;;
98+
99+
pubsub_http)
100+
verify_pubsub_http
101+
;;
102+
103+
bindings_grpc)
104+
verify_bindings_grpc
105+
;;
106+
107+
pubsub_grpc)
108+
verify_pubsub_grpc
109+
;;
110+
esac

.github/workflows/main.yml

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
name: Main CI
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
paths:
7+
- '.github/workflows/**'
8+
- 'pkg/**'
9+
- 'test/**'
10+
- 'go.mod'
11+
- 'main.go'
12+
13+
jobs:
14+
15+
build:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- uses: actions/checkout@v2
19+
20+
- name: Set up Go
21+
uses: actions/setup-go@v2
22+
with:
23+
go-version: 1.18
24+
25+
- name: Build
26+
run: go build -v ./...
27+
28+
- name: Test
29+
run: go test -v ./...
30+
31+
e2e_test:
32+
runs-on: ubuntu-latest
33+
timeout-minutes: 30
34+
name: E2E Tests
35+
steps:
36+
- name: Install Go
37+
uses: actions/setup-go@v2
38+
with:
39+
go-version: 1.18.x
40+
41+
- uses: actions/cache@v2
42+
with:
43+
path: ~/go/pkg/mod
44+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
45+
46+
- name: Checkout code
47+
uses: actions/checkout@v2
48+
with:
49+
fetch-depth: 0
50+
51+
- name: Login to Docker Hub
52+
uses: docker/login-action@v1
53+
with:
54+
username: ${{ secrets.DOCKERHUB_USERNAME }}
55+
password: ${{ secrets.DOCKERHUB_PASSWORD }}
56+
57+
- name: Create kind cluster
58+
uses: container-tools/kind-action@v1
59+
60+
- name: install yq
61+
env:
62+
VERSION: v4.22.1
63+
BINARY: yq_linux_amd64
64+
run: |
65+
wget https://github.com/mikefarah/yq/releases/download/${VERSION}/${BINARY}.tar.gz -O - |\
66+
tar xz && mv ${BINARY} /usr/local/bin/yq
67+
68+
- name: Install dependent components
69+
run: |
70+
# Install Dapr
71+
dapr -v || (wget -q https://raw.githubusercontent.com/dapr/cli/master/install/install.sh -O - | /bin/bash)
72+
dapr init -k --runtime-version 1.8.3 --log-as-json --wait --timeout 600
73+
# Install kafka
74+
helm repo add strimzi https://strimzi.io/charts/
75+
helm install kafka-operator -n default strimzi/strimzi-kafka-operator
76+
kubectl apply -f test/kafka.yaml
77+
78+
- name: Build and Push dapr-proxy image
79+
run: |
80+
docker build . -t openfunctiondev/dapr-proxy:ci -f Dockerfile --build-arg GOPROXY="https://proxy.golang.org"
81+
docker push openfunctiondev/dapr-proxy:ci
82+
83+
- name: Bindings HTTP e2e test
84+
run: |
85+
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/e2e-test.sh"
86+
bash "${GITHUB_WORKSPACE}"/.github/workflows/e2e-test.sh bindings_http
87+
88+
- name: Pubsub HTTP e2e test
89+
run: |
90+
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/e2e-test.sh"
91+
bash "${GITHUB_WORKSPACE}"/.github/workflows/e2e-test.sh pubsub_http
92+
93+
- name: Bindings GRPC e2e test
94+
run: |
95+
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/e2e-test.sh"
96+
bash "${GITHUB_WORKSPACE}"/.github/workflows/e2e-test.sh bindings_grpc
97+
98+
- name: Pubsub GRPC e2e test
99+
run: |
100+
chmod +x "${GITHUB_WORKSPACE}/.github/workflows/e2e-test.sh"
101+
bash "${GITHUB_WORKSPACE}"/.github/workflows/e2e-test.sh pubsub_grpc

Dockerfile

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
ARG GOPROXY="https://goproxy.cn"
2+
3+
# Build the dapr-proxy binary
4+
FROM golang:1.18 as builder
5+
WORKDIR /workspace
6+
7+
# Copy the Go Modules manifests
8+
COPY go.mod go.mod
9+
COPY go.sum go.sum
10+
# Download go module
11+
RUN go env -w GOPROXY=${GOPROXY} && go mod download
12+
13+
# Copy the go source
14+
Copy pkg/ pkg/
15+
COPY main.go main.go
16+
17+
# Build
18+
RUN GOPROXY=${GOPROXY} CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -a -o proxy main.go
19+
20+
# Use distroless as minimal base image to package the proxy binary
21+
FROM openfunction/distroless-static:nonroot
22+
WORKDIR /
23+
COPY --from=builder /workspace/proxy .
24+
USER 65532:65532
25+
26+
ENTRYPOINT ["/proxy"]

go.mod

Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
module github.com/OpenFunction/dapr-proxy
2+
3+
go 1.18
4+
5+
require (
6+
github.com/OpenFunction/functions-framework-go v0.0.0-20220925145105-86f7bcc9cf8c
7+
github.com/dapr/components-contrib v1.8.1-rc.1
8+
github.com/dapr/dapr v1.8.3
9+
github.com/dapr/go-sdk v1.5.0
10+
github.com/fatih/structs v1.1.0
11+
github.com/pkg/errors v0.9.1
12+
github.com/valyala/fasthttp v1.31.1-0.20211216042702-258a4c17b4f4
13+
go.opencensus.io v0.23.0
14+
google.golang.org/grpc v1.47.0
15+
k8s.io/klog/v2 v2.30.0
16+
)
17+
18+
require (
19+
contrib.go.opencensus.io/exporter/prometheus v0.4.1 // indirect
20+
contrib.go.opencensus.io/exporter/zipkin v0.1.1 // indirect
21+
github.com/AdhityaRamadhanus/fasthttpcors v0.0.0-20170121111917-d4c07198763a // indirect
22+
github.com/PuerkitoBio/purell v1.1.1 // indirect
23+
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
24+
github.com/SkyAPM/go2sky v1.4.1 // indirect
25+
github.com/andybalholm/brotli v1.0.2 // indirect
26+
github.com/antlr/antlr4/runtime/Go/antlr v0.0.0-20210826220005-b48c857c3a0e // indirect
27+
github.com/beorn7/perks v1.0.1 // indirect
28+
github.com/cenkalti/backoff/v4 v4.1.2 // indirect
29+
github.com/cespare/xxhash/v2 v2.1.2 // indirect
30+
github.com/cloudevents/sdk-go/v2 v2.4.1 // indirect
31+
github.com/dapr/kit v0.0.2-0.20210614175626-b9074b64d233 // indirect
32+
github.com/davecgh/go-spew v1.1.1 // indirect
33+
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
34+
github.com/fasthttp/router v1.3.8 // indirect
35+
github.com/fsnotify/fsnotify v1.5.4 // indirect
36+
github.com/ghodss/yaml v1.0.0 // indirect
37+
github.com/go-kit/log v0.2.0 // indirect
38+
github.com/go-logfmt/logfmt v0.5.1 // indirect
39+
github.com/go-logr/logr v1.2.3 // indirect
40+
github.com/gogo/protobuf v1.3.2 // indirect
41+
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
42+
github.com/golang/mock v1.6.0 // indirect
43+
github.com/golang/protobuf v1.5.2 // indirect
44+
github.com/google/cel-go v0.9.0 // indirect
45+
github.com/google/go-cmp v0.5.8 // indirect
46+
github.com/google/gofuzz v1.2.0 // indirect
47+
github.com/google/uuid v1.3.0 // indirect
48+
github.com/googleapis/gnostic v0.5.5 // indirect
49+
github.com/gorilla/mux v1.8.0 // indirect
50+
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 // indirect
51+
github.com/hashicorp/errwrap v1.1.0 // indirect
52+
github.com/hashicorp/go-multierror v1.1.1 // indirect
53+
github.com/hashicorp/golang-lru v0.5.4 // indirect
54+
github.com/imdario/mergo v0.3.12 // indirect
55+
github.com/json-iterator/go v1.1.12 // indirect
56+
github.com/klauspost/compress v1.14.4 // indirect
57+
github.com/matttproud/golang_protobuf_extensions v1.0.2-0.20181231171920-c182affec369 // indirect
58+
github.com/minio/blake2b-simd v0.0.0-20160723061019-3f5f724cb5b1 // indirect
59+
github.com/mitchellh/mapstructure v1.5.0 // indirect
60+
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
61+
github.com/modern-go/reflect2 v1.0.2 // indirect
62+
github.com/openzipkin/zipkin-go v0.2.2 // indirect
63+
github.com/pmezard/go-difflib v1.0.0 // indirect
64+
github.com/prometheus/client_golang v1.12.2 // indirect
65+
github.com/prometheus/client_model v0.2.0 // indirect
66+
github.com/prometheus/common v0.34.0 // indirect
67+
github.com/prometheus/procfs v0.7.3 // indirect
68+
github.com/prometheus/statsd_exporter v0.22.3 // indirect
69+
github.com/savsgio/gotils v0.0.0-20210217112953-d4a072536008 // indirect
70+
github.com/sirupsen/logrus v1.8.1 // indirect
71+
github.com/sony/gobreaker v0.4.2-0.20210216022020-dd874f9dd33b // indirect
72+
github.com/spf13/pflag v1.0.5 // indirect
73+
github.com/stoewer/go-strcase v1.2.0 // indirect
74+
github.com/stretchr/objx v0.4.0 // indirect
75+
github.com/stretchr/testify v1.7.4 // indirect
76+
github.com/valyala/bytebufferpool v1.0.0 // indirect
77+
go.opentelemetry.io/otel v1.7.0 // indirect
78+
go.uber.org/atomic v1.9.0 // indirect
79+
go.uber.org/multierr v1.7.0 // indirect
80+
go.uber.org/zap v1.21.0 // indirect
81+
golang.org/x/net v0.0.0-20220621193019-9d032be2e588 // indirect
82+
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a // indirect
83+
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
84+
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211 // indirect
85+
golang.org/x/text v0.3.7 // indirect
86+
golang.org/x/time v0.0.0-20211116232009-f0f3c7e86c11 // indirect
87+
gomodules.xyz/jsonpatch/v2 v2.2.0 // indirect
88+
google.golang.org/appengine v1.6.7 // indirect
89+
google.golang.org/genproto v0.0.0-20220622171453-ea41d75dfa0f // indirect
90+
google.golang.org/protobuf v1.28.0 // indirect
91+
gopkg.in/inf.v0 v0.9.1 // indirect
92+
gopkg.in/yaml.v2 v2.4.0 // indirect
93+
gopkg.in/yaml.v3 v3.0.1 // indirect
94+
k8s.io/api v0.23.0 // indirect
95+
k8s.io/apiextensions-apiserver v0.23.0 // indirect
96+
k8s.io/apimachinery v0.23.0 // indirect
97+
k8s.io/client-go v0.23.0 // indirect
98+
k8s.io/component-base v0.23.0 // indirect
99+
k8s.io/kube-openapi v0.0.0-20211115234752-e816edb12b65 // indirect
100+
k8s.io/utils v0.0.0-20210930125809-cb0fa318a74b // indirect
101+
sigs.k8s.io/controller-runtime v0.11.0 // indirect
102+
sigs.k8s.io/json v0.0.0-20211020170558-c049b76a60c6 // indirect
103+
sigs.k8s.io/structured-merge-diff/v4 v4.2.0 // indirect
104+
sigs.k8s.io/yaml v1.3.0 // indirect
105+
skywalking.apache.org/repo/goapi v0.0.0-20220401015832-2c9eee9481eb // indirect
106+
)
107+
108+
replace go.opentelemetry.io/otel => go.opentelemetry.io/otel v0.20.0

0 commit comments

Comments
 (0)