Skip to content

Instantly share code, notes, and snippets.

@dims
Last active May 8, 2024 23:52
Show Gist options
  • Save dims/c0857b86441442b15852a4c2355db130 to your computer and use it in GitHub Desktop.
Save dims/c0857b86441442b15852a4c2355db130 to your computer and use it in GitHub Desktop.
Python script to compute updates to the Kubernetes go.mod to see how far we are behind latest in vendored repos
Package Current Latest URL
github.com/Azure/go-ansiterm d185dfc1b5a1 306776ec8161 https://github.com/Azure/go-ansiterm/compare/d185dfc1b5a1...306776ec8161
github.com/Microsoft/go-winio v0.6.0 v0.6.2 https://github.com/Microsoft/go-winio/compare/v0.6.0...v0.6.2
github.com/Microsoft/hcsshim v0.8.25 v0.12.3 https://github.com/Microsoft/hcsshim/compare/v0.8.25...v0.12.3
github.com/armon/circbuf bbbad097214e 5111143e8da2 https://github.com/armon/circbuf/compare/bbbad097214e...5111143e8da2
github.com/asaskevich/govalidator f61b66f89f4a a9d515a09cc2 https://github.com/asaskevich/govalidator/compare/f61b66f89f4a...a9d515a09cc2
github.com/cenkalti/backoff/v4 v4.2.1 v4.3.0 https://github.com/cenkalti/backoff/v4/compare/v4.2.1...v4.3.0
github.com/cespare/xxhash/v2 v2.2.0 v2.3.0 https://github.com/cespare/xxhash/v2/compare/v2.2.0...v2.3.0
github.com/chai2010/gettext-go v1.0.2 v1.0.3 https://github.com/chai2010/gettext-go/compare/v1.0.2...v1.0.3
github.com/cilium/ebpf v0.9.1 v0.15.0 https://github.com/cilium/ebpf/compare/v0.9.1...v0.15.0
github.com/container-storage-interface/spec v1.8.0 v1.9.0 https://github.com/container-storage-interface/spec/compare/v1.8.0...v1.9.0
github.com/containerd/console v1.0.3 v1.0.4 https://github.com/containerd/console/compare/v1.0.3...v1.0.4
github.com/containerd/ttrpc v1.2.2 v1.2.3 https://github.com/containerd/ttrpc/compare/v1.2.2...v1.2.3
github.com/cpuguy83/go-md2man/v2 v2.0.2 v2.0.4 https://github.com/cpuguy83/go-md2man/v2/compare/v2.0.2...v2.0.4
github.com/cyphar/filepath-securejoin v0.2.4 v0.2.5 https://github.com/cyphar/filepath-securejoin/compare/v0.2.4...v0.2.5
github.com/distribution/reference v0.5.0 v0.6.0 https://github.com/distribution/reference/compare/v0.5.0...v0.6.0
github.com/emicklei/go-restful/v3 v3.11.0 v3.12.0 https://github.com/emicklei/go-restful/v3/compare/v3.11.0...v3.12.0
github.com/evanphx/json-patch v4.12.0 v5.9.0 https://github.com/evanphx/json-patch/compare/v4.12.0...v5.9.0
github.com/exponent-io/jsonpath d6023ce2651d 1de76d718b3f https://github.com/exponent-io/jsonpath/compare/d6023ce2651d...1de76d718b3f
github.com/felixge/httpsnoop v1.0.3 v1.0.4 https://github.com/felixge/httpsnoop/compare/v1.0.3...v1.0.4
github.com/go-errors/errors v1.4.2 v1.5.1 https://github.com/go-errors/errors/compare/v1.4.2...v1.5.1
github.com/go-openapi/jsonpointer v0.19.6 v0.21.0 https://github.com/go-openapi/jsonpointer/compare/v0.19.6...v0.21.0
github.com/go-openapi/jsonreference v0.20.2 v0.21.0 https://github.com/go-openapi/jsonreference/compare/v0.20.2...v0.21.0
github.com/go-openapi/swag v0.22.3 v0.23.0 https://github.com/go-openapi/swag/compare/v0.22.3...v0.23.0
github.com/google/btree v1.0.1 v1.1.2 https://github.com/google/btree/compare/v1.0.1...v1.1.2
github.com/google/cadvisor v0.49.0 v0.49.1 https://github.com/google/cadvisor/compare/v0.49.0...v0.49.1
github.com/google/pprof 4bb14d4b1be1 1db217f89380 https://github.com/google/pprof/compare/4bb14d4b1be1...1db217f89380
github.com/google/uuid v1.3.1 v1.6.0 https://github.com/google/uuid/compare/v1.3.1...v1.6.0
github.com/gorilla/websocket v1.5.0 v1.5.1 https://github.com/gorilla/websocket/compare/v1.5.0...v1.5.1
github.com/gregjones/httpcache 9cad4c3443a7 901d90724c79 https://github.com/gregjones/httpcache/compare/9cad4c3443a7...901d90724c79
github.com/grpc-ecosystem/go-grpc-middleware v1.3.0 v1.4.0 https://github.com/grpc-ecosystem/go-grpc-middleware/compare/v1.3.0...v1.4.0
github.com/grpc-ecosystem/grpc-gateway/v2 v2.16.0 v2.19.1 https://github.com/grpc-ecosystem/grpc-gateway/v2/compare/v2.16.0...v2.19.1
github.com/jonboulle/clockwork v0.2.2 v0.4.0 https://github.com/jonboulle/clockwork/compare/v0.2.2...v0.4.0
github.com/libopenstorage/openstorage v1.0.0 v9.4.47 https://github.com/libopenstorage/openstorage/compare/v1.0.0...v9.4.47
github.com/moby/sys/mountinfo v0.6.2 v0.7.1 https://github.com/moby/sys/mountinfo/compare/v0.6.2...v0.7.1
github.com/moby/term 1aeaba878587 v0.5.0 https://github.com/moby/term/compare/1aeaba878587...v0.5.0
github.com/mohae/deepcopy 491d3605edfb c48cc78d4826 https://github.com/mohae/deepcopy/compare/491d3605edfb...c48cc78d4826
github.com/onsi/ginkgo/v2 v2.15.0 v2.17.3 https://github.com/onsi/ginkgo/v2/compare/v2.15.0...v2.17.3
github.com/onsi/gomega v1.31.0 v1.33.1 https://github.com/onsi/gomega/compare/v1.31.0...v1.33.1
github.com/opencontainers/runtime-spec 494a5a6aca78 v1.2.0 https://github.com/opencontainers/runtime-spec/compare/494a5a6aca78...v1.2.0
github.com/pquerna/cachecontrol v0.1.0 v0.2.0 https://github.com/pquerna/cachecontrol/compare/v0.1.0...v0.2.0
github.com/prometheus/client_model v0.6.0 v0.6.1 https://github.com/prometheus/client_model/compare/v0.6.0...v0.6.1
github.com/prometheus/common v0.48.0 v0.53.0 https://github.com/prometheus/common/compare/v0.48.0...v0.53.0
github.com/prometheus/procfs v0.12.0 v0.14.0 https://github.com/prometheus/procfs/compare/v0.12.0...v0.14.0
github.com/spf13/cobra v1.7.0 v1.8.0 https://github.com/spf13/cobra/compare/v1.7.0...v1.8.0
github.com/stoewer/go-strcase v1.2.0 v1.3.0 https://github.com/stoewer/go-strcase/compare/v1.2.0...v1.3.0
github.com/stretchr/testify v1.8.4 v1.9.0 https://github.com/stretchr/testify/compare/v1.8.4...v1.9.0
github.com/vishvananda/netlink v1.1.0 v1.2.1-beta.2 https://github.com/vishvananda/netlink/compare/v1.1.0...v1.2.1-beta.2
github.com/xiang90/probing 43a291ad63a2 a49e3df8f510 https://github.com/xiang90/probing/compare/43a291ad63a2...a49e3df8f510
go.etcd.io/bbolt v1.3.9 v1.3.10 https://go.etcd.io/bbolt/compare/v1.3.9...v1.3.10
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.42.0 v0.51.0 https://github.com/open-telemetry/opentelemetry-go-contrib/compare/instrumentation/github.com/emicklei/go-restful/otelrestful/v0.42.0...instrumentation/github.com/emicklei/go-restful/otelrestful/v0.51.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0 v0.51.0 https://github.com/open-telemetry/opentelemetry-go-contrib/compare/instrumentation/google.golang.org/grpc/otelgrpc/v0.46.0...instrumentation/google.golang.org/grpc/otelgrpc/v0.51.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 v0.51.0 https://github.com/open-telemetry/opentelemetry-go-contrib/compare/instrumentation/net/http/otelhttp/v0.44.0...instrumentation/net/http/otelhttp/v0.51.0
go.opentelemetry.io/otel v1.20.0 v1.26.0 https://github.com/open-telemetry/opentelemetry-go/compare/v1.20.0...v1.26.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.20.0 v1.26.0 https://github.com/open-telemetry/opentelemetry-go/compare/exporters/otlp/otlptrace/v1.20.0...exporters/otlp/otlptrace/v1.26.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.20.0 v1.26.0 https://github.com/open-telemetry/opentelemetry-go/compare/exporters/otlp/otlptrace/otlptracegrpc/v1.20.0...exporters/otlp/otlptrace/otlptracegrpc/v1.26.0
go.opentelemetry.io/otel/metric v1.20.0 v1.26.0 https://github.com/open-telemetry/opentelemetry-go/compare/metric/v1.20.0...metric/v1.26.0
go.opentelemetry.io/otel/sdk v1.20.0 v1.26.0 https://github.com/open-telemetry/opentelemetry-go/compare/sdk/v1.20.0...sdk/v1.26.0
go.opentelemetry.io/otel/trace v1.20.0 v1.26.0 https://github.com/open-telemetry/opentelemetry-go/compare/trace/v1.20.0...trace/v1.26.0
go.opentelemetry.io/proto/otlp v1.0.0 v1.2.0 https://github.com/open-telemetry/opentelemetry-proto-go/compare/otlp/v1.0.0...otlp/v1.2.0
go.starlark.net a134d8f9ddca 35fe9f26b4bc https://github.com/google/starlark-go/compare/a134d8f9ddca...35fe9f26b4bc
go.uber.org/zap v1.26.0 v1.27.0 https://github.com/uber-go/zap/compare/v1.26.0...v1.27.0
golang.org/x/crypto v0.21.0 v0.23.0 https://github.com/golang/crypto/compare/v0.21.0...v0.23.0
golang.org/x/exp f3d0a9c9a5cc 9bf2ced13842 https://github.com/golang/exp/compare/f3d0a9c9a5cc...9bf2ced13842
golang.org/x/mod v0.15.0 v0.17.0 https://github.com/golang/mod/compare/v0.15.0...v0.17.0
golang.org/x/net v0.23.0 v0.25.0 https://github.com/golang/net/compare/v0.23.0...v0.25.0
golang.org/x/sync v0.6.0 v0.7.0 https://github.com/golang/sync/compare/v0.6.0...v0.7.0
golang.org/x/sys v0.18.0 v0.20.0 https://github.com/golang/sys/compare/v0.18.0...v0.20.0
golang.org/x/term v0.18.0 v0.20.0 https://github.com/golang/term/compare/v0.18.0...v0.20.0
golang.org/x/text v0.14.0 v0.15.0 https://github.com/golang/text/compare/v0.14.0...v0.15.0
golang.org/x/time v0.3.0 v0.5.0 https://github.com/golang/time/compare/v0.3.0...v0.5.0
golang.org/x/tools v0.18.0 v0.21.0 https://github.com/golang/tools/compare/v0.18.0...v0.21.0
google.golang.org/genproto b8732ec3820d b8a5c65736ae https://github.com/googleapis/go-genproto/compare/b8732ec3820d...b8a5c65736ae
google.golang.org/genproto/googleapis/api b8732ec3820d b8a5c65736ae https://github.com/googleapis/go-genproto/compare/b8732ec3820d...b8a5c65736ae
google.golang.org/genproto/googleapis/rpc b8732ec3820d b8a5c65736ae https://github.com/googleapis/go-genproto/compare/b8732ec3820d...b8a5c65736ae
google.golang.org/grpc v1.59.0 v1.63.2 https://github.com/protocolbuffers/protobuf-go/compare/v1.59.0...v1.63.2
google.golang.org/protobuf v1.33.0 v1.34.1 https://github.com/protocolbuffers/protobuf-go/compare/v1.33.0...v1.34.1
#!/usr/bin/python
import json
import subprocess
import logging
import os
def get_dependencies():
dependencies = {}
f = subprocess.Popen('go mod edit -json', stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
(stdout, stderr) = f.communicate()
if stderr:
logging.fatal(stderr)
data = json.loads(stdout)
for dep in data["Require"]:
if dep['Path'].startswith("k8s.io/") != -1:
dependencies[dep['Path']] = dep['Version']
return dependencies
def sanitize(param):
# v0.0.0-20190331200053-3d26580ed485
if param.count('-') == 2:
return param.split('-')[-1]
# v11.1.2+incompatible
if param.count('+') == 1:
return param.split('+')[0]
return param
def source(pkg, old, new):
if pkg.startswith("cloud.google.com/go"):
return "github.com/googleapis/google-cloud-go", old, new
elif pkg.startswith("golang.org/x/"):
return "github.com/golang" + pkg[len("golang.org/x"):], old, new
elif pkg.startswith("go.uber.org/"):
return "github.com/uber-go" + pkg[len("go.uber.org"):], old, new
elif pkg.startswith("go.starlark.net"):
return "github.com/google/starlark-go", old, new
elif pkg.startswith("gopkg.in"):
repo = pkg.split('/', 1)[1] # get the last part of `gopkg.in/gcfg.v1` which is `gcfg.v1`
repo = repo.split('.', 1)[0] # get the part before the `.` which is `gcfg`
# we could end up with `gcfg` or `square/go-jose` here, deal with them separately
if '/' not in repo:
repo = "github.com/go-" + repo + "/" + repo
else:
repo = "github.com/" + repo
return repo, old, new
elif pkg.startswith("google.golang.org"):
array = pkg.split('/', 2)
if array[1] == "api":
repo = "github.com/googleapis/google-api-go-client"
elif array[1] == "genproto":
repo = "github.com/googleapis/go-genproto"
else: # repo = "protobuf"
repo = "github.com/protocolbuffers/protobuf-go"
return repo, old, new
elif pkg.startswith("go.opentelemetry.io/"):
array = pkg.split('/', 2)
if array[1] == "contrib":
repo = "github.com/open-telemetry/opentelemetry-go-contrib"
elif array[1] == "proto":
repo = "github.com/open-telemetry/opentelemetry-proto-go"
else: # repo = "otel"
repo = "github.com/open-telemetry/opentelemetry-go"
if len(array) > 2:
path = array[2] + "/"
else:
path = ""
return repo, path + old, path + new
return pkg, old, new
def main():
cleanup_command = """git reset --hard HEAD"""
print(">>>> Running command %r" % cleanup_command)
os.system(cleanup_command)
print(">>>> parsing go.mod before updates")
before = get_dependencies()
print("Found %d packages before updating dependencies" % len(before.values()))
update_command = """\
go mod edit -json | jq -r ".Require[] | .Path | select(contains(\\"k8s.io/\\") | not)" | xargs -L1 go get -d\
"""
print(">>>> Running command %r" % update_command)
os.system(update_command)
print(">>>> parsing go.mod after updates")
after = get_dependencies()
print("Found %d packages after updating dependencies" % len(before.values()))
print(">>>> Packages that got dropped %r" % (list(set(before.keys()) - set(after.keys()))))
print(">>>> Packages that were added %r" % (list(set(after.keys()) - set(before.keys()))))
print(">>>>> Mark down of differences <<<<")
print("Package | Current | Latest | URL")
print("------------ | ------------- | ------------- |------------- ")
for pkg in sorted(before.keys()):
if pkg.startswith("k8s.io"):
continue
old = sanitize(before[pkg])
if pkg not in after:
print("~%s~ | %s | Dropped | NONE" % (pkg, old))
continue
new = sanitize(after[pkg])
repo, oldtag, newtag = source(pkg, old, new)
if old != new:
print("%s | %s | %s | https://%s/compare/%s...%s " % (pkg, old, new, repo, oldtag, newtag))
else:
print("~%s~ | %s | %s | No changes" % (pkg, old, new))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment