Skip to content

Commit c214dd7

Browse files
authored
Remove ModelMesh and Serverless from get_ca_bundle (#1173)
1 parent 24e100f commit c214dd7

File tree

8 files changed

+29
-86
lines changed

8 files changed

+29
-86
lines changed

tests/conftest.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -690,9 +690,7 @@ def prometheus(admin_client: DynamicClient) -> Prometheus:
690690
return Prometheus(
691691
client=admin_client,
692692
resource_name="thanos-querier",
693-
verify_ssl=create_ca_bundle_file(
694-
client=admin_client, ca_type="openshift"
695-
), # TODO: Verify SSL with appropriate certs
693+
verify_ssl=create_ca_bundle_file(client=admin_client), # TODO: Verify SSL with appropriate certs
696694
bearer_token=get_openshift_token(),
697695
)
698696

tests/model_explainability/evalhub/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,4 +66,4 @@ def evalhub_ca_bundle_file(
6666
admin_client: DynamicClient,
6767
) -> str:
6868
"""Create a CA bundle file for verifying the EvalHub route TLS certificate."""
69-
return create_ca_bundle_file(client=admin_client, ca_type="openshift")
69+
return create_ca_bundle_file(client=admin_client)

tests/model_explainability/guardrails/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def prompt_injection_detector_route(
107107
def openshift_ca_bundle_file(
108108
admin_client: DynamicClient,
109109
) -> str:
110-
return create_ca_bundle_file(client=admin_client, ca_type="openshift")
110+
return create_ca_bundle_file(client=admin_client)
111111

112112

113113
@pytest.fixture(scope="class")

tests/model_explainability/trustyai_service/trustyai_service_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def __init__(self, token: str, service: TrustyAIService, client: DynamicClient):
5959
self.service_route = Route(
6060
client=client, namespace=service.namespace, name=TRUSTYAI_SERVICE_NAME, ensure_exists=True
6161
)
62-
self.cert_path = create_ca_bundle_file(client=client, ca_type="openshift")
62+
self.cert_path = create_ca_bundle_file(client=client)
6363

6464
def _get_metric_base_url(self, metric_name: str) -> str:
6565
"""Gets base URL for a given metric type (fairness or drift).

utilities/certificates_utils.py

Lines changed: 23 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -9,98 +9,61 @@
99
from simple_logger.logger import get_logger
1010

1111
from utilities.constants import (
12-
ISTIO_CA_BUNDLE_FILENAME,
1312
OPENSHIFT_CA_BUNDLE_FILENAME,
14-
KServeDeploymentType,
1513
)
16-
from utilities.infra import is_managed_cluster, is_self_managed_operator
14+
from utilities.infra import is_managed_cluster
1715

1816
LOGGER = get_logger(name=__name__)
1917

2018

21-
def create_ca_bundle_file(client: DynamicClient, ca_type: str) -> str:
19+
def create_ca_bundle_file(client: DynamicClient) -> str:
2220
"""
2321
Creates a ca bundle file from a secret
2422
2523
Args:
2624
client (DynamicClient): DynamicClient object
27-
ca_type (str): The type of ca bundle to create. Can be "knative" or "openshift"
28-
2925
Returns:
30-
str: The path to the ca bundle file. If cert is not created, return empty string
26+
str: The path to the ca bundle file.
3127
3228
Raises:
33-
ValueError: If ca_type is not "knative" or "openshift"
34-
29+
AttributeError: If the router-certs-default secret does not exist in the cluster.
3530
"""
36-
if ca_type == "knative":
37-
certs_secret = Secret(
38-
client=client,
39-
name="knative-serving-cert",
40-
namespace="istio-system",
41-
)
42-
filename = ISTIO_CA_BUNDLE_FILENAME
43-
44-
elif ca_type == "openshift":
45-
certs_secret = Secret(
46-
client=client,
47-
name="router-certs-default",
48-
namespace="openshift-ingress",
49-
)
50-
filename = OPENSHIFT_CA_BUNDLE_FILENAME
5131

52-
else:
53-
raise ValueError("Invalid ca_type")
32+
certs_secret = Secret(
33+
client=client,
34+
name="router-certs-default",
35+
namespace="openshift-ingress",
36+
)
5437

55-
if certs_secret.exists:
56-
bundle = base64.b64decode(certs_secret.instance.data["tls.crt"]).decode()
57-
filepath = os.path.join(py_config["tmp_base_dir"], filename)
58-
with open(filepath, "w") as fd:
59-
fd.write(bundle)
38+
filename = OPENSHIFT_CA_BUNDLE_FILENAME
39+
bundle = base64.b64decode(certs_secret.instance.data["tls.crt"]).decode()
40+
filepath = os.path.join(py_config["tmp_base_dir"], filename)
6041

61-
return filepath
42+
with open(filepath, "w") as fd:
43+
fd.write(bundle)
6244

63-
LOGGER.warning(f"Could not find {certs_secret.name} secret")
64-
return ""
45+
return filepath
6546

6647

6748
@cache
68-
def get_ca_bundle(client: DynamicClient, deployment_mode: str) -> str:
49+
def get_ca_bundle(client: DynamicClient) -> str:
6950
"""
70-
Get the ca bundle for the given deployment mode.
51+
Get the CA bundle for TLS verification.
7152
72-
If running on managed cluster and deployment in serverless or raw deployment, return empty string.
73-
If running on self-managed operator and deployment is model mesh, return ca bundle.
53+
On managed clusters, no CA bundle is needed (returns empty string).
54+
On self-managed clusters, creates a CA bundle file.
7455
7556
Args:
7657
client (DynamicClient): DynamicClient object
77-
deployment_mode (str): The deployment mode. Can be "serverless", "model-mesh" or "raw-deployment"
7858
7959
Returns:
80-
str: The path to the ca bundle file. If cert is not created, return empty string
81-
82-
Raises:
83-
ValueError: If deployment_mode is not "serverless", "model-mesh" or "raw-deployment"
84-
60+
str: The path to the ca bundle file, or empty string if not needed or not found.
8561
"""
86-
if deployment_mode in (
87-
KServeDeploymentType.SERVERLESS,
88-
KServeDeploymentType.RAW_DEPLOYMENT,
89-
):
90-
if is_managed_cluster(client):
91-
LOGGER.info("Running on managed cluster, not using ca bundle")
92-
return ""
93-
else:
94-
return create_ca_bundle_file(client=client, ca_type="knative")
95-
96-
elif deployment_mode == KServeDeploymentType.MODEL_MESH:
97-
if is_self_managed_operator(client=client):
98-
return create_ca_bundle_file(client=client, ca_type="openshift")
99-
62+
if is_managed_cluster(client):
63+
LOGGER.info("Running on managed cluster, not using ca bundle")
10064
return ""
10165

102-
else:
103-
raise ValueError(f"Unknown deployment mode: {deployment_mode}")
66+
return create_ca_bundle_file(client=client)
10467

10568

10669
def create_k8s_secret(

utilities/inference_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ def generate_command(
327327
else:
328328
# admin client is needed to check if cluster is managed
329329
_client = get_client()
330-
if ca := get_ca_bundle(client=_client, deployment_mode=self.deployment_mode):
330+
if ca := get_ca_bundle(client=_client):
331331
cmd += f" --cacert {ca} "
332332

333333
else:

utilities/infra.py

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
ResourceNotFoundError,
2424
)
2525
from ocp_resources.authentication_config_openshift_io import Authentication
26-
from ocp_resources.catalog_source import CatalogSource
2726
from ocp_resources.cluster_service_version import ClusterServiceVersion
2827
from ocp_resources.config_imageregistry_operator_openshift_io import Config
2928
from ocp_resources.config_map import ConfigMap
@@ -468,23 +467,6 @@ def login_with_user_password(api_address: str, user: str, password: str | None =
468467
return bool(re.search(r"Login successful|Logged into", out))
469468

470469

471-
@cache
472-
def is_self_managed_operator(client: DynamicClient) -> bool:
473-
"""
474-
Check if the operator is self-managed.
475-
"""
476-
if py_config["distribution"] == "upstream":
477-
return True
478-
479-
return not bool(
480-
CatalogSource(
481-
client=client,
482-
name="addon-managed-odh-catalog",
483-
namespace=py_config["applications_namespace"],
484-
).exists
485-
)
486-
487-
488470
@cache
489471
def is_managed_cluster(client: DynamicClient) -> bool:
490472
"""

utilities/llmd_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,7 @@ def generate_command(
583583
from ocp_resources.resource import get_client
584584

585585
client = get_client()
586-
ca_bundle = get_ca_bundle(client=client, deployment_mode="raw")
586+
ca_bundle = get_ca_bundle(client=client)
587587
if ca_bundle:
588588
cmd += f" --cacert {ca_bundle}"
589589
else:

0 commit comments

Comments
 (0)