mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-28 14:07:14 +00:00
Merge pull request #75928 from falcon78921/wip-k8s-cleanup
hack: refactored code in update_owners.py
This commit is contained in:
commit
3b9c761212
50
hack/update_owners.py
Executable file → Normal file
50
hack/update_owners.py
Executable file → Normal file
@ -14,22 +14,23 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License.
|
# limitations under the License.
|
||||||
|
|
||||||
|
|
||||||
import argparse
|
import argparse
|
||||||
import collections
|
import collections
|
||||||
import csv
|
import csv
|
||||||
import json
|
import json
|
||||||
import os
|
import pathlib
|
||||||
import random
|
import random
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import urllib2
|
import urllib.request
|
||||||
import zlib
|
import zlib
|
||||||
|
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
OWNERS_PATH = os.path.abspath(
|
BASE_DIR = pathlib.Path(__file__).resolve()
|
||||||
os.path.join(BASE_DIR, '..', 'test', 'test_owners.csv'))
|
OWNERS_PATH = str(BASE_DIR.parents[1] / 'test')
|
||||||
OWNERS_JSON_PATH = OWNERS_PATH.replace('.csv', '.json')
|
OWNERS_JSON_PATH = OWNERS_PATH.replace('.csv', '.json')
|
||||||
GCS_URL_BASE = 'https://storage.googleapis.com/kubernetes-test-history/'
|
GCS_URL_BASE = 'https://storage.googleapis.com/kubernetes-test-history/'
|
||||||
SKIP_MAINTAINERS = {
|
SKIP_MAINTAINERS = {
|
||||||
@ -46,7 +47,7 @@ def normalize(name):
|
|||||||
def get_test_history(days_ago):
|
def get_test_history(days_ago):
|
||||||
url = time.strftime(GCS_URL_BASE + 'logs/%Y-%m-%d.json',
|
url = time.strftime(GCS_URL_BASE + 'logs/%Y-%m-%d.json',
|
||||||
time.gmtime(time.time() - days_ago * 24 * 60 * 60))
|
time.gmtime(time.time() - days_ago * 24 * 60 * 60))
|
||||||
resp = urllib2.urlopen(url)
|
resp = urllib.request.urlopen(url)
|
||||||
content = resp.read()
|
content = resp.read()
|
||||||
if resp.headers.get('content-encoding') == 'gzip':
|
if resp.headers.get('content-encoding') == 'gzip':
|
||||||
content = zlib.decompress(content, 15 | 16)
|
content = zlib.decompress(content, 15 | 16)
|
||||||
@ -62,7 +63,7 @@ def get_test_names_from_test_history():
|
|||||||
|
|
||||||
|
|
||||||
def get_test_names_from_local_files():
|
def get_test_names_from_local_files():
|
||||||
tests_json = subprocess.check_output(['go', 'run', 'test/list/main.go', '-json'])
|
tests_json = subprocess.check_output(['go', 'run', '../test/list/main.go', '-json'])
|
||||||
tests = json.loads(tests_json)
|
tests = json.loads(tests_json)
|
||||||
return {normalize(t['Name'] + (' ' + t['TestName'] if 'k8s.io/' not in t['Name'] else ''))
|
return {normalize(t['Name'] + (' ' + t['TestName'] if 'k8s.io/' not in t['Name'] else ''))
|
||||||
for t in tests}
|
for t in tests}
|
||||||
@ -70,7 +71,7 @@ def get_test_names_from_local_files():
|
|||||||
|
|
||||||
def load_owners(fname):
|
def load_owners(fname):
|
||||||
owners = {}
|
owners = {}
|
||||||
with open(fname) as f:
|
with pathlib.Path.open(fname) as f:
|
||||||
for n, cols in enumerate(csv.reader(f)):
|
for n, cols in enumerate(csv.reader(f)):
|
||||||
if n == 0:
|
if n == 0:
|
||||||
continue # header
|
continue # header
|
||||||
@ -84,7 +85,7 @@ def load_owners(fname):
|
|||||||
|
|
||||||
|
|
||||||
def write_owners(fname, owners):
|
def write_owners(fname, owners):
|
||||||
with open(fname, 'w') as f:
|
with pathlib.Path.open(fname, 'w') as f:
|
||||||
out = csv.writer(f, lineterminator='\n')
|
out = csv.writer(f, lineterminator='\n')
|
||||||
out.writerow(['name', 'owner', 'auto-assigned', 'sig'])
|
out.writerow(['name', 'owner', 'auto-assigned', 'sig'])
|
||||||
items = sorted(owners.items())
|
items = sorted(owners.items())
|
||||||
@ -93,7 +94,7 @@ def write_owners(fname, owners):
|
|||||||
|
|
||||||
|
|
||||||
def get_maintainers():
|
def get_maintainers():
|
||||||
# Github doesn't seem to support team membership listing without a key with
|
# GitHub doesn't seem to support team membership listing without a key with
|
||||||
# org admin privileges. Instead, we do it manually:
|
# org admin privileges. Instead, we do it manually:
|
||||||
# Open https://github.com/orgs/kubernetes/teams/kubernetes-maintainers
|
# Open https://github.com/orgs/kubernetes/teams/kubernetes-maintainers
|
||||||
# Run this in the js console:
|
# Run this in the js console:
|
||||||
@ -174,28 +175,26 @@ def main():
|
|||||||
|
|
||||||
prefixes = sig_prefixes(owners)
|
prefixes = sig_prefixes(owners)
|
||||||
|
|
||||||
with open(OWNERS_JSON_PATH, 'w') as f:
|
with pathlib.Path.open(OWNERS_JSON_PATH, 'w') as f:
|
||||||
f.write(prefixes + '\n')
|
f.write(prefixes + '\n')
|
||||||
|
|
||||||
if options.print_sig_prefixes:
|
if options.print_sig_prefixes:
|
||||||
print prefixes
|
print(prefixes)
|
||||||
return
|
|
||||||
|
|
||||||
outdated_tests = sorted(set(owners) - set(test_names))
|
outdated_tests = sorted(set(owners) - set(test_names))
|
||||||
new_tests = sorted(set(test_names) - set(owners))
|
new_tests = sorted(set(test_names) - set(owners))
|
||||||
maintainers = get_maintainers()
|
maintainers = get_maintainers()
|
||||||
|
|
||||||
print '# OUTDATED TESTS (%d):' % len(outdated_tests)
|
print('# OUTDATED TESTS (%d):' % len(outdated_tests))
|
||||||
print '\n'.join('%s -- %s%s' %
|
print('\n'.join('%s -- %s%s' %
|
||||||
(t, owners[t][0], ['', ' (random)'][owners[t][1]])
|
(t, owners[t][0], ['', ' (random)'][owners[t][1]])
|
||||||
for t in outdated_tests)
|
for t in outdated_tests))
|
||||||
print '# NEW TESTS (%d):' % len(new_tests)
|
print('# NEW TESTS (%d):' % len(new_tests))
|
||||||
print '\n'.join(new_tests)
|
print('\n'.join(new_tests))
|
||||||
|
|
||||||
if options.check:
|
if options.check:
|
||||||
if new_tests or outdated_tests:
|
if new_tests or outdated_tests:
|
||||||
print
|
print('ERROR: The test list has changed')
|
||||||
print 'ERROR: the test list has changed'
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
@ -206,13 +205,12 @@ def main():
|
|||||||
owners.pop(name)
|
owners.pop(name)
|
||||||
|
|
||||||
if not options.addonly:
|
if not options.addonly:
|
||||||
print '# UNEXPECTED MAINTAINERS ',
|
print('# UNEXPECTED MAINTAINERS ',)
|
||||||
print '(randomly assigned, but not in kubernetes-maintainers)'
|
print('(randomly assigned, but not in kubernetes-maintainers)')
|
||||||
for name, (owner, random_assignment, _) in sorted(owners.iteritems()):
|
for name, (owner, random_assignment, _) in sorted(owners.iteritems()):
|
||||||
if random_assignment and owner not in maintainers:
|
if random_assignment and owner not in maintainers:
|
||||||
print '%-16s %s' % (owner, name)
|
print('%-16s %s', (owner, name))
|
||||||
owners.pop(name)
|
owners.pop(name)
|
||||||
print
|
|
||||||
|
|
||||||
owner_counts = collections.Counter(
|
owner_counts = collections.Counter(
|
||||||
owner for name, (owner, random, sig) in owners.iteritems()
|
owner for name, (owner, random, sig) in owners.iteritems()
|
||||||
@ -228,9 +226,9 @@ def main():
|
|||||||
owners[test_name] = (new_owner, random_assignment, "")
|
owners[test_name] = (new_owner, random_assignment, "")
|
||||||
|
|
||||||
if options.user.lower() == 'random':
|
if options.user.lower() == 'random':
|
||||||
print '# Tests per maintainer:'
|
print('# Tests per maintainer:')
|
||||||
for owner, count in owner_counts.most_common():
|
for owner, count in owner_counts.most_common():
|
||||||
print '%-20s %3d' % (owner, count)
|
print('%-20s %3d', (owner, count))
|
||||||
|
|
||||||
write_owners(OWNERS_PATH, owners)
|
write_owners(OWNERS_PATH, owners)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user