Skip to content

Instantly share code, notes, and snippets.

@dims
Last active November 5, 2024 01:27
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/Microsoft/hnslib v0.0.7 v0.0.15 https://github.com/Microsoft/hnslib/compare/v0.0.7...v0.0.15
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/asaskevich/govalidator f61b66f89f4a a9d515a09cc2 https://github.com/asaskevich/govalidator/compare/f61b66f89f4a...a9d515a09cc2
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/container-storage-interface/spec v1.9.0 v1.10.0 https://github.com/container-storage-interface/spec/compare/v1.9.0...v1.10.0
github.com/containerd/containerd/api v1.7.19 v1.8.0 https://github.com/containerd/containerd/api/compare/v1.7.19...v1.8.0
github.com/containerd/errdefs v0.1.0 v1.0.0 https://github.com/containerd/errdefs/compare/v0.1.0...v1.0.0
github.com/containerd/ttrpc v1.2.5 v1.2.6 https://github.com/containerd/ttrpc/compare/v1.2.5...v1.2.6
github.com/cpuguy83/go-md2man/v2 v2.0.4 v2.0.5 https://github.com/cpuguy83/go-md2man/v2/compare/v2.0.4...v2.0.5
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/fsnotify/fsnotify v1.7.0 v1.8.0 https://github.com/fsnotify/fsnotify/compare/v1.7.0...v1.8.0
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/jsonreference v0.20.2 v0.21.0 https://github.com/go-openapi/jsonreference/compare/v0.20.2...v0.21.0
github.com/golang-jwt/jwt/v4 v4.5.0 v4.5.1 https://github.com/golang-jwt/jwt/v4/compare/v4.5.0...v4.5.1
github.com/google/btree v1.0.1 v1.1.3 https://github.com/google/btree/compare/v1.0.1...v1.1.3
github.com/gorilla/websocket v1.5.0 v1.5.3 https://github.com/gorilla/websocket/compare/v1.5.0...v1.5.3
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.20.0 v2.23.0 https://github.com/grpc-ecosystem/grpc-gateway/v2/compare/v2.20.0...v2.23.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/opencontainers/selinux v1.11.0 v1.11.1 https://github.com/opencontainers/selinux/compare/v1.11.0...v1.11.1
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_golang v1.19.1 v1.20.5 https://github.com/prometheus/client_golang/compare/v1.19.1...v1.20.5
github.com/prometheus/common v0.55.0 v0.60.1 https://github.com/prometheus/common/compare/v0.55.0...v0.60.1
go.opentelemetry.io/contrib/instrumentation/github.com/emicklei/go-restful/otelrestful v0.42.0 v0.56.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.56.0
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.53.0 v0.56.0 https://github.com/open-telemetry/opentelemetry-go-contrib/compare/instrumentation/google.golang.org/grpc/otelgrpc/v0.53.0...instrumentation/google.golang.org/grpc/otelgrpc/v0.56.0
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.53.0 v0.56.0 https://github.com/open-telemetry/opentelemetry-go-contrib/compare/instrumentation/net/http/otelhttp/v0.53.0...instrumentation/net/http/otelhttp/v0.56.0
go.opentelemetry.io/otel v1.28.0 v1.31.0 https://github.com/open-telemetry/opentelemetry-go/compare/v1.28.0...v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.28.0 v1.31.0 https://github.com/open-telemetry/opentelemetry-go/compare/exporters/otlp/otlptrace/v1.28.0...exporters/otlp/otlptrace/v1.31.0
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.27.0 v1.31.0 https://github.com/open-telemetry/opentelemetry-go/compare/exporters/otlp/otlptrace/otlptracegrpc/v1.27.0...exporters/otlp/otlptrace/otlptracegrpc/v1.31.0
go.opentelemetry.io/otel/metric v1.28.0 v1.31.0 https://github.com/open-telemetry/opentelemetry-go/compare/metric/v1.28.0...metric/v1.31.0
go.opentelemetry.io/otel/sdk v1.28.0 v1.31.0 https://github.com/open-telemetry/opentelemetry-go/compare/sdk/v1.28.0...sdk/v1.31.0
go.opentelemetry.io/otel/trace v1.28.0 v1.31.0 https://github.com/open-telemetry/opentelemetry-go/compare/trace/v1.28.0...trace/v1.31.0
golang.org/x/exp 8a7402abbf56 f66d83c29e7c https://github.com/golang/exp/compare/8a7402abbf56...f66d83c29e7c
google.golang.org/genproto ef4313101c80 dd2ea8efbc28 https://github.com/googleapis/go-genproto/compare/ef4313101c80...dd2ea8efbc28
google.golang.org/genproto/googleapis/api 531527333157 dd2ea8efbc28 https://github.com/googleapis/go-genproto/compare/531527333157...dd2ea8efbc28
google.golang.org/genproto/googleapis/rpc f6361c86f094 dd2ea8efbc28 https://github.com/googleapis/go-genproto/compare/f6361c86f094...dd2ea8efbc28
google.golang.org/grpc v1.65.0 v1.67.1 https://github.com/protocolbuffers/protobuf-go/compare/v1.65.0...v1.67.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