コード例 #1
0
ファイル: store.py プロジェクト: vamsikavuru/polyaxon
def get_base_store_container(
    container: Optional[k8s_schemas.V1Container],
    container_name: str,
    polyaxon_init: V1PolyaxonInitContainer,
    store: V1ConnectionType,
    env: List[k8s_schemas.V1EnvVar],
    env_from: List[k8s_schemas.V1EnvFromSource],
    volume_mounts: List[k8s_schemas.V1VolumeMount],
    args: List[str],
    is_artifact_store: Optional[bool] = False,
) -> Optional[k8s_schemas.V1Container]:
    env = env or []
    env_from = env_from or []
    volume_mounts = volume_mounts or []

    # Artifact store needs to allow init the contexts as well, so the store is not required
    if not is_artifact_store and not store:
        raise PolypodException("Init store container requires a store")
    secret = None
    if store.is_bucket:
        if not is_artifact_store:
            secret = store.get_secret()
            volume_mounts = volume_mounts + to_list(
                get_mount_from_resource(resource=secret), check_none=True)
            env = env + to_list(get_items_from_secret(secret=secret),
                                check_none=True)
            env_from = env_from + to_list(get_env_from_secret(secret=secret),
                                          check_none=True)
            env += to_list(get_connection_env_var(connection=store,
                                                  secret=secret),
                           check_none=True)

            config_map = store.get_config_map()
            volume_mounts = volume_mounts + to_list(
                get_mount_from_resource(resource=config_map), check_none=True)
            env = env + to_list(
                get_items_from_config_map(config_map=config_map),
                check_none=True)
            env_from = env_from + to_list(
                get_env_from_config_map(config_map=config_map),
                check_none=True)
    else:
        volume_mounts = volume_mounts + to_list(
            get_mount_from_store(store=store), check_none=True)
        env += to_list(get_connection_env_var(connection=store, secret=secret),
                       check_none=True)

    return patch_container(
        container=container,
        name=container_name,
        image=polyaxon_init.get_image(),
        image_pull_policy=polyaxon_init.image_pull_policy,
        command=["/bin/sh", "-c"],
        args=args,
        env=env,
        env_from=env_from,
        resources=polyaxon_init.get_resources(),
        volume_mounts=volume_mounts,
    )
コード例 #2
0
ファイル: custom.py プロジェクト: vishalbelsare/polyaxon
def get_custom_init_container(
    connection: V1ConnectionType,
    contexts: PluginsContextsSpec,
    container: Optional[k8s_schemas.V1Container],
    env: List[k8s_schemas.V1EnvVar] = None,
    mount_path: str = None,
) -> k8s_schemas.V1Container:
    if not connection:
        raise PolypodException(
            "A connection is required to create a repo context.")

    volume_name = (get_volume_name(mount_path)
                   if mount_path else constants.CONTEXT_VOLUME_ARTIFACTS)
    mount_path = mount_path or CONTEXT_MOUNT_ARTIFACTS
    volume_mounts = [
        get_connections_context_mount(name=volume_name, mount_path=mount_path)
    ]

    if contexts and contexts.auth:
        volume_mounts.append(get_auth_context_mount(read_only=True))

    env = to_list(env, check_none=True)
    env_from = []
    secret = connection.get_secret()
    if secret:
        volume_mounts += to_list(get_mount_from_resource(resource=secret),
                                 check_none=True)
        env += to_list(get_items_from_secret(secret=secret), check_none=True)
        env_from = to_list(get_env_from_secret(secret=secret), check_none=True)
    env += to_list(get_connection_env_var(connection=connection,
                                          secret=secret),
                   check_none=True)
    config_map = connection.get_config_map()
    if config_map:
        volume_mounts += to_list(get_mount_from_resource(resource=config_map),
                                 check_none=True)
        env += to_list(get_items_from_config_map(config_map=config_map),
                       check_none=True)
        env_from = to_list(get_env_from_config_map(config_map=config_map),
                           check_none=True)
    container_name = container.name or generate_container_name(
        INIT_CUSTOM_CONTAINER_PREFIX, connection.name)
    return patch_container(
        container=container,
        name=container_name,
        env=env,
        env_from=env_from,
        volume_mounts=volume_mounts,
    )
コード例 #3
0
def get_sidecar_container(
    container_id: str,
    polyaxon_sidecar: V1PolyaxonSidecarContainer,
    env: List[k8s_schemas.V1EnvVar],
    artifacts_store: V1ConnectionType,
    contexts: PluginsContextsSpec,
    run_path: Optional[str],
) -> Optional[k8s_schemas.V1Container]:

    if artifacts_store and not contexts:
        raise PolypodException(
            "Logs/artifacts store was passed and contexts was not passed.")

    has_artifacts = artifacts_store and contexts.collect_artifacts
    has_logs = artifacts_store and contexts.collect_logs

    if not has_logs and not has_artifacts:
        # No sidecar
        return None

    if (has_artifacts or has_logs) and not run_path:
        raise PolypodException(
            "Logs store / outputs store must have a run_path.")

    env = get_sidecar_env_vars(
        env_vars=env,
        container_id=container_id,
        artifacts_store_name=artifacts_store.name,
    )

    volume_mounts = get_mounts(
        use_auth_context=contexts.auth,
        use_artifacts_context=has_artifacts,
        use_docker_context=False,
        use_shm_context=False,
    )

    sidecar_args = get_sidecar_args(
        container_id=container_id,
        sleep_interval=polyaxon_sidecar.sleep_interval,
        sync_interval=polyaxon_sidecar.sync_interval,
    )

    env_from = []

    secret = None
    if artifacts_store.is_bucket:
        secret = artifacts_store.get_secret()
        volume_mounts += to_list(get_mount_from_resource(resource=secret),
                                 check_none=True)
        env += to_list(get_items_from_secret(secret=secret), check_none=True)
        env_from += to_list(get_env_from_secret(secret=secret),
                            check_none=True)

        config_map = artifacts_store.get_config_map()
        volume_mounts += to_list(get_mount_from_resource(resource=config_map),
                                 check_none=True)
        env += to_list(get_items_from_config_map(config_map=config_map),
                       check_none=True)
        env_from += to_list(get_env_from_config_map(config_map=config_map),
                            check_none=True)
    else:
        volume_mounts += to_list(get_mount_from_store(store=artifacts_store),
                                 check_none=True)
    env += to_list(
        get_connection_env_var(connection=artifacts_store, secret=secret),
        check_none=True,
    )

    return k8s_schemas.V1Container(
        name=SIDECAR_CONTAINER,
        image=polyaxon_sidecar.get_image(),
        image_pull_policy=polyaxon_sidecar.image_pull_policy,
        command=["/bin/bash", "-c"],
        args=[sidecar_args],
        env=env,
        env_from=env_from,
        resources=polyaxon_sidecar.get_resources(),
        volume_mounts=volume_mounts,
    )
コード例 #4
0
def get_git_init_container(
    polyaxon_init: V1PolyaxonInitContainer,
    connection: V1ConnectionType,
    contexts: PluginsContextsSpec,
    container: Optional[k8s_schemas.V1Container] = None,
    env: List[k8s_schemas.V1EnvVar] = None,
    mount_path: str = None,
    track: bool = False,
) -> k8s_schemas.V1Container:
    if not connection:
        raise PolypodException(
            "A connection is required to create a repo context.")
    if not container:
        container = k8s_schemas.V1Container(name=generate_container_name(
            INIT_GIT_CONTAINER_PREFIX, connection.name), )

    volume_name = (get_volume_name(mount_path)
                   if mount_path else constants.CONTEXT_VOLUME_ARTIFACTS)
    mount_path = mount_path or CONTEXT_MOUNT_ARTIFACTS
    volume_mounts = [
        get_connections_context_mount(name=volume_name, mount_path=mount_path)
    ]

    if contexts and contexts.auth:
        volume_mounts.append(get_auth_context_mount(read_only=True))

    env = to_list(env, check_none=True)
    env_from = []
    secret = connection.get_secret()
    if secret:
        volume_mounts += to_list(get_mount_from_resource(resource=secret),
                                 check_none=True)
        env += to_list(get_items_from_secret(secret=secret), check_none=True)
        env_from = to_list(get_env_from_secret(secret=secret), check_none=True)
    env += to_list(get_connection_env_var(connection=connection,
                                          secret=secret),
                   check_none=True)
    config_map = connection.get_config_map()
    if config_map:
        volume_mounts += to_list(get_mount_from_resource(resource=config_map),
                                 check_none=True)
        env += to_list(get_items_from_config_map(config_map=config_map),
                       check_none=True)
        env_from = to_list(get_env_from_config_map(config_map=config_map),
                           check_none=True)
    args = get_repo_context_args(
        name=connection.name,
        url=connection.schema.url,
        revision=connection.schema.revision,
        mount_path=mount_path,
        connection=connection.name if track else None,
    )
    return patch_container(
        container=container,
        name=generate_container_name(INIT_GIT_CONTAINER_PREFIX,
                                     connection.name),
        image=polyaxon_init.get_image(),
        image_pull_policy=polyaxon_init.image_pull_policy,
        command=["polyaxon", "initializer", "git"],
        args=args,
        env=env,
        env_from=env_from,
        volume_mounts=volume_mounts,
        resources=polyaxon_init.get_resources(),
    )