Пример #1
0
def get_volume(
    volume: str, claim_name: str = None, host_path: str = None, read_only: bool = None
) -> k8s_schemas.V1Volume:
    if claim_name:
        pv_claim = k8s_schemas.V1PersistentVolumeClaimVolumeSource(
            claim_name=claim_name, read_only=read_only
        )
        return k8s_schemas.V1Volume(name=volume, persistent_volume_claim=pv_claim)

    if host_path:
        return k8s_schemas.V1Volume(
            name=volume, host_path=k8s_schemas.V1HostPathVolumeSource(path=host_path)
        )

    empty_dir = k8s_schemas.V1EmptyDirVolumeSource()
    return k8s_schemas.V1Volume(name=volume, empty_dir=empty_dir)
Пример #2
0
def get_volume_from_connection(
    connection: V1ConnectionType, ) -> Optional[k8s_schemas.V1Volume]:
    if not connection:
        return None
    if connection.is_volume_claim:
        pv_claim = k8s_schemas.V1PersistentVolumeClaimVolumeSource(
            claim_name=connection.schema.volume_claim,
            read_only=connection.schema.read_only,
        )
        return k8s_schemas.V1Volume(name=connection.name,
                                    persistent_volume_claim=pv_claim)

    if connection.is_host_path:
        return k8s_schemas.V1Volume(
            name=connection.name,
            host_path=k8s_schemas.V1HostPathVolumeSource(
                path=connection.schema.host_path),
        )
Пример #3
0
    def test_get_volume_from_connection(self):
        # No store
        assert get_volume_from_connection(connection=None) is None

        # Bucket store
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.S3,
            schema=V1BucketConnection(bucket="s3//:foo"),
        )
        assert get_volume_from_connection(connection=store) is None

        # Claim store
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.VOLUME_CLAIM,
            schema=V1ClaimConnection(
                mount_path="/tmp", volume_claim="test", read_only=True
            ),
        )
        volume = get_volume_from_connection(connection=store)
        assert volume.name == store.name
        assert volume.persistent_volume_claim.claim_name == store.schema.volume_claim
        assert volume.persistent_volume_claim.read_only == store.schema.read_only

        # Host path
        store = V1ConnectionType(
            name="test",
            kind=V1ConnectionKind.HOST_PATH,
            schema=V1HostPathConnection(
                mount_path="/tmp", host_path="/tmp", read_only=True
            ),
        )
        volume = get_volume_from_connection(connection=store)
        assert volume.name == store.name
        assert volume.host_path == k8s_schemas.V1HostPathVolumeSource(
            path=store.schema.host_path
        )