mirror of
				https://github.com/k3s-io/kubernetes.git
				synced 2025-10-30 21:30:16 +00:00 
			
		
		
		
	Update go.mod files to go1.18, update license vendor script
This commit is contained in:
		
							
								
								
									
										2
									
								
								go.mod
									
									
									
									
									
								
							
							
						
						
									
										2
									
								
								go.mod
									
									
									
									
									
								
							| @@ -6,7 +6,7 @@ | |||||||
|  |  | ||||||
| module k8s.io/kubernetes | module k8s.io/kubernetes | ||||||
|  |  | ||||||
| go 1.16 | go 1.18 | ||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690 | 	bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690 | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| module k8s.io/kubernetes/hack/tools | module k8s.io/kubernetes/hack/tools | ||||||
|  |  | ||||||
| go 1.16 | go 1.18 | ||||||
|  |  | ||||||
| require ( | require ( | ||||||
| 	github.com/aojea/sloppy-netparser v0.0.0-20210819225411-1b3bd8b3b975 | 	github.com/aojea/sloppy-netparser v0.0.0-20210819225411-1b3bd8b3b975 | ||||||
|   | |||||||
| @@ -186,8 +186,10 @@ if [ -f "${LICENSE_ROOT}/LICENSE" ]; then | |||||||
|   mv "${TMP_LICENSE_FILE}" "${TMP_LICENSES_DIR}/LICENSE" |   mv "${TMP_LICENSE_FILE}" "${TMP_LICENSES_DIR}/LICENSE" | ||||||
| fi | fi | ||||||
|  |  | ||||||
|  | # Capture all module dependencies | ||||||
|  | modules=$(go list -m -json all | jq -r .Path | sort -f) | ||||||
| # Loop through every vendored package | # Loop through every vendored package | ||||||
| for PACKAGE in $(go list -m -json all | jq -r .Path | sort -f); do | for PACKAGE in ${modules}; do | ||||||
|   if [[ -e "staging/src/${PACKAGE}" ]]; then |   if [[ -e "staging/src/${PACKAGE}" ]]; then | ||||||
|     echo "${PACKAGE} is a staging package, skipping" >&2 |     echo "${PACKAGE} is a staging package, skipping" >&2 | ||||||
|     continue |     continue | ||||||
| @@ -196,26 +198,16 @@ for PACKAGE in $(go list -m -json all | jq -r .Path | sort -f); do | |||||||
|     echo "${PACKAGE} doesn't exist in ${DEPS_DIR}, skipping" >&2 |     echo "${PACKAGE} doesn't exist in ${DEPS_DIR}, skipping" >&2 | ||||||
|     continue |     continue | ||||||
|   fi |   fi | ||||||
|   # Skip a directory if 1) it has no files and 2) all the subdirectories contain a go.mod file. |  | ||||||
|   misses_go_mod=false |   # if there are no files vendored under this package... | ||||||
|   DEPS_SUBDIR="${DEPS_DIR}/${PACKAGE}" |   if [[ -z "$(find "${DEPS_DIR}/${PACKAGE}" -mindepth 1 -maxdepth 1 -type f)" ]]; then | ||||||
|   search_for_mods () { |     # and we have the same number of submodules as subdirectories... | ||||||
|     if [[ -z "$(find "${DEPS_SUBDIR}/" -mindepth 1 -maxdepth 1 -type f)" ]]; then |     if [[ "$(find "${DEPS_DIR}/${PACKAGE}/" -mindepth 1 -maxdepth 1 -type d | wc -l)" -eq "$(echo "${modules}" | grep -cE "^${PACKAGE}/")" ]]; then | ||||||
|       while read -d "" -r SUBDIR; do |       echo "Only submodules of ${PACKAGE} are vendored, skipping" >&2 | ||||||
|           if [[ ! -e "${SUBDIR}/go.mod" ]]; then |  | ||||||
|               DEPS_SUBDIR=${SUBDIR} |  | ||||||
|               search_for_mods |  | ||||||
|           fi |  | ||||||
|       done < <(find "${DEPS_SUBDIR}/" -mindepth 1 -maxdepth 1 -type d -print0) |  | ||||||
|     else |  | ||||||
|       misses_go_mod=true |  | ||||||
|     fi |  | ||||||
|   } |  | ||||||
|   search_for_mods |  | ||||||
|   if [[ $misses_go_mod = false ]]; then |  | ||||||
|       echo "${PACKAGE} has no files, skipping" >&2 |  | ||||||
|       continue |       continue | ||||||
|     fi |     fi | ||||||
|  |   fi | ||||||
|  |  | ||||||
|   echo "${PACKAGE}" |   echo "${PACKAGE}" | ||||||
|  |  | ||||||
|   process_content "${PACKAGE}" LICENSE |   process_content "${PACKAGE}" LICENSE | ||||||
|   | |||||||
| @@ -114,13 +114,21 @@ function ensure_require_replace_directives_for_all_dependencies() { | |||||||
|       | xargs -L 100 go mod edit -fmt |       | xargs -L 100 go mod edit -fmt | ||||||
| } | } | ||||||
|  |  | ||||||
| function group_replace_directives() { | function group_directives() { | ||||||
|   local local_tmp_dir |   local local_tmp_dir | ||||||
|   local_tmp_dir=$(mktemp -d "${TMP_DIR}/group_replace.XXXX") |   local_tmp_dir=$(mktemp -d "${TMP_DIR}/group_replace.XXXX") | ||||||
|  |   local go_mod_require_direct="${local_tmp_dir}/go.mod.require_direct.tmp" | ||||||
|  |   local go_mod_require_indirect="${local_tmp_dir}/go.mod.require_indirect.tmp" | ||||||
|   local go_mod_replace="${local_tmp_dir}/go.mod.replace.tmp" |   local go_mod_replace="${local_tmp_dir}/go.mod.replace.tmp" | ||||||
|   local go_mod_noreplace="${local_tmp_dir}/go.mod.noreplace.tmp" |   local go_mod_other="${local_tmp_dir}/go.mod.other.tmp" | ||||||
|   # separate replace and non-replace directives |   # separate replace and non-replace directives | ||||||
|   awk " |   awk " | ||||||
|  |      # print lines between 'require (' ... ')' lines | ||||||
|  |      /^require [(]/          { inrequire=1; next                            } | ||||||
|  |      inrequire && /^[)]/     { inrequire=0; next                            } | ||||||
|  |      inrequire && /\/\/ indirect/ { print > \"${go_mod_require_indirect}\"; next } | ||||||
|  |      inrequire               { print > \"${go_mod_require_direct}\";   next } | ||||||
|  |  | ||||||
|      # print lines between 'replace (' ... ')' lines |      # print lines between 'replace (' ... ')' lines | ||||||
|      /^replace [(]/      { inreplace=1; next                   } |      /^replace [(]/      { inreplace=1; next                   } | ||||||
|      inreplace && /^[)]/ { inreplace=0; next                   } |      inreplace && /^[)]/ { inreplace=0; next                   } | ||||||
| @@ -129,11 +137,21 @@ function group_replace_directives() { | |||||||
|      # print ungrouped replace directives with the replace directive trimmed |      # print ungrouped replace directives with the replace directive trimmed | ||||||
|      /^replace [^(]/ { sub(/^replace /,\"\"); print > \"${go_mod_replace}\"; next } |      /^replace [^(]/ { sub(/^replace /,\"\"); print > \"${go_mod_replace}\"; next } | ||||||
|  |  | ||||||
|      # otherwise print to the noreplace file |      # print ungrouped require directives with the require directive trimmed | ||||||
|      { print > \"${go_mod_noreplace}\" } |      /^require [^(].*\/\/ indirect/ { sub(/^require /,\"\"); print > \"${go_mod_require_indirect}\"; next } | ||||||
|  |      /^require [^(]/ { sub(/^require /,\"\"); print > \"${go_mod_require_direct}\"; next } | ||||||
|  |  | ||||||
|  |      # otherwise print to the other file | ||||||
|  |      { print > \"${go_mod_other}\" } | ||||||
|   " < go.mod |   " < go.mod | ||||||
|   { |   { | ||||||
|     cat "${go_mod_noreplace}"; |     cat "${go_mod_other}"; | ||||||
|  |     echo "require ("; | ||||||
|  |     cat "${go_mod_require_direct}"; | ||||||
|  |     echo ")"; | ||||||
|  |     echo "require ("; | ||||||
|  |     cat "${go_mod_require_indirect}"; | ||||||
|  |     echo ")"; | ||||||
|     echo "replace ("; |     echo "replace ("; | ||||||
|     cat "${go_mod_replace}"; |     cat "${go_mod_replace}"; | ||||||
|     echo ")"; |     echo ")"; | ||||||
| @@ -215,8 +233,8 @@ ensure_require_replace_directives_for_all_dependencies | |||||||
| go mod tidy >>"${LOG_FILE}" 2>&1 | go mod tidy >>"${LOG_FILE}" 2>&1 | ||||||
| # pin expanded versions | # pin expanded versions | ||||||
| ensure_require_replace_directives_for_all_dependencies | ensure_require_replace_directives_for_all_dependencies | ||||||
| # group replace directives | # group require/replace directives | ||||||
| group_replace_directives | group_directives | ||||||
|  |  | ||||||
| # Phase 4: copy root go.mod to staging dirs and rewrite | # Phase 4: copy root go.mod to staging dirs and rewrite | ||||||
|  |  | ||||||
| @@ -332,6 +350,9 @@ $(go mod why "${loopback_deps[@]}")" | |||||||
|              "-dropreplace \(.Replace.Path)"' | |              "-dropreplace \(.Replace.Path)"' | | ||||||
|     xargs -L 100 go mod edit -fmt |     xargs -L 100 go mod edit -fmt | ||||||
|  |  | ||||||
|  |     # group require/replace directives | ||||||
|  |     group_directives | ||||||
|  |  | ||||||
|   popd >/dev/null 2>&1 |   popd >/dev/null 2>&1 | ||||||
| done | done | ||||||
| echo "=== tidying root" >> "${LOG_FILE}" | echo "=== tidying root" >> "${LOG_FILE}" | ||||||
|   | |||||||
| @@ -25,7 +25,7 @@ set -o pipefail | |||||||
| KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. | KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. | ||||||
| source "${KUBE_ROOT}/hack/lib/init.sh" | source "${KUBE_ROOT}/hack/lib/init.sh" | ||||||
|  |  | ||||||
| export GO111MODULE=auto | export GO111MODULE=on | ||||||
|  |  | ||||||
| staging_repos=() | staging_repos=() | ||||||
| kube::util::read-array staging_repos < <(kube::util::list_staging_repos) | kube::util::read-array staging_repos < <(kube::util::list_staging_repos) | ||||||
| @@ -45,12 +45,18 @@ kube::util::ensure-temp-dir | |||||||
|  |  | ||||||
| # Get vendored packages dependencies | # Get vendored packages dependencies | ||||||
| # Use -deps flag to include transitive dependencies | # Use -deps flag to include transitive dependencies | ||||||
| go list -mod=vendor -test -deps -json ./vendor/... > "${KUBE_TEMP}/deps.json" | go list -mod=vendor -test -tags other   -e -deps -json ./vendor/... > "${KUBE_TEMP}/deps_other.json" | ||||||
|  | go list -mod=vendor -test -tags linux   -e -deps -json ./vendor/... > "${KUBE_TEMP}/deps_linux.json" | ||||||
|  | go list -mod=vendor -test -tags windows -e -deps -json ./vendor/... > "${KUBE_TEMP}/deps_windows.json" | ||||||
|  |  | ||||||
| # Check for any vendored package that imports main repo | # Check for any vendored package that imports main repo | ||||||
| # Staging repos are explicitly excluded even though go list does not currently consider symlinks | # Staging repos are explicitly excluded even though go list does not currently consider symlinks | ||||||
| go run cmd/dependencycheck/dependencycheck.go -restrict "^k8s\.io/kubernetes/" -exclude "^k8s\.io/(${staging_repos_pattern})(/|$)" "${KUBE_TEMP}/deps.json" | go run cmd/dependencycheck/dependencycheck.go -restrict "^k8s\.io/kubernetes/" -exclude "^k8s\.io/(${staging_repos_pattern})(/|$)" "${KUBE_TEMP}/deps_other.json" | ||||||
|  | go run cmd/dependencycheck/dependencycheck.go -restrict "^k8s\.io/kubernetes/" -exclude "^k8s\.io/(${staging_repos_pattern})(/|$)" "${KUBE_TEMP}/deps_linux.json" | ||||||
|  | go run cmd/dependencycheck/dependencycheck.go -restrict "^k8s\.io/kubernetes/" -exclude "^k8s\.io/(${staging_repos_pattern})(/|$)" "${KUBE_TEMP}/deps_windows.json" | ||||||
|  |  | ||||||
| # Check for any vendored package that imports a staging repo | # Check for any vendored package that imports a staging repo | ||||||
| # Staging repos are explicitly excluded even though go list does not currently consider symlinks | # Staging repos are explicitly excluded even though go list does not currently consider symlinks | ||||||
| go run cmd/dependencycheck/dependencycheck.go -restrict "^k8s\.io/(${staging_repos_pattern})(/|$)" -exclude "^k8s\.io/(${staging_repos_pattern})(/|$)" "${KUBE_TEMP}/deps.json" | go run cmd/dependencycheck/dependencycheck.go -restrict "^k8s\.io/(${staging_repos_pattern})(/|$)" -exclude "^k8s\.io/(${staging_repos_pattern})(/|$)" "${KUBE_TEMP}/deps_other.json" | ||||||
|  | go run cmd/dependencycheck/dependencycheck.go -restrict "^k8s\.io/(${staging_repos_pattern})(/|$)" -exclude "^k8s\.io/(${staging_repos_pattern})(/|$)" "${KUBE_TEMP}/deps_linux.json" | ||||||
|  | go run cmd/dependencycheck/dependencycheck.go -restrict "^k8s\.io/(${staging_repos_pattern})(/|$)" -exclude "^k8s\.io/(${staging_repos_pattern})(/|$)" "${KUBE_TEMP}/deps_windows.json" | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user