|
27 | 27 | LLS_OPENSHIFT_MINIMAL_VERSION, |
28 | 28 | ModelInfo, |
29 | 29 | ) |
30 | | - |
| 30 | +from ocp_resources.service import Service |
31 | 31 |
|
32 | 32 | LOGGER = get_logger(name=__name__) |
33 | 33 |
|
| 34 | +POSTGRES_IMAGE = os.getenv( |
| 35 | + "LLS_VECTOR_IO_POSTGRES_IMAGE", |
| 36 | + ( |
| 37 | + "registry.redhat.io/rhel9/postgresql-15@sha256:" |
| 38 | + "90ec347a35ab8a5d530c8d09f5347b13cc71df04f3b994bfa8b1a409b1171d59" # postgres 15 # pragma: allowlist secret |
| 39 | + ), |
| 40 | +) |
| 41 | + |
| 42 | +POSTGRESQL_USER = os.getenv("LLS_VECTOR_IO_POSTGRESQL_USER", "ps_user") |
| 43 | +POSTGRESQL_PASSWORD = os.getenv("LLS_VECTOR_IO_POSTGRESQL_PASSWORD", "ps_password") |
| 44 | + |
34 | 45 | distribution_name = generate_random_name(prefix="llama-stack-distribution") |
35 | 46 |
|
36 | 47 |
|
@@ -102,6 +113,8 @@ def enabled_llama_stack_operator(dsc_resource: DataScienceCluster) -> Generator[ |
102 | 113 | @pytest.fixture(scope="class") |
103 | 114 | def llama_stack_server_config( |
104 | 115 | request: FixtureRequest, |
| 116 | + postgres_deployment: Deployment, |
| 117 | + postgres_service: Service, |
105 | 118 | vector_io_provider_deployment_config_factory: Callable[[str], list[Dict[str, str]]], |
106 | 119 | files_provider_config_factory: Callable[[str], list[Dict[str, str]]], |
107 | 120 | ) -> Dict[str, Any]: |
@@ -251,6 +264,14 @@ def test_with_remote_milvus(llama_stack_server_config): |
251 | 264 | # KUBEFLOW_PIPELINES_TOKEN: Get from current client token |
252 | 265 | env_vars.append({"name": "KUBEFLOW_PIPELINES_TOKEN", "value": str(current_client_token)}) |
253 | 266 |
|
| 267 | + # POSTGRESQL environment variables for sql_default and kvstore_default |
| 268 | + env_vars.append({"name": "POSTGRES_HOST", "value": "vector-io-postgres-service"}) |
| 269 | + env_vars.append({"name": "POSTGRES_PORT", "value": "5432"}) |
| 270 | + env_vars.append({"name": "POSTGRES_USER", "value": POSTGRESQL_USER}) |
| 271 | + env_vars.append({"name": "POSTGRES_PASSWORD", "value": POSTGRESQL_PASSWORD}) |
| 272 | + env_vars.append({"name": "POSTGRES_DB", "value": "ps_db"}) |
| 273 | + env_vars.append({"name": "POSTGRES_TABLE_NAME", "value": "llamastack_kvstore"}) |
| 274 | + |
254 | 275 | # Depending on parameter files_provider, configure files provider and obtain required env_vars |
255 | 276 | files_provider = params.get("files_provider") or "local" |
256 | 277 | env_vars_files = files_provider_config_factory(provider_name=files_provider) |
@@ -681,3 +702,70 @@ def vector_store_with_example_docs( |
681 | 702 | ) |
682 | 703 |
|
683 | 704 | yield vector_store |
| 705 | + |
| 706 | + |
| 707 | +@pytest.fixture(scope="class") |
| 708 | +def postgres_service( |
| 709 | + unprivileged_client: DynamicClient, |
| 710 | + unprivileged_model_namespace: Namespace, |
| 711 | + postgres_deployment: Deployment, |
| 712 | +) -> Generator[Service, Any, Any]: |
| 713 | + """Create a service for the postgres deployment.""" |
| 714 | + with Service( |
| 715 | + client=unprivileged_client, |
| 716 | + namespace=unprivileged_model_namespace.name, |
| 717 | + name="vector-io-postgres-service", |
| 718 | + ports=[ |
| 719 | + { |
| 720 | + "port": 5432, |
| 721 | + "targetPort": 5432, |
| 722 | + } |
| 723 | + ], |
| 724 | + selector={"app": "postgres"}, |
| 725 | + wait_for_resource=True, |
| 726 | + ) as service: |
| 727 | + yield service |
| 728 | + |
| 729 | + |
| 730 | +@pytest.fixture(scope="class") |
| 731 | +def postgres_deployment( |
| 732 | + unprivileged_client: DynamicClient, |
| 733 | + unprivileged_model_namespace: Namespace, |
| 734 | +) -> Generator[Deployment, Any, Any]: |
| 735 | + """Deploy a Postgres instance for vector I/O provider testing.""" |
| 736 | + with Deployment( |
| 737 | + client=unprivileged_client, |
| 738 | + namespace=unprivileged_model_namespace.name, |
| 739 | + name="vector-io-postgres-deployment", |
| 740 | + min_ready_seconds=5, |
| 741 | + replicas=1, |
| 742 | + selector={"matchLabels": {"app": "postgres"}}, |
| 743 | + strategy={"type": "Recreate"}, |
| 744 | + template=get_postgres_deployment_template(), |
| 745 | + teardown=True, |
| 746 | + ) as deployment: |
| 747 | + deployment.wait_for_replicas(deployed=True, timeout=240) |
| 748 | + yield deployment |
| 749 | + |
| 750 | + |
| 751 | +def get_postgres_deployment_template() -> Dict[str, Any]: |
| 752 | + """Return a Kubernetes deployment for PostgreSQL""" |
| 753 | + return { |
| 754 | + "metadata": {"labels": {"app": "postgres"}}, |
| 755 | + "spec": { |
| 756 | + "containers": [ |
| 757 | + { |
| 758 | + "name": "postgres", |
| 759 | + "image": POSTGRES_IMAGE, |
| 760 | + "ports": [{"containerPort": 5432}], |
| 761 | + "env": [ |
| 762 | + {"name": "POSTGRESQL_DATABASE", "value": "ps_db"}, |
| 763 | + {"name": "POSTGRESQL_USER", "value": POSTGRESQL_USER}, |
| 764 | + {"name": "POSTGRESQL_PASSWORD", "value": POSTGRESQL_PASSWORD}, |
| 765 | + ], |
| 766 | + "volumeMounts": [{"name": "postgresdata", "mountPath": "/var/lib/pgsql/data"}], |
| 767 | + }, |
| 768 | + ], |
| 769 | + "volumes": [{"name": "postgresdata", "emptyDir": {}}], |
| 770 | + }, |
| 771 | + } |
0 commit comments