update-generated-kms-dockerized.sh 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. #!/usr/bin/env bash
  2. # Copyright 2018 The Kubernetes Authors.
  3. #
  4. # Licensed under the Apache License, Version 2.0 (the "License");
  5. # you may not use this file except in compliance with the License.
  6. # You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software
  11. # distributed under the License is distributed on an "AS IS" BASIS,
  12. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. # See the License for the specific language governing permissions and
  14. # limitations under the License.
  15. set -o errexit
  16. set -o nounset
  17. set -o pipefail
  18. KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
  19. KUBE_KMS_GRPC_ROOT="${KUBE_ROOT}/staging/src/k8s.io/apiserver/pkg/storage/value/encrypt/envelope/v1beta1/"
  20. source "${KUBE_ROOT}/hack/lib/init.sh"
  21. kube::golang::setup_env
  22. BINS=(
  23. vendor/k8s.io/code-generator/cmd/go-to-protobuf/protoc-gen-gogo
  24. )
  25. make -C "${KUBE_ROOT}" WHAT="${BINS[*]}"
  26. if [[ -z "$(which protoc)" || "$(protoc --version)" != "libprotoc 3."* ]]; then
  27. echo "Generating protobuf requires protoc 3.0.0-beta1 or newer. Please download and"
  28. echo "install the platform appropriate Protobuf package for your OS: "
  29. echo
  30. echo " https://github.com/google/protobuf/releases"
  31. echo
  32. echo "WARNING: Protobuf changes are not being validated"
  33. exit 1
  34. fi
  35. function cleanup {
  36. rm -f "${KUBE_KMS_GRPC_ROOT}/service.pb.go.bak"
  37. rm -f "${KUBE_KMS_GRPC_ROOT}/service.pb.go.tmp"
  38. }
  39. trap cleanup EXIT
  40. gogopath=$(dirname "$(kube::util::find-binary "protoc-gen-gogo")")
  41. PATH="${gogopath}:${PATH}" \
  42. protoc \
  43. --proto_path="${KUBE_KMS_GRPC_ROOT}" \
  44. --proto_path="${KUBE_ROOT}/vendor" \
  45. --gogo_out=plugins=grpc:"${KUBE_KMS_GRPC_ROOT}" "${KUBE_KMS_GRPC_ROOT}/service.proto"
  46. # Update boilerplate for the generated file.
  47. cat hack/boilerplate/boilerplate.generatego.txt "${KUBE_KMS_GRPC_ROOT}/service.pb.go" > "${KUBE_KMS_GRPC_ROOT}/service.pb.go.tmp" && \
  48. mv "${KUBE_KMS_GRPC_ROOT}/service.pb.go.tmp" "${KUBE_KMS_GRPC_ROOT}/service.pb.go"
  49. # Run gofmt to clean up the generated code.
  50. kube::golang::verify_go_version
  51. gofmt -l -s -w "${KUBE_KMS_GRPC_ROOT}/service.pb.go"