9
9
declare -i rc=0
10
10
declare -a POSTIONAL_ARGS=()
11
11
12
+ # Whitelisted dependencies
13
+ declare -a WHITELIST=(
14
+ " github.com/google/shlex"
15
+ " github.com/pkg/error"
16
+ " k8s.io/klog"
17
+ " github.com/json-iterator/go"
18
+ )
19
+
12
20
declare -x GO11MODULES=yes
13
21
declare -x GOFLAGS=-mod=mod
14
22
15
- # Explicit path of the unwanted depedency list
23
+ # Explicit path of the unwanted dependency list
16
24
JSON_PATH_URL=" "
17
25
JSON_PATH_LOCAL=" "
18
26
READ_PATH=" "
@@ -71,7 +79,7 @@ pull_unwanted_dependencies_json() {
71
79
READ_PATH=$( realpath ${JSON_PATH_LOCAL} )
72
80
else
73
81
# Default behavior: pull unwanted-dependencies.json from kubernetes/kubernetes upstream repo
74
- JSON_PATH_URL=' https://raw.githubusercontent.com/kubernetes/kubernetes/e51fe4a61cca7f4a0875630da433f280b52c138a /hack/unwanted-dependencies.json'
82
+ JSON_PATH_URL=' https://raw.githubusercontent.com/kubernetes/kubernetes/master /hack/unwanted-dependencies.json'
75
83
wget " ${JSON_PATH_URL} " -O " ${PWD} /hack/unwanted-dependencies.json"
76
84
READ_PATH=" ${PWD} /hack/unwanted-dependencies.json"
77
85
fi
@@ -80,7 +88,7 @@ pull_unwanted_dependencies_json() {
80
88
check_unwanted_dependencies (){
81
89
for dep in $( jq -r ' .spec.unwantedModules | keys[]' " ${READ_PATH} " ) ; do
82
90
for file in $( find . \( -type f -and -path ' */kyaml/*' -or -path ' */api/*' -or -path ' */kustomize/*' \) | fgrep go.sum) ; do
83
- if [[ $( cat $file | fgrep $dep ) ]]; then
91
+ if [[ $( cat $file | fgrep $dep ) && ! ${WHITELIST[@]} =~ " $dep " ]]; then
84
92
rc=1
85
93
echo " Error: unwanted dependencies found. ($dep at $( realpath $file ) )"
86
94
fi
@@ -89,13 +97,17 @@ check_unwanted_dependencies(){
89
97
90
98
for upstream in $( jq -r ' .status.unwantedReferences | keys[]' " ${READ_PATH} " ) ; do
91
99
for ref in $( jq -r ' .status.unwantedReferences.' \" ${upstream} \" ' []' " ${READ_PATH} " ) ; do
92
- if [[ $( go mod graph | fgrep $upstream | fgrep $ref ) ]]; then
100
+ if [[ $( go mod graph | fgrep $upstream | fgrep $ref ) && ! ${WHITELIST[@]} =~ " $upstream " ]]; then
93
101
rc=1
94
102
echo " Error: unwanted references found on one of the dependencies. ($upstream depends on $ref ))"
95
103
fi
96
104
done
97
105
done
98
106
107
+ if [[ $rc == 0 ]]; then
108
+ echo " No unwanted dependency detected."
109
+ fi
110
+
99
111
exit $rc
100
112
}
101
113
0 commit comments