示例#1
0
 def test_get_base_container(self):
     store = V1ConnectionType(
         name="test_claim",
         kind=V1ConnectionKind.VOLUME_CLAIM,
         schema=V1ClaimConnection(mount_path="/tmp",
                                  volume_claim="test",
                                  read_only=True),
     )
     env = [get_env_var(name="key", value="value")]
     env_from = [k8s_schemas.V1EnvFromSource(secret_ref={"name": "ref"})]
     mounts = [k8s_schemas.V1VolumeMount(name="test", mount_path="/test")]
     container = get_base_store_container(
         container=k8s_schemas.V1Container(name="init"),
         container_name="init",
         polyaxon_init=V1PolyaxonInitContainer(
             image="foo/foo",
             image_tag="",
             image_pull_policy="IfNotPresent"),
         store=store,
         env=env,
         env_from=env_from,
         volume_mounts=mounts,
         args=["test"],
     )
     assert container.name == "init"
     assert container.image == "foo/foo"
     assert container.image_pull_policy == "IfNotPresent"
     assert container.command == ["/bin/sh", "-c"]
     assert container.args == ["test"]
     assert container.env == env
     assert container.env_from == env_from
     assert container.resources is not None
     assert container.volume_mounts == mounts + [
         get_mount_from_store(store=store)
     ]
示例#2
0
文件: mounts.py 项目: zhaohb/polyaxon
def get_mount_from_resource(
    resource: V1K8sResourceType, ) -> Optional[k8s_schemas.V1VolumeMount]:
    if not resource or not resource.schema.mount_path:
        return None

    return k8s_schemas.V1VolumeMount(name=resource.name,
                                     mount_path=resource.schema.mount_path,
                                     read_only=True)
示例#3
0
文件: mounts.py 项目: zhaohb/polyaxon
def get_shm_context_mount() -> k8s_schemas.V1VolumeMount:
    """
    Mount an tmpfs volume to /dev/shm.
    This will set /dev/shm size to half of the RAM of node.
    By default, /dev/shm is very small, only 64MB.
    Some experiments will fail due to lack of share memory,
    such as some experiments running on Pytorch.
    """
    return k8s_schemas.V1VolumeMount(name=constants.CONTEXT_VOLUME_SHM,
                                     mount_path=CONTEXT_MOUNT_SHM)
示例#4
0
文件: mounts.py 项目: zhaohb/polyaxon
def get_mount_from_store(
    store: V1ConnectionType, ) -> Optional[k8s_schemas.V1VolumeMount]:
    if not store or not store.is_mount:
        return None

    return k8s_schemas.V1VolumeMount(
        name=store.name,
        mount_path=store.schema.mount_path,
        read_only=store.schema.read_only,
    )
    def test_get_main_container_simple_params(self):
        initial_mounts = [
            k8s_schemas.V1VolumeMount(name="test",
                                      mount_path="/mount_test",
                                      read_only=True)
        ]
        resources = k8s_schemas.V1ResourceRequirements(
            requests={
                "cpu": "1",
                "memory": "256Mi"
            },
            limits={
                "cpu": "1",
                "memory": "256Mi"
            },
        )
        container = get_main_container(
            container_id="new-name",
            main_container=k8s_schemas.V1Container(
                name="main",
                image="job_docker_image",
                image_pull_policy="IfNotPresent",
                command=["cmd", "-p", "-c"],
                args=["arg1", "arg2"],
                resources=resources,
            ),
            contexts=None,
            volume_mounts=initial_mounts,
            log_level="info",
            artifacts_store=None,
            init=None,
            connection_by_names=None,
            connections=None,
            secrets=None,
            config_maps=None,
            kv_env_vars=None,
            env=None,
            ports=23,
            run_path=None,
        )

        assert container.name == "new-name"
        assert container.image == "job_docker_image"
        assert container.image_pull_policy == "IfNotPresent"
        assert container.command == ["cmd", "-p", "-c"]
        assert container.args == ["arg1", "arg2"]
        assert container.ports == [
            k8s_schemas.V1ContainerPort(container_port=23)
        ]
        assert container.env == [
            get_env_var(name=POLYAXON_KEYS_LOG_LEVEL, value="info")
        ]
        assert container.env_from == []
        assert container.resources == resources
        assert container.volume_mounts == initial_mounts
示例#6
0
文件: mounts.py 项目: zhaohb/polyaxon
def get_connections_context_mount(
        name: str, mount_path: str) -> k8s_schemas.V1VolumeMount:
    return k8s_schemas.V1VolumeMount(name=name, mount_path=mount_path)
示例#7
0
文件: mounts.py 项目: zhaohb/polyaxon
def get_artifacts_context_mount(read_only=None) -> k8s_schemas.V1VolumeMount:
    return k8s_schemas.V1VolumeMount(
        name=constants.CONTEXT_VOLUME_ARTIFACTS,
        mount_path=CONTEXT_MOUNT_ARTIFACTS,
        read_only=read_only,
    )
示例#8
0
文件: mounts.py 项目: zhaohb/polyaxon
def get_auth_context_mount(read_only=None) -> k8s_schemas.V1VolumeMount:
    return k8s_schemas.V1VolumeMount(
        name=constants.CONTEXT_VOLUME_CONFIGS,
        mount_path=CONTEXT_MOUNT_CONFIGS,
        read_only=read_only,
    )
示例#9
0
文件: mounts.py 项目: zhaohb/polyaxon
def get_docker_context_mount() -> k8s_schemas.V1VolumeMount:
    return k8s_schemas.V1VolumeMount(name=constants.CONTEXT_VOLUME_DOCKER,
                                     mount_path=CONTEXT_MOUNT_DOCKER)