mirror of
				https://github.com/optim-enterprises-bv/kubernetes.git
				synced 2025-11-03 19:58:17 +00:00 
			
		
		
		
	Merge pull request #40659 from sttts/sttts-print-staging-import-cycles
Automatic merge from submit-queue (batch tested with PRs 40703, 40093, 40618, 40659, 39810) hack/verify-staging-imports.sh: print actual dependencies Example: ```shell $ hack/verify-staging-imports.sh apiserver has a forbidden dependency: k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/api/errors k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/api/meta k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/runtime k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/runtime/schema k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/util/errors k8s.io/apiserver/pkg/admission imports k8s.io/apimachinery/pkg/util/sets ```
This commit is contained in:
		@@ -23,13 +23,39 @@ source "${KUBE_ROOT}/hack/lib/init.sh"
 | 
			
		||||
 | 
			
		||||
kube::golang::setup_env
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
for dep in $(ls -1 ${KUBE_ROOT}/staging/src/k8s.io/); do
 | 
			
		||||
	if go list -f {{.Deps}} ./vendor/k8s.io/${dep}/... | tr " " '\n' | grep k8s.io/kubernetes | grep -v 'k8s.io/kubernetes/vendor' | LC_ALL=C sort -u | grep -e "."; then
 | 
			
		||||
		echo "${dep} has a cyclical dependency"
 | 
			
		||||
		exit 1
 | 
			
		||||
	fi
 | 
			
		||||
function print_forbidden_imports () {
 | 
			
		||||
    set -o errexit # this was unset by ||
 | 
			
		||||
    local PACKAGE="$1"
 | 
			
		||||
    shift
 | 
			
		||||
    local RE=""
 | 
			
		||||
    local SEP=""
 | 
			
		||||
    for CLAUSE in "$@"; do
 | 
			
		||||
        RE+="${SEP}${CLAUSE}"
 | 
			
		||||
        SEP='\|'
 | 
			
		||||
    done
 | 
			
		||||
    local FORBIDDEN=$(
 | 
			
		||||
        go list -f $'{{with $package := .ImportPath}}{{range $.Imports}}{{$package}} imports {{.}}\n{{end}}{{end}}' ./vendor/k8s.io/${PACKAGE}/... |
 | 
			
		||||
        sed 's|^k8s.io/kubernetes/vendor/||;s| k8s.io/kubernetes/vendor/| |' |
 | 
			
		||||
        grep -v " k8s.io/${PACKAGE}" |
 | 
			
		||||
        grep -e "imports \(${RE}\)"
 | 
			
		||||
    )
 | 
			
		||||
    if [ -n "${FORBIDDEN}" ]; then
 | 
			
		||||
        echo "${PACKAGE} has a forbidden dependency:"
 | 
			
		||||
		echo
 | 
			
		||||
		echo "${FORBIDDEN}" | sed 's/^/  /'
 | 
			
		||||
		echo
 | 
			
		||||
		return 1
 | 
			
		||||
    fi
 | 
			
		||||
    return 0
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
RC=0
 | 
			
		||||
print_forbidden_imports apimachinery k8s.io/ || RC=1
 | 
			
		||||
print_forbidden_imports apiserver k8s.io/kubernetes || RC=1
 | 
			
		||||
print_forbidden_imports client-go k8s.io/kubernetes k8s.io/apiserver || RC=1
 | 
			
		||||
if [ ${RC} != 0 ]; then
 | 
			
		||||
    exit ${RC}
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
if grep -rq '// import "k8s.io/kubernetes/' 'staging/'; then
 | 
			
		||||
	echo 'file has "// import "k8s.io/kubernetes/"'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user