def deploy_or_upgrade_concourse( config_set_name: CliHint(typehint=str, help=CONFIG_SET_HELP), deployment_name: CliHint(typehint=str, help="namespace and deployment name")='concourse', timeout_seconds: CliHint(typehint=int, help="how long to wait for concourse startup")=180, ): '''Deploys a new concourse-instance using the given deployment name and config-directory.''' ensure_helm_setup() cfg_factory = ctx().cfg_factory() config_set = cfg_factory.cfg_set(config_set_name) setup_concourse.deploy_concourse_landscape( config_set=config_set, deployment_name=deployment_name, timeout_seconds=timeout_seconds, )
def destroy_concourse_landscape(config_name: str, release_name: str): # Fetch concourse and kubernetes config config_factory = global_ctx().cfg_factory() config_set = config_factory.cfg_set(cfg_name=config_name) concourse_cfg = config_set.concourse() kubernetes_config_name = concourse_cfg.kubernetes_cluster_config() kubernetes_config = config_factory.kubernetes(kubernetes_config_name) context = kube_ctx context.set_kubecfg(kubernetes_config.kubeconfig()) # Delete helm release helm_cmd_path = ensure_helm_setup() KUBECONFIG_FILE_NAME = 'kubecfg' helm_env = os.environ.copy() helm_env['KUBECONFIG'] = KUBECONFIG_FILE_NAME with tempfile.TemporaryDirectory() as temp_dir: with open(os.path.join(temp_dir, KUBECONFIG_FILE_NAME), 'w') as f: yaml.dump(kubernetes_config.kubeconfig(), f) try: subprocess.run([helm_cmd_path, "delete", release_name], env=helm_env, check=True, cwd=temp_dir) except CalledProcessError: # ignore sporadic connection timeouts from infrastructure warning( "Connection to K8s cluster lost. Continue with deleting namespace {ns}" .format(ns=release_name)) # delete namespace namespace_helper = context.namespace_helper() namespace_helper.delete_namespace(namespace=release_name)
def deploy_concourse_landscape( config_set: ConfigurationSet, deployment_name: str = 'concourse', timeout_seconds: int = 180, ): ensure_helm_setup() # Fetch all the necessary config config_factory = global_ctx().cfg_factory() concourse_cfg = config_set.concourse() # Kubernetes cluster config kubernetes_config_name = concourse_cfg.kubernetes_cluster_config() kubernetes_config = config_factory.kubernetes(kubernetes_config_name) # Container-registry config image_pull_secret_name = concourse_cfg.image_pull_secret() container_registry = config_factory.container_registry( image_pull_secret_name) cr_credentials = container_registry.credentials() # Helm config helm_chart_default_values_name = concourse_cfg.helm_chart_default_values_config( ) default_helm_values = config_factory.concourse_helmchart( helm_chart_default_values_name).raw helm_chart_values_name = concourse_cfg.helm_chart_values() custom_helm_values = config_factory.concourse_helmchart( helm_chart_values_name).raw # Proxy config if concourse_cfg.proxy(): proxy_cfg_name = concourse_cfg.proxy() proxy_cfg = config_factory.proxy(proxy_cfg_name) info('Creating config-maps for the mitm proxy ...') create_proxy_configmaps( proxy_cfg=proxy_cfg, namespace=deployment_name, ) info('Creating default image-pull-secret ...') create_image_pull_secret( credentials=cr_credentials, image_pull_secret_name=image_pull_secret_name, namespace=deployment_name, ) warning( 'Teams will not be set up properly on Concourse if the deployment times out, ' 'even if Helm eventually succeeds. In this case, run the deployment command again after ' 'Concourse is available.') instance_specific_helm_values = create_instance_specific_helm_values( concourse_cfg=concourse_cfg, config_factory=config_factory, ) chart_version = concourse_cfg.helm_chart_version() # Add proxy sidecars to instance specific values. # NOTE: Only works for helm chart version 3.8.0 or greater if concourse_cfg.proxy(): chart_version_semver = version.parse_to_semver( concourse_cfg.helm_chart_version()) min_version = version.parse_to_semver('3.8.0') if chart_version_semver >= min_version: instance_specific_helm_values = add_proxy_values( config_set=config_set, instance_specific_values=instance_specific_helm_values, ) else: fail( 'Proxy deployment requires the configured helm chart version to be at least 3.8.0' ) execute_helm_deployment( kubernetes_config, deployment_name, 'concourse/concourse', deployment_name, default_helm_values, custom_helm_values, instance_specific_helm_values, chart_version=chart_version, ) info('Waiting until the webserver can be reached ...') deployment_helper = kube_ctx.deployment_helper() is_web_deployment_available = deployment_helper.wait_until_deployment_available( namespace=deployment_name, name='concourse-web', timeout_seconds=timeout_seconds, ) if not is_web_deployment_available: fail( dedent("""No Concourse webserver reachable after {t} second(s). Check status of Pods created by "concourse-web"-deployment in namespace {ns} """).format( t=timeout_seconds, ns=deployment_name, )) info('Webserver became accessible.') # Even though the deployment is available, the ingress might need a few seconds to update. time.sleep(3) info('Setting teams on Concourse ...') set_teams(config=concourse_cfg)
def deploy_concourse_landscape( config_name: str, deployment_name: str='concourse', timeout_seconds: int='180' ): not_empty(config_name) ensure_helm_setup() # Fetch all the necessary config config_factory = global_ctx().cfg_factory() config_set = config_factory.cfg_set(cfg_name=config_name) concourse_cfg = config_set.concourse() # Set the global context to the cluster specified in the ConcourseConfig kubernetes_config_name = concourse_cfg.kubernetes_cluster_config() kubernetes_config = config_factory.kubernetes(kubernetes_config_name) kube_ctx.set_kubecfg(kubernetes_config.kubeconfig()) ensure_cluster_version(kubernetes_config) # Container-registry config image_pull_secret_name = concourse_cfg.image_pull_secret() container_registry = config_factory.container_registry(image_pull_secret_name) cr_credentials = container_registry.credentials() # TLS config tls_config_name = concourse_cfg.tls_config() tls_config = config_factory.tls_config(tls_config_name) tls_secret_name = concourse_cfg.tls_secret_name() # Secrets server secrets_server_config = config_set.secrets_server() # Helm config helm_chart_default_values_name = concourse_cfg.helm_chart_default_values_config() default_helm_values = config_factory.concourse_helmchart(helm_chart_default_values_name).raw helm_chart_values_name = concourse_cfg.helm_chart_values() custom_helm_values = config_factory.concourse_helmchart(helm_chart_values_name).raw info('Creating default image-pull-secret ...') create_image_pull_secret( credentials=cr_credentials, image_pull_secret_name=image_pull_secret_name, namespace=deployment_name, ) info('Creating tls-secret ...') create_tls_secret( tls_config=tls_config, tls_secret_name=tls_secret_name, namespace=deployment_name, ) info('Deploying secrets-server ...') deploy_secrets_server( secrets_server_config=secrets_server_config, ) info('Deploying Concourse ...') warning( 'Teams will not be set up properly on Concourse if the deployment times out, ' 'even if Helm eventually succeeds. In this case, run the deployment command again after ' 'Concourse is available.' ) instance_specific_helm_values = create_instance_specific_helm_values( concourse_cfg=concourse_cfg, config_factory=config_factory, ) chart_version = concourse_cfg.helm_chart_version() execute_helm_deployment( kubernetes_config, deployment_name, 'stable/concourse', deployment_name, default_helm_values, custom_helm_values, instance_specific_helm_values, chart_version=chart_version, ) info('Waiting until the webserver can be reached ...') deployment_helper = kube_ctx.deployment_helper() is_web_deployment_available = deployment_helper.wait_until_deployment_available( namespace=deployment_name, name='concourse-web', timeout_seconds=timeout_seconds, ) if not is_web_deployment_available: fail( dedent( """No Concourse webserver reachable after {t} second(s). Check status of Pods created by "concourse-web"-deployment in namespace {ns} """ ).format( t = timeout_seconds, ns = deployment_name, ) ) info('Webserver became accessible.') # Even though the deployment is available, the ingress might need a few seconds to update. time.sleep(3) info('Setting teams on Concourse ...') set_teams(config=concourse_cfg)