diff --git a/hack/.shellcheck_failures b/hack/.shellcheck_failures index 0737ecb446..847663c561 100644 --- a/hack/.shellcheck_failures +++ b/hack/.shellcheck_failures @@ -5,17 +5,12 @@ ./hack/dev-build.sh ./hack/make-apimachinery.sh ./hack/new-iam-user.sh -./hack/publish-docs.sh ./hack/update-bazel.sh -./hack/update-expected.sh ./hack/update-header.sh -./hack/verify-apimachinery.sh ./hack/verify-bazel.sh ./hack/verify-boilerplate.sh ./hack/verify-gofmt.sh -./hack/verify-packages.sh ./hack/verify-spelling.sh -./hack/verify-staticcheck.sh ./hooks/nvidia-bootstrap/image/run.sh ./hooks/nvidia-device-plugin/image/files/01-aws-nvidia-driver.sh ./hooks/nvidia-device-plugin/image/files/02-nvidia-docker.sh diff --git a/hack/boilerplate/boilerplate.py b/hack/boilerplate/boilerplate.py index 8adc5adfa4..93b432b29a 100755 --- a/hack/boilerplate/boilerplate.py +++ b/hack/boilerplate/boilerplate.py @@ -129,7 +129,7 @@ def file_passes(filename, refs, regexs): def file_extension(filename): return os.path.splitext(filename)[1].split(".")[-1].lower() -skipped_dirs = ['Godeps', 'third_party', '_gopath', '_output', '.git', 'cluster/env.sh', +skipped_dirs = ['third_party', '_gopath', '_output', '.git', 'cluster/env.sh', "vendor", "test/e2e/generated/bindata.go", "hack/boilerplate/test", "pkg/generated/bindata.go"] diff --git a/hack/common.sh b/hack/common.sh index 78a634e648..b134bac132 100755 --- a/hack/common.sh +++ b/hack/common.sh @@ -19,4 +19,50 @@ set -o errexit set -o nounset set -o pipefail -KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. +KOPS_ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )"/.. >/dev/null 2>&1 && pwd )" + +kube::util::array_contains() { + local search="$1" + local element + shift + for element; do + if [[ "${element}" == "${search}" ]]; then + return 0 + fi + done + return 1 +} + +kube::util::read-array() { + local i=0 + unset -v "$1" + while IFS= read -r "$1[i++]"; do :; done + eval "[[ \${$1[--i]} ]]" || unset "$1[i]" # ensures last element isn't empty +} + +kube::util::trap_add() { + local trap_add_cmd + trap_add_cmd=$1 + shift + + for trap_add_name in "$@"; do + local existing_cmd + local new_cmd + + # Grab the currently defined trap commands for this trap + existing_cmd=$(trap -p "${trap_add_name}" | awk -F"'" '{print $2}') + + if [[ -z "${existing_cmd}" ]]; then + new_cmd="${trap_add_cmd}" + else + new_cmd="${trap_add_cmd};${existing_cmd}" + fi + + # Assign the test. Disable the shellcheck warning telling that trap + # commands should be single quoted to avoid evaluating them at this + # point instead evaluating them at run time. The logic of adding new + # commands to a single trap requires them to be evaluated right away. + # shellcheck disable=SC2064 + trap "${new_cmd}" "${trap_add_name}" + done +} diff --git a/hack/dep.py b/hack/dep.py deleted file mode 100755 index c006cbb643..0000000000 --- a/hack/dep.py +++ /dev/null @@ -1,72 +0,0 @@ -#!/usr/bin/env python - -# Copyright 2017 The Kubernetes Authors. -# -# 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. - -# This python script helps sync godeps from the k8s repos into our git submodules -# It generates bash commands where changes are needed -# We can probably also use it for deps when the time comes! - -import json -import os -import subprocess -from os.path import join - -if not os.environ['GOPATH']: - raise Exception("Must set GOPATH") - -kops_dir = join(os.environ['GOPATH'], 'src', 'k8s.io', 'kops') -k8s_dir = join(os.environ['GOPATH'], 'src', 'k8s.io', 'kubernetes') - -with open(join(k8s_dir, 'Godeps', 'Godeps.json')) as data_file: - godeps = json.load(data_file) - -# For debugging, because dep status is unbearably slow -# dep status -json | jq .> dep-status.json -# with open(join(kops_dir, 'dep-status.json')) as data_file: -# dep_status = json.load(data_file) - -process = subprocess.Popen(['dep', 'status', '-json'], stdout=subprocess.PIPE, cwd=kops_dir) -dep_status_stdout, err = process.communicate() -dep_status = json.loads(dep_status_stdout) - -#pprint(godeps) - -godep_map = {} -for godep in godeps['Deps']: - #print("%s %s" % (godep['ImportPath'], godep['Rev'])) - godep_map[godep['ImportPath']] = godep['Rev'] - -dep_status_map = {} -for dep in dep_status: - #print("%s %s" % (godep['ImportPath'], godep['Rev'])) - dep_status_map[dep['ProjectRoot']] = dep['Revision'] - - -for dep in dep_status_map: - sha = dep_status_map.get(dep) - godep_sha = godep_map.get(dep) - if not godep_sha: - for k in godep_map: - if k.startswith(dep): - godep_sha = godep_map[k] - break - if godep_sha: - if godep_sha != sha: - print("# update needed: %s %s vs %s" % (dep, godep_sha, sha)) - print("[[override]]") - print(' name = "%s"' % (dep)) - print(' revision = "%s"' % (godep_sha)) - else: - print("# UNKNOWN dep %s" % dep) diff --git a/hack/dev-build.sh b/hack/dev-build.sh index 8b7d472960..5e2b7f0b28 100755 --- a/hack/dev-build.sh +++ b/hack/dev-build.sh @@ -52,7 +52,7 @@ # ############################################################################### -KOPS_DIRECTORY="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" # # Check that required binaries are installed @@ -85,7 +85,7 @@ NETWORKING=${NETWORKING:-weave} # How verbose go logging is VERBOSITY=${VERBOSITY:-10} -cd $KOPS_DIRECTORY/.. +cd "${KOPS_ROOT}" GIT_VER=git-$(git describe --always) [ -z "$GIT_VER" ] && echo "we do not have GIT_VER something is very wrong" && exit 1; diff --git a/hack/publish-docs.sh b/hack/publish-docs.sh deleted file mode 100644 index f709813fd8..0000000000 --- a/hack/publish-docs.sh +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env bash - -# Copyright 2019 The Kubernetes Authors. -# -# 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. - -if ! [ -z $DEBUG ]; then - set -x -fi - -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" - -if [ "$COMPONENT" != "docs" ]; then - echo "This task runs only to publish docs" - exit 0 -fi - -make -C ${DIR}/.. build-docs - -git config --global user.email "travis@travis-ci.com" -git config --global user.name "Travis Bot" - -git clone --branch=gh-pages --depth=1 https://${GH_REF} ${DIR}/gh-pages -cd ${DIR}/gh-pages - -git rm -r . - -cp -r ${DIR}/../site/* . - -git add . -git commit -m "Deploy GitHub Pages" -git push --force --quiet "https://${GH_TOKEN}@${GH_REF}" gh-pages > /dev/null 2>&1 diff --git a/hack/update-bazel.sh b/hack/update-bazel.sh index 3f0fbeba9e..eb5ba28c53 100755 --- a/hack/update-bazel.sh +++ b/hack/update-bazel.sh @@ -18,21 +18,15 @@ set -o errexit set -o nounset set -o pipefail -KOPS_ROOT=$(git rev-parse --show-toplevel) -cd ${KOPS_ROOT} +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" -export GOPATH=${KOPS_ROOT}/../../../ +cd "${KOPS_ROOT}" TMP_OUT=$(mktemp -d) trap "{ rm -rf ${TMP_OUT}; }" EXIT GOBIN="${TMP_OUT}" go install ./vendor/github.com/bazelbuild/bazel-gazelle/cmd/gazelle -# manually remove BUILD file for k8s.io/apimachinery/pkg/util/sets/BUILD if it -# exists; there is a specific set-gen rule that breaks importing -# ref: https://github.com/kubernetes/kubernetes/blob/4e2f5e2212b05a305435ef96f4b49dc0932e1264/staging/src/k8s.io/apimachinery/pkg/util/sets/BUILD#L23-L49 -# rm -f ${KOPS_ROOT}/vendor/k8s.io/apimachinery/pkg/util/sets/{BUILD,BUILD.bazel} - "${TMP_OUT}/gazelle" fix \ -external=vendored \ -mode=fix \ diff --git a/hack/update-expected.sh b/hack/update-expected.sh index f3a108bdfa..5b3e29f03e 100755 --- a/hack/update-expected.sh +++ b/hack/update-expected.sh @@ -18,8 +18,9 @@ set -o errexit set -o nounset set -o pipefail -KOPS_ROOT=$(git rev-parse --show-toplevel) -cd ${KOPS_ROOT} +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +cd "${KOPS_ROOT}" # Update gobindata to reflect any yaml changes make kops-gobindata diff --git a/hack/update-header.sh b/hack/update-header.sh index 276240a655..a82bff9925 100755 --- a/hack/update-header.sh +++ b/hack/update-header.sh @@ -14,9 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -. $(dirname "${BASH_SOURCE}")/common.sh +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" -BAD_HEADERS=$((${KUBE_ROOT}/hack/verify-boilerplate.sh || true) | awk '{ print $7}') +BAD_HEADERS=$((${KOPS_ROOT}/hack/verify-boilerplate.sh || true) | awk '{ print $7}') FORMATS="sh go Makefile Dockerfile" YEAR=`date +%Y` @@ -27,7 +27,7 @@ do for j in ${BAD_HEADERS} do : - HEADER=$(cat ${KUBE_ROOT}/hack/boilerplate/boilerplate.${i}.txt | sed "s/YEAR/${YEAR}/") + HEADER=$(cat ${KOPS_ROOT}/hack/boilerplate/boilerplate.${i}.txt | sed "s/YEAR/${YEAR}/") value=$(<${j}) if [[ "$j" != *$i ]] then diff --git a/hack/verify-apimachinery.sh b/hack/verify-apimachinery.sh index bbe75133b1..98409ee3e9 100755 --- a/hack/verify-apimachinery.sh +++ b/hack/verify-apimachinery.sh @@ -18,7 +18,9 @@ set -o errexit set -o nounset set -o pipefail -KOPS_ROOT=$(git rev-parse --show-toplevel) +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +cd "${KOPS_ROOT}" export API_OPTIONS="--verify-only" if make apimachinery-codegen; then diff --git a/hack/verify-bazel.sh b/hack/verify-bazel.sh index 3a0accfb3f..5ec1bfbd61 100755 --- a/hack/verify-bazel.sh +++ b/hack/verify-bazel.sh @@ -13,10 +13,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -KOPS_ROOT=$(git rev-parse --show-toplevel) -cd ${KOPS_ROOT} +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" -export GOPATH=${KOPS_ROOT}/../../../ +cd "${KOPS_ROOT}" TMP_OUT=$(mktemp -d) trap "{ rm -rf ${TMP_OUT}; }" EXIT diff --git a/hack/verify-boilerplate.sh b/hack/verify-boilerplate.sh index 236168584c..ff80aad7e4 100755 --- a/hack/verify-boilerplate.sh +++ b/hack/verify-boilerplate.sh @@ -14,9 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -. $(dirname "${BASH_SOURCE}")/common.sh +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" -boiler="${KUBE_ROOT}/hack/boilerplate/boilerplate.py $@" +boiler="${KOPS_ROOT}/hack/boilerplate/boilerplate.py $@" files_need_boilerplate=( `${boiler}` ) @@ -24,7 +24,7 @@ if [[ -z ${files_need_boilerplate+x} ]]; then exit fi -TO_REMOVE=(${PWD}/federation/model/bindata.go ${PWD}/upup/models/bindata.go) +TO_REMOVE=(${KOPS_ROOT}/federation/model/bindata.go ${KOPS_ROOT}/upup/models/bindata.go) TEMP_ARRAY=() for pkg in "${files_need_boilerplate[@]}"; do diff --git a/hack/verify-generate.sh b/hack/verify-generate.sh index 86c08ba715..8f59c8a72b 100755 --- a/hack/verify-generate.sh +++ b/hack/verify-generate.sh @@ -18,7 +18,8 @@ set -o errexit set -o nounset set -o pipefail -KOPS_ROOT=$(git rev-parse --show-toplevel) +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" + cd "${KOPS_ROOT}" make crds diff --git a/hack/verify-gofmt.sh b/hack/verify-gofmt.sh index fc25f08170..8553e2de13 100755 --- a/hack/verify-gofmt.sh +++ b/hack/verify-gofmt.sh @@ -14,7 +14,9 @@ # See the License for the specific language governing permissions and # limitations under the License. -. $(dirname "${BASH_SOURCE}")/common.sh +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +cd "${KOPS_ROOT}" GOFMT="bazel run //:gofmt -- -s -w" diff --git a/hack/verify-gomod b/hack/verify-gomod index ca2e1cea0a..86a4142921 100755 --- a/hack/verify-gomod +++ b/hack/verify-gomod @@ -18,8 +18,9 @@ set -o errexit set -o nounset set -o pipefail -export REPO_ROOT="${REPO_ROOT:-$(git rev-parse --show-toplevel)}" -cd "${REPO_ROOT}" +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" + +cd "${KOPS_ROOT}" changes=$(git status --porcelain || true) if [ -n "${changes}" ]; then diff --git a/hack/verify-packages.sh b/hack/verify-packages.sh index 62ea79eba2..28611c274c 100755 --- a/hack/verify-packages.sh +++ b/hack/verify-packages.sh @@ -14,10 +14,10 @@ # See the License for the specific language governing permissions and # limitations under the License. -. $(dirname "${BASH_SOURCE}")/common.sh +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" # Check that the .packages file contains all packages -packages_file="${KUBE_ROOT}/hack/.packages" +packages_file="${KOPS_ROOT}/hack/.packages" if ! diff -u "${packages_file}" <(go list k8s.io/kops/... | grep -v vendor); then { echo diff --git a/hack/verify-shellcheck.sh b/hack/verify-shellcheck.sh index 99df63ab60..4ba8e003b5 100755 --- a/hack/verify-shellcheck.sh +++ b/hack/verify-shellcheck.sh @@ -18,45 +18,7 @@ set -o errexit set -o nounset set -o pipefail -KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. - -kube::util::array_contains() { - local search="$1" - local element - shift - for element; do - if [[ "${element}" == "${search}" ]]; then - return 0 - fi - done - return 1 -} -kube::util::trap_add() { - local trap_add_cmd - trap_add_cmd=$1 - shift - - for trap_add_name in "$@"; do - local existing_cmd - local new_cmd - - # Grab the currently defined trap commands for this trap - existing_cmd=$(trap -p "${trap_add_name}" | awk -F"'" '{print $2}') - - if [[ -z "${existing_cmd}" ]]; then - new_cmd="${trap_add_cmd}" - else - new_cmd="${trap_add_cmd};${existing_cmd}" - fi - - # Assign the test. Disable the shellcheck warning telling that trap - # commands should be single quoted to avoid evaluating them at this - # point instead evaluating them at run time. The logic of adding new - # commands to a single trap requires them to be evaluated right away. - # shellcheck disable=SC2064 - trap "${new_cmd}" "${trap_add_name}" - done -} +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" # required version for this script, if not installed on the host we will # use the official docker image instead. keep this in sync with SHELLCHECK_IMAGE @@ -92,7 +54,7 @@ create_container () { # we're done. # This is incredibly much faster than creating a container for each shellcheck # call ... - docker run --name "${SHELLCHECK_CONTAINER}" -d --rm -v "${KUBE_ROOT}:${KUBE_ROOT}" -w "${KUBE_ROOT}" --entrypoint="sleep" "${SHELLCHECK_IMAGE}" 2147483647 + docker run --name "${SHELLCHECK_CONTAINER}" -d --rm -v "${KOPS_ROOT}:/go/src/k8s.io/kops" -w "/go/src/k8s.io/kops" --entrypoint="sleep" "${SHELLCHECK_IMAGE}" 2147483647 } # removes the shellcheck container remove_container () { @@ -100,7 +62,7 @@ remove_container () { } # ensure we're linting the k8s source tree -cd "${KUBE_ROOT}" +cd "${KOPS_ROOT}" # Find all shell scripts excluding: # - Anything git-ignored - No need to lint untracked files. @@ -121,7 +83,7 @@ done < <(find . -name "*.sh" \ \)) # make sure known failures are sorted -failure_file="${KUBE_ROOT}/hack/.shellcheck_failures" +failure_file="${KOPS_ROOT}/hack/.shellcheck_failures" if ! diff -u "${failure_file}" <(LC_ALL=C sort "${failure_file}"); then { echo diff --git a/hack/verify-spelling.sh b/hack/verify-spelling.sh index 353b72da2d..686a2df613 100755 --- a/hack/verify-spelling.sh +++ b/hack/verify-spelling.sh @@ -18,10 +18,11 @@ set -o errexit set -o nounset set -o pipefail -REPO_ROOT=$(git rev-parse --show-toplevel) -cd "${REPO_ROOT}" +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" -OUTPUT_GOBIN="${REPO_ROOT}/_output/bin" +cd "${KOPS_ROOT}" + +OUTPUT_GOBIN="${KOPS_ROOT}/_output/bin" # Install tools we need, but from vendor/ GOBIN="${OUTPUT_GOBIN}" go install ./vendor/github.com/client9/misspell/cmd/misspell diff --git a/hack/verify-staticcheck.sh b/hack/verify-staticcheck.sh index 101bebb6f1..35e309cd20 100755 --- a/hack/verify-staticcheck.sh +++ b/hack/verify-staticcheck.sh @@ -18,26 +18,7 @@ set -o errexit set -o nounset set -o pipefail -KUBE_ROOT=$(git rev-parse --show-toplevel) - -kube::util::array_contains() { - local search="$1" - local element - shift - for element; do - if [[ "${element}" == "${search}" ]]; then - return 0 - fi - done - return 1 -} - -function kube::util::read-array { - local i=0 - unset -v "$1" - while IFS= read -r "$1[i++]"; do :; done - eval "[[ \${$1[--i]} ]]" || unset "$1[i]" # ensures last element isn't empty -} +. "$(dirname "${BASH_SOURCE[0]}")/common.sh" FOCUS="${1:-}" @@ -65,7 +46,7 @@ IGNORE=( export IFS='|'; ignore_pattern="^(${IGNORE[*]})\$"; unset IFS # Ensure that we find the binaries we build before anything else. -export GOBIN="${KUBE_ROOT}/_output/bin" +export GOBIN="${KOPS_ROOT}/_output/bin" PATH="${GOBIN}:${PATH}" # Install staticcheck from vendor @@ -73,10 +54,10 @@ echo 'installing staticcheck from vendor' go install k8s.io/kops/vendor/honnef.co/go/tools/cmd/staticcheck -cd "${KUBE_ROOT}" +cd "${KOPS_ROOT}" # Check that the file is in alphabetical order -failure_file="${KUBE_ROOT}/hack/.staticcheck_failures" +failure_file="${KOPS_ROOT}/hack/.staticcheck_failures" if ! diff -u "${failure_file}" <(LC_ALL=C sort "${failure_file}"); then { echo