Skip to content

feat: circuitbreker grpc proto buf transformation #14

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

Merged
merged 12 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
18 changes: 11 additions & 7 deletions .github/workflows/check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ jobs:
run: |
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.5/protoc-3.19.5-linux-x86_64.zip
unzip protoc-3.19.5-linux-x86_64.zip -d protoc3
rm -rf protoc-3.19.5-linux-x86_64.zip
- name: Setup Buf
run: |
GO111MODULE=on GOBIN=/usr/local/bin go install github.com/bufbuild/buf/cmd/buf@v1.26.1
GO111MODULE=on GOBIN=/usr/local/bin go install ./tools/protoc-gen-golang-deepcopy
- name: Cache Go Dependencies
uses: actions/cache@v2
with:
Expand All @@ -42,17 +47,16 @@ jobs:
- name: Run Unit Tests
run: |
export PATH="$PATH:$(pwd)/protoc3/bin"
ls $(pwd)
echo $PATH
make test
rm -rf protoc-3.19.5-linux-x86_64.zip
rm -rf protoc3
git status
# TODO: enable after public
# - name: Publish Unit Test Coverage
# uses: codecov/codecov-action@v3
# with:
# flags: unittests
# file: cover.out
- name: Publish Unit Test Coverage
uses: codecov/codecov-action@v3
with:
flags: unittests
file: cover.out
- name: Check diff
run: '[[ -z $(git status -s) ]] || (printf "Existing modified/untracked files.\nPlease run \"make generate manifests fmt vet\" and push again.\n"; exit 1)'

Expand Down
6 changes: 5 additions & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ jobs:
run: |
wget https://github.com/protocolbuffers/protobuf/releases/download/v3.19.5/protoc-3.19.5-linux-x86_64.zip
unzip protoc-3.19.5-linux-x86_64.zip -d protoc3
rm -rf protoc-3.19.5-linux-x86_64.zip
- name: Setup Buf
run: |
GO111MODULE=on GOBIN=/usr/local/bin go install github.com/bufbuild/buf/cmd/buf@v1.26.1
GO111MODULE=on GOBIN=/usr/local/bin go install ./tools/protoc-gen-golang-deepcopy
- name: Cache Go Dependencies
uses: actions/cache@v2
with:
Expand All @@ -39,7 +44,6 @@ jobs:
export PATH="$PATH:$(pwd)/protoc3/bin"
echo $PATH
make test
rm -rf protoc-3.19.5-linux-x86_64.zip
rm -rf protoc3
git status

Expand Down
1 change: 1 addition & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
run:
skip-files:
- ".*_test.go"
- ".*.gen.go"
- pkg/utils/http/reverse_proxy.go
- pkg/proxy/apiserver/options.go
skip-dirs:
Expand Down
2 changes: 2 additions & 0 deletions .licenserc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ header:
- '.gitignore'
- '.licenserc'
- '**/zz_generated.deepcopy.go'
- '**/*.connect.go'
- '**/*.pb.go'
- '**/*.proto'
- '**/*.gen.go'
comment: never
license-location-threshold: 80
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ generate-client: controller-gen ## Generate code containing DeepCopy, DeepCopyIn
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

generate-protobuf: controller-gen ## Generate protobuf code.
@artifacts/scripts/generate_protobuf.sh
#@artifacts/scripts/generate_protobuf.sh
buf generate --path pkg
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."

generate: generate-client generate-protobuf
Expand All @@ -54,7 +55,7 @@ fmt: ## Run go fmt against code.
go fmt ./...

vet: ## Run go vet against code.
go vet ./...
go vet -copylocks=false ./...

ENVTEST_ASSETS_DIR=$(shell pwd)/testbin
test: fmt vet generate manifests ## Run tests.
Expand Down
6 changes: 5 additions & 1 deletion artifacts/images/manager.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ RUN CGO_ENABLED=0 GO111MODULE=on GOOS=linux GOARCH=amd64 go build -mod=vendor -a
FROM ubuntu:focal
# This is required by daemon connnecting with cri
RUN ln -s /usr/bin/* /usr/sbin/ && apt-get update -y \
&& apt-get install --no-install-recommends -y ca-certificates \
&& apt-get install --no-install-recommends -y \
sudo \
net-tools \
curl \
ca-certificates \
&& apt-get clean && rm -rf /var/log/*log /var/lib/apt/lists/* /var/log/apt/* /var/lib/dpkg/*-old /var/cache/debconf/*-old
WORKDIR /
COPY --from=builder /workspace/ctrlmesh-manager .
Expand Down
14 changes: 7 additions & 7 deletions artifacts/scripts/generate_client.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ fi
set -e
TMP_DIR=$(mktemp -d)

mkdir -p "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/pkg/client
mkdir -p "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/pkg/client

cp -r ./{hack,vendor} "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/
cp -r ./pkg/apis "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/pkg/
cp ./go.mod "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/go.mod
cp -r ./{hack,vendor} "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/
cp -r ./pkg/apis "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/pkg/
cp ./go.mod "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/go.mod

(cd "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh; \
(cd "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh; \
GOPATH=${TMP_DIR} GO111MODULE=on /bin/bash vendor/k8s.io/code-generator/generate-groups.sh all \
github.com/KusionStack/ctrlmesh/pkg/client github.com/KusionStack/ctrlmesh/pkg/apis "ctrlmesh:v1alpha1" -h ./hack/boilerplate.go.txt)
github.com/KusionStack/controller-mesh/pkg/client github.com/KusionStack/controller-mesh/pkg/apis "ctrlmesh:v1alpha1" -h ./hack/boilerplate.go.txt)

rm -rf ./pkg/client/{clientset,informers,listers}
mv "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/pkg/client/* ./pkg/client
mv "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/pkg/client/* ./pkg/client
18 changes: 9 additions & 9 deletions artifacts/scripts/generate_protobuf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ fi
set -e
TMP_DIR=$(mktemp -d)
mkdir -p "${TMP_DIR}"/bin
mkdir -p "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/pkg
mkdir -p "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/pkg

cp -r ./{hack,vendor} "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/
cp -r ./pkg/apis "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/pkg/
cp ./go.mod "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/go.mod
cp -r ./{hack,vendor} "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/
cp -r ./pkg/apis "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/pkg/
cp ./go.mod "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/go.mod

(cd "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh; \
GO111MODULE=off GOPATH=${TMP_DIR} go build -o ${TMP_DIR}/bin/protoc-gen-gogo github.com/KusionStack/ctrlmesh/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo; \
(cd "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh; \
GO111MODULE=off GOPATH=${TMP_DIR} go build -o ${TMP_DIR}/bin/protoc-gen-gogo github.com/KusionStack/controller-mesh/vendor/k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo; \
PATH=${TMP_DIR}/bin:$PATH GOPATH=${TMP_DIR} \
protoc \
--gogo_out=plugins=grpc,paths=source_relative:. pkg/apis/ctrlmesh/proto/ctrlmesh.proto)
protoc --gogo_out=plugins=grpc,paths=source_relative:. pkg/apis/ctrlmesh/proto/ctrlmesh.proto; \
protoc --gogo_out=plugins=grpc,paths=source_relative:. pkg/apis/ctrlmesh/proto/throttling.proto )
# protoc bug in code-generator v0.26.1, can not contains '/' in path.


cp -f "${TMP_DIR}"/src/github.com/KusionStack/ctrlmesh/pkg/apis/ctrlmesh/proto/*.go pkg/apis/ctrlmesh/proto/
cp -f "${TMP_DIR}"/src/github.com/KusionStack/controller-mesh/pkg/apis/ctrlmesh/proto/*.go pkg/apis/ctrlmesh/proto/
18 changes: 18 additions & 0 deletions buf.gen.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: v1
#managed:
# enabled: true
# go_package_prefix:
# default: github.com/kusionstack/kridge/api/gen
plugins:
# Remote plugins
- plugin: buf.build/protocolbuffers/go
out: .
opt: paths=source_relative
- plugin: buf.build/connectrpc/go
out: .
opt: paths=source_relative
# Local plugins:
# golang-deepcopy: tools/cmd/protoc-gen-golang-deepcopy
- plugin: golang-deepcopy
out: .
opt: paths=source_relative
13 changes: 13 additions & 0 deletions buf.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Generated by buf. DO NOT EDIT.
version: v1
deps:
- remote: buf.build
owner: googleapis
repository: googleapis
commit: 28151c0d0a1641bf938a7672c500e01d
digest: shake256:49215edf8ef57f7863004539deff8834cfb2195113f0b890dd1f67815d9353e28e668019165b9d872395871eeafcbab3ccfdb2b5f11734d3cca95be9e8d139de
- remote: buf.build
owner: k8s
repository: api
commit: 8f68e41b943c4de8a5e9c9a921c889a7
digest: shake256:38ab77d24cf737d1204719a0ffc654056c29499f26b1546cc5af9ddb34e33799930d79d1f5a4a04b0f5c149097eabbeed37a5d2abf9552169a7d52011f6a8d6f
18 changes: 18 additions & 0 deletions buf.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: v1
breaking:
use:
- FILE
deps:
- buf.build/googleapis/googleapis
- buf.build/k8s/api
build:
excludes:
- vendor
- common-protos
lint:
use:
- BASIC
except:
- FIELD_LOWER_SNAKE_CASE
- PACKAGE_DIRECTORY_MATCH
allow_comment_ignores: true
Loading