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