update-codegen.sh 4.2 KB

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