---
# System prepended metadata

title: Analyzing dependencies in a Kubernetes PR

---

# Analyzing dependencies in a Kubernetes PR

## Start at kubernetes main directory
`cd $HOME/go/src/k8s.io/kubernetes`

## Fetch the patch
```
wget https://github.com/kubernetes/kubernetes/pull/98946.patch
```

## Eyeball the list of new dependencies
```
grep b/LICENSES 98946.patch | grep -v diff | cut -f 4- -d '/' | sed 's/\/LICENSE//' | xargs -L 1 echo
```

this should print the following
```
github.com/bgentry/go-netrc
github.com/go-errors/errors
github.com/google/shlex
github.com/hashicorp/errwrap
github.com/hashicorp/go-cleanhttp
github.com/hashicorp/go-multierror
github.com/hashicorp/go-safetemp
github.com/hashicorp/go-version
github.com/mitchellh/go-homedir
github.com/mitchellh/go-testing-interface
github.com/monochromegane/go-gitignore
github.com/qri-io/starlib
github.com/ulikunitz/xz
github.com/xlab/treeprint
github.com/yujunz/go-getter
go.starlark.net
sigs.k8s.io/kustomize/api
sigs.k8s.io/kustomize/kyaml
```

## Figure out where these new dependencies are getting called from/used

```
grep b/LICENSES 98946.patch | grep -v diff | cut -f 4- -d '/' | sed 's/\/LICENSE//' | xargs -L 1 go mod why -m 2>&1 | grep -v warning
```

This should output
```
# github.com/bgentry/go-netrc
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/loader
github.com/yujunz/go-getter
github.com/bgentry/go-netrc/netrc
# github.com/go-errors/errors
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/kyaml/openapi
sigs.k8s.io/kustomize/kyaml/errors
github.com/go-errors/errors
# github.com/google/shlex
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/internal/plugins/loader
sigs.k8s.io/kustomize/api/internal/plugins/execplugin
github.com/google/shlex
# github.com/hashicorp/errwrap
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/internal/target
github.com/hashicorp/go-multierror
github.com/hashicorp/errwrap
# github.com/hashicorp/go-cleanhttp
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/loader
github.com/yujunz/go-getter
github.com/hashicorp/go-cleanhttp
# github.com/hashicorp/go-multierror
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/internal/target
github.com/hashicorp/go-multierror
# github.com/hashicorp/go-safetemp
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/loader
github.com/yujunz/go-getter
github.com/hashicorp/go-safetemp
# github.com/hashicorp/go-version
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/loader
github.com/yujunz/go-getter
github.com/hashicorp/go-version
# github.com/mitchellh/go-homedir
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/loader
github.com/yujunz/go-getter
github.com/mitchellh/go-homedir
# github.com/mitchellh/go-testing-interface
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/loader
github.com/yujunz/go-getter
github.com/mitchellh/go-testing-interface
# github.com/monochromegane/go-gitignore
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/builtins
sigs.k8s.io/kustomize/api/filters/annotations
sigs.k8s.io/kustomize/kyaml/kio
github.com/monochromegane/go-gitignore
# github.com/qri-io/starlib
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/internal/plugins/loader
sigs.k8s.io/kustomize/api/internal/plugins/fnplugin
sigs.k8s.io/kustomize/kyaml/runfn
sigs.k8s.io/kustomize/kyaml/fn/runtime/starlark
github.com/qri-io/starlib/util
# github.com/ulikunitz/xz
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/loader
github.com/yujunz/go-getter
github.com/ulikunitz/xz
# github.com/xlab/treeprint
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/builtins
sigs.k8s.io/kustomize/api/filters/annotations
sigs.k8s.io/kustomize/kyaml/kio
github.com/xlab/treeprint
# github.com/yujunz/go-getter
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/loader
github.com/yujunz/go-getter
# go.starlark.net
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/api/internal/plugins/loader
sigs.k8s.io/kustomize/api/internal/plugins/fnplugin
sigs.k8s.io/kustomize/kyaml/runfn
sigs.k8s.io/kustomize/kyaml/fn/runtime/starlark
go.starlark.net/starlark
# sigs.k8s.io/kustomize/api
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
sigs.k8s.io/kustomize/api/filesys
# sigs.k8s.io/kustomize/kyaml
k8s.io/kubernetes/pkg/kubectl/cmd/convert
k8s.io/cli-runtime/pkg/resource
k8s.io/cli-runtime/pkg/kustomize
sigs.k8s.io/kustomize/api/krusty
sigs.k8s.io/kustomize/kyaml/openapi
```

## Convert to graph

Reformatted the output as follows by hand into a file named "filename.dot"
```
digraph G {

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/loader" -> "github.com/yujunz/go-getter" -> "github.com/bgentry/go-netrc/netrc" -> "github.com/bgentry/go-netrc"

"k8s.io/kubernetes/cmd/kubectl-convert" -> "k8s.io/kubectl/pkg/cmd/util" -> "k8s.io/kubectl/pkg/util/openapi/validation" -> "k8s.io/kube-openapi/pkg/util/proto/validation" -> "k8s.io/kube-openapi/pkg/util/proto/validation.test" -> "github.com/ghodss/yaml"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/kyaml/openapi" -> "sigs.k8s.io/kustomize/kyaml/errors" -> "github.com/go-errors/errors"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/internal/plugins/loader" -> "sigs.k8s.io/kustomize/api/internal/plugins/execplugin" -> "github.com/google/shlex"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/internal/target" -> "github.com/hashicorp/go-multierror" -> "github.com/hashicorp/errwrap"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/loader" -> "github.com/yujunz/go-getter" -> "github.com/hashicorp/go-cleanhttp"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/internal/target" -> "github.com/hashicorp/go-multierror"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/loader" -> "github.com/yujunz/go-getter" -> "github.com/hashicorp/go-safetemp"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/loader" -> "github.com/yujunz/go-getter" -> "github.com/hashicorp/go-version"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/loader" -> "github.com/yujunz/go-getter" -> "github.com/mitchellh/go-homedir"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/loader" -> "github.com/yujunz/go-getter" -> "github.com/mitchellh/go-testing-interface"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/builtins" -> "sigs.k8s.io/kustomize/api/filters/annotations" -> "sigs.k8s.io/kustomize/kyaml/kio" -> "github.com/monochromegane/go-gitignore"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/internal/plugins/loader" -> "sigs.k8s.io/kustomize/api/internal/plugins/fnplugin" -> "sigs.k8s.io/kustomize/kyaml/runfn" -> "sigs.k8s.io/kustomize/kyaml/fn/runtime/starlark" -> "github.com/qri-io/starlib/util" -> "github.com/qri-io/starlib"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/loader" -> "github.com/yujunz/go-getter" -> "github.com/ulikunitz/xz"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/builtins" -> "sigs.k8s.io/kustomize/api/filters/annotations" -> "sigs.k8s.io/kustomize/kyaml/kio" -> "github.com/xlab/treeprint"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/loader" -> "github.com/yujunz/go-getter"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/api/internal/plugins/loader" -> "sigs.k8s.io/kustomize/api/internal/plugins/fnplugin" -> "sigs.k8s.io/kustomize/kyaml/runfn" -> "sigs.k8s.io/kustomize/kyaml/fn/runtime/starlark" -> "go.starlark.net/starlark" -> "go.starlark.net"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "sigs.k8s.io/kustomize/api/filesys" -> "sigs.k8s.io/kustomize/api"

"k8s.io/kubernetes/pkg/kubectl/cmd/convert" -> "k8s.io/cli-runtime/pkg/resource" -> "k8s.io/cli-runtime/pkg/kustomize" -> "sigs.k8s.io/kustomize/api/krusty" -> "sigs.k8s.io/kustomize/kyaml/openapi" -> "sigs.k8s.io/kustomize/kyaml"

}
```

Then run the following graphviz command: `dot -Tsvg filename.dot -o filename.svg`

See a bunch of other options here: https://stackoverflow.com/questions/1494492/graphviz-how-to-go-from-dot-to-a-graph

Final output is here: https://github.com/kubernetes/kubernetes/pull/98946#issuecomment-776894986

Also see https://github.com/go-modules-by-example/index/blob/master/018_go_list_mod_graph_why/README.md