From b5e294414ac1378632bd7aab3137b08a436aec74 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Thu, 19 Sep 2024 13:55:29 +0200 Subject: [PATCH 1/3] codegen: ignore .gitignore when diffing examples The examples directory has a .gitignore file to ignore go.work.sum; this isn't reproduced by codegen and fails the diff. Signed-off-by: Stephen Kitt --- .../src/k8s.io/code-generator/examples/hack/verify-codegen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/staging/src/k8s.io/code-generator/examples/hack/verify-codegen.sh b/staging/src/k8s.io/code-generator/examples/hack/verify-codegen.sh index 789f2847244..7dd5e657671 100755 --- a/staging/src/k8s.io/code-generator/examples/hack/verify-codegen.sh +++ b/staging/src/k8s.io/code-generator/examples/hack/verify-codegen.sh @@ -35,7 +35,7 @@ cp -a "${DIFFROOT}"/* "${TMP_DIFFROOT}" "${SCRIPT_ROOT}/hack/update-codegen.sh" echo "diffing ${DIFFROOT} against freshly generated codegen" ret=0 -diff -Naupr "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? +diff -Naupr -x.gitignore "${DIFFROOT}" "${TMP_DIFFROOT}" || ret=$? if [[ $ret -eq 0 ]]; then echo "${DIFFROOT} up to date." else From 71c77414d402c188bcc27abc7c2a1d969130462f Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Thu, 19 Sep 2024 15:23:43 +0200 Subject: [PATCH 2/3] Fix the path to code-generator in example update-codegen.sh It seems this was copied from the main apiextensions-apiserver hack directory without adjusting. Signed-off-by: Stephen Kitt --- .../examples/client-go/hack/update-codegen.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh b/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh index 0160b3eb2e8..e9abdfeec7a 100755 --- a/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh +++ b/staging/src/k8s.io/apiextensions-apiserver/examples/client-go/hack/update-codegen.sh @@ -19,7 +19,7 @@ set -o nounset set -o pipefail SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. -CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)} +CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../../../code-generator)} source "${CODEGEN_PKG}/kube_codegen.sh" From beb51e17593d7c678df2b7c269de059f95b44771 Mon Sep 17 00:00:00 2001 From: Stephen Kitt Date: Thu, 19 Sep 2024 15:40:39 +0200 Subject: [PATCH 3/3] make verify: run checks in all module hack directories This ensures that all verification scripts are run throughout the repository. Signed-off-by: Stephen Kitt --- hack/lib/util.sh | 12 ++++++++++++ hack/make-rules/verify.sh | 27 ++++++++++++++++++++++----- 2 files changed, 34 insertions(+), 5 deletions(-) diff --git a/hack/lib/util.sh b/hack/lib/util.sh index e9197eff9bb..6000505318c 100755 --- a/hack/lib/util.sh +++ b/hack/lib/util.sh @@ -828,6 +828,18 @@ function kube::util::read-array { fi } +# kube::util::run-in +# Changes directory to "$1", runs the rest of the arguments, and restores the initial directory +# Returns 1 if a directory change fails, the result of running the arguments otherwise +function kube::util::run-in { + pushd "$1" > /dev/null || return 1 + shift + "$@" + local result=$? + popd > /dev/null || return 1 + return $result +} + # Some useful colors. if [[ -z "${color_start-}" ]]; then declare -r color_start="\033[" diff --git a/hack/make-rules/verify.sh b/hack/make-rules/verify.sh index c6e2894e74b..b7535fdbbd0 100755 --- a/hack/make-rules/verify.sh +++ b/hack/make-rules/verify.sh @@ -14,12 +14,17 @@ # See the License for the specific language governing permissions and # limitations under the License. +# Indirect calls through kube::util::run-in aren't interpreted +# shellcheck disable=SC2317 + set -o errexit set -o nounset set -o pipefail KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../.. -source "${KUBE_ROOT}/hack/lib/util.sh" +source "${KUBE_ROOT}/hack/lib/init.sh" + +kube::golang::setup_env # If KUBE_JUNIT_REPORT_DIR is unset, and ARTIFACTS is set, then have them match. if [[ -z "${KUBE_JUNIT_REPORT_DIR:-}" && -n "${ARTIFACTS:-}" ]]; then @@ -142,7 +147,7 @@ function run-cmd { juLog -output="${output}" -class="verify" -name="${testname}" -fail="^ERROR: " "$@" tr=$? fi - return ${tr} + return "${tr}" } # Collect Failed tests in this Array , initialize it to nil @@ -164,6 +169,10 @@ function run-checks { local t for t in ${pattern} do + if [ "$t" = "$pattern" ]; then + # The pattern didn't match any files + continue + fi local check_name check_name="$(basename "${t}")" if [[ -n ${WHAT:-} ]]; then @@ -190,7 +199,7 @@ function run-checks { else echo -e "${color_red}FAILED${color_norm} ${check_name}\t${elapsed}s" ret=1 - FAILED_TESTS+=("${t}") + FAILED_TESTS+=("${base}/${t}") fi done } @@ -220,9 +229,17 @@ if ${QUICK} ; then echo "Running in quick mode (QUICK=true). Only fast checks will run." fi +export API_KNOWN_VIOLATIONS_DIR="${KUBE_ROOT}"/api/api-rules ret=0 -run-checks "${KUBE_ROOT}/hack/verify-*.sh" bash -run-checks "${KUBE_ROOT}/hack/verify-*.py" python3 +modules=() # Pacify shellcheck +kube::util::read-array modules < <(go list -f '{{.Dir}}' -m) +for module in "${modules[@]}"; do + base=${module%/go.mod} + if [ -d "$base/hack" ]; then + kube::util::run-in "$base" run-checks "hack/verify-*.sh" bash + kube::util::run-in "$base" run-checks "hack/verify-*.py" python3 + fi +done missing-target-checks if [[ ${ret} -eq 1 ]]; then