def deploy_or_upgrade_tekton_dashboard_ingress( config_set_name: CliHint(typehint=str, help=CONFIG_SET_HELP), tekton_chart_dir: CliHints.existing_dir(help="directory of tekton-dashboard-ingress chart"), oauth_proxy_chart_dir: CliHints.existing_dir(help="directory of oauth2-proxy chart"), deployment_name: str='tekton-dashboard-ingress', ): oauth2_proxy_chart_dir = os.path.abspath(oauth_proxy_chart_dir) tekton_chart_dir = os.path.abspath(tekton_chart_dir) cfg_factory = ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(config_set_name) oauth2_proxy_cfg = cfg_set.oauth2_proxy() tekton_dashboard_ingress_cfg = cfg_set.tekton_dashboard_ingress() setup_oauth2_proxy.deploy_oauth2_proxy( oauth2_proxy_config=oauth2_proxy_cfg, chart_dir=oauth2_proxy_chart_dir, deployment_name=f'{deployment_name}-oauth2-proxy', ) setup_tekton_dashboard_ingress.deploy_tekton_dashboard_ingress( tekton_dashboard_ingress_config=tekton_dashboard_ingress_cfg, chart_dir=tekton_chart_dir, deployment_name=deployment_name, )
def serialise_cfg( cfg_dir: CliHints.existing_dir(), cfg_sets: [str], out_file: str): factory = ConfigFactory.from_cfg_dir(cfg_dir=cfg_dir) cfg_sets = [factory.cfg_set(cfg_set) for cfg_set in cfg_sets] serialiser = CSS(cfg_sets=cfg_sets, cfg_factory=factory) with open(out_file, 'w') as f: f.write(serialiser.serialise())
def deploy_or_upgrade_tekton_dashboard_ingress( config_set_name: CliHint(typehint=str, help=CONFIG_SET_HELP), chart_dir: CliHints.existing_dir( help="directory of tekton-dashboard-ingress chart"), deployment_name: str = 'tekton-dashboard-ingress', ): chart_dir = os.path.abspath(chart_dir) cfg_factory = ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(config_set_name) concourse_cfg = cfg_set.concourse() kubernetes_cfg = cfg_factory.kubernetes( concourse_cfg.kubernetes_cluster_config()) oauth2_proxy_cfg = cfg_set.oauth2_proxy() tekton_dashboard_ingress_cfg = cfg_set.tekton_dashboard_ingress() setup_oauth2_proxy.deploy_oauth2_proxy( oauth2_proxy_config=oauth2_proxy_cfg, kubernetes_config=kubernetes_cfg, deployment_name=f'{deployment_name}-oauth2-proxy', ) setup_tekton_dashboard.deploy_tekton_dashboard_ingress( tekton_dashboard_ingress_config=tekton_dashboard_ingress_cfg, kubernetes_config=kubernetes_cfg, chart_dir=chart_dir, deployment_name=deployment_name, )
def render_pipeline( definition_file: CliHints.existing_file(), cfg_name: str, out_dir: CliHints.existing_dir(), repo_path: str = 'example/example', repo_branch: str = 'master', repo_host: str = 'github.com', template_path: str=_template_path(), template_include_dir: str=None, ): cfg_factory = ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(cfg_name=cfg_name) logger.info(f'Template path: {template_path}') repo_url = urllib.parse.urlunparse(('https', repo_host, repo_path, '', '', '')) try: job_mapping = cfg_set.job_mapping().job_mapping_for_repo_url(repo_url, cfg_set) secret_cfg = cfg_factory.secret(job_mapping.secret_cfg()) except ValueError as e: logger.warning(f'An error occurred: {e}. Will use dummy values to render pipeline.') job_mapping = None secret_cfg = None def_enumerators = [ SimpleFileDefinitionEnumerator( definition_file=definition_file, cfg_set=cfg_set, repo_path=repo_path, repo_branch=repo_branch, repo_host=repo_host, job_mapping=job_mapping, secret_cfg=secret_cfg, ) ] preprocessor = DefinitionDescriptorPreprocessor() if not template_include_dir: template_include_dir = template_path template_retriever = TemplateRetriever(template_path=template_path) renderer = Renderer( template_retriever=template_retriever, template_include_dir=template_include_dir, cfg_set=cfg_set, render_origin=RenderOrigin.LOCAL, ) deployer = FilesystemDeployer(base_dir=out_dir) replicator = PipelineReplicator( definition_enumerators=def_enumerators, descriptor_preprocessor=preprocessor, definition_renderer=renderer, definition_deployer=deployer ) replicator.replicate()
def serialise_cfg( cfg_dir: CliHints.existing_dir(), out_file: str, cfg_sets: [str] = []): factory = ConfigFactory.from_cfg_dir(cfg_dir=cfg_dir) if not cfg_sets: cfg_sets = factory._cfg_element_names('cfg_set') cfg_sets = [factory.cfg_set(cfg_set) for cfg_set in cfg_sets] serialiser = CSS(cfg_sets=cfg_sets, cfg_factory=factory) with open(out_file, 'w') as f: f.write(serialiser.serialise())
def render_pipeline( definition_file: CliHints.existing_file(), template_path: CliHints.existing_dir(), cfg_name: str, out_dir: CliHints.existing_dir(), template_include_dir: str = None, ): cfg_factory = ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(cfg_name=cfg_name) def_enumerators = [ SimpleFileDefinitionEnumerator( definition_file=definition_file, cfg_set=cfg_set, repo_path='example/example', repo_branch='master', repo_host='github.com', ) ] preprocessor = DefinitionDescriptorPreprocessor() if not template_include_dir: template_include_dir = template_path template_retriever = TemplateRetriever(template_path=template_path) renderer = Renderer( template_retriever=template_retriever, template_include_dir=template_include_dir, cfg_set=cfg_set, ) deployer = FilesystemDeployer(base_dir=out_dir) replicator = PipelineReplicator(definition_enumerators=def_enumerators, descriptor_preprocessor=preprocessor, definition_renderer=renderer, definition_deployer=deployer) replicator.replicate()
def deploy_or_upgrade_gardenlinux_cache( config_set_name: CliHint(typehint=str, help=CONFIG_SET_HELP), chart_dir: CliHints.existing_dir(help="directory of gardenlinux-cache chart"), deployment_name: str='gardenlinux-cache', ): chart_dir = os.path.abspath(chart_dir) cfg_factory = ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(config_set_name) gardenlinux_cache_cfg = cfg_set.gardenlinux_cache() setup_gardenlinux_cache.deploy_gardenlinux_cache( gardenlinux_cache_config=gardenlinux_cache_cfg, chart_dir=chart_dir, deployment_name=deployment_name, )
def deploy_or_upgrade_webhook_dispatcher( config_set_name: CliHint(typehint=str, help=CONFIG_SET_HELP), chart_dir: CliHints.existing_dir(help="directory of webhook dispatcher chart"), deployment_name: str='webhook-dispatcher', ): chart_dir = os.path.abspath(chart_dir) cfg_factory = ctx().cfg_factory() cfg_set = cfg_factory.cfg_set(config_set_name) webhook_dispatcher_deployment_cfg = cfg_set.webhook_dispatcher_deployment() setup_whd.deploy_webhook_dispatcher_landscape( cfg_set=cfg_set, webhook_dispatcher_deployment_cfg=webhook_dispatcher_deployment_cfg, chart_dir=chart_dir, deployment_name=deployment_name, )
def update_certificate( tls_config_name: CliHint(typehint=str, help="TLS config element name to update"), certificate_file: CliHints.existing_file(help="certificate file path"), key_file: CliHints.existing_file(help="private key file path"), output_path: CliHints.existing_dir( help="TLS config file output path")): # Stuff used for yaml formatting, when dumping a dictionary class LiteralStr(str): """Used to create yaml block style indicator | """ def literal_str_representer(dumper, data): """Used to create yaml block style indicator""" return dumper.represent_scalar('tag:yaml.org,2002:str', data, style='|') # read new certificate data certificate_file = os.path.abspath(certificate_file) private_key_file = os.path.abspath(key_file) with open(certificate_file) as f: certificate = f.read() with open(private_key_file) as f: private_key = f.read() # set new certificate data to specified argument 'tls_config_name' cfg_factory = ctx().cfg_factory() tls_config_element = cfg_factory.tls_config(tls_config_name) tls_config_element.set_private_key(private_key) tls_config_element.set_certificate(certificate) # patch tls config dict so that yaml.dump outputs literal strings using '|' yaml.add_representer(LiteralStr, literal_str_representer) configs = cfg_factory._configs('tls_config') for k1, v1 in configs.items(): for k2, _ in v1.items(): configs[k1][k2] = LiteralStr(configs[k1][k2]) # dump updated tls config to given output path tls_config_type = cfg_factory._cfg_types()['tls_config'] tls_config_file = list(tls_config_type.sources())[0].file() with open(os.path.join(output_path, tls_config_file), 'w') as f: yaml.dump(configs, f, indent=2, default_flow_style=False)