From e0ecccff3f5148cc167117ac73233b4edc1640d8 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 5 Jan 2023 13:53:59 -0800 Subject: [PATCH 1/6] Merge 5 fragile proto-bindings scripts into 1 Each of these scripts is basically identical, and all were too brittle. Now they should be more resilient and easier to manage. The script still needs to be updated if we add new ones, which I do not love. More cleanup to follow. --- hack/lib/protoc.sh | 2 +- hack/make-rules/update.sh | 3 +- ...date-generated-device-plugin-dockerized.sh | 31 ---------- ...-dynamic-resource-allocation-dockerized.sh | 29 ---------- ...e-generated-dynamic-resource-allocation.sh | 27 --------- hack/update-generated-kms-dockerized.sh | 29 ---------- hack/update-generated-kms.sh | 29 ---------- ...-kubelet-plugin-registration-dockerized.sh | 39 ------------- ...e-generated-kubelet-plugin-registration.sh | 27 --------- ...date-generated-pod-resources-dockerized.sh | 37 ------------ hack/update-generated-pod-resources.sh | 32 ----------- ...ate-generated-proto-bindings-dockerized.sh | 51 +++++++++++++++++ ....sh => update-generated-proto-bindings.sh} | 2 +- hack/verify-generated-device-plugin.sh | 50 ----------------- ...y-generated-dynamic-resource-allocation.sh | 44 --------------- hack/verify-generated-kms.sh | 55 ------------------ ...y-generated-kubelet-plugin-registration.sh | 56 ------------------- hack/verify-generated-pod-resources.sh | 50 ----------------- hack/verify-generated-proto-bindings.sh | 49 ++++++++++++++++ .../encrypt/envelope/kmsv2/v2alpha1/api.proto | 2 +- staging/src/k8s.io/kms/apis/v1beta1/api.proto | 2 +- .../src/k8s.io/kms/apis/v2alpha1/api.proto | 2 +- .../pkg/apis/deviceplugin/v1alpha/api.proto | 2 +- .../pkg/apis/deviceplugin/v1beta1/api.proto | 2 +- .../kubelet/pkg/apis/dra/v1alpha1/api.proto | 4 +- .../pkg/apis/pluginregistration/v1/api.proto | 2 +- .../pluginregistration/v1alpha1/api.proto | 2 +- .../apis/pluginregistration/v1beta1/api.proto | 2 +- .../pkg/apis/podresources/v1/api.proto | 2 +- .../pkg/apis/podresources/v1alpha1/api.proto | 4 +- 30 files changed, 116 insertions(+), 552 deletions(-) delete mode 100755 hack/update-generated-device-plugin-dockerized.sh delete mode 100755 hack/update-generated-dynamic-resource-allocation-dockerized.sh delete mode 100755 hack/update-generated-dynamic-resource-allocation.sh delete mode 100755 hack/update-generated-kms-dockerized.sh delete mode 100755 hack/update-generated-kms.sh delete mode 100755 hack/update-generated-kubelet-plugin-registration-dockerized.sh delete mode 100755 hack/update-generated-kubelet-plugin-registration.sh delete mode 100755 hack/update-generated-pod-resources-dockerized.sh delete mode 100755 hack/update-generated-pod-resources.sh create mode 100755 hack/update-generated-proto-bindings-dockerized.sh rename hack/{update-generated-device-plugin.sh => update-generated-proto-bindings.sh} (91%) delete mode 100755 hack/verify-generated-device-plugin.sh delete mode 100755 hack/verify-generated-dynamic-resource-allocation.sh delete mode 100755 hack/verify-generated-kms.sh delete mode 100755 hack/verify-generated-kubelet-plugin-registration.sh delete mode 100755 hack/verify-generated-pod-resources.sh create mode 100755 hack/verify-generated-proto-bindings.sh diff --git a/hack/lib/protoc.sh b/hack/lib/protoc.sh index 7d4174a4565..d03eed4e9ed 100644 --- a/hack/lib/protoc.sh +++ b/hack/lib/protoc.sh @@ -72,7 +72,7 @@ function kube::protoc::format() { # Run gofmt to clean up the generated code. kube::golang::verify_go_version - gofmt -l -s -w "${package}/api.pb.go" + gofmt -s -w "${package}/api.pb.go" } # Compares the contents of $1 and $2 diff --git a/hack/make-rules/update.sh b/hack/make-rules/update.sh index a1ea51ce530..61b404bf5e1 100755 --- a/hack/make-rules/update.sh +++ b/hack/make-rules/update.sh @@ -39,8 +39,7 @@ BASH_TARGETS=( update-generated-protobuf update-codegen update-generated-runtime - update-generated-device-plugin - update-generated-dynamic-resource-allocation + update-generated-proto-bindings update-generated-api-compatibility-data update-generated-docs update-generated-swagger-docs diff --git a/hack/update-generated-device-plugin-dockerized.sh b/hack/update-generated-device-plugin-dockerized.sh deleted file mode 100755 index 3f507511d2f..00000000000 --- a/hack/update-generated-device-plugin-dockerized.sh +++ /dev/null @@ -1,31 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 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 generates `*/api.pb.go` from the protobuf file `*/api.proto`. -# Example: -# kube::protoc::generate_proto "${DEVICE_PLUGIN_ALPHA}" - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" -DEVICE_PLUGIN_ALPHA="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/" -DEVICE_PLUGIN_V1BETA1="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/" - -source "${KUBE_ROOT}/hack/lib/protoc.sh" -kube::protoc::generate_proto "${DEVICE_PLUGIN_ALPHA}" -kube::protoc::generate_proto "${DEVICE_PLUGIN_V1BETA1}" diff --git a/hack/update-generated-dynamic-resource-allocation-dockerized.sh b/hack/update-generated-dynamic-resource-allocation-dockerized.sh deleted file mode 100755 index ad9f75f114d..00000000000 --- a/hack/update-generated-dynamic-resource-allocation-dockerized.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 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 generates `*/api.pb.go` from the protobuf file `*/api.proto`. -# Example: -# kube::protoc::generate_proto "${DYNAMIC_RESOURCE_ALLOCATION_ALPHA}" - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" -DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/" - -source "${KUBE_ROOT}/hack/lib/protoc.sh" -kube::protoc::generate_proto "${DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1}" diff --git a/hack/update-generated-dynamic-resource-allocation.sh b/hack/update-generated-dynamic-resource-allocation.sh deleted file mode 100755 index d20db5edb5e..00000000000 --- a/hack/update-generated-dynamic-resource-allocation.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 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. - -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-dynamic-resource-allocation-dockerized.sh "$@" diff --git a/hack/update-generated-kms-dockerized.sh b/hack/update-generated-kms-dockerized.sh deleted file mode 100755 index 15d794ea7bd..00000000000 --- a/hack/update-generated-kms-dockerized.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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. - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -KUBE_KMS_V1BETA1="${KUBE_ROOT}/staging/src/k8s.io/kms/apis/v1beta1/" -KUBE_KMS_V2ALPHA1="${KUBE_ROOT}/staging/src/k8s.io/kms/apis/v2alpha1/" -KUBE_KMS_V2="${KUBE_ROOT}/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/" - -source "${KUBE_ROOT}/hack/lib/protoc.sh" -kube::protoc::generate_proto "${KUBE_KMS_V1BETA1}" -kube::protoc::generate_proto "${KUBE_KMS_V2ALPHA1}" -kube::protoc::generate_proto "${KUBE_KMS_V2}" diff --git a/hack/update-generated-kms.sh b/hack/update-generated-kms.sh deleted file mode 100755 index 6ae29450d0c..00000000000 --- a/hack/update-generated-kms.sh +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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. - -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-kms-dockerized.sh "$@" - -# ex: ts=2 sw=2 et filetype=sh diff --git a/hack/update-generated-kubelet-plugin-registration-dockerized.sh b/hack/update-generated-kubelet-plugin-registration-dockerized.sh deleted file mode 100755 index e3ead0696a1..00000000000 --- a/hack/update-generated-kubelet-plugin-registration-dockerized.sh +++ /dev/null @@ -1,39 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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 generates `*/api.pb.go` from the protobuf file `*/api.proto`. -# Example: -# kube::protoc::generate_proto "${KUBELET_PLUGIN_REGISTRATION_V1ALPHA}" - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" - -dirs=( - "staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/" - "staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/" - "staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/" - "pkg/kubelet/pluginmanager/pluginwatcher/example_plugin_apis/v1beta1/" - "pkg/kubelet/pluginmanager/pluginwatcher/example_plugin_apis/v1beta2/" -) - -source "${KUBE_ROOT}/hack/lib/protoc.sh" - -for d in "${dirs[@]}"; do - kube::protoc::generate_proto "${KUBE_ROOT}/${d}" -done diff --git a/hack/update-generated-kubelet-plugin-registration.sh b/hack/update-generated-kubelet-plugin-registration.sh deleted file mode 100755 index 46e3d1f8c83..00000000000 --- a/hack/update-generated-kubelet-plugin-registration.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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. - -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-kubelet-plugin-registration-dockerized.sh "$@" diff --git a/hack/update-generated-pod-resources-dockerized.sh b/hack/update-generated-pod-resources-dockerized.sh deleted file mode 100755 index a477e6e3b8d..00000000000 --- a/hack/update-generated-pod-resources-dockerized.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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 generates `*/api.pb.go` from the protobuf file `*/api.proto`. -# Example: -# kube::protoc::generate_proto "${POD_RESOURCES}" - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" - -dirs=( - "staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/" - "staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/" -) - -source "${KUBE_ROOT}/hack/lib/protoc.sh" - -for d in "${dirs[@]}"; do - kube::protoc::generate_proto "${KUBE_ROOT}/${d}" -done - diff --git a/hack/update-generated-pod-resources.sh b/hack/update-generated-pod-resources.sh deleted file mode 100755 index c51a156064d..00000000000 --- a/hack/update-generated-pod-resources.sh +++ /dev/null @@ -1,32 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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 generates `/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.pb.go` -# from the protobuf file `/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto` -# for pods. -# Usage: `hack/update-generated-pod-resources.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-pod-resources-dockerized.sh "$@" diff --git a/hack/update-generated-proto-bindings-dockerized.sh b/hack/update-generated-proto-bindings-dockerized.sh new file mode 100755 index 00000000000..c9f7352ca96 --- /dev/null +++ b/hack/update-generated-proto-bindings-dockerized.sh @@ -0,0 +1,51 @@ +#!/usr/bin/env bash + +# Copyright 2017 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 generates `*/api.pb.go` files from protobuf files `*/api.proto`. + +set -o errexit +set -o nounset +set -o pipefail + +KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" + +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/kubelet/pkg/apis/podresources" + + "staging/src/k8s.io/kubelet/pkg/apis/deviceplugin" + + "staging/src/k8s.io/kms/apis" + "staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2" + + "staging/src/k8s.io/kubelet/pkg/apis/dra" + + "staging/src/k8s.io/kubelet/pkg/apis/pluginregistration" + "pkg/kubelet/pluginmanager/pluginwatcher/example_plugin_apis" +) + +for api in "${APIS[@]}"; do + # This can't use `git ls-files` because it runs in a container without the + # .git dir synced. + find "${api}" -type f -name "api.proto" \ + | while read -r F; do + D="$(dirname "${F}")" + kube::protoc::generate_proto "${KUBE_ROOT}/${D}" + done +done diff --git a/hack/update-generated-device-plugin.sh b/hack/update-generated-proto-bindings.sh similarity index 91% rename from hack/update-generated-device-plugin.sh rename to hack/update-generated-proto-bindings.sh index 6652500887f..87bdee7fe14 100755 --- a/hack/update-generated-device-plugin.sh +++ b/hack/update-generated-proto-bindings.sh @@ -24,4 +24,4 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. # 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-device-plugin-dockerized.sh "$@" +"${KUBE_ROOT}/build/run.sh" hack/update-generated-proto-bindings-dockerized.sh diff --git a/hack/verify-generated-device-plugin.sh b/hack/verify-generated-device-plugin.sh deleted file mode 100755 index 88118821761..00000000000 --- a/hack/verify-generated-device-plugin.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 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 device plugin API is needed or not. We -# should run `hack/update-generated-device-plugin.sh` if device plugin API is -# out of date. -# Usage: `hack/verify-generated-device-plugin.sh`. - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -ERROR="Device plugin api is out of date. Please run hack/update-generated-device-plugin.sh" -DEVICE_PLUGIN_ALPHA="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/" -DEVICE_PLUGIN_V1BETA1="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/" - -source "${KUBE_ROOT}/hack/lib/protoc.sh" -kube::golang::setup_env - -function cleanup { - rm -rf "${DEVICE_PLUGIN_ALPHA}/_tmp/" - rm -rf "${DEVICE_PLUGIN_V1BETA1}/_tmp/" -} - -trap cleanup EXIT - -mkdir -p "${DEVICE_PLUGIN_ALPHA}/_tmp" -cp "${DEVICE_PLUGIN_ALPHA}/api.pb.go" "${DEVICE_PLUGIN_ALPHA}/_tmp/" -mkdir -p "${DEVICE_PLUGIN_V1BETA1}/_tmp" -cp "${DEVICE_PLUGIN_V1BETA1}/api.pb.go" "${DEVICE_PLUGIN_V1BETA1}/_tmp/" - -KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-device-plugin.sh" -kube::protoc::diff "${DEVICE_PLUGIN_ALPHA}/api.pb.go" "${DEVICE_PLUGIN_ALPHA}/_tmp/api.pb.go" "${ERROR}" -echo "Generated device plugin alpha api is up to date." -kube::protoc::diff "${DEVICE_PLUGIN_V1BETA1}/api.pb.go" "${DEVICE_PLUGIN_V1BETA1}/_tmp/api.pb.go" "${ERROR}" -echo "Generated device plugin beta api is up to date." diff --git a/hack/verify-generated-dynamic-resource-allocation.sh b/hack/verify-generated-dynamic-resource-allocation.sh deleted file mode 100755 index 3f38cbf5671..00000000000 --- a/hack/verify-generated-dynamic-resource-allocation.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2022 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 device plugin API is needed or not. We -# should run `hack/update-generated-dynamic-resource-allocation.sh` if device plugin API is -# out of date. -# Usage: `hack/verify-generated-dynamic-resource-allocation.sh`. - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -ERROR="Dynamic resource allocation kubelet plugin api is out of date. Please run hack/update-generated-dynamic-resource-allocation.sh" -DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/" - -source "${KUBE_ROOT}/hack/lib/protoc.sh" -kube::golang::setup_env - -function cleanup { - rm -rf "${DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1}/_tmp/" -} - -trap cleanup EXIT - -mkdir -p "${DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1}/_tmp" -cp "${DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1}/api.pb.go" "${DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1}/_tmp/" - -KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-dynamic-resource-allocation.sh" -kube::protoc::diff "${DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1}/api.pb.go" "${DYNAMIC_RESOURCE_ALLOCATION_V1ALPHA1}/_tmp/api.pb.go" "${ERROR}" -echo "Generated dynamic resource allocation kubelet plugin alpha api is up to date." diff --git a/hack/verify-generated-kms.sh b/hack/verify-generated-kms.sh deleted file mode 100755 index 632e4dd6cde..00000000000 --- a/hack/verify-generated-kms.sh +++ /dev/null @@ -1,55 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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 KMS gRPC is needed or not. We should -# run `hack/update-generated-kms.sh` if KMS gRPC is out of date. -# Usage: `hack/verify-generated-kms.sh`. - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -ERROR="KMS gRPC is out of date. Please run hack/update-generated-kms.sh" -KUBE_KMS_V1BETA1="${KUBE_ROOT}/staging/src/k8s.io/kms/apis/v1beta1/" -KUBE_KMS_V2ALPHA1="${KUBE_ROOT}/staging/src/k8s.io/kms/apis/v2alpha1/" -KUBE_KMS_V2="${KUBE_ROOT}/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/" - -source "${KUBE_ROOT}/hack/lib/protoc.sh" -kube::golang::setup_env - -function cleanup { - rm -rf "${KUBE_KMS_V1BETA1}/_tmp/" - rm -rf "${KUBE_KMS_V2ALPHA1}/_tmp/" - rm -rf "${KUBE_KMS_V2}/_tmp/" -} - -trap cleanup EXIT - -mkdir -p "${KUBE_KMS_V1BETA1}/_tmp" -cp "${KUBE_KMS_V1BETA1}/api.pb.go" "${KUBE_KMS_V1BETA1}/_tmp/" -mkdir -p "${KUBE_KMS_V2ALPHA1}/_tmp" -cp "${KUBE_KMS_V2ALPHA1}/api.pb.go" "${KUBE_KMS_V2ALPHA1}/_tmp/" -mkdir -p "${KUBE_KMS_V2}/_tmp" -cp "${KUBE_KMS_V2}/api.pb.go" "${KUBE_KMS_V2}/_tmp/" - -KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-kms.sh" -kube::protoc::diff "${KUBE_KMS_V1BETA1}/api.pb.go" "${KUBE_KMS_V1BETA1}/_tmp/api.pb.go" "${ERROR}" -echo "Generated kms v1beta1 api is up to date." -kube::protoc::diff "${KUBE_KMS_V2ALPHA1}/api.pb.go" "${KUBE_KMS_V2ALPHA1}/_tmp/api.pb.go" "${ERROR}" -echo "Generated kms v2alpha1 api is up to date." -kube::protoc::diff "${KUBE_KMS_V2}/api.pb.go" "${KUBE_KMS_V2}/_tmp/api.pb.go" "${ERROR}" -echo "Generated kms v2 api is up to date." diff --git a/hack/verify-generated-kubelet-plugin-registration.sh b/hack/verify-generated-kubelet-plugin-registration.sh deleted file mode 100755 index 07b2f2af7c7..00000000000 --- a/hack/verify-generated-kubelet-plugin-registration.sh +++ /dev/null @@ -1,56 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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 kubelet plugin registration API is -# needed or not. We should run -# `hack/update-generated-kubelet-plugin-registration.sh` if kubelet plugin -# registration API is out of date. -# Usage: `hack/verify-generated-kubelet-plugin-registration.sh`. - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -ERROR="Kubelet Plugin Registration api is out of date. Please run hack/update-generated-kubelet-plugin-registration.sh" -KUBELET_PLUGIN_REGISTRATION_V1ALPHA="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/" -KUBELET_PLUGIN_REGISTRATION_V1BETA="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/" - -source "${KUBE_ROOT}/hack/lib/protoc.sh" -kube::golang::setup_env - -function cleanup { - rm -rf "${KUBELET_PLUGIN_REGISTRATION_V1ALPHA}/_tmp/" - rm -rf "${KUBELET_PLUGIN_REGISTRATION_V1BETA}/_tmp/" -} - -trap cleanup EXIT - -mkdir -p "${KUBELET_PLUGIN_REGISTRATION_V1ALPHA}/_tmp" -mkdir -p "${KUBELET_PLUGIN_REGISTRATION_V1BETA}/_tmp" - -cp "${KUBELET_PLUGIN_REGISTRATION_V1ALPHA}/api.pb.go" "${KUBELET_PLUGIN_REGISTRATION_V1ALPHA}/_tmp/" -cp "${KUBELET_PLUGIN_REGISTRATION_V1BETA}/api.pb.go" "${KUBELET_PLUGIN_REGISTRATION_V1BETA}/_tmp/" - -# Check V1Alpha -KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-kubelet-plugin-registration.sh" -kube::protoc::diff "${KUBELET_PLUGIN_REGISTRATION_V1ALPHA}/api.pb.go" "${KUBELET_PLUGIN_REGISTRATION_V1ALPHA}/_tmp/api.pb.go" "${ERROR}" -echo "Generated Kubelet Plugin Registration api is up to date." - -# Check V1Beta -KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-kubelet-plugin-registration.sh" -kube::protoc::diff "${KUBELET_PLUGIN_REGISTRATION_V1BETA}/api.pb.go" "${KUBELET_PLUGIN_REGISTRATION_V1BETA}/_tmp/api.pb.go" "${ERROR}" -echo "Generated Kubelet Plugin Registration api is up to date." diff --git a/hack/verify-generated-pod-resources.sh b/hack/verify-generated-pod-resources.sh deleted file mode 100755 index 46e7442964f..00000000000 --- a/hack/verify-generated-pod-resources.sh +++ /dev/null @@ -1,50 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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 Pod resources API is needed or not. We -# should run `hack/update-generated-pod-resources.sh` if Pod resources API is -# out of date. -# Usage: `hack/verify-generated-pod-resources.sh`. - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -POD_RESOURCES="${KUBE_ROOT}/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/" -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -function cleanup { - rm -rf "${POD_RESOURCES}/_tmp/" -} - -trap cleanup EXIT - -mkdir -p "${POD_RESOURCES}/_tmp" -cp "${POD_RESOURCES}/api.pb.go" "${POD_RESOURCES}/_tmp/" - -ret=0 -KUBE_VERBOSE=3 "${KUBE_ROOT}/hack/update-generated-pod-resources.sh" -diff -I "gzipped FileDescriptorProto" -I "0x" -Naupr "${POD_RESOURCES}/_tmp/api.pb.go" "${POD_RESOURCES}/api.pb.go" || ret=$? -if [[ $ret -eq 0 ]]; then - echo "Generated pod resources api is up to date." - cp "${POD_RESOURCES}/_tmp/api.pb.go" "${POD_RESOURCES}/" -else - echo "Generated pod resources api is out of date. Please run hack/update-generated-pod-resources.sh" - exit 1 -fi diff --git a/hack/verify-generated-proto-bindings.sh b/hack/verify-generated-proto-bindings.sh new file mode 100755 index 00000000000..b0ae55b52f4 --- /dev/null +++ b/hack/verify-generated-proto-bindings.sh @@ -0,0 +1,49 @@ +#!/usr/bin/env bash + +# Copyright 2018 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 protobuf bindings is needed. +# Run `hack/update-generated-proto-bindings.sh` to regenerate them. +# +# Usage: `hack/verify-generated-proto-bindings.sh`. + + +set -o errexit +set -o nounset +set -o pipefail + +KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. +source "${KUBE_ROOT}/hack/lib/init.sh" + +kube::util::ensure_clean_working_dir + +_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")" +git worktree add -f -q "${_tmpdir}" HEAD +kube::util::trap_add "git worktree remove -f ${_tmpdir}" EXIT +cd "${_tmpdir}" + +# Regenerate. +hack/update-generated-proto-bindings.sh + +# Test for diffs +diffs=$(git status --porcelain | wc -l) +if [[ ${diffs} -gt 0 ]]; then + git status + git diff + echo + echo "Proto bindings need to be regenerated" >&2 + echo "Please run 'hack/update-generated-proto-bindings.sh'" >&2 + exit 1 +fi diff --git a/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/api.proto b/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/api.proto index e3b978b05ed..33176d2b00a 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/api.proto +++ b/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/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-kms.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package v2alpha1; diff --git a/staging/src/k8s.io/kms/apis/v1beta1/api.proto b/staging/src/k8s.io/kms/apis/v1beta1/api.proto index a9b44bf5fa1..b6576b2d242 100644 --- a/staging/src/k8s.io/kms/apis/v1beta1/api.proto +++ b/staging/src/k8s.io/kms/apis/v1beta1/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-kms.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package v1beta1; diff --git a/staging/src/k8s.io/kms/apis/v2alpha1/api.proto b/staging/src/k8s.io/kms/apis/v2alpha1/api.proto index 9b960b2acc4..eaf77077d5c 100644 --- a/staging/src/k8s.io/kms/apis/v2alpha1/api.proto +++ b/staging/src/k8s.io/kms/apis/v2alpha1/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-kms.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package v2alpha1; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto index 13ad6e7ff5d..61809b14253 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-device-plugin.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package deviceplugin; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/api.proto index d22da05b2a0..a907a84a2e5 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-device-plugin.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package v1beta1; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/api.proto index 2ba5c5c34d4..c86ef6928e0 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/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-kubelet-plugin-registration.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; @@ -78,4 +78,4 @@ message NodeUnprepareResourceRequest { message NodeUnprepareResourceResponse { // Intentionally empty. -} \ No newline at end of file +} diff --git a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/api.proto index 5c4f6f80168..03bab1af856 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-kubelet-plugin-registration.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package pluginregistration; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/api.proto index 5c4f6f80168..03bab1af856 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-kubelet-plugin-registration.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package pluginregistration; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/api.proto index 5c4f6f80168..03bab1af856 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-kubelet-plugin-registration.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package pluginregistration; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto index add2aad4874..40427bb5bbc 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-pod-resources.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package v1; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto index 782ac714b6a..6d74b6ba493 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-pod-resources.sh +// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh syntax = "proto3"; package v1alpha1; @@ -45,4 +45,4 @@ message ContainerResources { message ContainerDevices { string resource_name = 1; repeated string device_ids = 2; -} \ No newline at end of file +} From a057f35c90c069369ec9efe74cf01f1da0085198 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 14 Jan 2023 10:09:22 -0800 Subject: [PATCH 2/6] 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. --- hack/lib/protoc.sh | 17 ++++- hack/make-rules/update.sh | 1 - ...ate-generated-proto-bindings-dockerized.sh | 2 + hack/update-generated-runtime-dockerized.sh | 75 ------------------- hack/update-generated-runtime.sh | 34 --------- hack/verify-generated-runtime.sh | 62 --------------- .../cri-api/pkg/apis/runtime/v1/api.proto | 2 +- 7 files changed, 16 insertions(+), 177 deletions(-) delete mode 100755 hack/update-generated-runtime-dockerized.sh delete mode 100755 hack/update-generated-runtime.sh delete mode 100755 hack/verify-generated-runtime.sh 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; From 4dae505d531e149881788dc36148602967419c75 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Thu, 5 Jan 2023 15:41:51 -0800 Subject: [PATCH 3/6] Call update-proto-bindings from update-codegen One script to bring them all ... --- hack/make-rules/update.sh | 1 - hack/update-codegen.sh | 6 +++ hack/update-generated-proto-bindings.sh | 27 ---------- hack/verify-generated-proto-bindings.sh | 49 ------------------- .../encrypt/envelope/kmsv2/v2alpha1/api.proto | 2 +- .../cri-api/pkg/apis/runtime/v1/api.proto | 2 +- staging/src/k8s.io/kms/apis/v1beta1/api.proto | 2 +- .../src/k8s.io/kms/apis/v2alpha1/api.proto | 2 +- .../pkg/apis/deviceplugin/v1alpha/api.proto | 2 +- .../pkg/apis/deviceplugin/v1beta1/api.proto | 2 +- .../kubelet/pkg/apis/dra/v1alpha1/api.proto | 2 +- .../pkg/apis/pluginregistration/v1/api.proto | 2 +- .../pluginregistration/v1alpha1/api.proto | 2 +- .../apis/pluginregistration/v1beta1/api.proto | 2 +- .../pkg/apis/podresources/v1/api.proto | 2 +- .../pkg/apis/podresources/v1alpha1/api.proto | 2 +- 16 files changed, 18 insertions(+), 89 deletions(-) delete mode 100755 hack/update-generated-proto-bindings.sh delete mode 100755 hack/verify-generated-proto-bindings.sh diff --git a/hack/make-rules/update.sh b/hack/make-rules/update.sh index 37e5e58a711..abeb7b19c0e 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-proto-bindings update-generated-api-compatibility-data update-generated-docs update-generated-swagger-docs diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 69d620255f2..0447574e189 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -777,6 +777,12 @@ function codegen::subprojects() { done } +function codegen::protobindings() { + # 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. + build/run.sh hack/update-generated-proto-bindings-dockerized.sh +} # # main diff --git a/hack/update-generated-proto-bindings.sh b/hack/update-generated-proto-bindings.sh deleted file mode 100755 index 87bdee7fe14..00000000000 --- a/hack/update-generated-proto-bindings.sh +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2017 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. - -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-proto-bindings-dockerized.sh diff --git a/hack/verify-generated-proto-bindings.sh b/hack/verify-generated-proto-bindings.sh deleted file mode 100755 index b0ae55b52f4..00000000000 --- a/hack/verify-generated-proto-bindings.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2018 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 protobuf bindings is needed. -# Run `hack/update-generated-proto-bindings.sh` to regenerate them. -# -# Usage: `hack/verify-generated-proto-bindings.sh`. - - -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::util::ensure_clean_working_dir - -_tmpdir="$(kube::realpath "$(mktemp -d -t "$(basename "$0").XXXXXX")")" -git worktree add -f -q "${_tmpdir}" HEAD -kube::util::trap_add "git worktree remove -f ${_tmpdir}" EXIT -cd "${_tmpdir}" - -# Regenerate. -hack/update-generated-proto-bindings.sh - -# Test for diffs -diffs=$(git status --porcelain | wc -l) -if [[ ${diffs} -gt 0 ]]; then - git status - git diff - echo - echo "Proto bindings need to be regenerated" >&2 - echo "Please run 'hack/update-generated-proto-bindings.sh'" >&2 - exit 1 -fi diff --git a/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/api.proto b/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/api.proto index 33176d2b00a..ba61622714c 100644 --- a/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/api.proto +++ b/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2/v2alpha1/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-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package v2alpha1; 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 5475a7afa8c..7df44f2d2ee 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-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package runtime.v1; diff --git a/staging/src/k8s.io/kms/apis/v1beta1/api.proto b/staging/src/k8s.io/kms/apis/v1beta1/api.proto index b6576b2d242..ec3f570a57a 100644 --- a/staging/src/k8s.io/kms/apis/v1beta1/api.proto +++ b/staging/src/k8s.io/kms/apis/v1beta1/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-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package v1beta1; diff --git a/staging/src/k8s.io/kms/apis/v2alpha1/api.proto b/staging/src/k8s.io/kms/apis/v2alpha1/api.proto index eaf77077d5c..2c3b3fa669c 100644 --- a/staging/src/k8s.io/kms/apis/v2alpha1/api.proto +++ b/staging/src/k8s.io/kms/apis/v2alpha1/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-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package v2alpha1; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto index 61809b14253..201a4cb7cb8 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1alpha/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package deviceplugin; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/api.proto index a907a84a2e5..dbf608b810d 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/deviceplugin/v1beta1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package v1beta1; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/api.proto index c86ef6928e0..8278fbc9b98 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/dra/v1alpha1/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-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/api.proto index 03bab1af856..454404c3976 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package pluginregistration; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/api.proto index 03bab1af856..454404c3976 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1alpha1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package pluginregistration; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/api.proto index 03bab1af856..454404c3976 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/pluginregistration/v1beta1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package pluginregistration; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto index 40427bb5bbc..1157a162933 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package v1; diff --git a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto index 6d74b6ba493..c78660b5eee 100644 --- a/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto +++ b/staging/src/k8s.io/kubelet/pkg/apis/podresources/v1alpha1/api.proto @@ -1,4 +1,4 @@ -// To regenerate api.pb.go run hack/update-generated-proto-bindings.sh +// To regenerate api.pb.go run `hack/update-codegen.sh protobindings` syntax = "proto3"; package v1alpha1; From c8ce229e64207d5ad051959c35021907c406eb12 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Fri, 13 Jan 2023 15:23:42 -0800 Subject: [PATCH 4/6] Codegen: rm protobindings --- hack/update-codegen.sh | 25 ++++++++++++++++++- ...ate-generated-proto-bindings-dockerized.sh | 23 ++++------------- 2 files changed, 29 insertions(+), 19 deletions(-) diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 0447574e189..3207bbb4391 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -778,10 +778,33 @@ function codegen::subprojects() { } function codegen::protobindings() { + # Each element of this array is a directory containing subdirectories which + # eventually contain a file named "api.proto". + local 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" + + "staging/src/k8s.io/kms/apis" + "staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2" + + "staging/src/k8s.io/kubelet/pkg/apis/dra" + + "staging/src/k8s.io/kubelet/pkg/apis/pluginregistration" + "pkg/kubelet/pluginmanager/pluginwatcher/example_plugin_apis" + ) + + for api in "${apis[@]}"; do + git ls-files -z -cmo --exclude-standard ":(glob)${api}"/'**/api.pb.go' \ + | xargs -0 rm -f + done + # 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. - build/run.sh hack/update-generated-proto-bindings-dockerized.sh + build/run.sh hack/update-generated-proto-bindings-dockerized.sh "${apis[@]}" } # diff --git a/hack/update-generated-proto-bindings-dockerized.sh b/hack/update-generated-proto-bindings-dockerized.sh index 62d2ed9b474..0076d249bc7 100755 --- a/hack/update-generated-proto-bindings-dockerized.sh +++ b/hack/update-generated-proto-bindings-dockerized.sh @@ -24,25 +24,12 @@ KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" 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" +if [ "$#" = 0 ]; then + echo "usage: $0 ..." + exit 1 +fi - "staging/src/k8s.io/kubelet/pkg/apis/podresources" - - "staging/src/k8s.io/kubelet/pkg/apis/deviceplugin" - - "staging/src/k8s.io/kms/apis" - "staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/kmsv2" - - "staging/src/k8s.io/kubelet/pkg/apis/dra" - - "staging/src/k8s.io/kubelet/pkg/apis/pluginregistration" - "pkg/kubelet/pluginmanager/pluginwatcher/example_plugin_apis" -) - -for api in "${APIS[@]}"; do +for api; do # This can't use `git ls-files` because it runs in a container without the # .git dir synced. find "${api}" -type f -name "api.proto" \ From afae402865b8f329684b5a5d0f508d64074b25a7 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sun, 15 Jan 2023 10:06:21 -0800 Subject: [PATCH 5/6] Add debug output for protobindings generation --- hack/update-codegen.sh | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index 3207bbb4391..37344693bdd 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -796,6 +796,14 @@ function codegen::protobindings() { "pkg/kubelet/pluginmanager/pluginwatcher/example_plugin_apis" ) + kube::log::status "Generating protobuf bindings for ${#apis[@]} targets" + if [[ "${DBG_CODEGEN}" == 1 ]]; then + kube::log::status "DBG: generating protobuf bindings for:" + for dir in "${apis[@]}"; do + kube::log::status "DBG: $dir" + done + fi + for api in "${apis[@]}"; do git ls-files -z -cmo --exclude-standard ":(glob)${api}"/'**/api.pb.go' \ | xargs -0 rm -f From ac2890df45ded9d9f16174cfece88d4cd875ed99 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Sat, 21 Jan 2023 12:26:05 -0800 Subject: [PATCH 6/6] Make protobindings gen a bit safer --- hack/lib/protoc.sh | 2 +- ...ate-generated-proto-bindings-dockerized.sh | 21 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/hack/lib/protoc.sh b/hack/lib/protoc.sh index 0874ca07b17..1b02310f544 100644 --- a/hack/lib/protoc.sh +++ b/hack/lib/protoc.sh @@ -64,7 +64,7 @@ function kube::protoc::protoc() { # 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="$(pwd -P)" \ --proto_path="${KUBE_ROOT}/vendor" \ --gogo_out=paths=source_relative,plugins=grpc:. \ api.proto diff --git a/hack/update-generated-proto-bindings-dockerized.sh b/hack/update-generated-proto-bindings-dockerized.sh index 0076d249bc7..cd5dab862cb 100755 --- a/hack/update-generated-proto-bindings-dockerized.sh +++ b/hack/update-generated-proto-bindings-dockerized.sh @@ -23,8 +23,9 @@ set -o pipefail KUBE_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../" && pwd -P)" source "${KUBE_ROOT}/hack/lib/protoc.sh" +source "${KUBE_ROOT}/hack/lib/util.sh" -if [ "$#" = 0 ]; then +if [ "$#" == 0 ]; then echo "usage: $0 ..." exit 1 fi @@ -32,9 +33,17 @@ fi for api; do # This can't use `git ls-files` because it runs in a container without the # .git dir synced. - find "${api}" -type f -name "api.proto" \ - | while read -r F; do - D="$(dirname "${F}")" - kube::protoc::generate_proto "${KUBE_ROOT}/${D}" - done + protos=() + kube::util::read-array protos < <( \ + find "${api}" -type f -name "api.proto") + + if [ "${#protos[@]}" == 0 ]; then + echo "ERROR: no 'api.proto' files under '${api}'" + exit 1 + fi + + for file in "${protos[@]}"; do + dir="$(dirname "${file}")" + kube::protoc::generate_proto "${dir}" + done done