Skip to content

Commit

Permalink
Merge branch 'main' into pre-commit-ci-update-config
Browse files Browse the repository at this point in the history
  • Loading branch information
rnetser authored Jan 7, 2025
2 parents be5c702 + 453f931 commit 445d05e
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 102 deletions.
103 changes: 22 additions & 81 deletions tests/model_serving/model_server/private_endpoint/conftest.py
Original file line number Diff line number Diff line change
@@ -1,104 +1,53 @@
from typing import Any, Generator

import pytest
from typing import Generator, Any
from kubernetes.dynamic import DynamicClient
from ocp_resources.inference_service import InferenceService
from ocp_resources.secret import Secret
from ocp_resources.namespace import Namespace
from ocp_resources.pod import Pod
from simple_logger.logger import get_logger
from ocp_resources.secret import Secret
from ocp_resources.serving_runtime import ServingRuntime
from kubernetes.dynamic import DynamicClient
from simple_logger.logger import get_logger

from utilities.serving_runtime import ServingRuntimeFromTemplate
from tests.model_serving.model_server.private_endpoint.utils import create_sidecar_pod
from tests.model_serving.model_server.utils import create_isvc
from tests.model_serving.model_server.private_endpoint.utils import (
create_sidecar_pod,
)
from utilities.infra import (
create_ns,
create_storage_config_secret,
s3_endpoint_secret,
wait_for_kserve_predictor_deployment_replicas,
)
from utilities.constants import KServeDeploymentType, ModelStoragePath, ModelFormat

from utilities.constants import KServeDeploymentType, ModelFormat, ModelStoragePath
from utilities.infra import create_ns, create_storage_config_secret

LOGGER = get_logger(name=__name__)


@pytest.fixture(scope="class")
def endpoint_namespace(admin_client: DynamicClient) -> Generator[Namespace, None, None]:
with create_ns(admin_client=admin_client, name="endpoint-namespace") as ns:
yield ns


@pytest.fixture(scope="class")
def diff_namespace(admin_client: DynamicClient) -> Generator[Namespace, None, None]:
with create_ns(admin_client=admin_client, name="diff-namespace") as ns:
yield ns


@pytest.fixture(scope="class")
def endpoint_sr(
admin_client: DynamicClient,
endpoint_namespace: Namespace,
) -> Generator[ServingRuntime, None, None]:
with ServingRuntimeFromTemplate(
client=admin_client,
name="flan-example-sr",
namespace=endpoint_namespace.name,
template_name="caikit-tgis-serving-template",
) as model_runtime:
yield model_runtime


@pytest.fixture(scope="class")
def endpoint_s3_secret(
admin_client: DynamicClient,
endpoint_namespace: Namespace,
aws_access_key_id: str,
aws_secret_access_key: str,
models_s3_bucket_name: str,
models_s3_bucket_region: str,
models_s3_bucket_endpoint: str,
) -> Generator[Secret, None, None]:
with s3_endpoint_secret(
admin_client=admin_client,
name="endpoint-s3-secret",
namespace=endpoint_namespace.name,
aws_access_key=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_s3_region=models_s3_bucket_region,
aws_s3_bucket=models_s3_bucket_name,
aws_s3_endpoint=models_s3_bucket_endpoint,
) as secret:
yield secret


@pytest.fixture(scope="class")
def endpoint_isvc(
admin_client: DynamicClient,
endpoint_sr: ServingRuntime,
endpoint_s3_secret: Secret,
serving_runtime_from_template: ServingRuntime,
models_endpoint_s3_secret: Secret,
storage_config_secret: Secret,
endpoint_namespace: Namespace,
) -> Generator[InferenceService, None, None]:
with create_isvc(
client=admin_client,
name="test",
namespace=endpoint_namespace.name,
name="endpoint-isvc",
namespace=serving_runtime_from_template.namespace,
deployment_mode=KServeDeploymentType.SERVERLESS,
storage_key="endpoint-s3-secret",
storage_key=models_endpoint_s3_secret.name,
storage_path=ModelStoragePath.FLAN_T5_SMALL,
model_format=ModelFormat.CAIKIT,
runtime=endpoint_sr.name,
runtime=serving_runtime_from_template.name,
wait_for_predictor_pods=True,
) as isvc:
yield isvc


@pytest.fixture(scope="class")
def storage_config_secret(
admin_client: DynamicClient,
endpoint_s3_secret: Secret,
models_endpoint_s3_secret: Secret,
aws_access_key_id: str,
aws_secret_access_key: str,
models_s3_bucket_name: str,
Expand All @@ -107,8 +56,8 @@ def storage_config_secret(
) -> Generator[Secret, None, None]:
with create_storage_config_secret(
admin_client=admin_client,
endpoint_secret_name=endpoint_s3_secret.name,
namespace=endpoint_s3_secret.namespace,
endpoint_secret_name=models_endpoint_s3_secret.name,
namespace=models_endpoint_s3_secret.namespace,
aws_access_key=aws_access_key_id,
aws_secret_access_key=aws_secret_access_key,
aws_s3_bucket=models_s3_bucket_name,
Expand All @@ -120,11 +69,11 @@ def storage_config_secret(

@pytest.fixture()
def endpoint_pod_with_istio_sidecar(
admin_client: DynamicClient, endpoint_namespace: Namespace
admin_client: DynamicClient, model_namespace: Namespace
) -> Generator[Pod, Any, Any]:
with create_sidecar_pod(
admin_client=admin_client,
namespace=endpoint_namespace.name,
namespace=model_namespace.name,
use_istio=True,
pod_name="test-with-istio",
) as pod:
Expand All @@ -133,11 +82,11 @@ def endpoint_pod_with_istio_sidecar(

@pytest.fixture()
def endpoint_pod_without_istio_sidecar(
admin_client: DynamicClient, endpoint_namespace: Namespace
admin_client: DynamicClient, model_namespace: Namespace
) -> Generator[Pod, Any, Any]:
with create_sidecar_pod(
admin_client=admin_client,
namespace=endpoint_namespace.name,
namespace=model_namespace.name,
use_istio=False,
pod_name="test",
) as pod:
Expand Down Expand Up @@ -170,11 +119,3 @@ def diff_pod_without_istio_sidecar(
pod_name="test",
) as pod:
yield pod


@pytest.fixture()
def ready_predictor(admin_client: DynamicClient, endpoint_isvc: InferenceService) -> None:
wait_for_kserve_predictor_deployment_replicas(
client=admin_client,
isvc=endpoint_isvc,
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,44 @@

import pytest
from simple_logger.logger import get_logger
from ocp_resources.namespace import Namespace
from ocp_resources.inference_service import InferenceService
from ocp_resources.pod import Pod
from ocp_resources.deployment import Deployment
from tests.model_serving.model_server.private_endpoint.utils import curl_from_pod
from utilities.constants import CurlOutput, ModelEndpoint, Protocols
from utilities.constants import CurlOutput, ModelEndpoint, Protocols, RuntimeTemplates

LOGGER = get_logger(name=__name__)


pytestmark = pytest.mark.usefixtures("skip_if_no_deployed_openshift_serverless", "valid_aws_config")


@pytest.mark.parametrize(
"model_namespace, serving_runtime_from_template",
[
pytest.param(
{"name": "endpoint"},
{
"name": "flan-example-runtime",
"template-name": RuntimeTemplates.CAIKIT_TGIS_SERVING,
"multi-model": False,
},
)
],
indirect=True,
)
@pytest.mark.serverless
class TestKserveInternalEndpoint:
"""Tests the internal endpoint of a kserve predictor"""

def test_deploy_model_state_loaded(
self: Self, endpoint_namespace: Namespace, endpoint_isvc: InferenceService, ready_predictor: Deployment
) -> None:
def test_deploy_model_state_loaded(self: Self, endpoint_isvc: InferenceService) -> None:
"""Verifies that the predictor gets to state Loaded"""
assert endpoint_isvc.instance.status.modelStatus.states.activeModelState == "Loaded"

def test_deploy_model_url(
self: Self, endpoint_namespace: Namespace, endpoint_isvc: InferenceService, ready_predictor: Deployment
) -> None:
def test_deploy_model_url(self: Self, endpoint_isvc: InferenceService) -> None:
"""Verifies that the internal endpoint has the expected formatting"""
assert (
endpoint_isvc.instance.status.address.url
== f"https://{endpoint_isvc.name}.{endpoint_namespace.name}.svc.cluster.local"
== f"https://{endpoint_isvc.name}.{endpoint_isvc.namespace}.svc.cluster.local"
)

def test_curl_with_istio_same_ns(
Expand Down
12 changes: 2 additions & 10 deletions tests/model_serving/model_server/storage/pvc/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from tests.model_serving.model_server.storage.constants import NFS_STR
from tests.model_serving.model_server.utils import create_isvc
from utilities.constants import KServeDeploymentType
from utilities.infra import get_pods_by_isvc_label, wait_for_kserve_predictor_deployment_replicas
from utilities.infra import get_pods_by_isvc_label


@pytest.fixture(scope="class")
Expand Down Expand Up @@ -98,7 +98,6 @@ def predictor_pods_scope_function(admin_client: DynamicClient, pvc_inference_ser
def predictor_pods_scope_class(
admin_client: DynamicClient,
pvc_inference_service: InferenceService,
isvc_deployment_ready: None,
) -> List[Pod]:
return get_pods_by_isvc_label(
client=admin_client,
Expand Down Expand Up @@ -140,6 +139,7 @@ def pvc_inference_service(
"storage_uri": f"pvc://{model_pvc.name}/{downloaded_model_data}",
"model_format": serving_runtime_from_template.instance.spec.supportedModelFormats[0].name,
"deployment_mode": request.param.get("deployment-mode", KServeDeploymentType.SERVERLESS),
"wait_for_predictor_pods": True,
}

if min_replicas := request.param.get("min-replicas"):
Expand All @@ -149,14 +149,6 @@ def pvc_inference_service(
yield isvc


@pytest.fixture(scope="class")
def isvc_deployment_ready(admin_client: DynamicClient, pvc_inference_service: InferenceService) -> None:
wait_for_kserve_predictor_deployment_replicas(
client=admin_client,
isvc=pvc_inference_service,
)


@pytest.fixture()
def first_predictor_pod(predictor_pods_scope_function: List[Pod]) -> Pod:
return predictor_pods_scope_function[0]
Expand Down
10 changes: 9 additions & 1 deletion tests/model_serving/model_server/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
)
from utilities.constants import KServeDeploymentType
from utilities.inference_utils import UserInference

from utilities.infra import wait_for_kserve_predictor_deployment_replicas

LOGGER = get_logger(name=__name__)

Expand Down Expand Up @@ -43,6 +43,7 @@ def create_isvc(
volumes: Optional[dict[str, Any]] = None,
volumes_mounts: Optional[dict[str, Any]] = None,
model_version: Optional[str] = None,
wait_for_predictor_pods: bool = True,
) -> Generator[InferenceService, Any, Any]:
labels: Dict[str, str] = {}
predictor_dict: Dict[str, Any] = {
Expand Down Expand Up @@ -115,6 +116,13 @@ def create_isvc(
status=inference_service.Condition.Status.TRUE,
timeout=10 * 60,
)

if wait_for_predictor_pods:
wait_for_kserve_predictor_deployment_replicas(
client=client,
isvc=inference_service,
)

yield inference_service


Expand Down

0 comments on commit 445d05e

Please sign in to comment.