-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
update_config.py
executable file
·68 lines (55 loc) · 2.52 KB
/
update_config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/env python
# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Updates the Gubernator configuration from the Prow configuration."""
import argparse
import os
import yaml
def main(prow_config, prow_job_config, gubernator_config):
configs = [prow_config]
for root, _, files in os.walk(prow_job_config):
for name in files:
if name.endswith('.yaml'):
configs.append(os.path.join(root, name))
print(configs) # pylint: disable=superfluous-parens
default_presubmits = set()
periodic_names = set()
for config in configs:
prow_data = yaml.safe_load(open(config))
if not prow_data:
continue
if 'presubmits' in prow_data and 'kubernetes/kubernetes' in prow_data['presubmits']:
for job in prow_data['presubmits']['kubernetes/kubernetes']:
if job.get('always_run'):
default_presubmits.add(job['name'])
if 'periodics' in prow_data:
for job in prow_data['periodics']:
periodic_names.add(job['name'])
gubernator_data = yaml.safe_load(open(gubernator_config))
gubernator_data['jobs']['kubernetes-jenkins/pr-logs/directory/'] = sorted(
default_presubmits)
gubernator_data['jobs']['kubernetes-jenkins/logs/'] = sorted(
job for job in gubernator_data['jobs']['kubernetes-jenkins/logs/']
if job in periodic_names
)
with open(gubernator_config, 'w+') as gubernator_file:
yaml.dump(gubernator_data, gubernator_file, default_flow_style=False,
explicit_start=True)
if __name__ == '__main__':
PARSER = argparse.ArgumentParser()
PARSER.add_argument('prow_config', help="Path to Prow configuration YAML.")
PARSER.add_argument('prow_job_config', help="Path to Prow jobs configuration YAMLs.")
PARSER.add_argument('gubernator_config', help="Path to Gubernator configuration YAML.")
ARGS = PARSER.parse_args()
main(ARGS.prow_config, ARGS.prow_job_config, ARGS.gubernator_config)