|
9 | 9 | from simple_logger.logger import get_logger |
10 | 10 |
|
11 | 11 | from utilities.constants import ( |
12 | | - ISTIO_CA_BUNDLE_FILENAME, |
13 | 12 | OPENSHIFT_CA_BUNDLE_FILENAME, |
14 | | - KServeDeploymentType, |
15 | 13 | ) |
16 | | -from utilities.infra import is_managed_cluster, is_self_managed_operator |
| 14 | +from utilities.infra import is_managed_cluster |
17 | 15 |
|
18 | 16 | LOGGER = get_logger(name=__name__) |
19 | 17 |
|
20 | 18 |
|
21 | | -def create_ca_bundle_file(client: DynamicClient, ca_type: str) -> str: |
| 19 | +def create_ca_bundle_file(client: DynamicClient) -> str: |
22 | 20 | """ |
23 | 21 | Creates a ca bundle file from a secret |
24 | 22 |
|
25 | 23 | Args: |
26 | 24 | client (DynamicClient): DynamicClient object |
27 | | - ca_type (str): The type of ca bundle to create. Can be "knative" or "openshift" |
28 | | -
|
29 | 25 | 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. |
31 | 27 |
|
32 | 28 | 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. |
35 | 30 | """ |
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 |
51 | 31 |
|
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 | + ) |
54 | 37 |
|
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) |
60 | 41 |
|
61 | | - return filepath |
| 42 | + with open(filepath, "w") as fd: |
| 43 | + fd.write(bundle) |
62 | 44 |
|
63 | | - LOGGER.warning(f"Could not find {certs_secret.name} secret") |
64 | | - return "" |
| 45 | + return filepath |
65 | 46 |
|
66 | 47 |
|
67 | 48 | @cache |
68 | | -def get_ca_bundle(client: DynamicClient, deployment_mode: str) -> str: |
| 49 | +def get_ca_bundle(client: DynamicClient) -> str: |
69 | 50 | """ |
70 | | - Get the ca bundle for the given deployment mode. |
| 51 | + Get the CA bundle for TLS verification. |
71 | 52 |
|
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. |
74 | 55 |
|
75 | 56 | Args: |
76 | 57 | client (DynamicClient): DynamicClient object |
77 | | - deployment_mode (str): The deployment mode. Can be "serverless", "model-mesh" or "raw-deployment" |
78 | 58 |
|
79 | 59 | 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. |
85 | 61 | """ |
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") |
100 | 64 | return "" |
101 | 65 |
|
102 | | - else: |
103 | | - raise ValueError(f"Unknown deployment mode: {deployment_mode}") |
| 66 | + return create_ca_bundle_file(client=client) |
104 | 67 |
|
105 | 68 |
|
106 | 69 | def create_k8s_secret( |
|
0 commit comments