update-codegen.sh 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/usr/bin/env bash
  2. # Copyright 2014 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. source "${KUBE_ROOT}/hack/lib/init.sh"
  20. kube::golang::setup_env
  21. BUILD_TARGETS=(
  22. vendor/k8s.io/code-generator/cmd/client-gen
  23. vendor/k8s.io/code-generator/cmd/lister-gen
  24. vendor/k8s.io/code-generator/cmd/informer-gen
  25. )
  26. make -C "${KUBE_ROOT}" WHAT="${BUILD_TARGETS[*]}"
  27. clientgen=$(kube::util::find-binary "client-gen")
  28. listergen=$(kube::util::find-binary "lister-gen")
  29. informergen=$(kube::util::find-binary "informer-gen")
  30. # Please do not add any logic to this shell script. Add logic to the go code
  31. # that generates the set-gen program.
  32. #
  33. IFS=" " read -r -a GROUP_VERSIONS <<< "${KUBE_AVAILABLE_GROUP_VERSIONS}"
  34. GV_DIRS=()
  35. for gv in "${GROUP_VERSIONS[@]}"; do
  36. # add items, but strip off any leading apis/ you find to match command expectations
  37. api_dir=$(kube::util::group-version-to-pkg-path "${gv}")
  38. nopkg_dir=${api_dir#pkg/}
  39. nopkg_dir=${nopkg_dir#vendor/k8s.io/api/}
  40. pkg_dir=${nopkg_dir#apis/}
  41. # skip groups that aren't being served, clients for these don't matter
  42. if [[ " ${KUBE_NONSERVER_GROUP_VERSIONS} " == *" ${gv} "* ]]; then
  43. continue
  44. fi
  45. GV_DIRS+=("${pkg_dir}")
  46. done
  47. # delimit by commas for the command
  48. GV_DIRS_CSV=$(IFS=',';echo "${GV_DIRS[*]// /,}";IFS=$)
  49. # This can be called with one flag, --verify-only, so it works for both the
  50. # update- and verify- scripts.
  51. ${clientgen} --output-base "${KUBE_ROOT}/vendor" --output-package="k8s.io/client-go" --clientset-name="kubernetes" --input-base="k8s.io/kubernetes/vendor/k8s.io/api" --input="${GV_DIRS_CSV}" --go-header-file "${KUBE_ROOT}/hack/boilerplate/boilerplate.generatego.txt" "$@"
  52. listergen_external_apis=()
  53. kube::util::read-array listergen_external_apis < <(
  54. cd "${KUBE_ROOT}/staging/src"
  55. find k8s.io/api -name types.go -print0 | xargs -0 -n1 dirname | sort
  56. )
  57. listergen_external_apis_csv=$(IFS=,; echo "${listergen_external_apis[*]}")
  58. ${listergen} --output-base "${KUBE_ROOT}/vendor" --output-package "k8s.io/client-go/listers" --input-dirs "${listergen_external_apis_csv}" --go-header-file "${KUBE_ROOT}/hack/boilerplate/boilerplate.generatego.txt" "$@"
  59. informergen_external_apis=()
  60. # because client-gen doesn't do policy/v1alpha1, we have to skip it too
  61. kube::util::read-array informergen_external_apis < <(
  62. cd "${KUBE_ROOT}/staging/src"
  63. find k8s.io/api -name types.go -print0 | xargs -0 -n1 dirname | sort | grep -v pkg.apis.policy.v1alpha1
  64. )
  65. informergen_external_apis_csv=$(IFS=,; echo "${informergen_external_apis[*]}")
  66. ${informergen} \
  67. --output-base "${KUBE_ROOT}/vendor" \
  68. --output-package "k8s.io/client-go/informers" \
  69. --single-directory \
  70. --input-dirs "${informergen_external_apis_csv}" \
  71. --versioned-clientset-package k8s.io/client-go/kubernetes \
  72. --listers-package k8s.io/client-go/listers \
  73. --go-header-file "${KUBE_ROOT}/hack/boilerplate/boilerplate.generatego.txt" \
  74. "$@"
  75. # You may add additional calls of code generators like set-gen above.
  76. # call generation on sub-project for now
  77. CODEGEN_PKG=./vendor/k8s.io/code-generator vendor/k8s.io/code-generator/hack/update-codegen.sh
  78. CODEGEN_PKG=./vendor/k8s.io/code-generator vendor/k8s.io/kube-aggregator/hack/update-codegen.sh
  79. CODEGEN_PKG=./vendor/k8s.io/code-generator vendor/k8s.io/sample-apiserver/hack/update-codegen.sh
  80. CODEGEN_PKG=./vendor/k8s.io/code-generator vendor/k8s.io/sample-controller/hack/update-codegen.sh
  81. CODEGEN_PKG=./vendor/k8s.io/code-generator vendor/k8s.io/apiextensions-apiserver/hack/update-codegen.sh
  82. CODEGEN_PKG=./vendor/k8s.io/code-generator vendor/k8s.io/metrics/hack/update-codegen.sh
  83. CODEGEN_PKG=./vendor/k8s.io/code-generator vendor/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh
  84. CODEGEN_PKG=./vendor/k8s.io/code-generator vendor/k8s.io/node-api/hack/update-codegen.sh