Skip to content

Commit 1833c86

Browse files
authored
Merge pull request #4530 from chaosi-zju/proto
fix the issue of invalid protobuf execution
2 parents 181af49 + 50e2199 commit 1833c86

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

hack/update-estimator-protobuf.sh

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,14 +22,29 @@ KARMADA_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd -P)"
2222

2323
# Use `hack/generate-proto.sh` to generate proto files.
2424

25-
export GOPATH=$(go env GOPATH | awk -F ':' '{print $1}')
25+
DEFAULT_GOPATH=$(go env GOPATH | awk -F ':' '{print $1}')
26+
export GOPATH=${DEFAULT_GOPATH}
2627
export PATH=$PATH:$GOPATH/bin
2728

2829
GO111MODULE=on go install golang.org/x/tools/cmd/goimports
2930
GO111MODULE=on go install k8s.io/code-generator/cmd/go-to-protobuf
3031
GO111MODULE=on go install github.com/gogo/protobuf/protoc-gen-gogo
3132
GO111MODULE=on go install github.com/vektra/mockery/v2
3233

34+
# Make dummy GOPATH for go-to-protobuf to generate the files to repo root.
35+
# It is useful for case that karmada repo not in the real GOPATH.
36+
go_path="${KARMADA_ROOT}/_go"
37+
cleanup() {
38+
rm -rf "${go_path}"
39+
}
40+
trap "cleanup" EXIT SIGINT
41+
42+
cleanup
43+
44+
source "${KARMADA_ROOT}"/hack/util.sh
45+
util:create_gopath_tree "${KARMADA_ROOT}" "${go_path}"
46+
export GOPATH="${go_path}"
47+
3348
#ref https://github.com/kubernetes/kubernetes/blob/master/hack/update-generated-protobuf-dockerized.sh
3449
if [[ -z "$(which protoc)" || $(protoc --version | sed -r "s/libprotoc ([0-9]+).*/\1/g") -lt 3 ]]; then
3550
echo "Generating protobuf requires protoc 3.0.0-beta1 or newer. Please download and"
@@ -54,7 +69,7 @@ APIMACHINERY_PKGS=(
5469
k8s.io/api/core/v1
5570
)
5671

57-
${GOPATH}/bin/go-to-protobuf \
72+
go-to-protobuf \
5873
--go-header-file=./hack/boilerplate/boilerplate.go.txt \
5974
--apimachinery-packages=$(IFS=, ; echo "${APIMACHINERY_PKGS[*]}") \
6075
--packages=$(IFS=, ; echo "${PACKAGES[*]}") \
@@ -64,4 +79,5 @@ ${GOPATH}/bin/go-to-protobuf \
6479
go generate ./pkg/estimator/service
6580

6681
# The `go-to-protobuf` tool will modify all import proto files in vendor, so we should use go mod vendor to prevent.
82+
export GOPATH=${DEFAULT_GOPATH}
6783
go mod vendor

0 commit comments

Comments
 (0)