示例#1
0
def stop(namespace, charts):
    pc = ProjectConf()
    helm = Helm()

    cr = ClusterRules(namespace=namespace)

    if charts is None:
        # Stop each of the project's charts
        charts = [
            os.path.basename(chart_path)
            for chart_path in pc.get_helm_chart_paths()
        ]

    sync_required = False
    try:
        for chart_path in pc.get_helm_chart_paths():
            chart_name = os.path.basename(chart_path)
            if chart_name in charts:
                hr = HelmRules(cr, chart_name)
                helm.stop(hr, namespace)
                sync_required = True
    finally:
        # Sync if any helm.stop() call succeeded, even if a subsequent one failed
        if sync_required:
            sync_ingress.sync_ingress(namespace)
            sync_dns.sync_dns(namespace)
示例#2
0
def rollback(project, num_versions, namespace, chart=None):
    helm = Helm()

    hr = HelmRules(ClusterRules(namespace=namespace), chart or project)

    helm.rollback_relative(hr, num_versions, namespace)

    sync_ingress.sync_ingress(namespace)
    sync_dns.sync_dns(namespace)
示例#3
0
def start(
    namespace,
    charts=None,
    dry_run=False,
    with_mount=False,
    force_helm=False,
    set_override_values=None,
):
    if set_override_values is None:
        set_override_values = []
    pc = ProjectConf()
    helm = Helm()

    cr = cluster_rules(namespace=namespace)

    if charts is None:
        # Start each of the project's charts
        charts = [os.path.basename(chart_path) for chart_path in pc.get_helm_chart_paths()]

    # Values precedence is command < cluster rules < --set-override-values
    # Start command values
    values = {
        "deploy.imageTag": "local",
        "deploy.mountPath": pc.mount_path,
        "deploy.namespace": namespace,
        "deploy.withMount": with_mount,
        "project.name": pc.name,
        "service.certificateArn": cr.service_certificate_arn,
        "service.certificateScope": cr.service_certificate_scope,
        "service.domainName": cr.service_domain_name_suffix,
        "service.clusterCertificateArn": cr.cluster_certificate_arn,
        "service.clusterCertificateScope": cr.cluster_certificate_scope,
        "service.clusterDomainName": cr.cluster_domain_name_suffix,
    }
    # Update with cluster rule values
    values.update(cr.values)
    # Update with --set-override-values
    value_overrides = {k: v for k, v in (value.split("=") for value in set_override_values)}
    values.update(value_overrides)

    sync_required = False
    try:
        for chart_path in pc.get_helm_chart_paths():
            chart_name = os.path.basename(chart_path)
            if chart_name in charts:
                hr = HelmRules(cr, chart_name)
                if dry_run:
                    helm.dry_run(hr, chart_path, cr.cluster_name, namespace, **values)
                else:
                    helm.start(hr, chart_path, cr.cluster_name, namespace, force_helm, **values)
                    sync_required = True
    finally:
        # Sync if any helm.start() call succeeded, even if a subsequent one failed
        if sync_required:
            sync_ingress.sync_ingress(namespace)
            sync_dns.sync_dns(namespace)
示例#4
0
def undeploy(project, namespace, chart=None):
    helm = Helm()

    cr = cluster_rules(namespace=namespace)
    hr = HelmRules(cr, chart or project)

    helm.stop(hr, namespace)

    sync_ingress.sync_ingress(namespace)
    sync_dns.sync_dns(namespace)
示例#5
0
def start(
    namespace,
    charts=None,
    dry_run=False,
    force_helm=False,
    set_override_values=None,
    values_files=None,
):
    if set_override_values is None:
        set_override_values = []
    pc = ProjectConf()
    helm = Helm()

    cr = ClusterRules(namespace=namespace)

    if not charts:
        # Start each of the project's charts
        charts = [
            os.path.basename(chart_path)
            for chart_path in pc.get_helm_chart_paths()
        ]

    # Values precedence is command < cluster rules < --set-override-values
    # Start command values
    values = {
        "deploy.imageTag": "local",
        "deploy.namespace": namespace,
        "project.name": pc.name,
        "service.certificateScope": cr.service_certificate_scope,
        "service.domainName": cr.service_domain_name_suffix,
        "service.clusterCertificateScope": cr.cluster_certificate_scope,
        "service.clusterDomainName": cr.cluster_domain_name_suffix,
        "service.clusterName": cr.cluster_domain_name,  # aka root_dns
    }
    if cr.certificate_lookup:
        values.update({
            "service.certificateArn":
            get_service_certificate_arn(),
            "service.clusterCertificateArn":
            get_cluster_certificate_arn(),
        })
    # Update with cluster rule values
    values.update(cr.values)
    helm_args = []
    # Update with --set-override-values
    values.update(dict(value.split("=") for value in set_override_values))

    sync_required = False
    try:
        for chart_path in pc.get_helm_chart_paths():
            chart_name = os.path.basename(chart_path)
            # Add user-specified values files
            if values_files:
                for file_path in values_files:
                    helm_args.append(
                        f"--values={os.path.join(chart_path, 'values', file_path)}"
                    )
            if chart_name in charts:
                hr = HelmRules(cr, chart_name)
                if dry_run:
                    helm.dry_run(hr,
                                 chart_path,
                                 cr.cluster_name,
                                 namespace,
                                 helm_args=helm_args,
                                 **values)
                else:
                    helm.start(hr,
                               chart_path,
                               cr.cluster_name,
                               namespace,
                               force=force_helm,
                               helm_args=helm_args,
                               **values)
                    sync_required = True
    finally:
        # Sync if any helm.start() call succeeded, even if a subsequent one failed
        if sync_required:
            sync_ingress.sync_ingress(namespace)
            sync_dns.sync_dns(namespace)
示例#6
0
def deploy(
    project,
    git_ref,
    namespace,
    chart=None,
    dry_run=False,
    force=False,
    force_helm=False,
    repo=None,
    set_override_values=None
):
    if set_override_values is None:
        set_override_values = []
    with tempfile.TemporaryDirectory() as tmpdirname:
        pr = PublishRules()
        helm = Helm()
        cr = cluster_rules(namespace=namespace)
        helm_chart_path = "{}/{}".format(tmpdirname, chart or project)
        hr = HelmRules(cr, chart or project)
        git_account = load_git_configs()["account"]
        repo = repo or project
        git_url = f"[email protected]:{git_account}/{repo}.git"
        git_ref = Git.extract_hash(git_ref, git_url)

        if not force and cr.check_branch and Git.extract_hash(cr.check_branch, git_url) != git_ref:
            logging.error(
                f"You are deploying hash {git_ref} which does not match branch"
                f" {cr.check_branch} on cluster {cr.cluster_name} for project"
                f" {project}... exiting"
            )
            sys.exit(1)

        helm.pull_packages(project, pr, git_ref, tmpdirname)

        # We need to use --set-string in case the git ref is all digits
        helm_args = ["--set-string", f"deploy.imageTag={git_ref}"]

        # Values precedence is command < cluster rules < --set-override-values
        # Deploy command values
        values = {
            "deploy.ecr": pr.docker_registry,
            "deploy.namespace": namespace,
            "project.name": project,
            "service.certificateArn": cr.service_certificate_arn,
            "service.certificateScope": cr.service_certificate_scope,
            "service.domainName": cr.service_domain_name_suffix,
            "service.clusterCertificateArn": cr.cluster_certificate_arn,
            "service.clusterCertificateScope": cr.cluster_certificate_scope,
            "service.clusterDomainName": cr.cluster_domain_name_suffix,
        }
        # Update with cluster rule values
        values.update(cr.values)
        # Update with --set-override-values
        value_overrides = {k: v for k, v in (value.split("=") for value in set_override_values)}
        values.update(value_overrides)

        if dry_run:
            helm.dry_run(
                hr,
                helm_chart_path,
                cr.cluster_name,
                namespace,
                helm_args=helm_args,
                **values
            )
        else:
            helm.start(
                hr,
                helm_chart_path,
                cr.cluster_name,
                namespace,
                force_helm,
                helm_args=helm_args,
                **values,
            )
            sync_ingress.sync_ingress(namespace)
            sync_dns.sync_dns(namespace)