17
17
from typing import Literal , Optional , Union
18
18
19
19
from hopsworks .client import external , hopsworks
20
+ from hopsworks .client .istio import base as istio_base
21
+ from hopsworks .client .istio import external as istio_external
22
+ from hopsworks .client .istio import internal as istio_internal
23
+ from hopsworks .constants import HOSTS
20
24
21
25
22
26
_client = None
23
27
_python_version = None
24
28
29
+ _client_type = None
30
+ _saas_connection = None
31
+
32
+ _istio_client = None
33
+
34
+ _kserve_installed = None
35
+ _serving_resource_limits = None
36
+ _serving_num_instances_limits = None
37
+ _knative_domain = None
38
+
25
39
26
40
def init (
27
41
client_type : Union [Literal ["hopsworks" ], Literal ["external" ]],
@@ -37,6 +51,12 @@ def init(
37
51
api_key_file : Optional [str ] = None ,
38
52
api_key_value : Optional [str ] = None ,
39
53
) -> None :
54
+ global _client_type
55
+ _client_type = client_type
56
+
57
+ global _saas_connection
58
+ _saas_connection = host == HOSTS .APP_HOST
59
+
40
60
global _client
41
61
if not _client :
42
62
if client_type == "hopsworks" :
@@ -64,6 +84,77 @@ def get_instance() -> Union[hopsworks.Client, external.Client]:
64
84
raise Exception ("Couldn't find client. Try reconnecting to Hopsworks." )
65
85
66
86
87
+ def set_istio_client (host , port , project = None , api_key_value = None ):
88
+ global _client_type , _istio_client
89
+
90
+ if not _istio_client :
91
+ if _client_type == "internal" :
92
+ _istio_client = istio_internal .Client (host , port )
93
+ elif _client_type == "external" :
94
+ _istio_client = istio_external .Client (host , port , project , api_key_value )
95
+
96
+
97
+ def get_istio_instance () -> istio_base .Client :
98
+ global _istio_client
99
+ return _istio_client
100
+
101
+
102
+ def get_client_type () -> str :
103
+ global _client_type
104
+ return _client_type
105
+
106
+
107
+ def is_saas_connection () -> bool :
108
+ global _saas_connection
109
+ return _saas_connection
110
+
111
+
112
+ def set_kserve_installed (kserve_installed ):
113
+ global _kserve_installed
114
+ _kserve_installed = kserve_installed
115
+
116
+
117
+ def is_kserve_installed () -> bool :
118
+ global _kserve_installed
119
+ return _kserve_installed
120
+
121
+
122
+ def set_serving_resource_limits (max_resources ):
123
+ global _serving_resource_limits
124
+ _serving_resource_limits = max_resources
125
+
126
+
127
+ def get_serving_resource_limits ():
128
+ global _serving_resource_limits
129
+ return _serving_resource_limits
130
+
131
+
132
+ def set_serving_num_instances_limits (num_instances_range ):
133
+ global _serving_num_instances_limits
134
+ _serving_num_instances_limits = num_instances_range
135
+
136
+
137
+ def get_serving_num_instances_limits ():
138
+ global _serving_num_instances_limits
139
+ return _serving_num_instances_limits
140
+
141
+
142
+ def is_scale_to_zero_required ():
143
+ # scale-to-zero is required for KServe deployments if the Hopsworks variable `kube_serving_min_num_instances`
144
+ # is set to 0. Other possible values are -1 (unlimited num instances) or >1 num instances.
145
+ return get_serving_num_instances_limits ()[0 ] == 0
146
+
147
+
148
+ def get_knative_domain ():
149
+ global _knative_domain
150
+ return _knative_domain
151
+
152
+
153
+ def set_knative_domain (knative_domain ):
154
+ global _knative_domain
155
+ _knative_domain = knative_domain
156
+
157
+
67
158
def get_python_version ():
68
159
global _python_version
69
160
return _python_version
@@ -79,3 +170,8 @@ def stop():
79
170
if _client :
80
171
_client ._close ()
81
172
_client = None
173
+
174
+ global _istio_client
175
+ if _istio_client :
176
+ _istio_client ._close ()
177
+ _istio_client = None
0 commit comments