def deploy(
    plugin_id: str,
    context: "Context",
    team_context: "TeamContext",
    parameters: Dict[str, Any],
) -> None:
    _logger.debug("Team Env name: %s | Team name: %s", context.name,
                  team_context.name)
    plugin_id = plugin_id.replace("_", "-")
    _logger.debug("plugin_id: %s", plugin_id)
    release_name = f"{team_context.name}-{plugin_id}"

    _logger.info("Checking Chart %s is installed...", release_name)
    fresh_install = True
    if helm.is_exists_chart_release(release_name, team_context.name):
        _logger.info(
            "Chart %s already installed, removing to begin new install",
            release_name)

    vars: Dict[str, Optional[str]] = dict(
        team=team_context.name,
        region=context.region,
        account_id=context.account_id,
        env_name=context.name,
        plugin_id=plugin_id,
    )

    chart_path = helm.create_team_charts_copy(team_context=team_context,
                                              path=CHART_PATHS,
                                              target_path=plugin_id)
    _logger.debug("package dir")
    utils.print_dir(CHART_PATHS)
    _logger.debug("copy chart dir")
    utils.print_dir(chart_path)

    repo_location = team_context.team_helm_repository
    repo = team_context.name
    helm.add_repo(repo=repo, repo_location=repo_location)
    chart_name, chart_version, chart_package = helm.package_chart(
        repo=repo, chart_path=chart_path, values=vars)

    _logger.info("Chart %s installing ", release_name)
    helm.install_chart(
        repo=repo,
        namespace=team_context.name,
        name=release_name,
        chart_name=chart_name,
        chart_version=chart_version,
    )

    chart_name, chart_version, chart_package = helm.package_chart(
        repo=repo, chart_path=chart_path, values=vars)
    _logger.info(
        f"Sagemaker Operator Helm Chart {chart_name}@{chart_version} installed for {team_context.name} at {chart_package}"
    )
def deploy(
    plugin_id: str,
    context: "Context",
    team_context: "TeamContext",
    parameters: Dict[str, Any],
) -> None:
    _logger.debug("Team Env name: %s | Team name: %s", context.name,
                  team_context.name)
    plugin_id = plugin_id.replace("_", "-")
    _logger.debug("plugin_id: %s", plugin_id)
    chart_path = helm.create_team_charts_copy(team_context=team_context,
                                              path=CHART_PATH,
                                              target_path=plugin_id)
    containers = parameters["replicas"] if "replicas" in parameters else 1
    del parameters["replicas"]
    if "cpu" not in parameters:
        parameters["cpu"] = "1"

    if "node_group" not in parameters:
        raise Exception(
            f"The parameter 'node_group' is missing for {plugin_id}...please add it"
        )

    node_group = parameters["node_group"]
    del parameters["node_group"]

    resources = {"resources": parameters}

    _logger.info(
        f"overprovisioning installed with {containers} containers of resources:  {resources}."
    )

    vars: Dict[str, Optional[str]] = dict(
        team=team_context.name,
        region=context.region,
        account_id=context.account_id,
        env_name=context.name,
        restart_policy=parameters["restartPolicy"]
        if "restartPolicy" in parameters else "Never",
        plugin_id=plugin_id,
        containers=containers,
        resources=yaml.dump(resources),
        toolkit_s3_bucket=context.toolkit.s3_bucket,
        node_group=node_group,
    )

    repo = team_context.name
    chart_name, chart_version, chart_package = helm.package_chart(
        repo=repo, chart_path=chart_path, values=vars)
    helm.install_chart(
        repo=repo,
        namespace=team_context.name,
        name=f"{team_context.name}-{plugin_id}",
        chart_name=chart_name,
        chart_version=chart_version,
    )
예제 #3
0
def deploy(plugin_id: str, context: "Context", team_context: "TeamContext",
           parameters: Dict[str, Any]) -> None:
    _logger.debug("Team Env name: %s | Team name: %s", context.name,
                  team_context.name)
    plugin_id = plugin_id.replace("_", "-")
    _logger.debug("plugin_id: %s", plugin_id)
    chart_path = helm.create_team_charts_copy(team_context=team_context,
                                              path=CHART_PATH)
    _logger.debug("package dir")
    utils.print_dir(CHART_PATH)
    _logger.debug("copy chart dir")
    utils.print_dir(chart_path)
    vars: Dict[str, Optional[str]] = dict(
        team=team_context.name,
        region=context.region,
        account_id=context.account_id,
        env_name=context.name,
        tag=context.images.jupyter_hub.version,
        restart_policy=parameters["restartPolicy"]
        if "restartPolicy" in parameters else "Never",
        plugin_id=plugin_id,
        toolkit_s3_bucket=context.toolkit.s3_bucket,
        image_pull_policy="Always"
        if aws_orbit.__version__.endswith(".dev0") else "IfNotPresent",
    )

    if "script" in parameters:
        script_body = parameters["script"]
    else:
        raise Exception(f"Plugin {plugin_id} must define parameter 'script'")
    script_file = os.path.join(chart_path, "script.txt")

    script_body = utils.resolve_parameters(script_body, vars)
    with open(script_file, "w") as file:
        file.write(script_body)

    repo_location = helm.init_team_repo(context=context,
                                        team_context=team_context)
    repo = team_context.name
    _logger.debug(script_body)
    helm.add_repo(repo=repo, repo_location=repo_location)
    chart_name, chart_version, chart_package = helm.package_chart(
        repo=repo, chart_path=chart_path, values=vars)
    helm.install_chart(
        repo=repo,
        namespace=team_context.name,
        name=f"{team_context.name}-{plugin_id}",
        chart_name=chart_name,
        chart_version=chart_version,
    )
def deploy(
    plugin_id: str,
    context: "Context",
    team_context: "TeamContext",
    parameters: Dict[str, Any],
) -> None:
    _logger.debug("Team Env name: %s | Team name: %s", context.name,
                  team_context.name)
    plugin_id = plugin_id.replace("_", "-")
    _logger.debug("plugin_id: %s", plugin_id)
    chart_path = helm.create_team_charts_copy(team_context=team_context,
                                              path=CHART_PATH,
                                              target_path=plugin_id)

    vars: Dict[str, Optional[str]] = dict(
        team=team_context.name,
        region=context.region,
        account_id=context.account_id,
        env_name=context.name,
        restart_policy=parameters["restartPolicy"]
        if "restartPolicy" in parameters else "Always",
        path=parameters["path"]
        if "path" in parameters else "/home/jovyan/shared/voila",
        options=parameters["options"] if "options" in parameters else "",
        plugin_id=plugin_id,
        toolkit_s3_bucket=context.toolkit.s3_bucket,
        image_pull_policy="Always"
        if aws_orbit.__version__.endswith(".dev0") else "IfNotPresent",
        image=parameters["image"]
        if "image" in parameters else team_context.final_image_address,
        sts_ep="legacy"
        if context.networking.data.internet_accessible else "regional",
    )

    repo_location = team_context.team_helm_repository
    if repo_location:
        repo = team_context.name
        helm.add_repo(repo=repo, repo_location=repo_location)
        chart_name, chart_version, chart_package = helm.package_chart(
            repo=repo, chart_path=chart_path, values=vars)
        helm.install_chart(
            repo=repo,
            namespace=team_context.name,
            name=f"{team_context.name}-{plugin_id}",
            chart_name=chart_name,
            chart_version=chart_version,
        )
예제 #5
0
def deploy(plugin_id: str, context: "Context", team_context: "TeamContext",
           parameters: Dict[str, Any]) -> None:
    _logger.debug("Team Env name: %s | Team name: %s", context.name,
                  team_context.name)
    plugin_id = plugin_id.replace("_", "-")
    _logger.debug("plugin_id: %s", plugin_id)
    chart_path = helm.create_team_charts_copy(team_context=team_context,
                                              path=CHART_PATH)
    workers = parameters["workers"] if "workers" in parameters else "3"
    release_tag = parameters[
        "release_tag"] if "release_tag" in parameters else "latest"

    _logger.info(
        f"Ray cluster installed with {workers} workers , version {release_tag}."
    )

    vars: Dict[str, Optional[str]] = dict(
        team=team_context.name,
        region=context.region,
        account_id=context.account_id,
        env_name=context.name,
        restart_policy=parameters["restartPolicy"]
        if "restartPolicy" in parameters else "Never",
        plugin_id=plugin_id,
        workers=workers,
        release_tag=release_tag,
        toolkit_s3_bucket=context.toolkit.s3_bucket,
        image_pull_policy="Always"
        if aws_orbit.__version__.endswith(".dev0") else "IfNotPresent",
    )

    repo_location = helm.init_team_repo(context=context,
                                        team_context=team_context)
    repo = team_context.name
    helm.add_repo(repo=repo, repo_location=repo_location)
    chart_name, chart_version, chart_package = helm.package_chart(
        repo=repo, chart_path=chart_path, values=vars)
    helm.install_chart(
        repo=repo,
        namespace=team_context.name,
        name=f"{team_context.name}-{plugin_id}",
        chart_name=chart_name,
        chart_version=chart_version,
    )
def deploy(
    plugin_id: str,
    context: "Context",
    team_context: "TeamContext",
    parameters: Dict[str, Any],
) -> None:
    _logger.debug("Team Env name: %s | Team name: %s", context.name,
                  team_context.name)
    plugin_id = plugin_id.replace("_", "-")
    _logger.debug("plugin_id: %s", plugin_id)
    release_name = f"{team_context.name}-{plugin_id}"
    _logger.info("Checking Chart %s is installed...", release_name)

    fs_name = f"lustre-{team_context.name}-fs-{plugin_id}"

    vars: Dict[str, Optional[str]] = dict(
        team=team_context.name,
        region=context.region,
        account_id=context.account_id,
        env_name=context.name,
        plugin_id=plugin_id,
        deploymentType="SCRATCH_2",
        sg=team_context.team_security_group_id,
        subnet=context.networking.data.nodes_subnets[0],
        s3importpath=
        f"s3://{team_context.scratch_bucket}/{team_context.name}/lustre",
        s3exportpath=
        f"s3://{team_context.scratch_bucket}/{team_context.name}/lustre",
        storage=parameters["storage"] if "storage" in parameters else "1200Gi",
        folder=parameters["folder"] if "folder" in parameters else "data",
        k8s_utilities_image=
        f"{context.images.k8s_utilities.repository}:{context.images.k8s_utilities.version}",
        fs_name=fs_name,
    )

    if not helm.is_exists_chart_release(release_name, team_context.name):
        _logger.info("Chart %s already installed, skipping installation",
                     release_name)

        ec2.authorize_security_group_ingress(
            group_id=cast(str, team_context.team_security_group_id),
            ip_permissions=[
                IpPermission(
                    from_port=988,
                    to_port=988,
                    ip_protocol="tcp",
                    user_id_group_pairs=[
                        UserIdGroupPair(
                            description="All from Cluster",
                            group_id=cast(str, context.cluster_sg_id),
                        )
                    ],
                )
            ],
        )

        chart_path = helm.create_team_charts_copy(team_context=team_context,
                                                  path=TEAM_CHARTS_PATH,
                                                  target_path=plugin_id)
        _logger.debug("package dir")
        utils.print_dir(TEAM_CHARTS_PATH)
        _logger.debug("copy chart dir")
        utils.print_dir(chart_path)

        if not team_context.team_helm_repository:
            raise Exception("Missing team helm repository")

        repo_location = team_context.team_helm_repository

        repo = team_context.name
        helm.add_repo(repo=repo, repo_location=repo_location)
        chart_name, chart_version, chart_package = helm.package_chart(
            repo=repo,
            chart_path=os.path.join(chart_path, "fsx-storageclass"),
            values=vars)
        helm.install_chart_no_upgrade(
            repo=repo,
            namespace=team_context.name,
            name=release_name,
            chart_name=chart_name,
            chart_version=chart_version,
        )

    get_user_pv(fs_name, plugin_id, context, team_context, vars)

    # install this package at the user helm repository such that its installed on every user space
    chart_path = helm.create_team_charts_copy(team_context=team_context,
                                              path=USER_CHARTS_PATH,
                                              target_path=plugin_id)

    if not team_context.user_helm_repository:
        raise Exception("Missing user helm repository")
    user_location = team_context.user_helm_repository

    user_repo = team_context.name + "--user"
    helm.add_repo(repo=user_repo, repo_location=user_location)

    chart_name, chart_version, chart_package = helm.package_chart(
        repo=user_repo,
        chart_path=os.path.join(chart_path, "fsx-filesystem"),
        values=vars)
    _logger.info(
        f"Lustre Helm Chart {chart_name}@{chart_version} installed for {team_context.name} at {chart_package}"
    )
예제 #7
0
def deploy(plugin_id: str, context: "Context", team_context: "TeamContext",
           parameters: Dict[str, Any]) -> None:
    _logger.debug("Team Env name: %s | Team name: %s", context.name,
                  team_context.name)
    plugin_id = plugin_id.replace("_", "-")
    _logger.debug("plugin_id: %s", plugin_id)
    release_name = f"{team_context.name}-{plugin_id}"
    _logger.info("Checking Chart %s is installed...", release_name)
    if helm.is_exists_chart_release(release_name, team_context.name):
        _logger.info("Chart %s already installed, skipping installation",
                     release_name)
        return
    try:
        sh.run(
            f"kubectl delete sc fsx-lustre-{team_context.name}-fast-fs-lustre")
    except Exception as e:
        _logger.error(
            f"Deleting prior sc 'fsx-lustre-{team_context.name}-fast-fs-lustre' failed with:%s",
            str(e))

    vars: Dict[str, Optional[str]] = dict(
        team=team_context.name,
        region=context.region,
        account_id=context.account_id,
        env_name=context.name,
        plugin_id=plugin_id,
        deploymentType="SCRATCH_2",
        sg=team_context.team_security_group_id,
        subnet=context.networking.data.nodes_subnets[0],
        s3importpath=
        f"s3://{team_context.scratch_bucket}/{team_context.name}/lustre",
        s3exportpath=
        f"s3://{team_context.scratch_bucket}/{team_context.name}/lustre",
    )

    ec2.authorize_security_group_ingress(
        group_id=cast(str, team_context.team_security_group_id),
        ip_permissions=[
            IpPermission(
                from_port=988,
                to_port=988,
                ip_protocol="tcp",
                user_id_group_pairs=[
                    UserIdGroupPair(description="All from Cluster",
                                    group_id=cast(str, context.cluster_sg_id))
                ],
            )
        ],
    )

    chart_path = helm.create_team_charts_copy(team_context=team_context,
                                              path=CHARTS_PATH)
    _logger.debug("package dir")
    utils.print_dir(CHARTS_PATH)
    _logger.debug("copy chart dir")
    utils.print_dir(chart_path)

    repo_location = helm.init_team_repo(context=context,
                                        team_context=team_context)
    repo = team_context.name
    helm.add_repo(repo=repo, repo_location=repo_location)
    chart_name, chart_version, chart_package = helm.package_chart(
        repo=repo,
        chart_path=os.path.join(chart_path, "fsx_storageclass"),
        values=vars)
    helm.install_chart_no_upgrade(
        repo=repo,
        namespace=team_context.name,
        name=release_name,
        chart_name=chart_name,
        chart_version=chart_version,
    )

    chart_name, chart_version, chart_package = helm.package_chart(
        repo=repo,
        chart_path=os.path.join(chart_path, "fsx_filesystem"),
        values=vars)
    _logger.info(
        f"Lustre Helm Chart {chart_name}@{chart_version} installed for {team_context.name} at {chart_package}"
    )
def helm_package(plugin_id: str, context: "Context",
                 team_context: "TeamContext",
                 parameters: Dict[str, Any]) -> Tuple[str, str, str]:
    chart_path = helm.create_team_charts_copy(team_context=team_context,
                                              path=CHART_PATH,
                                              target_path=plugin_id)
    _logger.debug("copy chart dir")
    utils.print_dir(chart_path)
    if "image" not in parameters:
        image = f"{context.images.jupyter_user.repository}:{context.images.jupyter_user.version}"
    elif "aws-orbit-workbench/utility-data" in parameters["image"]:
        image = f"{context.images.utility_data.repository}:{context.images.utility_data.version}"
    else:
        image = parameters["image"]

    _logger.debug(f"For plugin {plugin_id} using image: {image}")

    vars: Dict[str, Optional[str]] = dict(
        team=team_context.name,
        region=context.region,
        account_id=context.account_id,
        env_name=context.name,
        tag=parameters["tag"]
        if "tag" in parameters else context.images.jupyter_user.version,
        restart_policy=parameters["restartPolicy"]
        if "restartPolicy" in parameters else "Never",
        plugin_id=plugin_id,
        toolkit_s3_bucket=context.toolkit.s3_bucket,
        image_pull_policy="Always"
        if aws_orbit.__version__.endswith(".dev0") else "IfNotPresent",
        image=image,
        uid=parameters["uid"] if "uid" in parameters else "1000",
        gid=parameters["gid"] if "gid" in parameters else "100",
    )

    if "script" in parameters:
        script_body = parameters["script"]
    else:
        raise Exception(f"Plugin {plugin_id} must define parameter 'script'")
    script_file = os.path.join(chart_path, "team-script-launcher",
                               "script.txt")

    script_body = utils.resolve_parameters(script_body, vars)
    with open(script_file, "w") as file:
        file.write(script_body)

    if not team_context.team_helm_repository:
        raise Exception("Missing team helm repository")

    repo_location = team_context.team_helm_repository
    repo = team_context.name
    _logger.debug(script_body)
    _init_team_repo(context=context,
                    team_context=team_context,
                    repo_location=repo_location)
    helm.add_repo(repo=repo, repo_location=repo_location)
    chart_name, chart_version, chart_package = helm.package_chart(
        repo=repo,
        chart_path=os.path.join(chart_path, "team-script-launcher"),
        values=vars)
    return (chart_name, chart_version, chart_package)