def ensure_helm_setup(): """Ensure up-to-date helm installation. Return the path to the found Helm executable""" # we currently have both helmV3 and helmV2 in our images. To keep it convenient for local # execution, try both try: helm_executable = which('helm3') except Failure: info("No executable 'helm3' found in path. Falling back to 'helm'") helm_executable = which('helm') with open(os.devnull) as devnull: subprocess.run([ helm_executable, 'repo', 'add', 'concourse', CONCOURSE_HELM_CHART_REPO ], check=True, stdout=devnull) subprocess.run( [helm_executable, 'repo', 'add', 'stable', STABLE_HELM_CHART_REPO], check=True, stdout=devnull) subprocess.run([helm_executable, 'repo', 'update'], check=True, stdout=devnull) return helm_executable
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 = which("helm") 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, "--purge"], 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_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.''' which("helm") 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 ensure_helm_setup(): """Ensure up-to-date helm installation. Return the path to the found Helm executable""" helm_executable = which('helm') with open(os.devnull) as devnull: subprocess.run([helm_executable, 'init', '--client-only'], check=True, stdout=devnull) subprocess.run([helm_executable, 'repo', 'update'], check=True, stdout=devnull) return helm_executable
def ensure_helm_setup(): """Ensure up-to-date helm installation. Return the path to the found Helm executable""" helm_executable = which('helm') with open(os.devnull) as devnull: subprocess.run([ helm_executable, 'repo', 'add', 'concourse', CONCOURSE_HELM_CHART_REPO ], check=True, stdout=devnull) subprocess.run([helm_executable, 'repo', 'update'], check=True, stdout=devnull) return helm_executable