diff --git a/hack/lib/protoc.sh b/hack/lib/protoc.sh index d03eed4e9ed..0874ca07b17 100644 --- a/hack/lib/protoc.sh +++ b/hack/lib/protoc.sh @@ -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 diff --git a/hack/make-rules/update.sh b/hack/make-rules/update.sh index 61b404bf5e1..37e5e58a711 100755 --- a/hack/make-rules/update.sh +++ b/hack/make-rules/update.sh @@ -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 diff --git a/hack/update-generated-proto-bindings-dockerized.sh b/hack/update-generated-proto-bindings-dockerized.sh index c9f7352ca96..62d2ed9b474 100755 --- a/hack/update-generated-proto-bindings-dockerized.sh +++ b/hack/update-generated-proto-bindings-dockerized.sh @@ -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" diff --git a/hack/update-generated-runtime-dockerized.sh b/hack/update-generated-runtime-dockerized.sh deleted file mode 100755 index e51be3e058e..00000000000 --- a/hack/update-generated-runtime-dockerized.sh +++ /dev/null @@ -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 diff --git a/hack/update-generated-runtime.sh b/hack/update-generated-runtime.sh deleted file mode 100755 index a2656daea98..00000000000 --- a/hack/update-generated-runtime.sh +++ /dev/null @@ -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 diff --git a/hack/verify-generated-runtime.sh b/hack/verify-generated-runtime.sh deleted file mode 100755 index 8b1345ac404..00000000000 --- a/hack/verify-generated-runtime.sh +++ /dev/null @@ -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 diff --git a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto index 83a7ac31215..5475a7afa8c 100644 --- a/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto +++ b/staging/src/k8s.io/cri-api/pkg/apis/runtime/v1/api.proto @@ -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;