From 00622da45e5df5c0afa77855dd1c18c5dad03325 Mon Sep 17 00:00:00 2001 From: Jordan Liggitt Date: Tue, 21 Sep 2021 10:14:35 -0400 Subject: [PATCH] Make staticcheck package-compatible --- hack/verify-staticcheck.sh | 23 ++++++++++++++++----- test/images/agnhost/inclusterclient/main.go | 1 - 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/hack/verify-staticcheck.sh b/hack/verify-staticcheck.sh index 9dafb6e35d1..e1ee254892a 100755 --- a/hack/verify-staticcheck.sh +++ b/hack/verify-staticcheck.sh @@ -45,6 +45,7 @@ export IFS=','; checks="${CHECKS[*]}"; unset IFS # NOTE: To ignore issues detected a package, add it to the .staticcheck_failures blacklist IGNORE=( "vendor/k8s.io/kubectl/pkg/cmd/edit/testdata" # golang/go#24854, dominikh/go-tools#565 + "cluster/addons/fluentd-elasticsearch/es-image" # cannot traverse go modules ) export IFS='|'; ignore_pattern="^(${IGNORE[*]})\$"; unset IFS @@ -63,10 +64,21 @@ cd "${KUBE_ROOT}" failure_file="${KUBE_ROOT}/hack/.staticcheck_failures" kube::util::check-file-in-alphabetical-order "${failure_file}" +function normalize_package() { + pkg="${1}" + if [[ "${pkg}" == "vendor/"* || "${pkg}" == "k8s.io/"* ]]; then + # Treat this as a full package path (stripping vendor prefix if needed) + echo "${pkg#"vendor/"}" + else + # Treat this as a relative package path to k8s.io/kubernetes + echo "./${pkg}" + fi +} + all_packages=() while IFS='' read -r line; do - # Prepend './' to get staticcheck to treat these as paths, not packages. - all_packages+=("./$line") + line=$(normalize_package "${line}") + all_packages+=("${line}") done < <( hack/make-rules/helpers/cache_go_dirs.sh "${KUBE_ROOT}/_tmp/all_go_dirs" | grep "^${FOCUS:-.}" | grep -vE "(third_party|generated|clientset_generated|hack|testdata|/_)" | @@ -95,7 +107,7 @@ while read -r error; do elif [[ "${in_failing}" -eq "0" ]]; then really_failing+=( "$pkg" ) fi -done < <(GOOS=linux staticcheck -checks "${checks}" "${all_packages[@]}" 2>/dev/null || true) +done < <(GO111MODULE=on GOOS=linux staticcheck -checks "${checks}" "${all_packages[@]}" 2>/dev/null || true) export IFS=$'\n' # Expand ${really_failing[*]} to separate lines kube::util::read-array really_failing < <(sort -u <<<"${really_failing[*]}") @@ -109,8 +121,9 @@ done # Check that all failing_packages actually still exist gone=() for p in "${failing_packages[@]}"; do - if ! kube::util::array_contains "./$p" "${all_packages[@]}"; then - gone+=( "$p" ) + p=$(normalize_package "${p}") + if ! kube::util::array_contains "${p}" "${all_packages[@]}"; then + gone+=( "${p}" ) fi done diff --git a/test/images/agnhost/inclusterclient/main.go b/test/images/agnhost/inclusterclient/main.go index 2aee88425f7..253dd75f8c1 100644 --- a/test/images/agnhost/inclusterclient/main.go +++ b/test/images/agnhost/inclusterclient/main.go @@ -73,7 +73,6 @@ func main(cmd *cobra.Command, args []string) { c := kubernetes.NewForConfigOrDie(cfg).RESTClient() - //lint:ignore SA1015 noisy positive, `time.Tick` is used in a main function which is fine t := time.Tick(time.Duration(pollInterval) * time.Second) for { <-t