verify-symbols.sh 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. kube::util::ensure-temp-dir
  22. OUTPUT="${KUBE_TEMP}"/symbols-output
  23. cleanup() {
  24. rm -rf "${OUTPUT}"
  25. }
  26. trap "cleanup" EXIT SIGINT
  27. mkdir -p "${OUTPUT}"
  28. GOLDFLAGS="-w" make -C "${KUBE_ROOT}" WHAT=cmd/hyperkube
  29. # Add other BADSYMBOLS here.
  30. BADSYMBOLS=(
  31. "httptest"
  32. "testify"
  33. "testing[.]"
  34. "TestOnlySetFatalOnDecodeError"
  35. "TrackStorageCleanup"
  36. )
  37. # b/c hyperkube binds everything simply check that for bad symbols
  38. go tool nm "${KUBE_OUTPUT_HOSTBIN}/hyperkube" > "${OUTPUT}/hyperkube-symbols"
  39. if ! grep -q "NewHyperKubeCommand" "${OUTPUT}/hyperkube-symbols"; then
  40. echo "No symbols found in hyperkube binary."
  41. exit 1
  42. fi
  43. RESULT=0
  44. for BADSYMBOL in "${BADSYMBOLS[@]}"; do
  45. if FOUND=$(grep "${BADSYMBOL}" < "${OUTPUT}/hyperkube-symbols"); then
  46. echo "Found bad symbol '${BADSYMBOL}':"
  47. echo "$FOUND"
  48. RESULT=1
  49. fi
  50. done
  51. exit $RESULT
  52. # ex: ts=2 sw=2 et filetype=sh