Generated on Sep 19, 2025
Last active
September 19, 2025 11:40
-
-
Save dims/c0857b86441442b15852a4c2355db130 to your computer and use it in GitHub Desktop.
[DEPRECATED] Python script to compute updates to the Kubernetes go.mod to see how far we are behind latest in vendored repos (please look in artifacts generated in this job - https://testgrid.k8s.io/sig-arch-code-organization#unit-master-dependencies&width=20)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| please check the markdown in https://gist.githubusercontent.com/dims/c0857b86441442b15852a4c2355db130/raw/b4fa76d27f13a959a01be98f0d2645d65abcac10/differences.md | |
| this has the differences between the current dependency versions of different packages we have in this (and directories recursively under this) and the newest versions available. | |
| please make a through analysis (3-4 pages) of each dependency. compare what we have and what is available. consult the changelog, check their websites, look at the code differences, | |
| use whatever tools you have possible to find out how urgently we have to update to the newer packages and through discussion of what are the newer things available. | |
| please be as through as possible, use all tools at your disposal (check website, docs, github, changelogs everything you can think of!) |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This gist is deprecated! please see comment here - kubernetes/kubernetes#131839 (comment)