mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-19 09:52:49 +00:00
Move update-generated-runtime into common script
Now update-generated-proto-bindings rules all the api.pb.go generation. Running this shows no delta on the runtime.pb.go This exposes an issue in how protoc is called for protos that specify `go_package` which is fixed here. Not all of our protos specify that option (even though it is recommended), which will be fixed subsequently.
This commit is contained in:
parent
e0ecccff3f
commit
a057f35c90
@ -56,10 +56,19 @@ function kube::protoc::protoc() {
|
||||
local package=${1}
|
||||
gogopath=$(dirname "$(kube::util::find-binary "protoc-gen-gogo")")
|
||||
|
||||
PATH="${gogopath}:${PATH}" protoc \
|
||||
--proto_path="${package}" \
|
||||
--proto_path="${KUBE_ROOT}/vendor" \
|
||||
--gogo_out=plugins=grpc:"${package}" "${package}/api.proto"
|
||||
(
|
||||
cd "${package}"
|
||||
|
||||
# This invocation of --gogo_out produces its output in the current
|
||||
# directory (despite gogo docs saying it would be source-relative, it
|
||||
# isn't). The inputs to this function do not all have a common root, so
|
||||
# this works best for all inputs.
|
||||
PATH="${gogopath}:${PATH}" protoc \
|
||||
--proto_path="${package}" \
|
||||
--proto_path="${KUBE_ROOT}/vendor" \
|
||||
--gogo_out=paths=source_relative,plugins=grpc:. \
|
||||
api.proto
|
||||
)
|
||||
}
|
||||
|
||||
# Formats $1/api.pb.go, adds the boilerplate comments and run gofmt on it
|
||||
|
@ -38,7 +38,6 @@ fi
|
||||
BASH_TARGETS=(
|
||||
update-generated-protobuf
|
||||
update-codegen
|
||||
update-generated-runtime
|
||||
update-generated-proto-bindings
|
||||
update-generated-api-compatibility-data
|
||||
update-generated-docs
|
||||
|
@ -27,6 +27,8 @@ source "${KUBE_ROOT}/hack/lib/protoc.sh"
|
||||
# Each element of this array is a directory containing subdirectories which
|
||||
# eventually contain a file named "api.proto".
|
||||
APIS=(
|
||||
"staging/src/k8s.io/cri-api/pkg/apis/runtime"
|
||||
|
||||
"staging/src/k8s.io/kubelet/pkg/apis/podresources"
|
||||
|
||||
"staging/src/k8s.io/kubelet/pkg/apis/deviceplugin"
|
||||
|
@ -1,75 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2016 The Kubernetes Authors.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# 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.
|
||||
|
||||
# This script builds protoc-gen-gogo binary in runtime and genertates
|
||||
# `*/api.pb.go` from the protobuf file `*/api.proto`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
KUBE_REMOTE_RUNTIME_ROOT="${KUBE_ROOT}/staging/src/k8s.io/cri-api/pkg/apis/runtime/"
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
runtime_versions=("v1")
|
||||
|
||||
kube::golang::setup_env
|
||||
|
||||
GO111MODULE=on GOPROXY=off go install k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo
|
||||
|
||||
if [[ -z "$(which protoc)" || "$(protoc --version)" != "libprotoc 3."* ]]; then
|
||||
echo "Generating protobuf requires protoc 3.0.0-beta1 or newer. Please download and"
|
||||
echo "install the platform appropriate Protobuf package for your OS: "
|
||||
echo
|
||||
echo " https://github.com/protocolbuffers/protobuf/releases"
|
||||
echo
|
||||
echo "WARNING: Protobuf changes are not being validated"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
function cleanup {
|
||||
for v in "${runtime_versions[@]}"; do
|
||||
rm -f "${KUBE_REMOTE_RUNTIME_ROOT}/${v}/api.pb.go.bak"
|
||||
rm -f "${KUBE_REMOTE_RUNTIME_ROOT}/${v}/api.pb.go.tmp"
|
||||
done
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
gogopath=$(dirname "$(kube::util::find-binary "protoc-gen-gogo")")
|
||||
PATH="${gogopath}:${PATH}"
|
||||
|
||||
function generate_code() {
|
||||
RUNTIME_API_VERSION="$1"
|
||||
KUBE_REMOTE_RUNTIME_PATH="${KUBE_REMOTE_RUNTIME_ROOT}/${RUNTIME_API_VERSION}"
|
||||
protoc \
|
||||
--proto_path="${KUBE_REMOTE_RUNTIME_PATH}" \
|
||||
--proto_path="${KUBE_ROOT}/vendor" \
|
||||
--gogo_out=plugins=grpc:"${KUBE_ROOT}/staging/src" "${KUBE_REMOTE_RUNTIME_PATH}/api.proto"
|
||||
|
||||
# Update boilerplate for the generated file.
|
||||
cat hack/boilerplate/boilerplate.generatego.txt "${KUBE_REMOTE_RUNTIME_PATH}/api.pb.go" > "${KUBE_REMOTE_RUNTIME_PATH}/api.pb.go.tmp"
|
||||
mv "${KUBE_REMOTE_RUNTIME_PATH}/api.pb.go.tmp" "${KUBE_REMOTE_RUNTIME_PATH}/api.pb.go"
|
||||
|
||||
# Run gofmt to clean up the generated code.
|
||||
kube::golang::verify_go_version
|
||||
gofmt -l -s -w "${KUBE_REMOTE_RUNTIME_PATH}/api.pb.go"
|
||||
}
|
||||
|
||||
for v in "${runtime_versions[@]}"; do
|
||||
generate_code "${v}"
|
||||
done
|
@ -1,34 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2016 The Kubernetes Authors.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# 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.
|
||||
|
||||
# This script builds protoc-gen-gogo binary in runtime and genertates
|
||||
# `*/api.pb.go` from the protobuf file `*/api.proto`.
|
||||
# Usage:
|
||||
# hack/update-generated-runtime.sh
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
|
||||
# NOTE: All output from this script needs to be copied back to the calling
|
||||
# source tree. This is managed in kube::build::copy_output in build/common.sh.
|
||||
# If the output set is changed update that function.
|
||||
|
||||
"${KUBE_ROOT}/build/run.sh" hack/update-generated-runtime-dockerized.sh "$@"
|
||||
|
||||
# ex: ts=2 sw=2 et filetype=sh
|
@ -1,62 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
# Copyright 2016 The Kubernetes Authors.
|
||||
#
|
||||
# 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
|
||||
#
|
||||
# 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.
|
||||
|
||||
# This script checks whether updating of container runtime API is needed or not.
|
||||
# We should run `hack/update-generated-runtime.sh` if container runtime API is
|
||||
# out of date.
|
||||
# Usage: `hack/verify-generated-runtime.sh`.
|
||||
|
||||
set -o errexit
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
|
||||
KUBE_REMOTE_RUNTIME_ROOT="${KUBE_ROOT}/staging/src/k8s.io/cri-api/pkg/apis/runtime/"
|
||||
source "${KUBE_ROOT}/hack/lib/init.sh"
|
||||
|
||||
runtime_versions=("v1")
|
||||
|
||||
kube::golang::setup_env
|
||||
|
||||
function cleanup {
|
||||
for v in "${runtime_versions[@]}"; do
|
||||
rm -rf "${KUBE_REMOTE_RUNTIME_ROOT}/${v}/_tmp/"
|
||||
done
|
||||
}
|
||||
|
||||
trap cleanup EXIT
|
||||
|
||||
function verify_generated_code() {
|
||||
RUNTIME_API_VERSION="$1"
|
||||
KUBE_REMOTE_RUNTIME_PATH="${KUBE_REMOTE_RUNTIME_ROOT}/${RUNTIME_API_VERSION}"
|
||||
mkdir -p "${KUBE_REMOTE_RUNTIME_PATH}/_tmp"
|
||||
cp "${KUBE_REMOTE_RUNTIME_PATH}/api.pb.go" "${KUBE_REMOTE_RUNTIME_PATH}/_tmp/"
|
||||
|
||||
ret=0
|
||||
KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-runtime.sh"
|
||||
diff -I "gzipped FileDescriptorProto" -I "0x" -Naupr "${KUBE_REMOTE_RUNTIME_PATH}/_tmp/api.pb.go" "${KUBE_REMOTE_RUNTIME_PATH}/api.pb.go" || ret=$?
|
||||
if [[ $ret -eq 0 ]]; then
|
||||
echo "Generated container runtime api is up to date."
|
||||
cp "${KUBE_REMOTE_RUNTIME_PATH}/_tmp/api.pb.go" "${KUBE_REMOTE_RUNTIME_PATH}/"
|
||||
else
|
||||
echo "Generated container runtime api is out of date. Please run hack/update-generated-runtime.sh"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
for v in "${runtime_versions[@]}"; do
|
||||
verify_generated_code "${v}"
|
||||
done
|
@ -14,7 +14,7 @@ See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
// To regenerate api.pb.go run hack/update-generated-runtime.sh
|
||||
// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh
|
||||
syntax = "proto3";
|
||||
|
||||
package runtime.v1;
|
||||
|
Loading…
Reference in New Issue
Block a user