Skip to content

Commit b710c13

Browse files
committed
add whitelist, make use of k/k master unwanted-dependencies.json
1 parent 0fa4698 commit b710c13

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

.github/workflows/unwanted-dependencies-check.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ jobs:
5454
# Only report failures of pushes (PRs have are visible through the Checks section) to the default branch
5555
if: failure() && github.event_name == 'push' && github.ref == 'refs/heads/master'
5656
with:
57-
title: 🐛 unwanted-dependencies-check failed for ${{ github.sha }}
57+
title: 📦 unwanted-dependencies-check failed for ${{ github.sha }}
5858
token: ${{ secrets.GITHUB_TOKEN }}
59-
labels: kind/bug
59+
labels: kind/dependencies
6060
body: https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}
6161

hack/unwanted-dependencies-check.sh

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,18 @@ set +u
99
declare -i rc=0
1010
declare -a POSTIONAL_ARGS=()
1111

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+
1220
declare -x GO11MODULES=yes
1321
declare -x GOFLAGS=-mod=mod
1422

15-
# Explicit path of the unwanted depedency list
23+
# Explicit path of the unwanted dependency list
1624
JSON_PATH_URL=""
1725
JSON_PATH_LOCAL=""
1826
READ_PATH=""
@@ -71,7 +79,7 @@ pull_unwanted_dependencies_json() {
7179
READ_PATH=$(realpath ${JSON_PATH_LOCAL})
7280
else
7381
# 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'
7583
wget "${JSON_PATH_URL}" -O "${PWD}/hack/unwanted-dependencies.json"
7684
READ_PATH="${PWD}/hack/unwanted-dependencies.json"
7785
fi
@@ -80,7 +88,7 @@ pull_unwanted_dependencies_json() {
8088
check_unwanted_dependencies(){
8189
for dep in $(jq -r '.spec.unwantedModules | keys[]' "${READ_PATH}"); do
8290
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
8492
rc=1
8593
echo "Error: unwanted dependencies found. ($dep at $(realpath $file))"
8694
fi
@@ -89,13 +97,17 @@ check_unwanted_dependencies(){
8997

9098
for upstream in $(jq -r '.status.unwantedReferences | keys[]' "${READ_PATH}"); do
9199
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
93101
rc=1
94102
echo "Error: unwanted references found on one of the dependencies. ($upstream depends on $ref))"
95103
fi
96104
done
97105
done
98106

107+
if [[ $rc == 0 ]]; then
108+
echo "No unwanted dependency detected."
109+
fi
110+
99111
exit $rc
100112
}
101113

0 commit comments

Comments
 (0)