Example #1
0
    def test_get_artifacts_path_container_with_non_managed_mount_store(self):
        store = V1ConnectionType(
            name="test_gcs",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/claim/path",
                                     volume_claim="claim"),
        )
        container = get_artifacts_path_container(
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"),
            artifacts_store=store,
            run_path="run_uid",
            auto_resume=True,
        )

        init_args = init_artifact_context_args("run_uid")
        init_args.append(
            get_volume_args(
                store=store,
                mount_path=CONTEXT_MOUNT_ARTIFACTS,
                artifacts=V1ArtifactsType(dirs=["run_uid"]),
            ))

        assert container == get_base_store_container(
            container=k8s_schemas.V1Container(name="init"),
            container_name=generate_container_name(
                INIT_ARTIFACTS_CONTAINER_PREFIX, "default", False),
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"),
            store=store,
            env=[],
            env_from=[],
            volume_mounts=[get_artifacts_context_mount()],
            args=[" ".join(init_args)],
        )

        container = get_artifacts_path_container(
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"),
            artifacts_store=store,
            run_path="run_uid",
            auto_resume=False,
        )

        init_args = init_artifact_context_args("run_uid")
        assert container == get_base_store_container(
            container=k8s_schemas.V1Container(name="init"),
            container_name=generate_container_name(
                INIT_ARTIFACTS_CONTAINER_PREFIX, "default", False),
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"),
            store=store,
            env=[],
            env_from=[],
            volume_mounts=[get_artifacts_context_mount()],
            args=[" ".join(init_args)],
        )
Example #2
0
 def test_get_base_store_container_with_none_values(self):
     with self.assertRaises(PolypodException):
         get_base_store_container(
             container=k8s_schemas.V1Container(name="init"),
             container_name=None,
             polyaxon_init=V1PolyaxonInitContainer(),
             store=None,
             env=None,
             env_from=None,
             volume_mounts=None,
             args=None,
         )
Example #3
0
def get_artifacts_path_container(
    polyaxon_init: V1PolyaxonInitContainer,
    artifacts_store: V1ConnectionType,
    run_path: str,
    auto_resume: bool,
) -> Optional[k8s_schemas.V1Container]:
    if not artifacts_store:
        raise PolypodException("Init artifacts container requires a store.")

    init_args = init_artifact_context_args(run_path=run_path)
    if auto_resume:
        init_args.append(
            get_volume_args(
                store=artifacts_store,
                mount_path=CONTEXT_MOUNT_ARTIFACTS,
                artifacts=V1ArtifactsType(dirs=[run_path]),
            ))

    container_name = generate_container_name(INIT_ARTIFACTS_CONTAINER_PREFIX,
                                             DEFAULT)
    container = k8s_schemas.V1Container(name=container_name)

    return get_base_store_container(
        container_name=container_name,
        container=container,
        polyaxon_init=polyaxon_init,
        store=artifacts_store,
        env=[],
        env_from=[],
        volume_mounts=[get_artifacts_context_mount()],
        # If we are dealing with a volume we need to make sure the path exists for the user
        # We also clean the path if this is not a resume run
        args=[" ".join(init_args)],
    )
Example #4
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)
     ]
Example #5
0
    def test_get_base_store_container_with_mount_store(self):
        claim_store = V1ConnectionType(
            name="test_claim",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/tmp",
                                     volume_claim="test",
                                     read_only=True),
        )

        container = get_base_store_container(
            container=k8s_schemas.V1Container(name="init"),
            container_name="init",
            polyaxon_init=V1PolyaxonInitContainer(image_tag=""),
            store=claim_store,
            env=None,
            env_from=None,
            volume_mounts=None,
            args=None,
        )
        assert container.name == "init"
        assert container.image == "polyaxon/polyaxon-init"
        assert container.image_pull_policy is None
        assert container.command == ["/bin/sh", "-c"]
        assert container.args is None
        assert container.env == get_connection_env_var(connection=claim_store,
                                                       secret=None)
        assert container.env_from == []
        assert container.resources is not None
        assert container.volume_mounts == [
            get_mount_from_store(store=claim_store)
        ]
Example #6
0
    def test_get_base_store_container_with_store_without_secret(self):
        bucket_store_without_secret = V1ConnectionType(
            name="test_gcs",
            kind=V1ConnectionKind.GCS,
            schema=V1BucketConnection(bucket="gs//:foo"),
        )
        container = get_base_store_container(
            container=k8s_schemas.V1Container(name="test"),
            container_name="init",
            polyaxon_init=V1PolyaxonInitContainer(image_tag=""),
            store=bucket_store_without_secret,
            env=None,
            env_from=None,
            volume_mounts=None,
            args=None,
        )

        assert container.name == "init"
        assert container.image == "polyaxon/polyaxon-init"
        assert container.image_pull_policy is None
        assert container.command == ["/bin/sh", "-c"]
        assert container.args is None
        assert container.env == get_connection_env_var(
            connection=bucket_store_without_secret, secret=None)
        assert container.env_from == []
        assert container.resources is not None
        assert container.volume_mounts == []
    def test_get_artifacts_path_container_with_bucket_store(self):
        store = V1ConnectionType(
            name="test_gcs",
            kind=V1ConnectionKind.GCS,
            schema=V1BucketConnection(bucket="gs//:foo"),
        )
        container = get_artifacts_path_container(
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"),
            artifacts_store=store,
            run_path="run_uid",
            auto_resume=True,
        )

        init_args = init_artifact_context_args("run_uid")
        init_args.append(
            get_volume_args(
                store=store,
                mount_path=CONTEXT_MOUNT_ARTIFACTS,
                artifacts=V1ArtifactsType(dirs=["run_uid"]),
            ))

        assert container == get_base_store_container(
            container=k8s_schemas.V1Container(name="default"),
            container_name=INIT_ARTIFACTS_CONTAINER.format("default"),
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"),
            store=store,
            env=[],
            env_from=[],
            volume_mounts=[get_artifacts_context_mount()],
            args=[" ".join(init_args)],
        )
Example #8
0
def get_artifacts_path_container(
    polyaxon_init: V1PolyaxonInitContainer,
    artifacts_store: V1ConnectionType,
    run_path: str,
    clean: bool = True,
) -> Optional[k8s_schemas.V1Container]:
    if not artifacts_store:
        raise PolypodException("Init artifacts container requires a store.")

    init_args = init_artifact_context_args(run_path=run_path)
    if not artifacts_store.is_bucket:
        artifacts_path = get_path(artifacts_store.store_path, run_path)
        init_args.append(
            get_artifacts_store_args(artifacts_path=artifacts_path,
                                     clean=clean))

    container_name = INIT_ARTIFACTS_CONTAINER.format(DEFAULT)
    container = k8s_schemas.V1Container(name=container_name)

    return get_base_store_container(
        container_name=container_name,
        container=container,
        polyaxon_init=polyaxon_init,
        store=artifacts_store,
        env=[],
        env_from=[],
        volume_mounts=[get_artifacts_context_mount()],
        # If we are dealing with a volume we need to make sure the path exists for the user
        # We also clean the path if this is not a resume run
        args=[" ".join(init_args)],
        is_artifact_store=True,
    )
    def test_get_artifacts_path_container_with_managed_mount_store(self):
        store = V1ConnectionType(
            name="test_gcs",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(mount_path="/claim/path", volume_claim="claim"),
        )
        container = get_artifacts_path_container(
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"
            ),
            artifacts_store=store,
            run_path="run_uid",
            clean=True,
        )

        init_args = init_artifact_context_args("run_uid")
        init_args.append(
            get_artifacts_store_args(
                artifacts_path=get_path(store.store_path, "run_uid"), clean=True
            )
        )

        assert container == get_base_store_container(
            container=k8s_schemas.V1Container(name="default"),
            container_name=INIT_ARTIFACTS_CONTAINER.format("default"),
            polyaxon_init=V1PolyaxonInitContainer(
                image="init", image_pull_policy="IfNotPresent"
            ),
            store=store,
            env=[],
            env_from=[],
            volume_mounts=[get_artifacts_context_mount()],
            args=[" ".join(init_args)],
            is_artifact_store=True,
        )
Example #10
0
    def test_get_base_store_container_with_store_with_secret(self):
        non_mount_resource1 = V1K8sResourceType(
            name="resource",
            schema=V1K8sResourceSchema(name="ref", items=["item1", "item2"]),
            is_requested=False,
        )
        bucket_store_with_secret = V1ConnectionType(
            name="test_gcs",
            kind=V1ConnectionKind.GCS,
            schema=V1BucketConnection(bucket="gs//:foo"),
            secret=non_mount_resource1.schema,
        )
        container = get_base_store_container(
            container=k8s_schemas.V1Container(name="init"),
            container_name="init",
            polyaxon_init=V1PolyaxonInitContainer(image_tag=""),
            store=bucket_store_with_secret,
            env=None,
            env_from=None,
            volume_mounts=None,
            args=None,
        )
        assert container.name == "init"
        assert container.image == "polyaxon/polyaxon-init"
        assert container.image_pull_policy is None
        assert container.command == ["/bin/sh", "-c"]
        assert container.args is None
        env = get_items_from_secret(
            secret=non_mount_resource1) + get_connection_env_var(
                connection=bucket_store_with_secret,
                secret=non_mount_resource1)
        assert container.env == env
        assert container.env_from == []
        assert container.resources is not None
        assert container.volume_mounts == []

        mount_resource1 = V1K8sResourceType(
            name="resource",
            schema=V1K8sResourceSchema(name="resource",
                                       items=["item1", "item2"],
                                       mount_path="/tmp1"),
            is_requested=False,
        )
        bucket_store_with_secret.secret = mount_resource1.schema
        container = get_base_store_container(
            container=k8s_schemas.V1Container(name="init"),
            container_name="init",
            polyaxon_init=V1PolyaxonInitContainer(image_tag=""),
            store=bucket_store_with_secret,
            env=None,
            env_from=None,
            volume_mounts=None,
            args=None,
        )
        assert container.name == "init"
        assert container.image == "polyaxon/polyaxon-init"
        assert container.image_pull_policy is None
        assert container.command == ["/bin/sh", "-c"]
        assert container.args is None
        assert container.env == get_connection_env_var(
            connection=bucket_store_with_secret, secret=mount_resource1)
        assert container.env_from == []
        assert container.resources is not None
        assert container.volume_mounts == [
            get_mount_from_resource(resource=mount_resource1)
        ]