Skip to content

Commit a8c955a

Browse files
authored
Merge pull request kubernetes#127606 from thockin/skip_test_target_normalization
Skip Go target normalization in integration tests
2 parents 466a6c3 + cf280dd commit a8c955a

File tree

5 files changed

+41
-15
lines changed

5 files changed

+41
-15
lines changed

hack/install-etcd.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,6 @@ set -o pipefail
2525
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
2626
source "${KUBE_ROOT}/hack/lib/init.sh"
2727

28+
FOUND="$(echo "${PATH}" | sed 's/:/\n/g' | grep -q "^${KUBE_ROOT}/third_party/etcd$" || true)"
2829
kube::etcd::install
30+
test -n "${FOUND}" || echo " PATH=\"\$PATH:${KUBE_ROOT}/third_party/etcd\""

hack/lib/etcd.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ kube::etcd::install() {
159159

160160
cd "${KUBE_ROOT}/third_party" || return 1
161161
if [[ $(readlink etcd) == etcd-v${ETCD_VERSION}-${os}-* ]]; then
162-
V=3 kube::log::info "etcd v${ETCD_VERSION} is already installed"
162+
V=4 kube::log::info "etcd v${ETCD_VERSION} is already installed"
163163
return 0 # already installed
164164
fi
165165

hack/lib/golang.sh

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ kube::golang::best_guess_go_targets() {
383383
continue
384384
fi
385385

386-
if [[ "${target}" =~ ^([[:alnum:]]+".")+[[:alnum:]]+"/" ]]; then
386+
if [[ "${target}" =~ ^([[:alnum:]]+".")+[[:alnum:]]+"/".+ ]]; then
387387
# If the target starts with what looks like a domain name, assume it has a
388388
# fully-qualified Go package name.
389389
echo "${target}"
@@ -413,6 +413,19 @@ kube::golang::best_guess_go_targets() {
413413
done
414414
}
415415

416+
kube::golang::internal::lazy_normalize() {
417+
target="$1"
418+
419+
if [[ "${target}" =~ ^([[:alnum:]]+".")+[[:alnum:]]+"/".+ ]]; then
420+
# If the target starts with what looks like a domain name, assume it has a
421+
# fully-qualified Go package name.
422+
echo "${target}"
423+
return
424+
fi
425+
426+
go list -find -e "${target}"
427+
}
428+
416429
# kube::golang::normalize_go_targets takes a list of build targets, which might
417430
# be Go-style names (e.g. example.com/foo/bar or ./foo/bar) or just local paths
418431
# (e.g. foo/bar) and produces a respective list (on stdout) of Go package
@@ -433,19 +446,19 @@ kube::golang::normalize_go_targets() {
433446
local tst
434447
tst="$(basename "${target}")"
435448
local pkg
436-
pkg="$(go list -find -e "${dir}")"
449+
pkg="$(kube::golang::internal::lazy_normalize "${dir}")"
437450
echo "${pkg}/${tst}"
438451
continue
439452
fi
440453
if [[ "${target}" =~ "/..."$ ]]; then
441454
local dir
442455
dir="$(dirname "${target}")"
443456
local pkg
444-
pkg="$(go list -find -e "${dir}")"
457+
pkg="$(kube::golang::internal::lazy_normalize "${dir}")"
445458
echo "${pkg}/..."
446459
continue
447460
fi
448-
go list -find -e "${target}"
461+
kube::golang::internal::lazy_normalize "${target}"
449462
done
450463
}
451464

hack/make-rules/test-integration.sh

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ set -o pipefail
2121
KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/../..
2222
source "${KUBE_ROOT}/hack/lib/init.sh"
2323

24+
kube::golang::setup_env
25+
kube::golang::setup_gomaxprocs
26+
kube::util::require-jq
27+
2428
# start the cache mutation detector by default so that cache mutators will be found
2529
KUBE_CACHE_MUTATION_DETECTOR="${KUBE_CACHE_MUTATION_DETECTOR:-true}"
2630
export KUBE_CACHE_MUTATION_DETECTOR
@@ -43,16 +47,23 @@ KUBE_TEST_ARGS=${KUBE_TEST_ARGS:-}
4347
# Default glog module settings.
4448
KUBE_TEST_VMODULE=${KUBE_TEST_VMODULE:-""}
4549

46-
kube::test::find_integration_test_dirs() {
50+
kube::test::find_integration_test_pkgs() {
4751
(
4852
cd "${KUBE_ROOT}"
49-
# The "./" syntax here produces Go-compatible package names.
50-
find ./test/integration/ -name '*_test.go' -print0 \
51-
| xargs -0n1 dirname \
52-
| LC_ALL=C sort -u
53-
find ./staging/src/k8s.io/apiextensions-apiserver/test/integration/ -name '*_test.go' -print0 \
54-
| xargs -0n1 dirname \
55-
| LC_ALL=C sort -u
53+
54+
# Get a list of all the modules in this workspace.
55+
local -a workspace_module_patterns
56+
kube::util::read-array workspace_module_patterns < <(
57+
go list -m -json | jq -r '.Dir' \
58+
| while read -r D; do
59+
SUB="${D}/test/integration";
60+
test -d "${SUB}" && echo "${SUB}/...";
61+
done)
62+
63+
# Get a list of all packages which have test files.
64+
go list -find \
65+
-f '{{if or (gt (len .TestGoFiles) 0) (gt (len .XTestGoFiles) 0)}}{{.ImportPath}}{{end}}' \
66+
"${workspace_module_patterns[@]}"
5667
)
5768
}
5869
@@ -81,7 +92,7 @@ runTests() {
8192
# empty here to ensure that we aren't unintentionally consuming them from the
8293
# previous make invocation.
8394
KUBE_TEST_ARGS="${SHORT:--short=true} --vmodule=${KUBE_TEST_VMODULE} ${KUBE_TEST_ARGS}" \
84-
WHAT="${WHAT:-$(kube::test::find_integration_test_dirs | paste -sd' ' -)}" \
95+
WHAT="${WHAT:-$(kube::test::find_integration_test_pkgs | paste -sd' ' -)}" \
8596
GOFLAGS="${GOFLAGS:-}" \
8697
KUBE_TIMEOUT="${KUBE_TIMEOUT}" \
8798
KUBE_RACE="" \

hack/make-rules/test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ if [[ ${#testcases[@]} -eq 0 ]]; then
158158
kube::util::read-array testcases < <(kube::test::find_go_packages)
159159
else
160160
# If the user passed targets, we should normalize them.
161-
# This can be slow!
161+
# This can be slow for large numbers of inputs.
162162
kube::log::status "Normalizing Go targets"
163163
kube::util::read-array testcases < <(kube::golang::normalize_go_targets "${testcases[@]}")
164164
fi

0 commit comments

Comments
 (0)