Example #1
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)
Example #2
0
def rollback(project, num_versions, namespace, chart=None):
    helm = Helm()

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

    helm.rollback_relative(hr, num_versions)

    sync_ingress.sync_ingress(namespace)
    sync_dns.sync_dns(namespace)
Example #3
0
def undeploy(project, namespace):
    helm = Helm()

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

    helm.stop(hr)

    sync_ingress.sync_ingress(namespace)
    sync_dns.sync_dns(namespace)
Example #4
0
def stop(namespace):
    pc = ProjectConf()
    helm = Helm()

    cr = cluster_rules(namespace=namespace)
    hr = HelmRules(cr, pc.name)

    helm.stop(hr)

    sync_ingress.sync_ingress(namespace)
    sync_dns.sync_dns(namespace)
Example #5
0
def stop(namespace, charts):
    pc = ProjectConf()
    helm = Helm()

    cr = cluster_rules(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)
                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)
Example #6
0
def start(namespace,
          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)
    hr = HelmRules(cr, pc.name)

    # Values precedence is command < cluster rules < --set-override-values
    # Start command values
    values = {
        "deploy.withMount": with_mount,
        "deploy.mountPath": pc.mount_path,
        "deploy.imageTag": "local",
    }
    # 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, pc.helm_path, cr.cluster_name, namespace, **values)
    else:
        helm.start(hr, pc.helm_path, cr.cluster_name, namespace, force_helm,
                   **values)
        sync_ingress.sync_ingress(namespace)
        sync_dns.sync_dns(namespace)
Example #7
0
def deploy(
    project,
    git_ref,
    namespace,
    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_path = "{}/{}".format(tmpdirname, project)
        hr = HelmRules(cr, 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_package(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 = {
            "service.certificateArn": cr.get_certificate_arn(),
            "deploy.ecr": pr.docker_registry,
        }
        # 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_path,
                         cr.cluster_name,
                         namespace,
                         helm_args=helm_args,
                         **values)
        else:
            helm.start(hr,
                       helm_path,
                       cr.cluster_name,
                       namespace,
                       force_helm,
                       helm_args=helm_args,
                       **values)
            sync_ingress.sync_ingress(namespace)
            sync_dns.sync_dns(namespace)