Skip to content

Instantly share code, notes, and snippets.

@dims
Last active June 28, 2024 12:30
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.26 v0.12.4 https://github.com/Microsoft/hcsshim/compare/v0.8.26...v0.12.4
github.com/antlr4-go/antlr/v4 v4.13.0 v4.13.1 https://github.com/antlr4-go/antlr/v4/compare/v4.13.0...v4.13.1
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/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.5 https://github.com/containerd/ttrpc/compare/v1.2.2...v1.2.5
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.1 https://github.com/emicklei/go-restful/v3/compare/v3.11.0...v3.12.1
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-logr/logr v1.4.1 v1.4.2 https://github.com/go-logr/logr/compare/v1.4.1...v1.4.2
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.4 v0.23.0 https://github.com/go-openapi/swag/compare/v0.22.4...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 4bfdf5a9a2af 27f56978b8b0 https://github.com/google/pprof/compare/4bfdf5a9a2af...27f56978b8b0
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.3 https://github.com/gorilla/websocket/compare/v1.5.0...v1.5.3
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.20.0 https://github.com/grpc-ecosystem/grpc-gateway/v2/compare/v2.16.0...v2.20.0
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/mohae/deepcopy 491d3605edfb c48cc78d4826 https://github.com/mohae/deepcopy/compare/491d3605edfb...c48cc78d4826
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/stoewer/go-strcase v1.2.0 v1.3.0 https://github.com/stoewer/go-strcase/compare/v1.2.0...v1.3.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.etcd.io/etcd/client/v2 v2.305.13 v2.305.14 https://go.etcd.io/etcd/client/v2/compare/v2.305.13...v2.305.14
go.etcd.io/etcd/pkg/v3 v3.5.13 v3.5.14 https://go.etcd.io/etcd/pkg/v3/compare/v3.5.13...v3.5.14
go.etcd.io/etcd/raft/v3 v3.5.13 v3.5.14 https://go.etcd.io/etcd/raft/v3/compare/v3.5.13...v3.5.14
go.etcd.io/etcd/server/v3 v3.5.13 v3.5.14 https://go.etcd.io/etcd/server/v3/compare/v3.5.13...v3.5.14
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.42.0 v0.52.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.52.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.46.0 v0.52.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.52.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.44.0 v0.52.0 https://github.com/open-telemetry/opentelemetry-go-contrib/compare/instrumentation/net/http/otelhttp/v0.44.0...instrumentation/net/http/otelhttp/v0.52.0
go.opentelemetry.io/otel v1.20.0 v1.27.0 https://github.com/open-telemetry/opentelemetry-go/compare/v1.20.0...v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.20.0 v1.27.0 https://github.com/open-telemetry/opentelemetry-go/compare/exporters/otlp/otlptrace/v1.20.0...exporters/otlp/otlptrace/v1.27.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.20.0 v1.27.0 https://github.com/open-telemetry/opentelemetry-go/compare/exporters/otlp/otlptrace/otlptracegrpc/v1.20.0...exporters/otlp/otlptrace/otlptracegrpc/v1.27.0
go.opentelemetry.io/otel/metric v1.20.0 v1.27.0 https://github.com/open-telemetry/opentelemetry-go/compare/metric/v1.20.0...metric/v1.27.0
go.opentelemetry.io/otel/sdk v1.20.0 v1.27.0 https://github.com/open-telemetry/opentelemetry-go/compare/sdk/v1.20.0...sdk/v1.27.0
go.opentelemetry.io/otel/trace v1.20.0 v1.27.0 https://github.com/open-telemetry/opentelemetry-go/compare/trace/v1.20.0...trace/v1.27.0
go.opentelemetry.io/proto/otlp v1.0.0 v1.3.1 https://github.com/open-telemetry/opentelemetry-proto-go/compare/otlp/v1.0.0...otlp/v1.3.1
go.starlark.net a134d8f9ddca 046347dcd104 https://github.com/google/starlark-go/compare/a134d8f9ddca...046347dcd104
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/exp f3d0a9c9a5cc 7f521ea00fb8 https://github.com/golang/exp/compare/f3d0a9c9a5cc...7f521ea00fb8
golang.org/x/mod v0.17.0 v0.18.0 https://github.com/golang/mod/compare/v0.17.0...v0.18.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 e35e4ccd0d2d v0.22.0 https://github.com/golang/tools/compare/e35e4ccd0d2d...v0.22.0
google.golang.org/genproto b8732ec3820d dc46fd24d27d https://github.com/googleapis/go-genproto/compare/b8732ec3820d...dc46fd24d27d
google.golang.org/genproto/googleapis/api b8732ec3820d dc46fd24d27d https://github.com/googleapis/go-genproto/compare/b8732ec3820d...dc46fd24d27d
google.golang.org/genproto/googleapis/rpc b8732ec3820d dc46fd24d27d https://github.com/googleapis/go-genproto/compare/b8732ec3820d...dc46fd24d27d
google.golang.org/grpc v1.59.0 v1.64.0 https://github.com/protocolbuffers/protobuf-go/compare/v1.59.0...v1.64.0
#!/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