|
| 1 | +from polyaxon._auxiliaries import V1PolyaxonSidecarContainer |
| 2 | +from polyaxon._connections import ( |
| 3 | + V1ClaimConnection, |
| 4 | + V1Connection, |
| 5 | + V1ConnectionKind, |
| 6 | +) |
| 7 | +from polyaxon._flow import V1Plugins |
| 8 | +from polyaxon._k8s import k8s_schemas |
| 9 | +from tests.test_k8s.test_converters.base import BaseConverterTest |
| 10 | + |
| 11 | + |
| 12 | +class TestSidecarConnections(BaseConverterTest): |
| 13 | + def test_get_sidecars_with_connections(self): |
| 14 | + store = V1Connection( |
| 15 | + name="test_claim", |
| 16 | + kind=V1ConnectionKind.VOLUME_CLAIM, |
| 17 | + schema_=V1ClaimConnection( |
| 18 | + mount_path="/claim/path", volume_claim="claim", read_only=True |
| 19 | + ), |
| 20 | + ) |
| 21 | + plugins = V1Plugins.get_or_create( |
| 22 | + V1Plugins( |
| 23 | + collect_logs=False, |
| 24 | + collect_artifacts=False, |
| 25 | + auth=True, |
| 26 | + sidecar=V1PolyaxonSidecarContainer(no_connections=False), |
| 27 | + ) |
| 28 | + ) |
| 29 | + sidecar = k8s_schemas.V1Container(name="sidecar", image="foo") |
| 30 | + |
| 31 | + containers = self.converter.get_sidecar_containers( |
| 32 | + plugins=plugins, |
| 33 | + artifacts_store=None, |
| 34 | + sidecar_containers=[sidecar], |
| 35 | + polyaxon_sidecar=V1PolyaxonSidecarContainer(image="sidecar/sidecar"), |
| 36 | + connections=[store.name], |
| 37 | + connection_by_names={store.name: store}, |
| 38 | + ) |
| 39 | + |
| 40 | + # Check that sidecar has volume mounts |
| 41 | + # Since collect_artifacts=False and collect_logs=False, polyaxon sidecar is not created |
| 42 | + # Only user sidecar is returned |
| 43 | + assert len(containers) == 1 |
| 44 | + user_sidecar = containers[0] |
| 45 | + assert "sidecar" in user_sidecar.name |
| 46 | + |
| 47 | + # Check mounts |
| 48 | + mount_paths = [m.mount_path for m in user_sidecar.volume_mounts] |
| 49 | + assert "/claim/path" in mount_paths |
| 50 | + |
| 51 | + # Check auth context (since plugins.auth=True) |
| 52 | + # Auth context mount path is /plx-context/configs |
| 53 | + from polyaxon._contexts import paths as ctx_paths |
| 54 | + |
| 55 | + assert ctx_paths.CONTEXT_MOUNT_CONFIGS in mount_paths |
| 56 | + |
| 57 | + def test_get_sidecars_with_multiple_connections(self): |
| 58 | + """Test that sidecars get volume mounts for multiple connections.""" |
| 59 | + store1 = V1Connection( |
| 60 | + name="test_claim", |
| 61 | + kind=V1ConnectionKind.VOLUME_CLAIM, |
| 62 | + schema_=V1ClaimConnection( |
| 63 | + mount_path="/claim/path", volume_claim="claim", read_only=True |
| 64 | + ), |
| 65 | + ) |
| 66 | + store2 = V1Connection( |
| 67 | + name="test_claim2", |
| 68 | + kind=V1ConnectionKind.VOLUME_CLAIM, |
| 69 | + schema_=V1ClaimConnection( |
| 70 | + mount_path="/claim/path2", volume_claim="claim2", read_only=False |
| 71 | + ), |
| 72 | + ) |
| 73 | + plugins = V1Plugins.get_or_create( |
| 74 | + V1Plugins(collect_logs=False, collect_artifacts=False, auth=False) |
| 75 | + ) |
| 76 | + sidecar = k8s_schemas.V1Container(name="sidecar", image="foo") |
| 77 | + |
| 78 | + containers = self.converter.get_sidecar_containers( |
| 79 | + plugins=plugins, |
| 80 | + artifacts_store=None, |
| 81 | + sidecar_containers=[sidecar], |
| 82 | + polyaxon_sidecar=V1PolyaxonSidecarContainer(image="sidecar/sidecar"), |
| 83 | + connections=[store1.name, store2.name], |
| 84 | + connection_by_names={store1.name: store1, store2.name: store2}, |
| 85 | + ) |
| 86 | + |
| 87 | + assert len(containers) == 1 |
| 88 | + user_sidecar = containers[0] |
| 89 | + |
| 90 | + # Check both connections are mounted |
| 91 | + mount_paths = [m.mount_path for m in user_sidecar.volume_mounts] |
| 92 | + assert "/claim/path" in mount_paths |
| 93 | + assert "/claim/path2" in mount_paths |
| 94 | + |
| 95 | + def test_get_sidecars_without_mirroring(self): |
| 96 | + """Test that sidecars do NOT get volume mounts when mirror_connections is False or default.""" |
| 97 | + store = V1Connection( |
| 98 | + name="test_claim", |
| 99 | + kind=V1ConnectionKind.VOLUME_CLAIM, |
| 100 | + schema_=V1ClaimConnection( |
| 101 | + mount_path="/claim/path", volume_claim="claim", read_only=True |
| 102 | + ), |
| 103 | + ) |
| 104 | + # plugins without sidecar config (defaults to mirror_connections=None/False) |
| 105 | + plugins = V1Plugins.get_or_create( |
| 106 | + V1Plugins( |
| 107 | + collect_logs=False, |
| 108 | + collect_artifacts=False, |
| 109 | + auth=True, |
| 110 | + sidecar=V1PolyaxonSidecarContainer(no_connections=True), |
| 111 | + ) |
| 112 | + ) |
| 113 | + sidecar = k8s_schemas.V1Container(name="sidecar", image="foo") |
| 114 | + |
| 115 | + containers = self.converter.get_sidecar_containers( |
| 116 | + plugins=plugins, |
| 117 | + artifacts_store=None, |
| 118 | + sidecar_containers=[sidecar], |
| 119 | + polyaxon_sidecar=V1PolyaxonSidecarContainer(image="sidecar/sidecar"), |
| 120 | + connections=[store.name], |
| 121 | + connection_by_names={store.name: store}, |
| 122 | + ) |
| 123 | + |
| 124 | + assert len(containers) == 1 |
| 125 | + user_sidecar = containers[0] |
| 126 | + |
| 127 | + # Check NO connection mounts are present |
| 128 | + mount_paths = ( |
| 129 | + [m.mount_path for m in user_sidecar.volume_mounts] |
| 130 | + if user_sidecar.volume_mounts |
| 131 | + else [] |
| 132 | + ) |
| 133 | + assert "/claim/path" not in mount_paths |
0 commit comments