def test_get_sidecar_container_with_managed_bucket_outputs_logs_store_and_env_from( self, ): env_vars = [ get_env_var(name="key1", value="value1"), get_env_var(name="key2", value="value2"), ] resource1 = V1K8sResourceType(name="test1", schema=V1K8sResourceSchema(name="ref"), is_requested=False) bucket_managed_store = V1ConnectionType( name="test_gcs", kind=V1ConnectionKind.GCS, schema=V1BucketConnection(bucket="gs//:foo"), secret=resource1.schema, ) # both logs and outputs sidecar = get_sidecar_container( container_id=MAIN_JOB_CONTAINER, env=env_vars, polyaxon_sidecar=V1PolyaxonSidecarContainer( image="sidecar/sidecar", image_tag="", image_pull_policy="IfNotPresent", sleep_interval=213, sync_interval=212, ), artifacts_store=bucket_managed_store, contexts=PluginsContextsSpec.from_config(None, default_auth=True), run_path="test", ) assert sidecar.name == SIDECAR_CONTAINER assert sidecar.image == "sidecar/sidecar" assert sidecar.image_pull_policy == "IfNotPresent" assert sidecar.command == ["polyaxon", "sidecar"] assert sidecar.args == get_sidecar_args( container_id=MAIN_JOB_CONTAINER, sleep_interval=213, sync_interval=212, monitor_logs=False, ) assert (sidecar.env == get_sidecar_env_vars( env_vars=env_vars, container_id=MAIN_JOB_CONTAINER, artifacts_store_name=bucket_managed_store.name, ) + get_items_from_secret(secret=resource1) + get_connection_env_var( connection=bucket_managed_store, secret=resource1)) assert sidecar.env_from == [get_env_from_secret(secret=resource1)] assert sidecar.resources == get_sidecar_resources() assert sidecar.volume_mounts == [ get_auth_context_mount(read_only=True), get_artifacts_context_mount(read_only=False), ] # logs and no outputs sidecar = get_sidecar_container( container_id=MAIN_JOB_CONTAINER, env=env_vars, polyaxon_sidecar=V1PolyaxonSidecarContainer( image="sidecar/sidecar", image_tag="", image_pull_policy="IfNotPresent", sleep_interval=213, sync_interval=212, ), artifacts_store=bucket_managed_store, contexts=PluginsContextsSpec.from_config( V1Plugins(collect_artifacts=False, auth=True)), run_path="test", ) assert sidecar.name == SIDECAR_CONTAINER assert sidecar.image == "sidecar/sidecar" assert sidecar.image_pull_policy == "IfNotPresent" assert sidecar.command == ["polyaxon", "sidecar"] assert sidecar.args == get_sidecar_args( container_id=MAIN_JOB_CONTAINER, sleep_interval=213, sync_interval=212, monitor_logs=False, ) assert (sidecar.env == get_sidecar_env_vars( env_vars=env_vars, container_id=MAIN_JOB_CONTAINER, artifacts_store_name=bucket_managed_store.name, ) + get_items_from_secret(secret=resource1) + get_connection_env_var( connection=bucket_managed_store, secret=resource1)) assert sidecar.env_from == [get_env_from_secret(secret=resource1)] assert sidecar.resources == get_sidecar_resources() assert sidecar.volume_mounts == [ get_auth_context_mount(read_only=True), ] # outputs and no logs sidecar = get_sidecar_container( container_id=MAIN_JOB_CONTAINER, env=env_vars, polyaxon_sidecar=V1PolyaxonSidecarContainer( image="sidecar/sidecar", image_tag="", image_pull_policy="IfNotPresent", sleep_interval=213, sync_interval=212, ), artifacts_store=bucket_managed_store, contexts=PluginsContextsSpec.from_config( V1Plugins(collect_logs=False, auth=True)), run_path="test", ) assert sidecar.name == SIDECAR_CONTAINER assert sidecar.image == "sidecar/sidecar" assert sidecar.image_pull_policy == "IfNotPresent" assert sidecar.command == ["polyaxon", "sidecar"] assert sidecar.args == get_sidecar_args( container_id=MAIN_JOB_CONTAINER, sleep_interval=213, sync_interval=212, monitor_logs=False, ) assert (sidecar.env == get_sidecar_env_vars( env_vars=env_vars, container_id=MAIN_JOB_CONTAINER, artifacts_store_name=bucket_managed_store.name, ) + get_items_from_secret(secret=resource1) + get_connection_env_var( connection=bucket_managed_store, secret=resource1)) assert sidecar.env_from == [get_env_from_secret(secret=resource1)] assert sidecar.resources == get_sidecar_resources() assert sidecar.volume_mounts == [ get_auth_context_mount(read_only=True), get_artifacts_context_mount(read_only=False), ]
def test_get_sidecar_container_auth_context(self, ): env_vars = [ get_env_var(name="key1", value="value1"), get_env_var(name="key2", value="value2"), ] resource1 = V1K8sResourceType( name="test1", schema=V1K8sResourceSchema(name="ref1", items=["item1", "item2"]), is_requested=False, ) bucket_managed_store = V1ConnectionType( name="test_gcs", kind=V1ConnectionKind.GCS, schema=V1BucketConnection(bucket="gs//:foo"), secret=resource1.schema, ) # Default auth is included sidecar = get_sidecar_container( container_id=MAIN_JOB_CONTAINER, env=env_vars, polyaxon_sidecar=V1PolyaxonSidecarContainer( image="sidecar/sidecar", image_tag="", image_pull_policy="IfNotPresent", sleep_interval=213, sync_interval=212, ), artifacts_store=bucket_managed_store, contexts=PluginsContextsSpec.from_config(V1Plugins(auth=True)), run_path="test", ) assert sidecar.name == SIDECAR_CONTAINER assert sidecar.image == "sidecar/sidecar" assert sidecar.image_pull_policy == "IfNotPresent" assert sidecar.command == ["polyaxon", "sidecar"] assert sidecar.volume_mounts == [ get_auth_context_mount(read_only=True), get_artifacts_context_mount(read_only=False), ] # Nno auth sidecar = get_sidecar_container( container_id=MAIN_JOB_CONTAINER, env=env_vars, polyaxon_sidecar=V1PolyaxonSidecarContainer( image="sidecar/sidecar", image_tag="", image_pull_policy="IfNotPresent", sleep_interval=213, sync_interval=-212, ), artifacts_store=bucket_managed_store, contexts=PluginsContextsSpec.from_config(V1Plugins(auth=False)), run_path="test", ) assert sidecar.name == SIDECAR_CONTAINER assert sidecar.image == "sidecar/sidecar" assert sidecar.image_pull_policy == "IfNotPresent" assert sidecar.command == ["polyaxon", "sidecar"] assert sidecar.volume_mounts == [ get_artifacts_context_mount(read_only=False) ]
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" ), 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" ), polyaxon_init=V1PolyaxonInitContainer( image="init", image_pull_policy="IfNotPresent" ), store=store, env=[], env_from=[], volume_mounts=[get_artifacts_context_mount()], args=[" ".join(init_args)], )
def test_get_sidecar_container_with_managed_mount_outputs_logs_store(self): env_vars = [ get_env_var(name="key1", value="value1"), get_env_var(name="key2", value="value2"), ] mount_managed_store = V1ConnectionType( name="test_path", kind=V1ConnectionKind.HOST_PATH, schema=V1HostPathConnection(mount_path="/tmp", host_path="/tmp"), secret=None, ) # logs and outputs sidecar = get_sidecar_container( env=env_vars, polyaxon_sidecar=V1PolyaxonSidecarContainer( image="sidecar/sidecar", image_tag="", image_pull_policy="IfNotPresent", sleep_interval=213, sync_interval=212, ), artifacts_store=mount_managed_store, contexts=PluginsContextsSpec.from_config(None), run_path="test", ) assert sidecar.name == SIDECAR_CONTAINER assert sidecar.image == "sidecar/sidecar" assert sidecar.image_pull_policy == "IfNotPresent" assert sidecar.command == ["/bin/bash", "-c"] assert sidecar.args == [ get_sidecar_args( container_id=MAIN_JOB_CONTAINER, sleep_interval=213, sync_interval=212 ) ] assert sidecar.env == get_sidecar_env_vars( env_vars=env_vars, job_container_name=MAIN_JOB_CONTAINER, artifacts_store_name=mount_managed_store.name, ) + get_connection_env_var(connection=mount_managed_store, secret=None) assert sidecar.env_from == [] assert sidecar.resources == get_sidecar_resources() assert sidecar.volume_mounts == [ get_auth_context_mount(read_only=True), get_artifacts_context_mount(read_only=False), get_mount_from_store(store=mount_managed_store), ] # logs and no outputs sidecar = get_sidecar_container( env=env_vars, polyaxon_sidecar=V1PolyaxonSidecarContainer( image="sidecar/sidecar", image_tag="", image_pull_policy="IfNotPresent", sleep_interval=213, sync_interval=212, ), artifacts_store=mount_managed_store, contexts=PluginsContextsSpec.from_config( V1Plugins(collect_artifacts=False) ), run_path="test", ) assert sidecar.name == SIDECAR_CONTAINER assert sidecar.image == "sidecar/sidecar" assert sidecar.image_pull_policy == "IfNotPresent" assert sidecar.command == ["/bin/bash", "-c"] assert sidecar.args == [ get_sidecar_args( container_id=MAIN_JOB_CONTAINER, sleep_interval=213, sync_interval=212 ) ] assert sidecar.env == get_sidecar_env_vars( env_vars=env_vars, job_container_name=MAIN_JOB_CONTAINER, artifacts_store_name=mount_managed_store.name, ) + get_connection_env_var(connection=mount_managed_store, secret=None) assert sidecar.env_from == [] assert sidecar.resources == get_sidecar_resources() assert sidecar.volume_mounts == [ get_auth_context_mount(read_only=True), get_mount_from_store(store=mount_managed_store), ] # outputs and no logs sidecar = get_sidecar_container( env=env_vars, polyaxon_sidecar=V1PolyaxonSidecarContainer( image="sidecar/sidecar", image_tag="", image_pull_policy="IfNotPresent", sleep_interval=213, sync_interval=212, ), artifacts_store=mount_managed_store, contexts=PluginsContextsSpec.from_config(V1Plugins(collect_logs=False)), run_path="test", ) assert sidecar.name == SIDECAR_CONTAINER assert sidecar.image == "sidecar/sidecar" assert sidecar.image_pull_policy == "IfNotPresent" assert sidecar.command == ["/bin/bash", "-c"] assert sidecar.args == [ get_sidecar_args( container_id=MAIN_JOB_CONTAINER, sleep_interval=213, sync_interval=212 ) ] assert sidecar.env == get_sidecar_env_vars( env_vars=env_vars, job_container_name=MAIN_JOB_CONTAINER, artifacts_store_name=mount_managed_store.name, ) + get_connection_env_var(connection=mount_managed_store, secret=None) assert sidecar.env_from == [] assert sidecar.resources == get_sidecar_resources() assert sidecar.volume_mounts == [ get_auth_context_mount(read_only=True), get_artifacts_context_mount(read_only=False), get_mount_from_store(store=mount_managed_store), ]
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", 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="init"), 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, ) container = get_artifacts_path_container( polyaxon_init=V1PolyaxonInitContainer( image="init", image_pull_policy="IfNotPresent" ), artifacts_store=store, run_path="run_uid", clean=False, ) 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=False ) ) assert container == get_base_store_container( container=k8s_schemas.V1Container(name="init"), 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, )