From 18e7a3eb243f4fa74ea3258dad946999c327da01 Mon Sep 17 00:00:00 2001 From: Tim Hockin Date: Tue, 3 May 2016 22:00:27 -0700 Subject: [PATCH] Get rid of hack/after-build scripts The build is now fast enough to not need them. --- docs/devel/adding-an-APIGroup.md | 13 +-- hack/after-build/README.md | 4 - hack/after-build/run-codegen.sh | 42 -------- hack/after-build/run-import-boss.sh | 26 ----- hack/after-build/update-generated-docs.sh | 73 ------------- hack/after-build/update-swagger-spec.sh | 101 ------------------ hack/after-build/verify-description.sh | 86 --------------- hack/after-build/verify-e2e.sh | 35 ------ hack/after-build/verify-generated-docs.sh | 82 -------------- hack/after-build/verify-generated-protobuf.sh | 59 ---------- .../verify-generated-swagger-docs.sh | 58 ---------- hack/after-build/verify-linkcheck.sh | 58 ---------- hack/after-build/verify-swagger-spec.sh | 49 --------- hack/after-build/verify-symbols.sh | 47 -------- hack/update-codegen.sh | 29 ++++- hack/update-generated-docs.sh | 55 +++++++++- ...> update-generated-protobuf-dockerized.sh} | 2 +- hack/update-generated-protobuf.sh | 2 +- hack/update-swagger-spec.sh | 78 +++++++++++++- hack/verify-codegen.sh | 10 +- hack/verify-description.sh | 63 ++++++++++- hack/verify-generated-docs.sh | 64 ++++++++++- hack/verify-generated-protobuf.sh | 37 ++++++- hack/verify-generated-swagger-docs.sh | 34 +++++- hack/verify-import-boss.sh | 2 +- hack/verify-linkcheck.sh | 33 +++++- hack/verify-swagger-spec.sh | 23 +++- hack/verify-symbols.sh | 21 +++- hooks/pre-commit | 8 +- 29 files changed, 434 insertions(+), 760 deletions(-) delete mode 100644 hack/after-build/README.md delete mode 100755 hack/after-build/run-codegen.sh delete mode 100755 hack/after-build/run-import-boss.sh delete mode 100755 hack/after-build/update-generated-docs.sh delete mode 100755 hack/after-build/update-swagger-spec.sh delete mode 100755 hack/after-build/verify-description.sh delete mode 100755 hack/after-build/verify-e2e.sh delete mode 100755 hack/after-build/verify-generated-docs.sh delete mode 100755 hack/after-build/verify-generated-protobuf.sh delete mode 100755 hack/after-build/verify-generated-swagger-docs.sh delete mode 100755 hack/after-build/verify-linkcheck.sh delete mode 100755 hack/after-build/verify-swagger-spec.sh delete mode 100755 hack/after-build/verify-symbols.sh rename hack/{after-build/update-generated-protobuf.sh => update-generated-protobuf-dockerized.sh} (97%) diff --git a/docs/devel/adding-an-APIGroup.md b/docs/devel/adding-an-APIGroup.md index 2b31882842664..e0f95fc777f6e 100644 --- a/docs/devel/adding-an-APIGroup.md +++ b/docs/devel/adding-an-APIGroup.md @@ -50,8 +50,8 @@ We plan on improving the way the types are factored in the future; see in which this might evolve. 1. Create a folder in pkg/apis to hold you group. Create types.go in - pkg/apis/``/ and pkg/apis/``/``/ to define API objects - in your group; +pkg/apis/``/ and pkg/apis/``/``/ to define API objects +in your group; 2. Create pkg/apis/``/{register.go, ``/register.go} to register this group's API objects to the encoding/decoding scheme (e.g., @@ -75,10 +75,10 @@ cmd/libs/go2idl/ tool. 1. Generate conversions and deep-copies: 1. Add your "group/" or "group/version" into -cmd/libs/go2idl/{conversion-gen, deep-copy-gen}/main.go; + cmd/libs/go2idl/{conversion-gen, deep-copy-gen}/main.go; 2. Make sure your pkg/apis/``/`` directory has a doc.go file -with the comment `// +genconversion=true`, to catch the attention of our -gen-conversion script. + with the comment `// +genconversion=true`, to catch the attention of our + gen-conversion script. 3. Run hack/update-all.sh. @@ -89,7 +89,8 @@ gen-conversion script. 3. Generate protobuf objects: - 1. Add your group to `cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go` to `New()` in the `Packages` field + 1. Add your group to `cmd/libs/go2idl/go-to-protobuf/protobuf/cmd.go` to + `New()` in the `Packages` field 2. Run hack/update-generated-protobuf.sh ### Client (optional): diff --git a/hack/after-build/README.md b/hack/after-build/README.md deleted file mode 100644 index 4930a4066565b..0000000000000 --- a/hack/after-build/README.md +++ /dev/null @@ -1,4 +0,0 @@ -These should be called only by a script (or a user) who knows that the binaries are built and correct. Normal users should just have the versions in ../ which should just always do a build. - - -[![Analytics](https://kubernetes-site.appspot.com/UA-36037335-10/GitHub/hack/after-build/README.md?pixel)]() diff --git a/hack/after-build/run-codegen.sh b/hack/after-build/run-codegen.sh deleted file mode 100755 index a4f7b6b9f2321..0000000000000 --- a/hack/after-build/run-codegen.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/bin/bash - -# Copyright 2015 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -clientgen=$(kube::util::find-binary "client-gen") -conversiongen=$(kube::util::find-binary "conversion-gen") -deepcopygen=$(kube::util::find-binary "deepcopy-gen") -setgen=$(kube::util::find-binary "set-gen") - -# Please do not add any logic to this shell script. Add logic to the go code -# that generates the set-gen program. -# -# This can be called with one flag, --verify-only, so it works for both the -# update- and verify- scripts. -${clientgen} "$@" -${clientgen} -t "$@" -${conversiongen} "$@" -${deepcopygen} "$@" -${setgen} "$@" - -# You may add additional calls of code generators like set-gen above. diff --git a/hack/after-build/run-import-boss.sh b/hack/after-build/run-import-boss.sh deleted file mode 100755 index d57b2730394b9..0000000000000 --- a/hack/after-build/run-import-boss.sh +++ /dev/null @@ -1,26 +0,0 @@ -#!/bin/bash - -# Copyright 2015 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -$(kube::util::find-binary "import-boss") "$@" diff --git a/hack/after-build/update-generated-docs.sh b/hack/after-build/update-generated-docs.sh deleted file mode 100755 index 735c83737c38a..0000000000000 --- a/hack/after-build/update-generated-docs.sh +++ /dev/null @@ -1,73 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -kube::util::ensure-temp-dir - -kube::util::gen-docs "${KUBE_TEMP}" - -# remove all of the old docs -while read file; do - rm "${KUBE_ROOT}/${file}" 2>/dev/null || true -done <"${KUBE_ROOT}/.generated_docs" - -# the shopt is so that we get .generated_docs from the glob. -shopt -s dotglob -cp -af "${KUBE_TEMP}"/* "${KUBE_ROOT}" -shopt -u dotglob - -kube::util::gen-analytics "${KUBE_ROOT}" - -mungedocs=$(kube::util::find-binary "mungedocs") -"${mungedocs}" "--upstream=${KUBE_GIT_UPSTREAM}" "--root-dir=${KUBE_ROOT}/docs/" && ret=0 || ret=$? -if [[ $ret -eq 1 ]]; then - echo "${KUBE_ROOT}/docs/ requires manual changes. See preceding errors." - exit 1 -elif [[ $ret -gt 1 ]]; then - echo "Error running mungedocs." - exit 1 -fi - -"${mungedocs}" "--upstream=${KUBE_GIT_UPSTREAM}" "--root-dir=${KUBE_ROOT}/examples/" && ret=0 || ret=$? -if [[ $ret -eq 1 ]]; then - echo "${KUBE_ROOT}/examples/ requires manual changes. See preceding errors." - exit 1 -elif [[ $ret -gt 1 ]]; then - echo "Error running mungedocs." - exit 1 -fi - -"${mungedocs}" "--upstream=${KUBE_GIT_UPSTREAM}" \ - "--skip-munges=unversioned-warning,analytics" \ - "--norecurse" \ - "--root-dir=${KUBE_ROOT}/" && ret=0 || ret=$? -if [[ $ret -eq 1 ]]; then - echo "${KUBE_ROOT}/ requires manual changes. See preceding errors." - exit 1 -elif [[ $ret -gt 1 ]]; then - echo "Error running mungedocs." - exit 1 -fi - -# ex: ts=2 sw=2 et filetype=sh diff --git a/hack/after-build/update-swagger-spec.sh b/hack/after-build/update-swagger-spec.sh deleted file mode 100755 index 0648aefa1c6be..0000000000000 --- a/hack/after-build/update-swagger-spec.sh +++ /dev/null @@ -1,101 +0,0 @@ -#!/bin/bash - -# Copyright 2015 The Kubernetes Authors All rights reserved. -# -# 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. - -# Script to fetch latest swagger spec. -# Puts the updated spec at swagger-spec/ - -set -o errexit -set -o nounset -set -o pipefail - -echo "Note: This assumes that types_swagger_doc_generated.go has been updated for all API group versions. Please run hack/update-generated-swagger-docs.sh to ensure that." - -KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. -SWAGGER_ROOT_DIR="${KUBE_ROOT}/api/swagger-spec" -source "${KUBE_ROOT}/hack/lib/init.sh" - -function cleanup() -{ - [[ -n ${APISERVER_PID-} ]] && kill ${APISERVER_PID} 1>&2 2>/dev/null - - kube::etcd::cleanup - - kube::log::status "Clean up complete" -} - -trap cleanup EXIT SIGINT - -kube::golang::setup_env - -apiserver=$(kube::util::find-binary "kube-apiserver") - -TMP_DIR=$(mktemp -d /tmp/update-swagger-spec.XXXX) -ETCD_HOST=${ETCD_HOST:-127.0.0.1} -ETCD_PORT=${ETCD_PORT:-4001} -API_PORT=${API_PORT:-8050} -API_HOST=${API_HOST:-127.0.0.1} -KUBELET_PORT=${KUBELET_PORT:-10250} - -kube::etcd::start - -# Start kube-apiserver -kube::log::status "Starting kube-apiserver" -"${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \ - --insecure-bind-address="127.0.0.1" \ - --bind-address="127.0.0.1" \ - --insecure-port="${API_PORT}" \ - --etcd-servers="http://${ETCD_HOST}:${ETCD_PORT}" \ - --advertise-address="10.10.10.10" \ - --cert-dir="${TMP_DIR}/certs" \ - --service-cluster-ip-range="10.0.0.0/24" >/tmp/swagger-api-server.log 2>&1 & -APISERVER_PID=$! - -kube::util::wait_for_url "http://127.0.0.1:${API_PORT}/healthz" "apiserver: " - -SWAGGER_API_PATH="http://127.0.0.1:${API_PORT}/swaggerapi/" -DEFAULT_GROUP_VERSIONS="v1 autoscaling/v1 batch/v1 extensions/v1beta1 apps/v1alpha1" -VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS} - -kube::log::status "Updating " ${SWAGGER_ROOT_DIR} - -for ver in ${VERSIONS}; do - # fetch the swagger spec for each group version. - if [[ ${ver} == "v1" ]]; then - SUBPATH="api" - else - SUBPATH="apis" - fi - SUBPATH="${SUBPATH}/${ver}" - SWAGGER_JSON_NAME="$(kube::util::gv-to-swagger-name ${ver}).json" - curl -w "\n" -fs "${SWAGGER_API_PATH}${SUBPATH}" > "${SWAGGER_ROOT_DIR}/${SWAGGER_JSON_NAME}" - - # fetch the swagger spec for the discovery mechanism at group level. - if [[ ${ver} == "v1" ]]; then - continue - fi - SUBPATH="apis/"${ver%/*} - SWAGGER_JSON_NAME="${ver%/*}.json" - curl -w "\n" -fs "${SWAGGER_API_PATH}${SUBPATH}" > "${SWAGGER_ROOT_DIR}/${SWAGGER_JSON_NAME}" -done - -# fetch swagger specs for other discovery mechanism. -curl -w "\n" -fs "${SWAGGER_API_PATH}" > "${SWAGGER_ROOT_DIR}/resourceListing.json" -curl -w "\n" -fs "${SWAGGER_API_PATH}version" > "${SWAGGER_ROOT_DIR}/version.json" -curl -w "\n" -fs "${SWAGGER_API_PATH}api" > "${SWAGGER_ROOT_DIR}/api.json" -curl -w "\n" -fs "${SWAGGER_API_PATH}apis" > "${SWAGGER_ROOT_DIR}/apis.json" -kube::log::status "SUCCESS" - -# ex: ts=2 sw=2 et filetype=sh diff --git a/hack/after-build/verify-description.sh b/hack/after-build/verify-description.sh deleted file mode 100755 index 74243014fa01b..0000000000000 --- a/hack/after-build/verify-description.sh +++ /dev/null @@ -1,86 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -# Find binary -genswaggertypedocs=$(kube::util::find-binary "genswaggertypedocs") - -gen_swagger_result=0 -result=0 - -find_files() { - find . -not \( \ - \( \ - -wholename './output' \ - -o -wholename './_output' \ - -o -wholename './_gopath' \ - -o -wholename './release' \ - -o -wholename './target' \ - -o -wholename '*/third_party/*' \ - -o -wholename '*/vendor/*' \ - \) -prune \ - \) \ - \( -wholename '*pkg/api/v*/types.go' \ - -o -wholename '*pkg/apis/*/v*/types.go' \ - -o -wholename '*pkg/api/unversioned/types.go' \ - \) -} - -if [[ $# -eq 0 ]]; then - versioned_api_files=$(find_files | egrep "pkg/.[^/]*/((v.[^/]*)|unversioned)/types\.go") -else - versioned_api_files="${*}" -fi - -for file in $versioned_api_files; do - $genswaggertypedocs -v -s "${file}" -f - || gen_swagger_result=$? - if [[ "${gen_swagger_result}" -ne "0" ]]; then - echo "API file: ${file} is missing: ${gen_swagger_result} descriptions" - result=1 - fi - if grep json: "${file}" | grep -v // | grep description: ; then - echo "API file: ${file} should not contain descriptions in struct tags" - result=1 - fi - if grep json: "${file}" | grep -Ee ",[[:space:]]+omitempty|omitempty[[:space:]]+" ; then - echo "API file: ${file} should not contain leading or trailing spaces for omitempty directive" - result=1 - fi -done - -internal_types_files="${KUBE_ROOT}/pkg/api/types.go ${KUBE_ROOT}/pkg/apis/extensions/types.go" -for internal_types_file in $internal_types_files; do - if [[ ! -e $internal_types_file ]]; then - echo "Internal types file ${internal_types_file} does not exist" - result=1 - continue - fi - - if grep json: "${internal_types_file}" | grep -v // | grep description: ; then - echo "Internal API types should not contain descriptions" - result=1 - fi -done - -exit ${result} diff --git a/hack/after-build/verify-e2e.sh b/hack/after-build/verify-e2e.sh deleted file mode 100755 index ace9a8609cb30..0000000000000 --- a/hack/after-build/verify-e2e.sh +++ /dev/null @@ -1,35 +0,0 @@ -#!/bin/bash - -# Copyright 2016 The Kubernetes Authors All rights reserved. -# -# 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. - -# Verify that E2E's use Describe wrappers, so that we can auto tag and provide -# other wrapper functionality for the entire suite. -set -o errexit -set -o nounset -set -o pipefail - -KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. -cd "${KUBE_ROOT}" - -findDescViolations() { - find ./test/e2e/ -name '*.go' | xargs cat | grep "\sDescribe(" -} - -# There should be only one call to describe. -if [ $(findDescViolations | wc -l) != 1 ]; then - echo "The following lines use Describe instead of KubeDescribe." - echo "Describe() is a reserved term which only should called via the KubeDescribe wrapper function." - findDescViolations -fi diff --git a/hack/after-build/verify-generated-docs.sh b/hack/after-build/verify-generated-docs.sh deleted file mode 100755 index bc6714aa7e18f..0000000000000 --- a/hack/after-build/verify-generated-docs.sh +++ /dev/null @@ -1,82 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -# Find binary -gendocs=$(kube::util::find-binary "gendocs") -genkubedocs=$(kube::util::find-binary "genkubedocs") -genman=$(kube::util::find-binary "genman") -genyaml=$(kube::util::find-binary "genyaml") -genbashcomp=$(kube::util::find-binary "genbashcomp") -mungedocs=$(kube::util::find-binary "mungedocs") - -DOCROOT="${KUBE_ROOT}/docs/" -EXAMPLEROOT="${KUBE_ROOT}/examples/" - -# mungedocs --verify can (and should) be run on the real docs, otherwise their -# links will be distorted. --verify means that it will not make changes. -# --verbose gives us output we can use for a diff. -"${mungedocs}" "--verify=true" "--verbose=true" "--upstream=${KUBE_GIT_UPSTREAM}" "--root-dir=${DOCROOT}" && ret=0 || ret=$? -if [[ $ret -eq 1 ]]; then - echo "${DOCROOT} is out of date. Please run hack/update-generated-docs.sh" - exit 1 -fi -if [[ $ret -gt 1 ]]; then - echo "Error running mungedocs" - exit 1 -fi - -"${mungedocs}" "--verify=true" "--verbose=true" "--upstream=${KUBE_GIT_UPSTREAM}" "--root-dir=${EXAMPLEROOT}" && ret=0 || ret=$? -if [[ $ret -eq 1 ]]; then - echo "${EXAMPLEROOT} is out of date. Please run hack/update-generated-docs.sh" - exit 1 -fi -if [[ $ret -gt 1 ]]; then - echo "Error running mungedocs" - exit 1 -fi - - -kube::util::ensure-temp-dir - -kube::util::gen-docs "${KUBE_TEMP}" -diff -Naup "${KUBE_TEMP}/.generated_docs" "${KUBE_ROOT}/.generated_docs" || ret=1 || true -while read file; do - diff -Naup "${KUBE_TEMP}/${file}" "${KUBE_ROOT}/${file}" || ret=1 || true -done <"${KUBE_TEMP}/.generated_docs" - -needsanalytics=($(kube::util::gen-analytics "${KUBE_ROOT}" 1)) -if [[ ${#needsanalytics[@]} -ne 0 ]]; then - echo -e "Some md files are missing ga-beacon analytics link:" - printf '%s\n' "${needsanalytics[@]}" - ret=1 -fi -if [[ $ret -eq 0 ]] -then - echo "Generated docs are up to date." -else - echo "Generated docs are out of date. Please run hack/update-generated-docs.sh" - exit 1 -fi -# ex: ts=2 sw=2 et filetype=sh diff --git a/hack/after-build/verify-generated-protobuf.sh b/hack/after-build/verify-generated-protobuf.sh deleted file mode 100755 index 965b8cefe0478..0000000000000 --- a/hack/after-build/verify-generated-protobuf.sh +++ /dev/null @@ -1,59 +0,0 @@ -#!/bin/bash - -# Copyright 2015 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -APIROOTS=${APIROOTS:-pkg/api pkg/apis pkg/runtime pkg/util/intstr pkg/watch} -_tmp="${KUBE_ROOT}/_tmp" - -cleanup() { - rm -rf "${_tmp}" -} - -trap "cleanup" EXIT SIGINT - -cleanup -for APIROOT in ${APIROOTS}; do - mkdir -p "${_tmp}/${APIROOT%/*}" - cp -a "${KUBE_ROOT}/${APIROOT}" "${_tmp}/${APIROOT}" -done - -# If not running as root, we need to use sudo to restore the original generated -# protobuf files. -SUDO="" -if [[ "$(id -u)" != '0' ]]; then - SUDO="sudo" -fi - -"${KUBE_ROOT}/hack/update-generated-protobuf.sh" -for APIROOT in ${APIROOTS}; do - TMP_APIROOT="${_tmp}/${APIROOT}" - echo "diffing ${APIROOT} against freshly generated protobuf" - ret=0 - diff -Naupr -I 'Auto generated by' "${KUBE_ROOT}/${APIROOT}" "${TMP_APIROOT}" || ret=$? - ${SUDO} cp -a "${TMP_APIROOT}" "${KUBE_ROOT}/${APIROOT%/*}" - if [[ $ret -eq 0 ]]; then - echo "${APIROOT} up to date." - else - echo "${APIROOT} is out of date. Please run hack/update-generated-protobuf.sh" - exit 1 - fi -done diff --git a/hack/after-build/verify-generated-swagger-docs.sh b/hack/after-build/verify-generated-swagger-docs.sh deleted file mode 100755 index 4126e3b77ea47..0000000000000 --- a/hack/after-build/verify-generated-swagger-docs.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -# Find binary -genswaggertypedocs=$(kube::util::find-binary "genswaggertypedocs") - -if [[ ! -x "$genswaggertypedocs" ]]; then - { - echo "It looks as if you don't have a compiled genswaggertypedocs binary" - echo - echo "If you are running from a clone of the git repo, please run" - echo "'./hack/build-go.sh cmd/genswaggertypedocs'." - } >&2 - exit 1 -fi - -DIFFROOT="${KUBE_ROOT}/pkg" -TMP_DIFFROOT="${KUBE_ROOT}/_tmp/pkg" -_tmp="${KUBE_ROOT}/_tmp" - -mkdir -p "${_tmp}" -cp -a "${DIFFROOT}" "${TMP_DIFFROOT}" - -"${KUBE_ROOT}/hack/update-generated-swagger-docs.sh" -echo "diffing ${DIFFROOT} against freshly generated swagger type documentation" -ret=0 -diff -Naupr -I 'Auto generated by' "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? -cp -a "${TMP_DIFFROOT}" "${KUBE_ROOT}/" -rm -rf "${_tmp}" -if [[ $ret -eq 0 ]] -then - echo "${DIFFROOT} up to date." -else - echo "${DIFFROOT} is out of date. Please run hack/update-generated-swagger-docs.sh" - exit 1 -fi diff --git a/hack/after-build/verify-linkcheck.sh b/hack/after-build/verify-linkcheck.sh deleted file mode 100755 index 577de2dee76f3..0000000000000 --- a/hack/after-build/verify-linkcheck.sh +++ /dev/null @@ -1,58 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env -linkcheck=$(kube::util::find-binary "linkcheck") - -kube::util::ensure-temp-dir -OUTPUT="${KUBE_TEMP}"/linkcheck-output -cleanup() { - rm -rf "${OUTPUT}" -} -trap "cleanup" EXIT SIGINT -mkdir -p "$OUTPUT" - -APIROOT="${KUBE_ROOT}/pkg/api/" -APISROOT="${KUBE_ROOT}/pkg/apis/" -DOCROOT="${KUBE_ROOT}/docs/" -ROOTS=($APIROOT $APISROOT $DOCROOT) -found_invalid=false -for root in "${ROOTS[@]}"; do - "${linkcheck}" "--root-dir=${root}" 2> >(tee -a "${OUTPUT}/error" >&2) && ret=0 || ret=$? - if [[ $ret -eq 1 ]]; then - echo "Failed: found invalid links in ${root}." - found_invalid=true - fi - if [[ $ret -gt 1 ]]; then - echo "Error running linkcheck" - exit 1 - fi -done - -if [ ${found_invalid} = true ]; then - echo "Summary of invalid links:" - cat ${OUTPUT}/error - exit 1 -fi - -# ex: ts=2 sw=2 et filetype=sh diff --git a/hack/after-build/verify-swagger-spec.sh b/hack/after-build/verify-swagger-spec.sh deleted file mode 100755 index b633b5ffb1293..0000000000000 --- a/hack/after-build/verify-swagger-spec.sh +++ /dev/null @@ -1,49 +0,0 @@ -#!/bin/bash - -# Copyright 2015 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -apiserver=$(kube::util::find-binary "kube-apiserver") - -SPECROOT="${KUBE_ROOT}/api/swagger-spec" -TMP_SPECROOT="${KUBE_ROOT}/_tmp/swagger-spec" -_tmp="${KUBE_ROOT}/_tmp" - -mkdir -p "${_tmp}" -cp -a "${SPECROOT}" "${TMP_SPECROOT}" - -"${KUBE_ROOT}/hack/update-swagger-spec.sh" -echo "diffing ${SPECROOT} against freshly generated swagger spec" -ret=0 -diff -Naupr -I 'Auto generated by' "${SPECROOT}" "${TMP_SPECROOT}" || ret=$? -cp -a ${TMP_SPECROOT} "${KUBE_ROOT}/api" -rm -rf "${_tmp}" -if [[ $ret -eq 0 ]] -then - echo "${SPECROOT} up to date." -else - echo "${SPECROOT} is out of date. Please run hack/update-swagger-spec.sh" - exit 1 -fi - -# ex: ts=2 sw=2 et filetype=sh diff --git a/hack/after-build/verify-symbols.sh b/hack/after-build/verify-symbols.sh deleted file mode 100755 index 09a4d5f517803..0000000000000 --- a/hack/after-build/verify-symbols.sh +++ /dev/null @@ -1,47 +0,0 @@ -#!/bin/bash - -# Copyright 2014 The Kubernetes Authors All rights reserved. -# -# 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}")/../.. -source "${KUBE_ROOT}/hack/lib/init.sh" - -kube::golang::setup_env - -# add other BADSYMBOLS here. -BADSYMBOLS=( - "httptest" - "testify" - "testing[.]" -) - -# b/c hyperkube binds everything simply check that for bad symbols -SYMBOLS="$(nm ${KUBE_OUTPUT_HOSTBIN}/hyperkube)" - -RESULT=0 -for BADSYMBOL in "${BADSYMBOLS[@]}"; do - if FOUND=$(echo "$SYMBOLS" | grep "$BADSYMBOL"); then - echo "Found bad symbol '${BADSYMBOL}':" - echo "$FOUND" - RESULT=1 - fi -done - -exit $RESULT - -# ex: ts=2 sw=2 et filetype=sh diff --git a/hack/update-codegen.sh b/hack/update-codegen.sh index e9ef40a628912..ae8e7363cdf28 100755 --- a/hack/update-codegen.sh +++ b/hack/update-codegen.sh @@ -23,9 +23,28 @@ source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env -"${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/client-gen -"${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/conversion-gen -"${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/deepcopy-gen -"${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/set-gen +BUILD_TARGETS=( + cmd/libs/go2idl/client-gen + cmd/libs/go2idl/conversion-gen + cmd/libs/go2idl/deepcopy-gen + cmd/libs/go2idl/set-gen +) +"${KUBE_ROOT}/hack/build-go.sh" ${BUILD_TARGETS[*]} -"${KUBE_ROOT}/hack/after-build/run-codegen.sh" "$@" +clientgen=$(kube::util::find-binary "client-gen") +conversiongen=$(kube::util::find-binary "conversion-gen") +deepcopygen=$(kube::util::find-binary "deepcopy-gen") +setgen=$(kube::util::find-binary "set-gen") + +# Please do not add any logic to this shell script. Add logic to the go code +# that generates the set-gen program. +# +# This can be called with one flag, --verify-only, so it works for both the +# update- and verify- scripts. +${clientgen} "$@" +${clientgen} -t "$@" +${conversiongen} "$@" +${deepcopygen} "$@" +${setgen} "$@" + +# You may add additional calls of code generators like set-gen above. diff --git a/hack/update-generated-docs.sh b/hack/update-generated-docs.sh index 13bc8c0cb60f4..ddcbbb0cf2c98 100755 --- a/hack/update-generated-docs.sh +++ b/hack/update-generated-docs.sh @@ -23,8 +23,59 @@ source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env -"${KUBE_ROOT}/hack/build-go.sh" cmd/gendocs cmd/genkubedocs cmd/genman cmd/genyaml cmd/genbashcomp cmd/mungedocs +"${KUBE_ROOT}/hack/build-go.sh" \ + cmd/gendocs \ + cmd/genkubedocs \ + cmd/genman \ + cmd/genyaml \ + cmd/genbashcomp \ + cmd/mungedocs -"${KUBE_ROOT}/hack/after-build/update-generated-docs.sh" "$@" +kube::util::ensure-temp-dir + +kube::util::gen-docs "${KUBE_TEMP}" + +# remove all of the old docs +while read file; do + rm "${KUBE_ROOT}/${file}" 2>/dev/null || true +done <"${KUBE_ROOT}/.generated_docs" + +# the shopt is so that we get .generated_docs from the glob. +shopt -s dotglob +cp -af "${KUBE_TEMP}"/* "${KUBE_ROOT}" +shopt -u dotglob + +kube::util::gen-analytics "${KUBE_ROOT}" + +mungedocs=$(kube::util::find-binary "mungedocs") +"${mungedocs}" "--upstream=${KUBE_GIT_UPSTREAM}" "--root-dir=${KUBE_ROOT}/docs/" && ret=0 || ret=$? +if [[ $ret -eq 1 ]]; then + echo "${KUBE_ROOT}/docs/ requires manual changes. See preceding errors." + exit 1 +elif [[ $ret -gt 1 ]]; then + echo "Error running mungedocs." + exit 1 +fi + +"${mungedocs}" "--upstream=${KUBE_GIT_UPSTREAM}" "--root-dir=${KUBE_ROOT}/examples/" && ret=0 || ret=$? +if [[ $ret -eq 1 ]]; then + echo "${KUBE_ROOT}/examples/ requires manual changes. See preceding errors." + exit 1 +elif [[ $ret -gt 1 ]]; then + echo "Error running mungedocs." + exit 1 +fi + +"${mungedocs}" "--upstream=${KUBE_GIT_UPSTREAM}" \ + "--skip-munges=unversioned-warning,analytics" \ + "--norecurse" \ + "--root-dir=${KUBE_ROOT}/" && ret=0 || ret=$? +if [[ $ret -eq 1 ]]; then + echo "${KUBE_ROOT}/ requires manual changes. See preceding errors." + exit 1 +elif [[ $ret -gt 1 ]]; then + echo "Error running mungedocs." + exit 1 +fi # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/after-build/update-generated-protobuf.sh b/hack/update-generated-protobuf-dockerized.sh similarity index 97% rename from hack/after-build/update-generated-protobuf.sh rename to hack/update-generated-protobuf-dockerized.sh index c8d45e7d20ea4..3e281348f49f3 100755 --- a/hack/after-build/update-generated-protobuf.sh +++ b/hack/update-generated-protobuf-dockerized.sh @@ -18,7 +18,7 @@ set -o errexit set -o nounset set -o pipefail -KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../.. +KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env diff --git a/hack/update-generated-protobuf.sh b/hack/update-generated-protobuf.sh index 67809bc66dac5..c0c280606bd53 100755 --- a/hack/update-generated-protobuf.sh +++ b/hack/update-generated-protobuf.sh @@ -49,6 +49,6 @@ mkdir -p "${LOCAL_OUTPUT_BUILD_CONTEXT}" cp "${KUBE_ROOT}/cmd/libs/go2idl/go-to-protobuf/build-image/Dockerfile" "${LOCAL_OUTPUT_BUILD_CONTEXT}/Dockerfile" kube::build::update_dockerfile kube::build::docker_build "${KUBE_BUILD_IMAGE}" "${LOCAL_OUTPUT_BUILD_CONTEXT}" 'false' -kube::build::run_build_command hack/after-build/update-generated-protobuf.sh "$@" +kube::build::run_build_command hack/update-generated-protobuf-dockerized.sh "$@" # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/update-swagger-spec.sh b/hack/update-swagger-spec.sh index f01d197a1f794..c349c6d2f6f38 100755 --- a/hack/update-swagger-spec.sh +++ b/hack/update-swagger-spec.sh @@ -21,13 +21,89 @@ set -o errexit set -o nounset set -o pipefail +cat << __EOF__ +Note: This assumes that the 'types_swagger_doc_generated.go' file has been +updated for all API group versions. If you are unsure, please run +hack/update-generated-swagger-docs.sh first. +__EOF__ + KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +SWAGGER_ROOT_DIR="${KUBE_ROOT}/api/swagger-spec" source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env "${KUBE_ROOT}/hack/build-go.sh" cmd/kube-apiserver -"${KUBE_ROOT}/hack/after-build/update-swagger-spec.sh" "$@" +function cleanup() +{ + [[ -n ${APISERVER_PID-} ]] && kill ${APISERVER_PID} 1>&2 2>/dev/null + + kube::etcd::cleanup + + kube::log::status "Clean up complete" +} + +trap cleanup EXIT SIGINT + +kube::golang::setup_env + +apiserver=$(kube::util::find-binary "kube-apiserver") + +TMP_DIR=$(mktemp -d /tmp/update-swagger-spec.XXXX) +ETCD_HOST=${ETCD_HOST:-127.0.0.1} +ETCD_PORT=${ETCD_PORT:-4001} +API_PORT=${API_PORT:-8050} +API_HOST=${API_HOST:-127.0.0.1} +KUBELET_PORT=${KUBELET_PORT:-10250} + +kube::etcd::start + +# Start kube-apiserver +kube::log::status "Starting kube-apiserver" +"${KUBE_OUTPUT_HOSTBIN}/kube-apiserver" \ + --insecure-bind-address="127.0.0.1" \ + --bind-address="127.0.0.1" \ + --insecure-port="${API_PORT}" \ + --etcd-servers="http://${ETCD_HOST}:${ETCD_PORT}" \ + --advertise-address="10.10.10.10" \ + --cert-dir="${TMP_DIR}/certs" \ + --service-cluster-ip-range="10.0.0.0/24" >/tmp/swagger-api-server.log 2>&1 & +APISERVER_PID=$! + +kube::util::wait_for_url "http://127.0.0.1:${API_PORT}/healthz" "apiserver: " + +SWAGGER_API_PATH="http://127.0.0.1:${API_PORT}/swaggerapi/" +DEFAULT_GROUP_VERSIONS="v1 autoscaling/v1 batch/v1 extensions/v1beta1 apps/v1alpha1" +VERSIONS=${VERSIONS:-$DEFAULT_GROUP_VERSIONS} + +kube::log::status "Updating " ${SWAGGER_ROOT_DIR} + +for ver in ${VERSIONS}; do + # fetch the swagger spec for each group version. + if [[ ${ver} == "v1" ]]; then + SUBPATH="api" + else + SUBPATH="apis" + fi + SUBPATH="${SUBPATH}/${ver}" + SWAGGER_JSON_NAME="$(kube::util::gv-to-swagger-name ${ver}).json" + curl -w "\n" -fs "${SWAGGER_API_PATH}${SUBPATH}" > "${SWAGGER_ROOT_DIR}/${SWAGGER_JSON_NAME}" + + # fetch the swagger spec for the discovery mechanism at group level. + if [[ ${ver} == "v1" ]]; then + continue + fi + SUBPATH="apis/"${ver%/*} + SWAGGER_JSON_NAME="${ver%/*}.json" + curl -w "\n" -fs "${SWAGGER_API_PATH}${SUBPATH}" > "${SWAGGER_ROOT_DIR}/${SWAGGER_JSON_NAME}" +done + +# fetch swagger specs for other discovery mechanism. +curl -w "\n" -fs "${SWAGGER_API_PATH}" > "${SWAGGER_ROOT_DIR}/resourceListing.json" +curl -w "\n" -fs "${SWAGGER_API_PATH}version" > "${SWAGGER_ROOT_DIR}/version.json" +curl -w "\n" -fs "${SWAGGER_API_PATH}api" > "${SWAGGER_ROOT_DIR}/api.json" +curl -w "\n" -fs "${SWAGGER_API_PATH}apis" > "${SWAGGER_ROOT_DIR}/apis.json" +kube::log::status "SUCCESS" # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/verify-codegen.sh b/hack/verify-codegen.sh index 475909e243b50..cbd31ed3c5136 100755 --- a/hack/verify-codegen.sh +++ b/hack/verify-codegen.sh @@ -23,12 +23,4 @@ source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env -BUILD_TARGETS=( - cmd/libs/go2idl/client-gen - cmd/libs/go2idl/conversion-gen - cmd/libs/go2idl/deepcopy-gen - cmd/libs/go2idl/set-gen -) -"${KUBE_ROOT}/hack/build-go.sh" ${BUILD_TARGETS[*]} - -"${KUBE_ROOT}/hack/after-build/run-codegen.sh" --verify-only +"${KUBE_ROOT}/hack/update-codegen.sh" --verify-only diff --git a/hack/verify-description.sh b/hack/verify-description.sh index 86a7bc269d3fa..2854d70e56964 100755 --- a/hack/verify-description.sh +++ b/hack/verify-description.sh @@ -22,8 +22,67 @@ KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env + "${KUBE_ROOT}/hack/build-go.sh" cmd/genswaggertypedocs -"${KUBE_ROOT}/hack/after-build/verify-description.sh" "$@" +# Find binary +genswaggertypedocs=$(kube::util::find-binary "genswaggertypedocs") + +gen_swagger_result=0 +result=0 + +find_files() { + find . -not \( \ + \( \ + -wholename './output' \ + -o -wholename './_output' \ + -o -wholename './_gopath' \ + -o -wholename './release' \ + -o -wholename './target' \ + -o -wholename '*/third_party/*' \ + -o -wholename '*/vendor/*' \ + \) -prune \ + \) \ + \( -wholename '*pkg/api/v*/types.go' \ + -o -wholename '*pkg/apis/*/v*/types.go' \ + -o -wholename '*pkg/api/unversioned/types.go' \ + \) +} + +if [[ $# -eq 0 ]]; then + versioned_api_files=$(find_files | egrep "pkg/.[^/]*/((v.[^/]*)|unversioned)/types\.go") +else + versioned_api_files="${*}" +fi + +for file in $versioned_api_files; do + $genswaggertypedocs -v -s "${file}" -f - || gen_swagger_result=$? + if [[ "${gen_swagger_result}" -ne "0" ]]; then + echo "API file: ${file} is missing: ${gen_swagger_result} descriptions" + result=1 + fi + if grep json: "${file}" | grep -v // | grep description: ; then + echo "API file: ${file} should not contain descriptions in struct tags" + result=1 + fi + if grep json: "${file}" | grep -Ee ",[[:space:]]+omitempty|omitempty[[:space:]]+" ; then + echo "API file: ${file} should not contain leading or trailing spaces for omitempty directive" + result=1 + fi +done + +internal_types_files="${KUBE_ROOT}/pkg/api/types.go ${KUBE_ROOT}/pkg/apis/extensions/types.go" +for internal_types_file in $internal_types_files; do + if [[ ! -e $internal_types_file ]]; then + echo "Internal types file ${internal_types_file} does not exist" + result=1 + continue + fi + + if grep json: "${internal_types_file}" | grep -v // | grep description: ; then + echo "Internal API types should not contain descriptions" + result=1 + fi +done -# ex: ts=2 sw=2 et filetype=sh +exit ${result} diff --git a/hack/verify-generated-docs.sh b/hack/verify-generated-docs.sh index 7d2605dcf7ccb..a39d39a2af0d4 100755 --- a/hack/verify-generated-docs.sh +++ b/hack/verify-generated-docs.sh @@ -23,8 +23,68 @@ source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env -"${KUBE_ROOT}/hack/build-go.sh" cmd/gendocs cmd/genkubedocs cmd/genman cmd/genyaml cmd/genbashcomp cmd/mungedocs +"${KUBE_ROOT}/hack/build-go.sh" \ + cmd/gendocs \ + cmd/genkubedocs \ + cmd/genman \ + cmd/genyaml \ + cmd/genbashcomp \ + cmd/mungedocs -"${KUBE_ROOT}/hack/after-build/verify-generated-docs.sh" "$@" +# Find binary +gendocs=$(kube::util::find-binary "gendocs") +genkubedocs=$(kube::util::find-binary "genkubedocs") +genman=$(kube::util::find-binary "genman") +genyaml=$(kube::util::find-binary "genyaml") +genbashcomp=$(kube::util::find-binary "genbashcomp") +mungedocs=$(kube::util::find-binary "mungedocs") + +DOCROOT="${KUBE_ROOT}/docs/" +EXAMPLEROOT="${KUBE_ROOT}/examples/" + +# mungedocs --verify can (and should) be run on the real docs, otherwise their +# links will be distorted. --verify means that it will not make changes. +# --verbose gives us output we can use for a diff. +"${mungedocs}" "--verify=true" "--verbose=true" "--upstream=${KUBE_GIT_UPSTREAM}" "--root-dir=${DOCROOT}" && ret=0 || ret=$? +if [[ $ret -eq 1 ]]; then + echo "${DOCROOT} is out of date. Please run hack/update-generated-docs.sh" + exit 1 +fi +if [[ $ret -gt 1 ]]; then + echo "Error running mungedocs" + exit 1 +fi + +"${mungedocs}" "--verify=true" "--verbose=true" "--upstream=${KUBE_GIT_UPSTREAM}" "--root-dir=${EXAMPLEROOT}" && ret=0 || ret=$? +if [[ $ret -eq 1 ]]; then + echo "${EXAMPLEROOT} is out of date. Please run hack/update-generated-docs.sh" + exit 1 +fi +if [[ $ret -gt 1 ]]; then + echo "Error running mungedocs" + exit 1 +fi + +kube::util::ensure-temp-dir + +kube::util::gen-docs "${KUBE_TEMP}" +diff -Naup "${KUBE_TEMP}/.generated_docs" "${KUBE_ROOT}/.generated_docs" || ret=1 || true +while read file; do + diff -Naup "${KUBE_TEMP}/${file}" "${KUBE_ROOT}/${file}" || ret=1 || true +done <"${KUBE_TEMP}/.generated_docs" + +needsanalytics=($(kube::util::gen-analytics "${KUBE_ROOT}" 1)) +if [[ ${#needsanalytics[@]} -ne 0 ]]; then + echo -e "Some md files are missing ga-beacon analytics link:" + printf '%s\n' "${needsanalytics[@]}" + ret=1 +fi +if [[ $ret -eq 0 ]] +then + echo "Generated docs are up to date." +else + echo "Generated docs are out of date. Please run hack/update-generated-docs.sh" + exit 1 +fi # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/verify-generated-protobuf.sh b/hack/verify-generated-protobuf.sh index c43bd1b9bcfae..694face6a833c 100755 --- a/hack/verify-generated-protobuf.sh +++ b/hack/verify-generated-protobuf.sh @@ -23,6 +23,39 @@ source "${KUBE_ROOT}/hack/lib/init.sh" kube::golang::setup_env -"${KUBE_ROOT}/hack/after-build/verify-generated-protobuf.sh" "$@" +APIROOTS=${APIROOTS:-pkg/api pkg/apis pkg/runtime pkg/util/intstr pkg/watch} +_tmp="${KUBE_ROOT}/_tmp" -# ex: ts=2 sw=2 et filetype=sh +cleanup() { + rm -rf "${_tmp}" +} + +trap "cleanup" EXIT SIGINT + +cleanup +for APIROOT in ${APIROOTS}; do + mkdir -p "${_tmp}/${APIROOT%/*}" + cp -a "${KUBE_ROOT}/${APIROOT}" "${_tmp}/${APIROOT}" +done + +# If not running as root, we need to use sudo to restore the original generated +# protobuf files. +SUDO="" +if [[ "$(id -u)" != '0' ]]; then + SUDO="sudo" +fi + +"${KUBE_ROOT}/hack/update-generated-protobuf.sh" +for APIROOT in ${APIROOTS}; do + TMP_APIROOT="${_tmp}/${APIROOT}" + echo "diffing ${APIROOT} against freshly generated protobuf" + ret=0 + diff -Naupr -I 'Auto generated by' "${KUBE_ROOT}/${APIROOT}" "${TMP_APIROOT}" || ret=$? + ${SUDO} cp -a "${TMP_APIROOT}" "${KUBE_ROOT}/${APIROOT%/*}" + if [[ $ret -eq 0 ]]; then + echo "${APIROOT} up to date." + else + echo "${APIROOT} is out of date. Please run hack/update-generated-protobuf.sh" + exit 1 + fi +done diff --git a/hack/verify-generated-swagger-docs.sh b/hack/verify-generated-swagger-docs.sh index 2bd11f784a9af..f7ff66ed7ba47 100755 --- a/hack/verify-generated-swagger-docs.sh +++ b/hack/verify-generated-swagger-docs.sh @@ -25,4 +25,36 @@ kube::golang::setup_env "${KUBE_ROOT}/hack/build-go.sh" cmd/genswaggertypedocs -"${KUBE_ROOT}/hack/after-build/verify-generated-swagger-docs.sh" "$@" +# Find binary +genswaggertypedocs=$(kube::util::find-binary "genswaggertypedocs") + +if [[ ! -x "$genswaggertypedocs" ]]; then + { + echo "It looks as if you don't have a compiled genswaggertypedocs binary" + echo + echo "If you are running from a clone of the git repo, please run" + echo "'./hack/build-go.sh cmd/genswaggertypedocs'." + } >&2 + exit 1 +fi + +DIFFROOT="${KUBE_ROOT}/pkg" +TMP_DIFFROOT="${KUBE_ROOT}/_tmp/pkg" +_tmp="${KUBE_ROOT}/_tmp" + +mkdir -p "${_tmp}" +cp -a "${DIFFROOT}" "${TMP_DIFFROOT}" + +"${KUBE_ROOT}/hack/update-generated-swagger-docs.sh" +echo "diffing ${DIFFROOT} against freshly generated swagger type documentation" +ret=0 +diff -Naupr -I 'Auto generated by' "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? +cp -a "${TMP_DIFFROOT}" "${KUBE_ROOT}/" +rm -rf "${_tmp}" +if [[ $ret -eq 0 ]] +then + echo "${DIFFROOT} up to date." +else + echo "${DIFFROOT} is out of date. Please run hack/update-generated-swagger-docs.sh" + exit 1 +fi diff --git a/hack/verify-import-boss.sh b/hack/verify-import-boss.sh index c4aace20af106..89e96c1781fcb 100755 --- a/hack/verify-import-boss.sh +++ b/hack/verify-import-boss.sh @@ -25,4 +25,4 @@ kube::golang::setup_env "${KUBE_ROOT}/hack/build-go.sh" cmd/libs/go2idl/import-boss -"${KUBE_ROOT}/hack/after-build/run-import-boss.sh" --verify-only +$(kube::util::find-binary "import-boss") --verify-only diff --git a/hack/verify-linkcheck.sh b/hack/verify-linkcheck.sh index c111f9e35d235..7aba555cac933 100755 --- a/hack/verify-linkcheck.sh +++ b/hack/verify-linkcheck.sh @@ -25,6 +25,37 @@ kube::golang::setup_env "${KUBE_ROOT}/hack/build-go.sh" cmd/linkcheck -"${KUBE_ROOT}/hack/after-build/verify-linkcheck.sh" "$@" +linkcheck=$(kube::util::find-binary "linkcheck") + +kube::util::ensure-temp-dir +OUTPUT="${KUBE_TEMP}"/linkcheck-output +cleanup() { + rm -rf "${OUTPUT}" +} +trap "cleanup" EXIT SIGINT +mkdir -p "$OUTPUT" + +APIROOT="${KUBE_ROOT}/pkg/api/" +APISROOT="${KUBE_ROOT}/pkg/apis/" +DOCROOT="${KUBE_ROOT}/docs/" +ROOTS=($APIROOT $APISROOT $DOCROOT) +found_invalid=false +for root in "${ROOTS[@]}"; do + "${linkcheck}" "--root-dir=${root}" 2> >(tee -a "${OUTPUT}/error" >&2) && ret=0 || ret=$? + if [[ $ret -eq 1 ]]; then + echo "Failed: found invalid links in ${root}." + found_invalid=true + fi + if [[ $ret -gt 1 ]]; then + echo "Error running linkcheck" + exit 1 + fi +done + +if [ ${found_invalid} = true ]; then + echo "Summary of invalid links:" + cat ${OUTPUT}/error + exit 1 +fi # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/verify-swagger-spec.sh b/hack/verify-swagger-spec.sh index 0fcd252030c9d..e73cb07a8b916 100755 --- a/hack/verify-swagger-spec.sh +++ b/hack/verify-swagger-spec.sh @@ -25,6 +25,27 @@ kube::golang::setup_env "${KUBE_ROOT}/hack/build-go.sh" cmd/kube-apiserver -"${KUBE_ROOT}/hack/after-build/verify-swagger-spec.sh" "$@" +apiserver=$(kube::util::find-binary "kube-apiserver") + +SPECROOT="${KUBE_ROOT}/api/swagger-spec" +TMP_SPECROOT="${KUBE_ROOT}/_tmp/swagger-spec" +_tmp="${KUBE_ROOT}/_tmp" + +mkdir -p "${_tmp}" +cp -a "${SPECROOT}" "${TMP_SPECROOT}" + +"${KUBE_ROOT}/hack/update-swagger-spec.sh" +echo "diffing ${SPECROOT} against freshly generated swagger spec" +ret=0 +diff -Naupr -I 'Auto generated by' "${SPECROOT}" "${TMP_SPECROOT}" || ret=$? +cp -a ${TMP_SPECROOT} "${KUBE_ROOT}/api" +rm -rf "${_tmp}" +if [[ $ret -eq 0 ]] +then + echo "${SPECROOT} up to date." +else + echo "${SPECROOT} is out of date. Please run hack/update-swagger-spec.sh" + exit 1 +fi # ex: ts=2 sw=2 et filetype=sh diff --git a/hack/verify-symbols.sh b/hack/verify-symbols.sh index c2c9afa336f3a..220588a7d8615 100755 --- a/hack/verify-symbols.sh +++ b/hack/verify-symbols.sh @@ -25,6 +25,25 @@ kube::golang::setup_env "${KUBE_ROOT}/hack/build-go.sh" cmd/hyperkube -"${KUBE_ROOT}/hack/after-build/verify-symbols.sh" +# add other BADSYMBOLS here. +BADSYMBOLS=( + "httptest" + "testify" + "testing[.]" +) + +# b/c hyperkube binds everything simply check that for bad symbols +SYMBOLS="$(nm ${KUBE_OUTPUT_HOSTBIN}/hyperkube)" + +RESULT=0 +for BADSYMBOL in "${BADSYMBOLS[@]}"; do + if FOUND=$(echo "$SYMBOLS" | grep "$BADSYMBOL"); then + echo "Found bad symbol '${BADSYMBOL}':" + echo "$FOUND" + RESULT=1 + fi +done + +exit $RESULT # ex: ts=2 sw=2 et filetype=sh diff --git a/hooks/pre-commit b/hooks/pre-commit index e3ca4a24e0615..0553a034574ee 100755 --- a/hooks/pre-commit +++ b/hooks/pre-commit @@ -103,7 +103,7 @@ files_need_description=() # Check API schema definitions for field descriptions for file in $(git diff --cached --name-only --diff-filter ACM | egrep "pkg/api/v.[^/]*/types\.go" | grep -v "third_party"); do # Check for files with fields without description tags - descriptionless=$(hack/after-build/verify-description.sh "${file}" > /dev/null; echo $?) + descriptionless=$(hack/verify-description.sh "${file}" > /dev/null; echo $?) if [[ "$descriptionless" -ne "0" ]]; then files_need_description+=("${file}") fi @@ -123,7 +123,7 @@ fi echo "${reset}" echo -ne "Checking for docs that need updating... " -if ! hack/after-build/verify-generated-docs.sh > /dev/null; then +if ! hack/verify-generated-docs.sh > /dev/null; then echo "${red}ERROR!" echo "Some docs are out of sync between CLI and markdown." echo "To regenerate docs, run:" @@ -135,7 +135,7 @@ fi echo "${reset}" echo -ne "Checking for swagger type documentation that need updating... " -if ! hack/after-build/verify-generated-swagger-docs.sh > /dev/null; then +if ! hack/verify-generated-swagger-docs.sh > /dev/null; then echo "${red}ERROR!" echo "Swagger type documentation needs to be updated." echo "To regenerate the spec, run:" @@ -147,7 +147,7 @@ fi echo "${reset}" echo -ne "Checking for swagger spec that need updating... " -if ! hack/after-build/verify-swagger-spec.sh > /dev/null; then +if ! hack/verify-swagger-spec.sh > /dev/null; then echo "${red}ERROR!" echo "Swagger spec needs to be updated." echo "To regenerate the spec, run:"